+ private SymbolConnectionData _connectElement(WriteGraph g, Symbol symbolConf2, Resource elementConRel1, Resource elementConRel2, Resource connectorType) throws DatabaseException {
+ Layer0 b = Layer0.getInstance(g);
+ StructuralResource2 s = StructuralResource2.getInstance(g);
+ DiagramResource d = DiagramResource.getInstance(g);
+ ModelingResources m = ModelingResources.getInstance(g);
+
+
+ if (g.isInstanceOf(elementConRel1, b.FunctionalRelation) && getDiagramSingleConnected(g, elementConRel1) != null) {
+ Symbol current = getDiagramSingleConnected(g, elementConRel1);
+ if (current.component.equals(symbolConf2.component))
+ return new SymbolExistsImpl();
+ String err = "Cannot connect, terminal 1 is reserved: " + component + " " + NameUtils.getSafeName(g, component) + " terminals: " + g.getPossibleURI(elementConRel1) + " "+ elementConRel1 + " " + g.getPossibleURI(elementConRel2) + " "+ elementConRel2;
+ Logger.error(err);
+ return new ConnectionErrorImpl(err);
+ }
+ if (g.isInstanceOf(elementConRel2, b.FunctionalRelation) && symbolConf2.getDiagramSingleConnected(g, elementConRel2) != null) {
+ Symbol current = symbolConf2.getDiagramSingleConnected(g, elementConRel2);
+ if (current.component.equals(component))
+ return new SymbolExistsImpl();
+ String err = "Cannot connect, terminal 2 is reserved: " + component + " " + NameUtils.getSafeName(g, component) + " terminals: " + g.getPossibleURI(elementConRel1) + " "+ elementConRel1 + " " + g.getPossibleURI(elementConRel2) + " "+ elementConRel2;
+ Logger.error(err);
+ return new ConnectionErrorImpl(err);
+ }
+
+// // connection object in module level
+// Resource moduleConnection = g.newResource();
+// g.claim(moduleConnection, b.InstanceOf, s.Connection);
+//
+// // connect the modules
+//
+// g.claim(component, componentConRel1, moduleConnection);
+// g.claim(symbolConf2.component, componentConRel2, moduleConnection);
+
+ // connection object in diagram level
+ Resource diagramConnection = g.newResource();
+ g.claim(diagramConnection, b.InstanceOf, diagramConnectionType(g, null));
+ DiagramUtils.addElementFirst(g, diagram, diagramConnection);
+
+ g.claim(diagramConnection, s.HasConnectionType, connectorType);
+
+ // Relation from element1 to connector1
+// Resource elementConRel1 = getDiagramConnectionRelation(g, element, componentConRel1);
+// Resource connectorRel1 = g.getPossibleObject(componentConRel1, s.HasAttachmentRelation);
+// if (connectorRel1 == null)
+// connectorRel1 = d.HasPlainConnector;
+ Resource connectorRel1 = d.HasPlainConnector;
+
+ // connector1
+ Resource connector1 = g.newResource();
+ g.claim(connector1, b.InstanceOf, d.Connector);
+ g.claim(element, elementConRel1, connector1);
+ g.claim(diagramConnection, connectorRel1, connector1);
+
+ // Relation from element2 to connector2
+// Resource elementConRel2 = getDiagramConnectionRelation(g, symbolConf2.element, componentConRel2);
+// Resource connectorRel2 = g.getPossibleObject(componentConRel2, s.HasAttachmentRelation);
+// if (connectorRel2 == null)
+// connectorRel2 = d.HasArrowConnector;
+
+ Resource connectorRel2 = d.HasArrowConnector;
+ // connector2
+ Resource connector2 = g.newResource();
+ g.claim(connector2, b.InstanceOf, d.Connector);
+ g.claim(symbolConf2.element, elementConRel2, connector2);
+ g.claim(diagramConnection, connectorRel2, connector2);
+
+ // connect connectors
+ g.claim(connector1, d.AreConnected, connector2);
+
+// g.claim(moduleConnection, m.ConnectionToDiagramConnection, diagramConnection);
+
+ return new ConnectorDataImpl(diagramConnection);
+ }
+