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