1 package org.simantics.interop.mapping.data;
\r
3 import java.util.ArrayList;
\r
4 import java.util.Collection;
\r
6 import org.simantics.db.Resource;
\r
8 public class ResourceIdentifiable implements Identifiable {
\r
10 protected Resource resource;
\r
12 public ResourceIdentifiable(Resource resource) {
\r
13 this.resource = resource;
\r
16 public Resource getResource() {
\r
21 public int hashCode() {
\r
22 return resource.hashCode();
\r
25 @SuppressWarnings("unchecked")
\r
26 public <T> T getAdapter(Class<T> clazz) {
\r
27 if (clazz.equals(Resource.class))
\r
29 if (clazz.equals(Resource[].class))
\r
30 return (T) new Resource[]{resource};
\r
31 if (clazz.equals(String.class)) {
\r
32 // TODO : have to use org.simantics.db.common.utils.Transaction to get access to ReadGraph.
\r
33 return (T)resource.toString();//NameUtils.getSafeName(g,resource);
\r
39 public boolean equals(Object arg0) {
\r
42 if (this.getClass() != arg0.getClass())
\r
44 ResourceIdentifiable other = (ResourceIdentifiable)arg0;
\r
45 return resource.equals(other.resource);
\r
49 public Identifiable merge(Identifiable other) {
\r
50 if (other instanceof ResourceIdentifiable) {
\r
51 ResourceSetIdentifiable i = new ResourceSetIdentifiable(this.resource,((ResourceIdentifiable)other).resource);
\r
53 } else if (other instanceof ResourceSetIdentifiable) {
\r
54 Collection<Resource> coll = new ArrayList<Resource>();
\r
55 coll.add(this.resource);
\r
56 coll.addAll(((ResourceSetIdentifiable)other).getResources());
\r
57 ResourceSetIdentifiable i = new ResourceSetIdentifiable(resource,coll);
\r
64 public String toString() {
\r
65 return resource.toString();
\r