import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
+import java.util.Collection;
+import java.util.Map;
import java.util.TreeMap;
import java.util.TreeSet;
import org.simantics.db.ReadGraph;
import org.simantics.db.Resource;
import org.simantics.db.common.utils.CommonDBUtils;
+import org.simantics.db.common.utils.NameUtils;
import org.simantics.db.exception.DatabaseException;
import org.simantics.db.layer0.variable.Variable;
import org.simantics.db.layer0.variable.Variables;
return graph.getRelatedValue(resource, GF.HasFiledata, Bindings.BYTE_ARRAY);
}
- public static byte[] structuralComponentContentDump(ReadGraph graph, Resource resource) throws DatabaseException {
-
- StringBuilder dump = new StringBuilder();
+ private static StringBuilder structuralComponentContentDump(ReadGraph graph, Resource resource, StringBuilder dump) throws DatabaseException {
Variable v = Variables.getVariable(graph, resource);
-
+
TreeSet<String> types = new TreeSet<>();
for(Resource t : graph.getPrincipalTypes(resource)) {
types.add(graph.getURI(t));
dump.append("\n");
}
}
+
+ return dump;
+ }
+
+ public static byte[] structuralComponentContentDump(ReadGraph graph, Resource resource) throws DatabaseException {
+ return structuralComponentContentDump(graph, resource, new StringBuilder()).toString().getBytes(UTF8);
+ }
+
+ public static byte[] structuralComponentTypeContentDump(ReadGraph graph, Resource resource) throws DatabaseException {
+ StringBuilder dump = structuralComponentContentDump(graph, resource, new StringBuilder());
+
+ StructuralResource2 STR = StructuralResource2.getInstance(graph);
+
+ // Dump procedural component type code if present
+ String proceduralCode = graph.getPossibleRelatedValue(resource, STR.ProceduralComponentType_code, Bindings.STRING);
+ if (proceduralCode != null) {
+ dump
+ .append("\n---- ProceduralComponentType.code begins ----\n")
+ .append(proceduralCode)
+ .append("---- ProceduralComponentType.code ends ----\n");
+ }
+
+ // Dump component type SCL scripts
+ Collection<Resource> scripts = graph.getObjects(resource, STR.ComponentType_hasScript);
+ if (!scripts.isEmpty()) {
+ dump.append("\nComponentType.hasScript (").append(scripts.size()).append(")\n");
+ TreeMap<String,Resource> sortedScripts = new TreeMap<>();
+ for (Resource script : scripts)
+ sortedScripts.put(NameUtils.getSafeName(graph, script), script);
+ for (Map.Entry<String, Resource> entry : sortedScripts.entrySet()) {
+ String name = entry.getKey();
+ Resource script = entry.getValue();
+ String type = graph.getPossibleRelatedValue(script, STR.ComponentTypeScript_type, Bindings.STRING);
+ String code = graph.getPossibleRelatedValue(script, STR.ComponentTypeScript_code, Bindings.STRING);
+ dump
+ .append("---- script `").append(name).append("` of type `").append(type).append("` begins ----\n")
+ .append(code)
+ .append("\n---- script `").append(name).append("` of type `").append(type).append("` ends ----\n");
+ }
+ }
+
return dump.toString().getBytes(UTF8);
}