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.layer0.utils.predicates;
\r
14 import java.util.Collection;
\r
16 import org.simantics.db.Resource;
\r
17 import org.simantics.db.ReadGraph;
\r
18 import org.simantics.db.WriteGraph;
\r
19 import org.simantics.db.exception.DatabaseException;
\r
20 import org.simantics.layer0.Layer0;
\r
22 public class Type extends UnaryPredicate {
\r
26 public Type(Resource type) {
\r
30 public Resource getType() {
\r
35 public Collection<Resource> getResources(ReadGraph g) {
\r
36 throw new UnsupportedOperationException();
\r
40 public boolean has(ReadGraph g, Resource resource) throws DatabaseException {
\r
41 return g.isInstanceOf(resource, type);
\r
45 public boolean supportsUnboundedQuery() {
\r
50 public void add(WriteGraph g, Resource r) throws DatabaseException {
\r
51 Layer0 b = Layer0.getInstance(g);
\r
52 if(!g.isInstanceOf(r, type))
\r
53 g.claim(r, b.InstanceOf, null, type);
\r
57 public void remove(WriteGraph g, Resource r) throws DatabaseException {
\r
58 // FIXME not implemented correctly
\r
59 Layer0 b = Layer0.getInstance(g);
\r
60 if(g.isInstanceOf(r, type))
\r
61 g.denyStatement(r, b.InstanceOf, type);
\r
65 public boolean supportsAddition() {
\r
70 public boolean supportsRemoval() {
\r
75 public int hashCode() {
\r
76 final int prime = 31;
\r
78 result = prime * result + ((type == null) ? 0 : type.hashCode());
\r
83 public boolean equals(Object obj) {
\r
88 if (getClass() != obj.getClass())
\r
90 Type other = (Type) obj;
\r
92 if (other.type != null)
\r
94 } else if (!type.equals(other.type))
\r