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