]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/TransferableGraphConfiguration2.java
Clean up and support internal seed resources in tg export
[simantics/platform.git] / bundles / org.simantics.db.layer0 / src / org / simantics / db / layer0 / util / TransferableGraphConfiguration2.java
index 2203ecaeb6bd792635aa1648495f20c3b5f03956..ec9c8b80c9e8fda57dd623660b6819f7b05e95aa 100644 (file)
@@ -16,44 +16,55 @@ import org.simantics.db.common.request.UniqueRead;
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.layer0.adapter.SubgraphExtent.ExtentStatus;
 import org.simantics.db.layer0.util.DomainProcessor3.ExclusionDecision;
+import org.simantics.db.layer0.util.TransferableGraphConfiguration2.SeedSpec.SeedSpecType;
 import org.simantics.scl.runtime.function.Function1;
 
 public class TransferableGraphConfiguration2 {
-       
-       public static class RootSpec {
+
+       public static class SeedSpec {
+
+               public static enum SeedSpecType {
+                       INTERNAL, ROOT, SPECIAL_ROOT
+               }
+
                public final Resource resource;
                public final String name;
-               public final boolean internal;
+               // Special roots are not normal seeds - e.g. %model
+               public final SeedSpecType specType;
                /**
                 * Optional, may be null.
                 */
                public final String type;
 
-               public RootSpec(Resource resource, String name, boolean internal) {
-                       this(resource, name, internal, null);
+               public SeedSpec(Resource resource, String name, SeedSpecType specType) {
+                       this(resource, name, specType, null);
                }
 
-               public RootSpec(Resource resource, String name, boolean internal, String type) {
+               public SeedSpec(Resource resource, String name, SeedSpecType specType, String type) {
                        if (resource == null)
                                throw new NullPointerException("null resource");
                        if (name == null)
                                throw new NullPointerException("null name");
                        this.resource = resource;
                        this.name = name;
-                       this.internal = internal;
+                       this.specType = specType;
                        this.type = type;
                }
 
+               public static SeedSpec internal(Resource resource) {
+                       return new SeedSpec(resource, null, SeedSpecType.ROOT);
+               }
+
                @Override
                public String toString() {
-                       return "RootSpec[" + name + ", " + resource + ", " + internal + ", " + type + "]"; 
+                       return "SeedSpec[" + name + ", " + resource + ", " + specType + ", " + type + "]";
                }
 
                @Override
                public int hashCode() {
                        final int prime = 31;
                        int result = 1;
-                       result = prime * result + (internal ? 1231 : 1237);
+                       result = prime * result + specType.hashCode();
                        result = prime * result + resource.hashCode();
                        result = prime * result + name.hashCode();
                        result = prime * result + (type != null ? type.hashCode() : 0);
@@ -68,8 +79,8 @@ public class TransferableGraphConfiguration2 {
                                return false;
                        if (getClass() != obj.getClass())
                                return false;
-                       RootSpec other = (RootSpec) obj;
-                       return internal == other.internal && resource.equals(other.resource) && name.equals(other.name)
+                       SeedSpec other = (SeedSpec) obj;
+                       return specType.equals(other.specType) && resource.equals(other.resource) && name.equals(other.name)
                                        && objectEquals(type, other.type);
                }
 
@@ -81,13 +92,13 @@ public class TransferableGraphConfiguration2 {
                }
        }
 
-       final public TreeMap<String, Variant> baseExtensions = new TreeMap<String,Variant>();
+       final public TreeMap<String, Variant> baseExtensions = new TreeMap<>();
        final public Resource indexRoot;
-       final public Collection<RootSpec> roots;
+       final public Collection<SeedSpec> seeds;
        final public Map<Resource, ExtentStatus> preStatus;
        final public boolean ignoreVirtualResources;
        final public boolean validate;
-       
+
        /**
         * <code>true</code> to export values, <code>false</code> to skip the actual
         * values and only write the resource id.
@@ -97,25 +108,25 @@ public class TransferableGraphConfiguration2 {
        public Collection<TGValueModifier> valueModifiers;
        public Function1<Statement,ExclusionDecision> exclusionFunction;
 
-       public TransferableGraphConfiguration2(Resource indexRoot, Collection<RootSpec> roots, Map<Resource, ExtentStatus> preStatus, boolean ignoreVirtualResources, boolean validate) {
+       public TransferableGraphConfiguration2(Resource indexRoot, Collection<SeedSpec> seeds, Map<Resource, ExtentStatus> preStatus, boolean ignoreVirtualResources, boolean validate) {
                this.indexRoot = indexRoot;
-               this.roots = roots;
+               this.seeds = seeds;
                this.preStatus = preStatus;
                this.ignoreVirtualResources = ignoreVirtualResources;
                this.validate = validate;
                this.valueModifiers = null;
        }
 
-       public TransferableGraphConfiguration2(Resource indexRoot, Collection<RootSpec> roots, Map<Resource, ExtentStatus> preStatus, boolean ignoreVirtualResources) {
+       public TransferableGraphConfiguration2(Resource indexRoot, Collection<SeedSpec> roots, Map<Resource, ExtentStatus> preStatus, boolean ignoreVirtualResources) {
                this(indexRoot, roots, preStatus, ignoreVirtualResources, true);
        }
 
-       public TransferableGraphConfiguration2(Resource indexRoot, Collection<RootSpec> roots, Map<Resource, ExtentStatus> preStatus) {
+       public TransferableGraphConfiguration2(Resource indexRoot, Collection<SeedSpec> roots, Map<Resource, ExtentStatus> preStatus) {
                this(indexRoot, roots, preStatus, true);
        }
 
        public TransferableGraphConfiguration2(TransferableGraphConfiguration2 conf) throws DatabaseException {
-               this(conf.indexRoot, conf.roots, conf.preStatus, conf.ignoreVirtualResources, conf.validate);
+               this(conf.indexRoot, conf.seeds, conf.preStatus, conf.ignoreVirtualResources, conf.validate);
        }
 
        public TransferableGraphConfiguration2(ReadGraph graph, Resource model, boolean ignoreVirtualResources, boolean validate) throws DatabaseException {
@@ -133,12 +144,12 @@ public class TransferableGraphConfiguration2 {
        public TransferableGraphConfiguration2(ReadGraph graph, Resource model) throws DatabaseException {
                this(graph, model, true);
        }
-       
-       public TransferableGraphConfiguration2(ReadGraph graph, Collection<RootSpec> roots, Collection<Resource> resourceRoots, Collection<Resource> exclusions) throws DatabaseException {
+
+       public TransferableGraphConfiguration2(ReadGraph graph, Collection<SeedSpec> roots, Collection<Resource> resourceRoots, Collection<Resource> exclusions) throws DatabaseException {
                this(new TGConfigurer(graph, true).roots(roots).roots2(resourceRoots).exclusions(exclusions).create());
        }
 
-       public TransferableGraphConfiguration2(ReadGraph graph, Collection<RootSpec> roots, Collection<Resource> resourceRoots, Collection<Resource> exclusions, boolean ignoreVirtualResource, boolean validate) throws DatabaseException {
+       public TransferableGraphConfiguration2(ReadGraph graph, Collection<SeedSpec> roots, Collection<Resource> resourceRoots, Collection<Resource> exclusions, boolean ignoreVirtualResource, boolean validate) throws DatabaseException {
                this(new TGConfigurer(graph, ignoreVirtualResource, validate).roots(roots).roots2(resourceRoots).exclusions(exclusions).create());
        }
 
@@ -149,18 +160,18 @@ public class TransferableGraphConfiguration2 {
                        public TransferableGraphConfiguration2 perform(ReadGraph graph) throws DatabaseException {
                                return new TransferableGraphConfiguration2(graph, translate(roots), Collections.<Resource>emptyList(), exclusions, ignoreVirtualResource, validate);
                        }
-                       
+
                });
        }
 
-       public static TransferableGraphConfiguration2 createWithNames2(RequestProcessor processor, final Collection<RootSpec> roots, final Collection<Resource> exclusions, final boolean ignoreVirtualResource, final boolean validate) throws DatabaseException {
+       public static TransferableGraphConfiguration2 createWithNames2(RequestProcessor processor, final Collection<SeedSpec> roots, final Collection<Resource> exclusions, final boolean ignoreVirtualResource, final boolean validate) throws DatabaseException {
                return processor.sync(new UniqueRead<TransferableGraphConfiguration2>() {
 
                        @Override
                        public TransferableGraphConfiguration2 perform(ReadGraph graph) throws DatabaseException {
                                return new TransferableGraphConfiguration2(graph, roots, Collections.<Resource>emptyList(), exclusions, ignoreVirtualResource, validate);
                        }
-                       
+
                });
        }
 
@@ -173,9 +184,9 @@ public class TransferableGraphConfiguration2 {
 
                        @Override
                        public TransferableGraphConfiguration2 perform(ReadGraph graph) throws DatabaseException {
-                               return new TransferableGraphConfiguration2(graph, Collections.<RootSpec>emptyList(), roots, exclusions);
+                               return new TransferableGraphConfiguration2(graph, Collections.<SeedSpec>emptyList(), roots, exclusions);
                        }
-                       
+
                });
        }
 
@@ -183,10 +194,10 @@ public class TransferableGraphConfiguration2 {
                return createWithResources(processor, Collections.singletonList(model), Collections.<Resource>emptyList());
        }
 
-       private static Collection<RootSpec> translate(Collection<NamedResource> roots) {
-               ArrayList<RootSpec> result = new ArrayList<RootSpec>();
-               for(NamedResource nr : roots) result.add(new RootSpec(nr.getResource(), nr.getName(), true));
+       private static Collection<SeedSpec> translate(Collection<NamedResource> roots) {
+               ArrayList<SeedSpec> result = new ArrayList<>();
+               for(NamedResource nr : roots) result.add(new SeedSpec(nr.getResource(), nr.getName(), SeedSpecType.ROOT));
                return result;
        }
-       
+
 }