import org.simantics.graph.representation.Identity;
import org.simantics.graph.representation.IdentityDefinition;
import org.simantics.graph.representation.Internal;
+import org.simantics.graph.representation.Optional;
import org.simantics.graph.representation.Root;
import org.simantics.graph.representation.TransferableGraph1;
import org.simantics.graph.representation.Value;
else if(definition instanceof Root) {
resources[identity.resource] = RootLibrary;
}
+ else if(definition instanceof Optional) {
+ Optional def = (Optional)definition;
+ Resource parent = resources[def.parent];
+ if(parent == null)
+ continue;
+ Resource child = graph.syncRequest(
+ new UnescapedChildMapOfResource(parent),
+ new TransientCacheAsyncListener<Map<String, Resource>>())
+ .get(def.name);
+ resources[identity.resource] = child; // might be null
+ }
}
}
External ext = (External)id.definition;
if(ext.name.equals(name) && ext.parent == parent) return id;
}
+ else if(id.definition instanceof Optional) {
+ Optional ext = (Optional)id.definition;
+ if(ext.name.equals(name) && ext.parent == parent) return id;
+ }
}
return null;
} else if (definition instanceof Internal) {
Internal def = (Internal)definition;
return getURI(identities, def.parent) + "/" + def.name;
+ } else if (definition instanceof Optional) {
+ Optional def = (Optional)definition;
+ return getURI(identities, def.parent) + "/" + def.name;
} else {
return "";
}
} else if (definition instanceof Internal) {
Internal def = (Internal)definition;
return getURI(resourceCount, identities, def.parent) + "/" + URIStringUtils.escape(def.name);
+ } else if (definition instanceof Optional) {
+ Optional def = (Optional)definition;
+ return getURI(resourceCount, identities, def.parent) + "/" + URIStringUtils.escape(def.name);
} else {
return "";
}
package org.simantics.graph.store;
+import java.util.ArrayList;
+import java.util.regex.Pattern;
+
+import org.simantics.graph.query.Path;
+import org.simantics.graph.query.PathChild;
+import org.simantics.graph.query.PathRoot;
+import org.simantics.graph.representation.External;
+import org.simantics.graph.representation.Identity;
+import org.simantics.graph.representation.Internal;
+import org.simantics.graph.representation.Optional;
+import org.simantics.graph.representation.Root;
+
import gnu.trove.list.array.TIntArrayList;
import gnu.trove.map.hash.THashMap;
import gnu.trove.map.hash.TIntIntHashMap;
import gnu.trove.set.hash.THashSet;
import gnu.trove.set.hash.TIntHashSet;
-import java.util.ArrayList;
-import java.util.regex.Pattern;
-
-import org.simantics.graph.query.Path;
-import org.simantics.graph.query.PathChild;
-import org.simantics.graph.query.PathRoot;
-import org.simantics.graph.representation.External;
-import org.simantics.graph.representation.Identity;
-import org.simantics.graph.representation.Internal;
-import org.simantics.graph.representation.Root;
-
public class IdentityStore implements IStore {
private static int[] EMPTY_INT_ARRAY = new int[0];
new TIntObjectHashMap<THashMap<String, ConsistsOf>>();
TIntObjectHashMap<ConsistsOf> childMap = new TIntObjectHashMap<ConsistsOf>();
TIntHashSet newResources = new TIntHashSet();
+ TIntHashSet optionalResources = new TIntHashSet();
int resourceCount = 0;
TIntIntHashMap unifications = new TIntIntHashMap();
TIntHashSet collisions = new TIntHashSet();
public boolean markNew(int resource) {
return newResources.add(resource);
}
-
+
+ public boolean markOptional(int resource) {
+ return optionalResources.add(resource);
+ }
+
public int[] getNewResources() {
return newResources.toArray();
}
@Override
public boolean execute(String a, ConsistsOf b) {
- if(newResources.contains(b.child))
- identities.add(new Identity(b.child, new Internal(parent, a)));
+ int child = b.child;
+ if(newResources.contains(child))
+ identities.add(new Identity(child, new Internal(parent, a)));
+ else if(optionalResources.contains(child))
+ identities.add(new Identity(child, new Optional(parent, a)));
else
- identities.add(new Identity(b.child, new External(parent, a)));
+ identities.add(new Identity(child, new External(parent, a)));
collectIdentities(b.child, identities);
return true;
}
return newResources.contains(id);
}
+ public boolean isOptionalResource(int id) {
+ return optionalResources.contains(id);
+ }
+
+ public boolean isRoot(int id) {
+ return invRoots.contains(id);
+ }
+
public Identity[] toArray() {
final ArrayList<Identity> identities = new ArrayList<Identity>();
collectIdentities(identities);
return childMap.containsKey(id);
}
+ public int getParent(int id) {
+ ConsistsOf consistsOf = childMap.get(id);
+ if(consistsOf == null)
+ return -1;
+ return consistsOf.parent;
+ }
+
public void definePath(Path path, int resource) {
if(path instanceof PathChild) {
PathChild child = (PathChild)path;
map.put(name, consistsOf);
childMap.put(child, consistsOf);
}
-
+
+ public void removeOptionalMark(int id) {
+ optionalResources.remove(id);
+ }
+
}