]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.structural2/src/org/simantics/structural2/modelingRules/SimpleModelingRules.java
Fixed multiple issues causing dangling references to discarded queries
[simantics/platform.git] / bundles / org.simantics.structural2 / src / org / simantics / structural2 / modelingRules / SimpleModelingRules.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.structural2.modelingRules;
13
14 import java.util.Collection;
15 import java.util.Set;
16
17 import org.simantics.db.ReadGraph;
18 import org.simantics.db.Resource;
19 import org.simantics.db.exception.DatabaseException;
20
21 public class SimpleModelingRules extends AbstractModelingRules {
22
23         private Resource connectionType;        
24         private Resource attachmentRelation;
25         
26         public SimpleModelingRules(Resource connectionType, Resource attachmentRelation) {
27                 this.connectionType = connectionType;
28                 this.attachmentRelation = attachmentRelation;
29         }
30
31         IAttachmentRelationMap attachmentRelations = new IAttachmentRelationMap() {             
32                 @Override
33                 public Resource get(ReadGraph g, CPTerminal cp) throws DatabaseException {
34                         return attachmentRelation;
35                 }
36         };
37         
38         @Override
39         public ConnectionJudgement judgeConnection(ReadGraph g,
40                         Collection<IConnectionPoint> connectionPoints)
41                         throws DatabaseException {
42                 ConnectionJudgement judgement = new ConnectionJudgement(connectionType);
43                 judgement.attachmentRelations = attachmentRelations;
44                 return judgement;
45         }
46
47         @Override
48         public Resource computeConnectionType(ReadGraph g, Collection<IConnectionPoint> connectionPoints)
49                         throws DatabaseException {
50                 return connectionType;
51         }
52         
53         @Override
54         public IAttachmentRelationMap getAttachmentRelations(ReadGraph g,
55                         Resource connection) {
56                 return attachmentRelations;
57         }
58
59         @Override
60         public Set<CPTerminal> resolveTerminals(ReadGraph g,
61                         Collection<IConnectionPoint> connectionPoints)
62                         throws DatabaseException {
63                 throw new UnsupportedOperationException("Simple Modelling Rules do not process actual connection points");
64         }
65
66 }