]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.modeling/src/org/simantics/modeling/validation/ValidateMapping.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.modeling / src / org / simantics / modeling / validation / ValidateMapping.java
index 82651fde699fc4316c12476e50f397a06e294a03..7dfb10e9fed00cf5854e03e7a6a551d29cb346c7 100644 (file)
-package org.simantics.modeling.validation;\r
-\r
-import java.util.Collection;\r
-\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.Statement;\r
-import org.simantics.db.common.request.ReadRequest;\r
-import org.simantics.db.common.utils.NameUtils;\r
-import org.simantics.db.common.utils.OrderedSetUtils;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.diagram.stubs.DiagramResource;\r
-import org.simantics.layer0.Layer0;\r
-import org.simantics.modeling.ModelingResources;\r
-import org.simantics.structural.stubs.StructuralResource2;\r
-\r
-public class ValidateMapping extends ReadRequest {\r
-\r
-       Resource composite;\r
-       Resource diagram;\r
-       \r
-       ReadGraph g;\r
-       Layer0 b;\r
-       DiagramResource dr;\r
-       StructuralResource2 sr;\r
-       ModelingResources mr;   \r
-       \r
-       public ValidateMapping(Resource composite) {\r
-               this.composite = composite;\r
-       }\r
-\r
-       @Override\r
-       public void run(ReadGraph g) throws DatabaseException {\r
-               this.g = g;\r
-               this.b = Layer0.getInstance(g);\r
-               this.dr = DiagramResource.getInstance(g);\r
-               this.sr = StructuralResource2.getInstance(g);\r
-               this.mr = ModelingResources.getInstance(g);\r
-       \r
-               this.diagram = g.getPossibleObject(composite, mr.CompositeToDiagram);\r
-               \r
-               System.out.println("------------------------------------------------------------------");\r
-               System.out.println("---- " + NameUtils.getSafeName(g, composite));\r
-               if (diagram == null) {\r
-                       System.out.println("No diagram.");\r
-               } else {\r
-                       additiveRule();\r
-                       destructiveRule();\r
-               }\r
-       }\r
-\r
-       private void additiveRule() throws DatabaseException {\r
-               for(Resource element : OrderedSetUtils.toList(g, diagram)) {\r
-                       Resource elementType = g.getPossibleObject(element, b.InstanceOf);\r
-                       if(elementType == null) {\r
-                               System.out.println("Element " + NameUtils.getSafeName(g, element) + " has no type.");\r
-                               continue;\r
-                       }\r
-                       Resource componentType = g.getPossibleObject(elementType, mr.SymbolToComponentType);\r
-                       if(componentType != null)\r
-                               createComponentRule(element, componentType);\r
-                       else if(g.isInstanceOf(element, dr.Connection))\r
-                               createNormalConnectionRule(element);\r
-                       else if(g.isInstanceOf(element, dr.Flag))\r
-                               createFlagRule(element);\r
-                       /*else\r
-                               System.out.println("No rule for element " + NameUtils.getSafeName(g, element));\r
-                               */\r
-               }\r
-       }               \r
-\r
-       private void createComponentRule(Resource element, Resource componentType) throws DatabaseException {\r
-               Collection<Resource> components = g.getObjects(element, mr.ElementToComponent);\r
-               if(components.isEmpty())\r
-                       System.out.println("Element " + NameUtils.getSafeName(g, element) + " is not mapped.");\r
-               else if(components.size() > 1)\r
-                       System.out.println("Element " + NameUtils.getSafeName(g, element) + " is not multiple times.");\r
-               else for(Resource component : components) {\r
-                       if(!g.isInstanceOf(component, componentType))\r
-                               System.out.println("Component " + NameUtils.getSafeName(g, component) + \r
-                                               " is not an instance of " + NameUtils.getSafeName(g, componentType));\r
-                       if(!g.hasStatement(component, b.PartOf, composite))\r
-                               System.out.println("Component " + NameUtils.getSafeName(g, component) + " is not a part of composite.");\r
-                       if(!g.hasStatement(component, mr.Mapped))\r
-                               System.out.println("Component " + NameUtils.getSafeName(g, component) + " is not tagged as Mapped.");\r
-               }\r
-       }\r
-\r
-       private void createNormalConnectionRule(Resource element) throws DatabaseException {\r
-               Collection<Resource> connections = g.getObjects(element, mr.DiagramConnectionToConnection);\r
-               if(connections.isEmpty())\r
-                       System.out.println("Diagram connection " + NameUtils.getSafeName(g, element) + " is not mapped.");\r
-               else if(connections.size() > 1)\r
-                       System.out.println("Diagram connection " + NameUtils.getSafeName(g, element) + " is not multiple times.");\r
-               else for(Resource connection : connections) {\r
-                       if(!g.isInstanceOf(connection, sr.Connection))\r
-                               System.out.println("Resource " + NameUtils.getSafeName(g, connection) + " is not a connection.");\r
-                       if(!g.hasStatement(connection, mr.Mapped))\r
-                               System.out.println("Connection " + NameUtils.getSafeName(g, connection) + " is not tagged as Mapped.");\r
-                       \r
-                       for(Resource connector : g.getObjects(element, sr.IsConnectedTo)) {\r
-                               for(Statement stat : g.getStatements(connector, sr.Connects)) {\r
-                                       Resource diagramConnectionRelation = g.getInverse(stat.getPredicate());\r
-                                       Resource cElement = stat.getObject();\r
-                                       Resource connectionRelation = g.getPossibleObject(diagramConnectionRelation, mr.DiagramConnectionRelationToConnectionRelation);\r
-                                       if(connectionRelation == null)\r
-                                               continue;\r
-                                       Resource component = g.getPossibleObject(cElement, mr.ElementToComponent);\r
-                                       if(component == null)\r
-                                               continue;\r
-                                       \r
-                                       // Special connection data\r
-                                       Resource connectionRelation2 = g.getPossibleObject(diagramConnectionRelation, mr.DiagramConnectionRelationToConnectionRelationB);\r
-                                       Resource connectionRelation3 = g.getPossibleObject(diagramConnectionRelation, mr.DiagramConnectionRelationToConnectionRelationC);\r
-                                       Resource componentType = g.getPossibleObject(diagramConnectionRelation, mr.DiagramConnectionRelationToComponentType);\r
-                                       \r
-                                       // Normal connection\r
-                                       if(connectionRelation2 == null || connectionRelation3 == null || componentType == null) {\r
-                                               if(!g.hasStatement(component, connectionRelation, connection))\r
-                                                       System.out.println("Missing connection statement " + NameUtils.getSafeName(g, component) + " . " +\r
-                                                                       NameUtils.getSafeName(g, connectionRelation));\r
-                                       }\r
-                                       \r
-                                       // Special connection\r
-                                       else {\r
-                                               Resource component2 = g.getPossibleObject(element, mr.ElementToComponent);\r
-                                               if(component2 == null)\r
-                                                       System.out.println("Special connection " + NameUtils.getSafeName(g, element) + " is not mapped.");\r
-                                               else {\r
-                                                       if(!g.isInstanceOf(component2, componentType))\r
-                                                               System.out.println("Component " + NameUtils.getSafeName(g, component2) + \r
-                                                                               " is not an instance of " + NameUtils.getSafeName(g, componentType));\r
-                                                       if(!g.hasStatement(component2, b.PartOf, composite))\r
-                                                               System.out.println("Component " + NameUtils.getSafeName(g, component2) + " is not a part of composite.");\r
-                                                       if(!g.hasStatement(component2, mr.Mapped))\r
-                                                               System.out.println("Component " + NameUtils.getSafeName(g, component2) + " is not tagged as Mapped.");\r
-                                                       \r
-                                                       boolean foundConnection2 = false;\r
-                                                       for(Resource connection2 : g.getObjects(component2, connectionRelation2))\r
-                                                               if(g.hasStatement(component, connectionRelation, connection2)) {\r
-                                                                       foundConnection2 = true;\r
-                                                                       if(!g.isInstanceOf(connection2, sr.Connection))\r
-                                                                               System.out.println(NameUtils.getSafeName(g, connection2) + " is not a connection.");\r
-                                                                       if(!g.hasStatement(component2, connectionRelation3, connection))\r
-                                                                               System.out.println("Missing connection point " + NameUtils.getSafeName(g, component2) + " . "\r
-                                                                                               + NameUtils.getSafeName(g, connectionRelation3));\r
-                                                               }\r
-                                                       if(!foundConnection2)\r
-                                                               System.out.println("Special connection "+ NameUtils.getSafeName(g, element) + " is not correctly mapped (missing configuration connection).");\r
-                                               }\r
-                                       }\r
-                               }\r
-                       }\r
-               }\r
-       }\r
-\r
-       /*\r
-                claim(          \r
-                   \r
-                   // Create a connection\r
-                   exists(\r
-                        and(statement_bbf(Component2, ConnectionRelation2, Connection2),\r
-                            statement    (Component,  ConnectionRelation,  Connection2)\r
-                        ),\r
-                        Connection2\r
-                    ),\r
-                    b(sr.Connection, Connection2),\r
-                    //b(mapped, Connection2),\r
-                   \r
-                   // \r
-                   statement(Component2, ConnectionRelation3, Connection)\r
-                ),\r
-}*/\r
-       \r
-       private void createFlagRule(Resource element) throws DatabaseException {\r
-               for(Resource connectionJoin : g.getObjects(element, dr.FlagIsJoinedBy))\r
-                       for(Resource connector : g.getObjects(element, sr.IsConnectedTo))\r
-                               for(Resource diagramConnection : g.getObjects(connector, sr.Connects))\r
-                                       for(Resource connection : g.getObjects(diagramConnection, mr.DiagramConnectionToConnection)) {\r
-                                               if(!g.hasStatement(connectionJoin, sr.Joins, connection))\r
-                                                       System.out.println("Joins-relation of flag " + NameUtils.getSafeName(g, element) + " is not mapped.");\r
-                                               if(!g.hasStatement(composite, sr.HasConnectionJoin, connectionJoin))\r
-                                                       System.out.println("Connection join is not attached to the composite.");\r
-                                       }\r
-               \r
-       }\r
-       \r
-       private void destructiveRule() throws DatabaseException {\r
-               for(Resource component : g.getObjects(composite, b.ConsistsOf)) {\r
-                       if(g.hasStatement(component, mr.Mapped)) {\r
-                               //Resource element = g.getPossibleObject(component, mr.ComponentToElement);\r
-                               Collection<Resource> elements = g.getObjects(component, mr.ComponentToElement);\r
-                               if (elements.isEmpty())\r
-                                       System.out.println("Component " + NameUtils.getSafeName(g, component) + \r
-                                                       " does not have corresponding element (but is tagged Mapped).");\r
-                               for (Resource element : elements) {\r
-                                       if(!OrderedSetUtils.contains(g, diagram, element))\r
-                                               System.out.println("Element corresponding to component " + NameUtils.getSafeName(g, component) + \r
-                                               " is not included in the diagram.");\r
-                                       else {\r
-                                               for(Statement stat : g.getStatements(component, sr.IsConnectedTo)) {\r
-                                                       //Resource connectionRelation = stat.getPredicate();\r
-                                                       Resource connection = stat.getObject();\r
-                                                       if(g.hasStatement(connection, mr.Mapped)) {\r
-                                                               if (!g.hasStatement(connection, mr.ConnectionMapsTo))\r
-                                                                       System.out.println("Connection " + NameUtils.getSafeName(g, connection) + \r
-                                                                       " does not have a correspondence in diagram (but is tagged Mapped).");\r
-                                                       }\r
-                                               }\r
-                                       }\r
-                               }\r
-                       }\r
-               }\r
-       }\r
-\r
-}\r
+package org.simantics.modeling.validation;
+
+import java.util.Collection;
+
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.Statement;
+import org.simantics.db.common.request.ReadRequest;
+import org.simantics.db.common.utils.NameUtils;
+import org.simantics.db.common.utils.OrderedSetUtils;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.diagram.stubs.DiagramResource;
+import org.simantics.layer0.Layer0;
+import org.simantics.modeling.ModelingResources;
+import org.simantics.structural.stubs.StructuralResource2;
+
+public class ValidateMapping extends ReadRequest {
+
+       Resource composite;
+       Resource diagram;
+       
+       ReadGraph g;
+       Layer0 b;
+       DiagramResource dr;
+       StructuralResource2 sr;
+       ModelingResources mr;   
+       
+       public ValidateMapping(Resource composite) {
+               this.composite = composite;
+       }
+
+       @Override
+       public void run(ReadGraph g) throws DatabaseException {
+               this.g = g;
+               this.b = Layer0.getInstance(g);
+               this.dr = DiagramResource.getInstance(g);
+               this.sr = StructuralResource2.getInstance(g);
+               this.mr = ModelingResources.getInstance(g);
+       
+               this.diagram = g.getPossibleObject(composite, mr.CompositeToDiagram);
+               
+               System.out.println("------------------------------------------------------------------");
+               System.out.println("---- " + NameUtils.getSafeName(g, composite));
+               if (diagram == null) {
+                       System.out.println("No diagram.");
+               } else {
+                       additiveRule();
+                       destructiveRule();
+               }
+       }
+
+       private void additiveRule() throws DatabaseException {
+               for(Resource element : OrderedSetUtils.toList(g, diagram)) {
+                       Resource elementType = g.getPossibleObject(element, b.InstanceOf);
+                       if(elementType == null) {
+                               System.out.println("Element " + NameUtils.getSafeName(g, element) + " has no type.");
+                               continue;
+                       }
+                       Resource componentType = g.getPossibleObject(elementType, mr.SymbolToComponentType);
+                       if(componentType != null)
+                               createComponentRule(element, componentType);
+                       else if(g.isInstanceOf(element, dr.Connection))
+                               createNormalConnectionRule(element);
+                       else if(g.isInstanceOf(element, dr.Flag))
+                               createFlagRule(element);
+                       /*else
+                               System.out.println("No rule for element " + NameUtils.getSafeName(g, element));
+                               */
+               }
+       }               
+
+       private void createComponentRule(Resource element, Resource componentType) throws DatabaseException {
+               Collection<Resource> components = g.getObjects(element, mr.ElementToComponent);
+               if(components.isEmpty())
+                       System.out.println("Element " + NameUtils.getSafeName(g, element) + " is not mapped.");
+               else if(components.size() > 1)
+                       System.out.println("Element " + NameUtils.getSafeName(g, element) + " is not multiple times.");
+               else for(Resource component : components) {
+                       if(!g.isInstanceOf(component, componentType))
+                               System.out.println("Component " + NameUtils.getSafeName(g, component) + 
+                                               " is not an instance of " + NameUtils.getSafeName(g, componentType));
+                       if(!g.hasStatement(component, b.PartOf, composite))
+                               System.out.println("Component " + NameUtils.getSafeName(g, component) + " is not a part of composite.");
+                       if(!g.hasStatement(component, mr.Mapped))
+                               System.out.println("Component " + NameUtils.getSafeName(g, component) + " is not tagged as Mapped.");
+               }
+       }
+
+       private void createNormalConnectionRule(Resource element) throws DatabaseException {
+               Collection<Resource> connections = g.getObjects(element, mr.DiagramConnectionToConnection);
+               if(connections.isEmpty())
+                       System.out.println("Diagram connection " + NameUtils.getSafeName(g, element) + " is not mapped.");
+               else if(connections.size() > 1)
+                       System.out.println("Diagram connection " + NameUtils.getSafeName(g, element) + " is not multiple times.");
+               else for(Resource connection : connections) {
+                       if(!g.isInstanceOf(connection, sr.Connection))
+                               System.out.println("Resource " + NameUtils.getSafeName(g, connection) + " is not a connection.");
+                       if(!g.hasStatement(connection, mr.Mapped))
+                               System.out.println("Connection " + NameUtils.getSafeName(g, connection) + " is not tagged as Mapped.");
+                       
+                       for(Resource connector : g.getObjects(element, sr.IsConnectedTo)) {
+                               for(Statement stat : g.getStatements(connector, sr.Connects)) {
+                                       Resource diagramConnectionRelation = g.getInverse(stat.getPredicate());
+                                       Resource cElement = stat.getObject();
+                                       Resource connectionRelation = g.getPossibleObject(diagramConnectionRelation, mr.DiagramConnectionRelationToConnectionRelation);
+                                       if(connectionRelation == null)
+                                               continue;
+                                       Resource component = g.getPossibleObject(cElement, mr.ElementToComponent);
+                                       if(component == null)
+                                               continue;
+                                       
+                                       // Special connection data
+                                       Resource connectionRelation2 = g.getPossibleObject(diagramConnectionRelation, mr.DiagramConnectionRelationToConnectionRelationB);
+                                       Resource connectionRelation3 = g.getPossibleObject(diagramConnectionRelation, mr.DiagramConnectionRelationToConnectionRelationC);
+                                       Resource componentType = g.getPossibleObject(diagramConnectionRelation, mr.DiagramConnectionRelationToComponentType);
+                                       
+                                       // Normal connection
+                                       if(connectionRelation2 == null || connectionRelation3 == null || componentType == null) {
+                                               if(!g.hasStatement(component, connectionRelation, connection))
+                                                       System.out.println("Missing connection statement " + NameUtils.getSafeName(g, component) + " . " +
+                                                                       NameUtils.getSafeName(g, connectionRelation));
+                                       }
+                                       
+                                       // Special connection
+                                       else {
+                                               Resource component2 = g.getPossibleObject(element, mr.ElementToComponent);
+                                               if(component2 == null)
+                                                       System.out.println("Special connection " + NameUtils.getSafeName(g, element) + " is not mapped.");
+                                               else {
+                                                       if(!g.isInstanceOf(component2, componentType))
+                                                               System.out.println("Component " + NameUtils.getSafeName(g, component2) + 
+                                                                               " is not an instance of " + NameUtils.getSafeName(g, componentType));
+                                                       if(!g.hasStatement(component2, b.PartOf, composite))
+                                                               System.out.println("Component " + NameUtils.getSafeName(g, component2) + " is not a part of composite.");
+                                                       if(!g.hasStatement(component2, mr.Mapped))
+                                                               System.out.println("Component " + NameUtils.getSafeName(g, component2) + " is not tagged as Mapped.");
+                                                       
+                                                       boolean foundConnection2 = false;
+                                                       for(Resource connection2 : g.getObjects(component2, connectionRelation2))
+                                                               if(g.hasStatement(component, connectionRelation, connection2)) {
+                                                                       foundConnection2 = true;
+                                                                       if(!g.isInstanceOf(connection2, sr.Connection))
+                                                                               System.out.println(NameUtils.getSafeName(g, connection2) + " is not a connection.");
+                                                                       if(!g.hasStatement(component2, connectionRelation3, connection))
+                                                                               System.out.println("Missing connection point " + NameUtils.getSafeName(g, component2) + " . "
+                                                                                               + NameUtils.getSafeName(g, connectionRelation3));
+                                                               }
+                                                       if(!foundConnection2)
+                                                               System.out.println("Special connection "+ NameUtils.getSafeName(g, element) + " is not correctly mapped (missing configuration connection).");
+                                               }
+                                       }
+                               }
+                       }
+               }
+       }
+
+       /*
+                claim(          
+                   
+                   // Create a connection
+                   exists(
+                        and(statement_bbf(Component2, ConnectionRelation2, Connection2),
+                            statement    (Component,  ConnectionRelation,  Connection2)
+                        ),
+                        Connection2
+                    ),
+                    b(sr.Connection, Connection2),
+                    //b(mapped, Connection2),
+                   
+                   // 
+                   statement(Component2, ConnectionRelation3, Connection)
+                ),
+}*/
+       
+       private void createFlagRule(Resource element) throws DatabaseException {
+               for(Resource connectionJoin : g.getObjects(element, dr.FlagIsJoinedBy))
+                       for(Resource connector : g.getObjects(element, sr.IsConnectedTo))
+                               for(Resource diagramConnection : g.getObjects(connector, sr.Connects))
+                                       for(Resource connection : g.getObjects(diagramConnection, mr.DiagramConnectionToConnection)) {
+                                               if(!g.hasStatement(connectionJoin, sr.Joins, connection))
+                                                       System.out.println("Joins-relation of flag " + NameUtils.getSafeName(g, element) + " is not mapped.");
+                                               if(!g.hasStatement(composite, sr.HasConnectionJoin, connectionJoin))
+                                                       System.out.println("Connection join is not attached to the composite.");
+                                       }
+               
+       }
+       
+       private void destructiveRule() throws DatabaseException {
+               for(Resource component : g.getObjects(composite, b.ConsistsOf)) {
+                       if(g.hasStatement(component, mr.Mapped)) {
+                               //Resource element = g.getPossibleObject(component, mr.ComponentToElement);
+                               Collection<Resource> elements = g.getObjects(component, mr.ComponentToElement);
+                               if (elements.isEmpty())
+                                       System.out.println("Component " + NameUtils.getSafeName(g, component) + 
+                                                       " does not have corresponding element (but is tagged Mapped).");
+                               for (Resource element : elements) {
+                                       if(!OrderedSetUtils.contains(g, diagram, element))
+                                               System.out.println("Element corresponding to component " + NameUtils.getSafeName(g, component) + 
+                                               " is not included in the diagram.");
+                                       else {
+                                               for(Statement stat : g.getStatements(component, sr.IsConnectedTo)) {
+                                                       //Resource connectionRelation = stat.getPredicate();
+                                                       Resource connection = stat.getObject();
+                                                       if(g.hasStatement(connection, mr.Mapped)) {
+                                                               if (!g.hasStatement(connection, mr.ConnectionMapsTo))
+                                                                       System.out.println("Connection " + NameUtils.getSafeName(g, connection) + 
+                                                                       " does not have a correspondence in diagram (but is tagged Mapped).");
+                                                       }
+                                               }
+                                       }
+                               }
+                       }
+               }
+       }
+
+}