import org.apache.batik.svggen.SVGGeneratorContext;
import org.apache.batik.svggen.SVGGraphics2D;
import org.simantics.Simantics;
+import org.simantics.datatypes.literal.GUID;
import org.simantics.db.ReadGraph;
import org.simantics.db.Resource;
import org.simantics.db.common.request.UnaryRead;
try {
if (p instanceof Resource) {
Resource element = (Resource) p;
- if (graph.isInstanceOf(element, DIA.Connection) || graph.isInstanceOf(element, DIA.Terminal)) {
- // Ok, lets create a hashcode for connections and terminals as they do not have identifiers
- return graph.getURI(element).hashCode();
- } else if (graph.isInstanceOf(element, DIA.Element)) {
+ if (graph.isInstanceOf(element, DIA.Element)) {
Resource component = graph.getPossibleObject(element, MOD.ElementToComponent);
if (component != null) {
- Object relatedValue = graph.getPossibleRelatedValue(component, L0.identifier);
- if (relatedValue != null) {
- if (relatedValue instanceof Object[]) {
- // OK, found guid, lets generate new based on URI
- return Arrays.toString(createURIBasedL0Identifier(graph, component));
- } else {
- System.err.println("Component " + component + " identifeir is not normal: " + relatedValue);
- }
+ GUID identifier = graph.getPossibleRelatedValue(component, L0.identifier, GUID.BINDING);
+ if (identifier != null) {
+ return Arrays.toString(createURIBasedL0Identifier(graph, component));
} else {
- System.err.println("Compoennt " + component + " dooes not have identifier");
+ LOGGER.error("Component {} does not have GUID identifier!", component);
}
+ } else if (graph.isInstanceOf(element, DIA.Connection) || graph.isInstanceOf(element, DIA.Terminal)) {
+ // Ok, lets create a hashcode for connections and terminals as they do not have identifiers
+ return graph.getURI(element).hashCode();
} else {
- System.err.println("Element " + element + " does not have component");
+ // Ok, lets create a hashcode or either return empty string in cases where no ID is required
+ if (graph.hasStatement(element, L0.HasName))
+ return graph.getURI(element).hashCode();
+ return "";
}
}
} else {
- System.err.println("p is not resource but is " + p);
+ LOGGER.error("Parameter p {} is not resource but it is {}", p, p.getClass());
}
return p;
} catch (DatabaseException e) {