1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
\r
3 * in Industry THTH ry.
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.browsing.ui.graph.impl;
\r
14 import org.simantics.browsing.ui.common.property.IProperty;
\r
15 import org.simantics.db.Resource;
\r
16 import org.simantics.db.common.ResourceArray;
\r
19 * @author Tuukka Lehtonen
\r
21 public class ResourceProperty implements IProperty {
\r
23 protected final Type type;
\r
25 protected final Resource subject;
\r
26 protected final Resource predicate;
\r
27 protected final Resource value;
\r
28 protected final ResourceArray path;
\r
30 public ResourceProperty(Type type, Resource subject, Resource predicate, Resource value, ResourceArray path) {
\r
32 this.subject = subject;
\r
33 this.predicate = predicate;
\r
39 public Type getType() {
\r
43 @SuppressWarnings("unchecked")
\r
45 public <T> T getData(Class<T> clazz) {
\r
46 T t = (T) getAdapter(clazz);
\r
49 throw new ClassCastException("class " + clazz.getCanonicalName() + " not adaptable from " + toString());
\r
53 public String toString() {
\r
54 return getClass().getSimpleName() + "[subject=" + subject + ", predicate=" + predicate + ", value=" + value
\r
55 + ", path=" + path + "]";
\r
58 @SuppressWarnings({ "rawtypes", "unchecked" })
\r
60 public Object getAdapter(Class adapter) {
\r
61 return adapt(adapter);
\r
64 @SuppressWarnings("unchecked")
\r
66 public <T> T adapt(Class<T> adapter) {
\r
67 if (adapter == ResourceArray[].class)
\r
68 return (T) new ResourceArray[] { new ResourceArray(subject, predicate, value), path };
\r
69 if (adapter == ResourceArray.class)
\r
70 return (T) new ResourceArray(subject, predicate, value);
\r
71 if (adapter == Resource[].class)
\r
72 return (T) new Resource[] { subject, predicate, value };
\r
73 if (adapter == Resource.class)
\r
74 // Return the object of the specified statement
\r
80 public int propertyHashCode() {
\r
81 final int prime = 31;
\r
83 result = prime * result + subject.hashCode();
\r
84 result = prime * result + predicate.hashCode();
\r
85 result = prime * result + path.hashCode();
\r
90 public boolean propertyEquals(Object obj) {
\r
95 if (getClass() != obj.getClass())
\r
97 ResourceProperty other = (ResourceProperty) obj;
\r
98 return subject.equals(other.subject) && predicate.equals(other.predicate) && path.equals(other.path);
\r
102 public int hashCode() {
\r
103 return propertyHashCode() * 31 + value.hashCode();
\r
107 public boolean equals(Object obj) {
\r
110 if (!propertyEquals(obj))
\r
112 ResourceProperty other = (ResourceProperty) obj;
\r
113 return value.equals(other.value) && type.equals(other.type);
\r