+ public SymbolConnectionData connectElement(WriteGraph g, Symbol symbolConf2, Resource elementConRel1, Resource elementConRel2) throws DatabaseException {
+
+ StructuralResource2 sr = StructuralResource2.getInstance(g);
+ ModelingResources mod = ModelingResources.getInstance(g);
+
+ Resource componentConRel1 = g.getPossibleObject(elementConRel1, mod.DiagramConnectionRelationToConnectionRelation);
+ Resource componentConRel2 = g.getPossibleObject(elementConRel2, mod.DiagramConnectionRelationToConnectionRelation);
+
+ if (componentConRel1 != null && componentConRel2 != null) {
+ return connect(g, symbolConf2, componentConRel1, componentConRel2);
+ }
+
+ Collection<Resource> connType1 = Collections.EMPTY_LIST;
+ Collection<Resource> connType2 = Collections.EMPTY_LIST;
+ if (componentConRel1 != null) {
+ connType1 = getConnectionTypes(g, componentConRel1);
+ if (connType1.size() > 1)
+ connType1 = getNonAssertedConnectionTypes(g,componentConRel1);
+ } else if (componentConRel2 != null) {
+ connType2 = getConnectionTypes(g, componentConRel2);
+ if (connType2.size() > 1)
+ connType2 = getNonAssertedConnectionTypes(g,componentConRel2);
+ }
+ Resource usedConnType = null;
+ if (connType1.size() == 1)
+ usedConnType = connType1.iterator().next();
+ else if (connType2.size() == 1)
+ usedConnType = connType2.iterator().next();
+ else {
+ String err = "Cannot locate connection type for: " + component + " " + NameUtils.getSafeName(g, component) + " terminals: " + g.getPossibleURI(elementConRel1) + " "+ elementConRel1 + " " + g.getPossibleURI(elementConRel2) + " "+ elementConRel2;
+ Logger.defaultLogError(err);
+ return new ConnectionErrorImpl(err);
+ }
+ if (!diagram.equals(symbolConf2.diagram)) {
+ String err = "Element connections must be done on the same diagram: " + component + " " + NameUtils.getSafeName(g, component) + " terminals: " + g.getPossibleURI(elementConRel1) + " "+ elementConRel1 + " " + g.getPossibleURI(elementConRel2) + " "+ elementConRel2;
+ Logger.defaultLogError(err);
+ return new ConnectionErrorImpl(err);
+ }
+ return connectElement(g, symbolConf2, elementConRel1, elementConRel2, usedConnType);
+ }
+
+ public SymbolConnectionData connectElement(WriteGraph g, Symbol symbolConf2, Resource elementConRel1, Resource elementConRel2, Resource usedConnType) throws DatabaseException {
+ if (this.equals(symbolConf2)) {
+ if (PREVENT_SELF_CONNECTIONS) {
+ String err = "Preventing connection to self: " + component + " " + NameUtils.getSafeName(g, component) + " terminals: " + g.getPossibleURI(elementConRel1) + " "+ elementConRel1 + " " + g.getPossibleURI(elementConRel2) + " "+ elementConRel2;
+ Logger.defaultLogError(err);
+ return new ConnectionErrorImpl(err);
+ }
+ if (elementConRel1.equals(elementConRel2)) {
+ String err = "Preventing connection to self: " + component + " " + NameUtils.getSafeName(g, component) + " terminals: " + g.getPossibleURI(elementConRel1) + " "+ elementConRel1 + " " + g.getPossibleURI(elementConRel2) + " "+ elementConRel2;
+ Logger.defaultLogError(err);
+ return new ConnectionErrorImpl(err);
+ }
+ }
+ // TODO : should we have separate customConnect method for element level connections?
+ SymbolConnectionData data = customConnect(g, symbolConf2, elementConRel1, elementConRel2, usedConnType);
+ if (data == null) {
+ return _connectElement(g, symbolConf2, elementConRel1, elementConRel2,usedConnType);
+ } else {
+ return data;
+ }
+ }
+