X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.graph.compiler%2Fsrc%2Forg%2Fsimantics%2Fgraph%2Fcompiler%2Finternal%2FresourceFiles%2FresourceFile.ftl;fp=bundles%2Forg.simantics.graph.compiler%2Fsrc%2Forg%2Fsimantics%2Fgraph%2Fcompiler%2Finternal%2FresourceFiles%2FresourceFile.ftl;h=432d14f615fe9d121e4e1c7fb03bf1575fcfc0b5;hp=0000000000000000000000000000000000000000;hb=969bd23cab98a79ca9101af33334000879fb60c5;hpb=866dba5cd5a3929bbeae85991796acb212338a08 diff --git a/bundles/org.simantics.graph.compiler/src/org/simantics/graph/compiler/internal/resourceFiles/resourceFile.ftl b/bundles/org.simantics.graph.compiler/src/org/simantics/graph/compiler/internal/resourceFiles/resourceFile.ftl new file mode 100644 index 000000000..432d14f61 --- /dev/null +++ b/bundles/org.simantics.graph.compiler/src/org/simantics/graph/compiler/internal/resourceFiles/resourceFile.ftl @@ -0,0 +1,64 @@ +package ${packageName}; + +import org.simantics.db.RequestProcessor; +import org.simantics.db.Resource; +import org.simantics.db.ReadGraph; +import org.simantics.db.request.Read; +import org.simantics.db.Session; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.service.QueryControl; + +public class ${className} { + + <#list resources as resource> + <#if resource.deprecated>@Deprecated public final Resource ${resource.javaName}; + + + public static class URIs { + <#list resources as resource> + <#if resource.deprecated>@Deprecated public static final String ${resource.javaName} = "${resource.uri}"; + + } + + public static Resource getResourceOrNull(ReadGraph graph, String uri) { + try { + return graph.getResource(uri); + } catch(DatabaseException e) { + System.err.println(e.getMessage()); + return null; + } + } + + public ${className}(ReadGraph graph) { + <#list resources as resource> + ${resource.javaName} = getResourceOrNull(graph, URIs.${resource.javaName}); + + } + + public static ${className} getInstance(ReadGraph graph) { + Session session = graph.getSession(); + ${className} ret = session.peekService(${className}.class); + if(ret == null) { + QueryControl qc = graph.getService(QueryControl.class); + ret = new ${className}(qc.getIndependentGraph(graph)); + session.registerService(${className}.class, ret); + } + return ret; + } + + public static ${className} getInstance(RequestProcessor session) throws DatabaseException { + ${className} ret = session.peekService(${className}.class); + if(ret == null) { + ret = session.syncRequest(new Read<${className}>() { + public ${className} perform(ReadGraph graph) throws DatabaseException { + QueryControl qc = graph.getService(QueryControl.class); + return new ${className}(qc.getIndependentGraph(graph)); + } + }); + session.registerService(${className}.class, ret); + } + return ret; + } + +} +