package org.simantics.workbench.search; import org.simantics.NameLabelUtil; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.ServiceLocator; import org.simantics.db.exception.DatabaseException; import org.simantics.db.service.SerialisationSupport; /** * @author Tuukka Lehtonen */ public class NamedResource { private final String resource; private final String name; private final String uri; public static NamedResource of(ReadGraph graph, Resource resource) throws DatabaseException { return of(graph, resource, NameLabelUtil.modalName(graph, resource)); } public static NamedResource of(ReadGraph graph, Resource resource, String name) throws DatabaseException { return of(graph, resource, name, graph.getPossibleURI(resource)); } public static NamedResource of(ServiceLocator locator, Resource resource, String name, String uri) throws DatabaseException { SerialisationSupport ss = locator.getService(SerialisationSupport.class); return new NamedResource("" + ss.getRandomAccessId(resource), name, uri); } public NamedResource(String resource, String name) { this(resource, name, null); } public NamedResource(String resource, String name, String uri) { this.resource = resource; this.name = name; this.uri = uri; } public String getResource() { return resource; } public String getName() { return name; } public String getUri() { return uri; } }