]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.structural2/src/org/simantics/structural2/modelingRules/CPTerminal.java
IConnectionPoint and canBeConnected-checking util to SCL
[simantics/platform.git] / bundles / org.simantics.structural2 / src / org / simantics / structural2 / modelingRules / CPTerminal.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 org.simantics.db.ReadGraph;
15 import org.simantics.db.Resource;
16 import org.simantics.db.common.request.SafeName;
17 import org.simantics.db.exception.DatabaseException;
18
19 public class CPTerminal implements IConnectionPoint {
20
21     public final Resource component; // may be null for reference elements
22     public final Resource relation;
23
24     public CPTerminal(Resource component, Resource relation) {
25         if (relation == null)
26             throw new NullPointerException("null relation");
27         this.component = component;
28         this.relation = relation;
29     }
30
31     @Override
32     public String toString(ReadGraph g) throws DatabaseException {
33         return "CPTerminal(" + 
34             g.syncRequest(new SafeName(component)) + ", " +
35             g.syncRequest(new SafeName(relation)) + ")";
36     }
37
38     @Override
39     public int hashCode() {
40         final int prime = 31;
41         int result = 1;
42         result = prime * result + (component == null ? 0 : component.hashCode());
43         result = prime * result + relation.hashCode();
44         return result;
45     }
46
47     @Override
48     public boolean equals(Object obj) {
49         if (this == obj)
50             return true;
51         if (obj == null)
52             return false;
53         if (getClass() != obj.getClass())
54             return false;
55         CPTerminal other = (CPTerminal) obj;
56         return (component == null ? other.component == null : component.equals(other.component)) && relation.equals(other.relation);
57     }
58
59     /**
60      * Convenience method for SCL
61      * 
62      * @param component
63      * @param relation
64      * @return
65      */
66     public static IConnectionPoint makeIConnectionPoint(Resource component, Resource relation) {
67         return new CPTerminal(component, relation);
68     }
69 }