-package org.simantics.structural2.utils;\r
-\r
-import gnu.trove.set.hash.THashSet;\r
-\r
-import java.util.ArrayList;\r
-import java.util.Collection;\r
-import java.util.HashMap;\r
-import java.util.Set;\r
-\r
-import org.simantics.databoard.Bindings;\r
-import org.simantics.datatypes.literal.GUID;\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.RequestProcessor;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.Statement;\r
-import org.simantics.db.WriteGraph;\r
-import org.simantics.db.common.CommentMetadata;\r
-import org.simantics.db.common.request.ObjectsWithType;\r
-import org.simantics.db.common.utils.NameUtils;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.layer0.exception.MissingVariableException;\r
-import org.simantics.db.layer0.request.InstantiateRequest;\r
-import org.simantics.db.layer0.util.Layer0Utils;\r
-import org.simantics.db.layer0.variable.Variable;\r
-import org.simantics.layer0.Layer0;\r
-import org.simantics.structural.stubs.StructuralResource2;\r
-import org.simantics.structural2.internal.queries.ConnectedTo;\r
-import org.simantics.structural2.internal.queries.RelatedConnections;\r
-import org.simantics.structural2.internal.queries.RelatedConnectionsOfConnectionJoin;\r
-import org.simantics.structural2.queries.Terminal;\r
-import org.simantics.structural2.variables.Connection;\r
-import org.simantics.utils.datastructures.Pair;\r
-\r
-/**\r
- * A utility class for manipulating structural models.\r
- * \r
- * @author Hannu Niemistö\r
- */\r
-public class StructuralUtils {\r
- \r
- public static Collection<Resource> getConnectionRelations(ReadGraph graph, Resource componentType) throws DatabaseException {\r
- Layer0 L0 = Layer0.getInstance(graph);\r
- StructuralResource2 STR = StructuralResource2.getInstance(graph);\r
- return graph.syncRequest(new ObjectsWithType(componentType, L0.DomainOf, STR.ConnectionRelation));\r
- }\r
-\r
- public static Collection<Resource> getPropertyRelations(ReadGraph graph, Resource componentType) throws DatabaseException {\r
- Layer0 L0 = Layer0.getInstance(graph);\r
- ArrayList<Resource> result = new ArrayList<Resource>();\r
- for(Resource relation : graph.getObjects(componentType, L0.DomainOf))\r
- if(graph.isSubrelationOf(relation, L0.HasProperty))\r
- result.add(relation);\r
- return result;\r
- }\r
- \r
- public static boolean isDomainOfRelation(ReadGraph graph,\r
- Resource componentType, Resource connectionRelation) throws DatabaseException {\r
- Layer0 L0 = Layer0.getInstance(graph);\r
- for(Resource domain : graph.getObjects(connectionRelation, L0.HasDomain))\r
- if(graph.isInheritedFrom(componentType, domain))\r
- return true;\r
- return false;\r
- }\r
- \r
- public static void addConnectionPoint(WriteGraph g, Resource componentType,\r
- Resource connectionPoint) throws DatabaseException {\r
- Layer0 L0 = Layer0.getInstance(g);\r
- g.claim(connectionPoint, L0.HasDomain, componentType);\r
- }\r
- \r
- public static Resource createConnectionPoint(WriteGraph g, Resource componentType, Resource copy) throws DatabaseException {\r
- String proposition = NameUtils.getSafeName(g, copy);\r
- String newName = NameUtils.findFreshName(g, proposition, componentType);\r
- return createConnectionPoint(g, componentType, copy, newName);\r
- }\r
- \r
- public static Resource createConnectionPoint(WriteGraph g, Resource componentType, Resource copy, String name) throws DatabaseException {\r
- return createConnectionPointP(g, componentType, copy, name).first;\r
- }\r
- \r
- public static Pair<Resource,Resource> createConnectionPointP(WriteGraph g, Resource componentType, Resource copy, String name) throws DatabaseException {\r
- \r
- Layer0 L0 = Layer0.getInstance(g);\r
- StructuralResource2 STR = StructuralResource2.getInstance(g);\r
-\r
- // Create the connection point\r
- Resource connectionPoint = g.newResource();\r
- Resource connectionPointInv = g.newResource();\r
-\r
- for (Resource superrelation : g.getObjects(copy, L0.SubrelationOf)) {\r
- g.claim(connectionPoint, L0.SubrelationOf, null, superrelation);\r
- Resource inverse = g.getPossibleInverse(superrelation);\r
- if (inverse != null)\r
- g.claim(connectionPointInv, L0.SubrelationOf, null, inverse);\r
- }\r
- for (Resource type : g.getObjects(copy, L0.InstanceOf)) {\r
- g.claim(connectionPoint, L0.InstanceOf, null, type);\r
- }\r
- for (Resource attachment : g.getObjects(copy, STR.HasAttachmentRelation)) {\r
- g.claim(connectionPoint, STR.HasAttachmentRelation, attachment);\r
- }\r
- for (Statement stm : g.getStatements(copy, STR.AllowsConnectionType)) {\r
- if (!stm.isAsserted(copy)) {\r
- g.claim(connectionPoint, stm.getPredicate(), stm.getObject());\r
- }\r
- }\r
-\r
- g.claim(connectionPoint, L0.InverseOf, connectionPointInv);\r
- g.claimLiteral(connectionPoint, L0.HasName, name, Bindings.STRING);\r
- g.claim(connectionPoint, L0.ConsistsOf, connectionPointInv);\r
- g.claimLiteral(connectionPointInv, L0.HasName, "Inverse", Bindings.STRING);\r
-\r
- StructuralUtils.addConnectionPoint(g, componentType, connectionPoint);\r
-\r
- g.claim(componentType, L0.ConsistsOf, connectionPoint);\r
-\r
- return Pair.make(connectionPoint, connectionPointInv);\r
- \r
- }\r
-\r
- /**\r
- * Creates a new component and the templates associated with it.\r
- * This method does not check whether there already exists \r
- * a component with the same name and parent.\r
- * @param g\r
- * @param parent The parent composite of the new component.\r
- * @param name The name of the new component.\r
- * @param componentType The type of the new component.\r
- * @return\r
- * @throws DatabaseException\r
- */\r
- public static Resource newComponent(WriteGraph g, Resource parent, String name, Resource componentType) throws DatabaseException {\r
- Layer0 L0 = Layer0.getInstance(g);\r
- \r
- HashMap<String,Object> parameters = new HashMap<String,Object>();\r
- parameters.put("parent", parent);\r
-\r
- InstantiateRequest ir = new InstantiateRequest(componentType, parameters);\r
- Resource component = ir.perform(g); \r
- g.claim(component, L0.HasName, Layer0Utils.literal(g, name));\r
- g.claim(component, L0.HasLabel, Layer0Utils.literal(g, ""));\r
- g.addLiteral(component, L0.identifier, L0.identifier_Inverse, L0.GUID, GUID.random(), GUID.BINDING);\r
- g.claim(parent, L0.ConsistsOf, component);\r
- // Add comment to change set.\r
- CommentMetadata cm = g.getMetadata(CommentMetadata.class);\r
- g.addMetadata(cm.add("Created component " + component));\r
- return component;\r
- }\r
- \r
- /**\r
- * Returns all child components of a composite.\r
- */\r
- public static Collection<Resource> getChildComponents(ReadGraph g, Resource parent) throws DatabaseException {\r
- Layer0 L0 = Layer0.getInstance(g);\r
- StructuralResource2 STR = StructuralResource2.getInstance(g);\r
- \r
- Collection<Resource> allChildren = g.getObjects(parent, L0.ConsistsOf);\r
- ArrayList<Resource> result = new ArrayList<Resource>(allChildren.size());\r
- for(Resource child : allChildren)\r
- // Composite may contain other things than components, therefore we must do checking\r
- if(g.isInstanceOf(child, STR.Component))\r
- result.add(child);\r
- return result;\r
- }\r
-\r
- /**\r
- * Returns the component type of the given component or null if the \r
- * parameter is not a component.\r
- */\r
- public static Resource getComponentType(ReadGraph g, Resource component) throws DatabaseException {\r
- StructuralResource2 STR = StructuralResource2.getInstance(g);\r
- return g.getPossibleType(component, STR.Component);\r
- }\r
- \r
- /**\r
- * Returns the definitions of the component type or null, if the component\r
- * type does not have a definition.\r
- */\r
- public static Resource getComponentTypeDefinition(ReadGraph g, Resource componentType) throws DatabaseException {\r
- StructuralResource2 STR = StructuralResource2.getInstance(g);\r
- return g.getPossibleObject(componentType, STR.IsDefinedBy);\r
- }\r
- \r
- /**\r
- * Returns all (component,connectionRelation) pairs that are connected\r
- * to the given component and connectionRelation.\r
- * @param component\r
- * @param bindingRelation\r
- * @return\r
- */\r
- public static Set<Terminal> getRelatedTerminals(RequestProcessor g, Resource component, Resource connectionRelation) throws DatabaseException {\r
- return g.syncRequest(new ConnectedTo(component, connectionRelation));\r
- }\r
- \r
- /**\r
- * Returns all connections that are reachable from the given connection\r
- * with IsJoinedBy-relation including the given connection itself. \r
- */ \r
- public static Set<Resource> getRelatedConnections(RequestProcessor g, Resource connection) throws DatabaseException {\r
- return g.syncRequest(new RelatedConnections(connection));\r
- }\r
- \r
- /**\r
- * Returns all connections that are reachable from the given connection join. * \r
- */ \r
- public static Set<Resource> getRelatedConnectionsOfConnectionJoin(RequestProcessor g, Resource connectionJoin) throws DatabaseException {\r
- return g.syncRequest(new RelatedConnectionsOfConnectionJoin(connectionJoin));\r
- }\r
- \r
- /**\r
- * Returns all connections that are reachable from the given connection join\r
- * without visiting the resources in the collection excludedConnections.\r
- */\r
- public static Set<Resource> getRelatedConnectionsOfConnectionJoin(RequestProcessor g, Resource connectionJoin, Collection<Resource> excludedConnections) throws DatabaseException {\r
- return g.syncRequest(new RelatedConnectionsOfConnectionJoin(connectionJoin, excludedConnections));\r
- }\r
- \r
- /**\r
- * Returns true if the given composite is a parent of some/all components \r
- * where the connection is attached to.\r
- */\r
- public static boolean isConnectionInComposite(ReadGraph g, Resource connection, Resource composite) throws DatabaseException {\r
- StructuralResource2 STR = StructuralResource2.getInstance(g);\r
- Layer0 L0 = Layer0.getInstance(g);\r
- Collection<Resource> connects = g.getObjects(connection, STR.Connects);\r
- if (!connects.isEmpty()) {\r
- for(Resource component : connects)\r
- for(Resource parent : g.getObjects(component, L0.PartOf))\r
- if(parent.equals(composite))\r
- return true;\r
- } else {\r
- Set<Resource> joinedComposites = null;\r
- for(Resource join : g.getObjects(connection, STR.IsJoinedBy)) {\r
- Collection<Resource> joined = g.getObjects(join, STR.JoinsComposite);\r
- if (joinedComposites == null) {\r
- joinedComposites = new THashSet<Resource>(joined);\r
- } else {\r
- joinedComposites.retainAll(joined);\r
- }\r
- }\r
- if (joinedComposites != null && joinedComposites.size() == 1) {\r
- return joinedComposites.contains(composite);\r
- }\r
- }\r
- return false;\r
- }\r
- \r
- public static Variable getConnectionPoint(ReadGraph graph, Variable component, Resource relation) throws DatabaseException {\r
- Layer0 L0 = Layer0.getInstance(graph);\r
- String relationName = graph.getRelatedValue(relation, L0.HasName, Bindings.STRING);\r
- return component.getProperty(graph, relationName);\r
- }\r
-\r
- public static Variable getPossibleConnectionPoint(ReadGraph graph, Variable component, Resource relation) throws DatabaseException {\r
- try {\r
- return getConnectionPoint(graph, component, relation);\r
- } catch (MissingVariableException e) {\r
- return null;\r
- }\r
- }\r
-\r
- public static Variable getPossibleConnectionTo(ReadGraph graph, Variable component, Resource relation) throws DatabaseException {\r
- Variable property = component.getPossibleProperty(graph, relation);\r
- if(property == null) return null;\r
- Connection conn = property.getPossibleValue(graph);\r
- if(conn == null) return null;\r
- Collection<Variable> cps = conn.getConnectionPoints(graph, null);\r
- if(cps.size() == 2) {\r
- for(Variable var : cps) {\r
- if(property.equals(var)) continue;\r
- return var;\r
- }\r
- }\r
- return null;\r
- }\r
- \r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.structural2.utils;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Set;
+
+import org.simantics.databoard.Bindings;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.RequestProcessor;
+import org.simantics.db.Resource;
+import org.simantics.db.Statement;
+import org.simantics.db.WriteGraph;
+import org.simantics.db.common.CommentMetadata;
+import org.simantics.db.common.request.ObjectsWithType;
+import org.simantics.db.common.request.PossibleTypedParent;
+import org.simantics.db.common.utils.NameUtils;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.exception.MissingVariableException;
+import org.simantics.db.layer0.request.InstantiateRequest;
+import org.simantics.db.layer0.util.Layer0Utils;
+import org.simantics.db.layer0.variable.Variable;
+import org.simantics.layer0.Layer0;
+import org.simantics.structural.stubs.StructuralResource2;
+import org.simantics.structural2.Functions.StructuralOverrideData;
+import org.simantics.structural2.internal.queries.ConnectedTo;
+import org.simantics.structural2.internal.queries.RelatedConnections;
+import org.simantics.structural2.internal.queries.RelatedConnectionsOfConnectionJoin;
+import org.simantics.structural2.queries.Terminal;
+import org.simantics.structural2.variables.Connection;
+import org.simantics.utils.datastructures.Pair;
+
+import gnu.trove.set.hash.THashSet;
+
+/**
+ * A utility class for manipulating structural models.
+ *
+ * @author Hannu Niemistö
+ */
+public class StructuralUtils {
+
+ public static enum StructuralComponentClass {
+
+ PRIMITIVE,REPLACEABLE,DEFINED,PROCEDURAL;
+
+ public static StructuralComponentClass get(ReadGraph graph, Resource componentType) throws DatabaseException {
+ StructuralResource2 STR = StructuralResource2.getInstance(graph);
+ Set<Resource> types = graph.getTypes(componentType);
+ if(types.contains(STR.ProceduralComponentType))
+ return StructuralComponentClass.PROCEDURAL;
+ else if(graph.hasStatement(componentType, STR.IsDefinedBy))
+ return StructuralComponentClass.DEFINED;
+ else if(types.contains(STR.ReplaceableDefinedComponentType))
+ return StructuralComponentClass.REPLACEABLE;
+ else
+ return StructuralComponentClass.PRIMITIVE;
+ }
+
+ }
+
+ public static Collection<Resource> getConnectionRelations(ReadGraph graph, Resource componentType) throws DatabaseException {
+ Layer0 L0 = Layer0.getInstance(graph);
+ StructuralResource2 STR = StructuralResource2.getInstance(graph);
+ return graph.syncRequest(new ObjectsWithType(componentType, L0.DomainOf, STR.ConnectionRelation));
+ }
+
+ public static Collection<Resource> getPropertyRelations(ReadGraph graph, Resource componentType) throws DatabaseException {
+ Layer0 L0 = Layer0.getInstance(graph);
+ ArrayList<Resource> result = new ArrayList<Resource>();
+ for(Resource relation : graph.getObjects(componentType, L0.DomainOf))
+ if(graph.isSubrelationOf(relation, L0.HasProperty))
+ result.add(relation);
+ return result;
+ }
+
+ public static boolean isDomainOfRelation(ReadGraph graph,
+ Resource componentType, Resource connectionRelation) throws DatabaseException {
+ Layer0 L0 = Layer0.getInstance(graph);
+ for(Resource domain : graph.getObjects(connectionRelation, L0.HasDomain))
+ if(graph.isInheritedFrom(componentType, domain))
+ return true;
+ return false;
+ }
+
+ public static void addConnectionPoint(WriteGraph g, Resource componentType,
+ Resource connectionPoint) throws DatabaseException {
+ Layer0 L0 = Layer0.getInstance(g);
+ g.claim(connectionPoint, L0.HasDomain, componentType);
+ }
+
+ public static Resource createConnectionPoint(WriteGraph g, Resource componentType, Resource copy) throws DatabaseException {
+ String proposition = NameUtils.getSafeName(g, copy);
+ String newName = NameUtils.findFreshName(g, proposition, componentType);
+ return createConnectionPoint(g, componentType, copy, newName);
+ }
+
+ public static Resource createConnectionPoint(WriteGraph g, Resource componentType, Resource copy, String name) throws DatabaseException {
+ return createConnectionPointP(g, componentType, copy, name).first;
+ }
+
+ public static Pair<Resource,Resource> createConnectionPointP(WriteGraph g, Resource componentType, Resource copy, String name) throws DatabaseException {
+
+ Layer0 L0 = Layer0.getInstance(g);
+ StructuralResource2 STR = StructuralResource2.getInstance(g);
+
+ // Create the connection point
+ Resource connectionPoint = g.newResource();
+ Resource connectionPointInv = g.newResource();
+
+ for (Resource superrelation : g.getObjects(copy, L0.SubrelationOf)) {
+ g.claim(connectionPoint, L0.SubrelationOf, null, superrelation);
+ Resource inverse = g.getPossibleInverse(superrelation);
+ if (inverse != null)
+ g.claim(connectionPointInv, L0.SubrelationOf, null, inverse);
+ }
+ for (Resource type : g.getObjects(copy, L0.InstanceOf)) {
+ g.claim(connectionPoint, L0.InstanceOf, null, type);
+ }
+ for (Resource attachment : g.getObjects(copy, STR.HasAttachmentRelation)) {
+ g.claim(connectionPoint, STR.HasAttachmentRelation, attachment);
+ }
+ for (Statement stm : g.getStatements(copy, STR.AllowsConnectionType)) {
+ if (!stm.isAsserted(copy)) {
+ g.claim(connectionPoint, stm.getPredicate(), stm.getObject());
+ }
+ }
+
+ g.claim(connectionPoint, L0.InverseOf, connectionPointInv);
+ g.claimLiteral(connectionPoint, L0.HasName, name, Bindings.STRING);
+ g.claim(connectionPoint, L0.ConsistsOf, connectionPointInv);
+ g.claimLiteral(connectionPointInv, L0.HasName, "Inverse", Bindings.STRING);
+
+ StructuralUtils.addConnectionPoint(g, componentType, connectionPoint);
+
+ g.claim(componentType, L0.ConsistsOf, connectionPoint);
+
+ return Pair.make(connectionPoint, connectionPointInv);
+
+ }
+
+ /**
+ * Creates a new component and the templates associated with it.
+ * This method does not check whether there already exists
+ * a component with the same name and parent.
+ * @param g
+ * @param parent The parent composite of the new component.
+ * @param name The name of the new component.
+ * @param componentType The type of the new component.
+ * @return
+ * @throws DatabaseException
+ */
+ public static Resource newComponent(WriteGraph g, Resource parent, String name, Resource componentType) throws DatabaseException {
+ Layer0 L0 = Layer0.getInstance(g);
+
+ HashMap<String,Object> parameters = new HashMap<String,Object>();
+ parameters.put("parent", parent);
+
+ InstantiateRequest ir = new InstantiateRequest(componentType, parameters);
+ Resource component = ir.perform(g);
+ g.claim(component, L0.HasName, Layer0Utils.literal(g, name));
+ g.claim(component, L0.HasLabel, Layer0Utils.literal(g, ""));
+ g.claim(parent, L0.ConsistsOf, component);
+ Layer0Utils.claimNewIdentifier(g, component, true);
+ // Add comment to change set.
+ CommentMetadata cm = g.getMetadata(CommentMetadata.class);
+ g.addMetadata(cm.add("Created component " + component));
+ return component;
+ }
+
+ /**
+ * Returns all child components of a composite.
+ */
+ public static Collection<Resource> getChildComponents(ReadGraph g, Resource parent) throws DatabaseException {
+ Layer0 L0 = Layer0.getInstance(g);
+ StructuralResource2 STR = StructuralResource2.getInstance(g);
+
+ Collection<Resource> allChildren = g.getObjects(parent, L0.ConsistsOf);
+ ArrayList<Resource> result = new ArrayList<Resource>(allChildren.size());
+ for(Resource child : allChildren)
+ // Composite may contain other things than components, therefore we must do checking
+ if(g.isInstanceOf(child, STR.Component))
+ result.add(child);
+ return result;
+ }
+
+ /**
+ * Returns the component type of the given component or null if the
+ * parameter is not a component.
+ */
+ @Deprecated
+ public static Resource getComponentType(ReadGraph g, Resource component) throws DatabaseException {
+ StructuralResource2 STR = StructuralResource2.getInstance(g);
+ return g.getPossibleType(component, STR.Component);
+ }
+
+ /**
+ * Returns the definitions of the component type or null, if the component
+ * type does not have a definition.
+ */
+ public static Resource getComponentTypeDefinition(ReadGraph g, Resource componentType) throws DatabaseException {
+ StructuralResource2 STR = StructuralResource2.getInstance(g);
+ return g.getPossibleObject(componentType, STR.IsDefinedBy);
+ }
+
+ /**
+ * Returns all (component,connectionRelation) pairs that are connected
+ * to the given component and connectionRelation.
+ * @param component
+ * @param bindingRelation
+ * @return
+ */
+ public static Set<Terminal> getRelatedTerminals(RequestProcessor g, Resource component, Resource connectionRelation) throws DatabaseException {
+ return g.syncRequest(new ConnectedTo(component, connectionRelation));
+ }
+
+ /**
+ * Returns all connections that are reachable from the given connection
+ * with IsJoinedBy-relation including the given connection itself.
+ */
+ public static Set<Resource> getRelatedConnections(RequestProcessor g, Resource connection) throws DatabaseException {
+ return g.syncRequest(new RelatedConnections(connection));
+ }
+
+ /**
+ * Returns all connections that are reachable from the given connection join. *
+ */
+ public static Set<Resource> getRelatedConnectionsOfConnectionJoin(RequestProcessor g, Resource connectionJoin) throws DatabaseException {
+ return g.syncRequest(new RelatedConnectionsOfConnectionJoin(connectionJoin));
+ }
+
+ /**
+ * Returns all connections that are reachable from the given connection join
+ * without visiting the resources in the collection excludedConnections.
+ */
+ public static Set<Resource> getRelatedConnectionsOfConnectionJoin(RequestProcessor g, Resource connectionJoin, Collection<Resource> excludedConnections) throws DatabaseException {
+ return g.syncRequest(new RelatedConnectionsOfConnectionJoin(connectionJoin, excludedConnections));
+ }
+
+ /**
+ * Returns true if the given composite is a parent of some/all components
+ * where the connection is attached to.
+ */
+ public static boolean isConnectionInComposite(ReadGraph g, Resource connection, Resource composite) throws DatabaseException {
+ StructuralResource2 STR = StructuralResource2.getInstance(g);
+ Layer0 L0 = Layer0.getInstance(g);
+ Collection<Resource> connects = g.getObjects(connection, STR.Connects);
+ if (!connects.isEmpty()) {
+ for(Resource component : connects)
+ for(Resource parent : g.getObjects(component, L0.PartOf))
+ if(parent.equals(composite))
+ return true;
+ } else {
+ Set<Resource> joinedComposites = null;
+ for(Resource join : g.getObjects(connection, STR.IsJoinedBy)) {
+ Collection<Resource> joined = g.getObjects(join, STR.JoinsComposite);
+ if (joinedComposites == null) {
+ joinedComposites = new THashSet<Resource>(joined);
+ } else {
+ joinedComposites.retainAll(joined);
+ }
+ }
+ if (joinedComposites != null && joinedComposites.size() == 1) {
+ return joinedComposites.contains(composite);
+ }
+ }
+ return false;
+ }
+
+ public static Variable getConnectionPoint(ReadGraph graph, Variable component, Resource relation) throws DatabaseException {
+ Layer0 L0 = Layer0.getInstance(graph);
+ String relationName = graph.getRelatedValue(relation, L0.HasName, Bindings.STRING);
+ return component.getProperty(graph, relationName);
+ }
+
+ public static Variable getPossibleConnectionPoint(ReadGraph graph, Variable component, Resource relation) throws DatabaseException {
+ try {
+ return getConnectionPoint(graph, component, relation);
+ } catch (MissingVariableException e) {
+ return null;
+ }
+ }
+
+ public static Variable getPossibleConnectionTo(ReadGraph graph, Variable component, Resource relation) throws DatabaseException {
+ Variable property = component.getPossibleProperty(graph, relation);
+ if(property == null) return null;
+ Connection conn = property.getPossibleValue(graph);
+ if(conn == null) return null;
+ Collection<Variable> cps = conn.getConnectionPoints(graph, null);
+ if(cps.size() == 2) {
+ for(Variable var : cps) {
+ if(property.equals(var)) continue;
+ return var;
+ }
+ }
+ return null;
+ }
+
+ public static boolean isImmutable(ReadGraph graph, Resource r) throws DatabaseException {
+ StructuralResource2 STR = StructuralResource2.getInstance(graph);
+ Resource uc = graph.syncRequest(new PossibleTypedParent(r, STR.ComponentType));
+ return graph.isImmutable(r)
+ // Anything under a published or locked user component is published as well
+ || (uc != null && (Layer0Utils.isPublished(graph, uc)
+ || graph.hasStatement(uc, STR.ComponentType_Locked)))
+ // Anything under a published container (shared library) is published as well
+ || Layer0Utils.isContainerPublished(graph, r)
+ ;
+ }
+
+ public static List<Variable> structuralConnectionConnectionPoints(ReadGraph graph, Connection conn, Resource relationType) throws DatabaseException {
+ return new ArrayList<Variable>(conn.getConnectionPoints(graph, relationType));
+ }
+
+ public static Resource structuralTypeResource(ReadGraph graph, Variable component, Resource baseType) throws DatabaseException {
+ StructuralOverrideData od = StructuralOverrideData.compute(graph, component);
+ return od.type();
+ }
+
+ public static Resource getComponentType(ReadGraph graph, Variable configuration, Resource component) throws DatabaseException {
+
+ Variable componentVariable = configuration.browse(graph, component);
+ return componentVariable.getType(graph);
+
+ }
+
+
+
+}