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.mapping.constraint.instructions;
14 import org.simantics.db.ReadGraph;
15 import org.simantics.db.Resource;
16 import org.simantics.db.WriteGraph;
17 import org.simantics.db.common.utils.NameUtils;
18 import org.simantics.db.exception.DatabaseException;
19 import org.simantics.mapping.IContextualModification;
21 public class TripletInstruction extends Instruction3 {
23 public TripletInstruction(int variable0, int variable1, int variable2) {
24 super(variable0, variable1, variable2);
28 public IContextualModification claim(ReadGraph g, Object[] bindings) throws DatabaseException {
29 Resource r0 = (Resource)bindings[variable0];
30 Resource r1 = (Resource)bindings[variable1];
31 Resource r2 = (Resource)bindings[variable2];
32 // ITask task = ThreadLogger.getInstance().begin("g");
33 if(!g.hasStatement(r0, r1, r2)) {
35 return new IContextualModification() {
38 public void perform(WriteGraph g, Object[] bindings) throws DatabaseException {
39 Resource r0 = (Resource)bindings[variable0];
40 Resource r1 = (Resource)bindings[variable1];
41 Resource r2 = (Resource)bindings[variable2];
43 System.out.println("claim(" +
44 NameUtils.getSafeName(g, r0) + ", " +
45 NameUtils.getSafeName(g, r1) + ", " +
46 NameUtils.getSafeName(g, r2) + ")"
59 public void doClaim(WriteGraph g, Object[] bindings) throws DatabaseException {
60 Resource r0 = (Resource)bindings[variable0];
61 Resource r1 = (Resource)bindings[variable1];
62 Resource r2 = (Resource)bindings[variable2];
64 System.out.println("@ claim(" +
65 NameUtils.getSafeName(g, r0) + ", " +
66 NameUtils.getSafeName(g, r1) + ", " +
67 NameUtils.getSafeName(g, r2) + ")");
70 System.out.println("claim(" +
71 NameUtils.getSafeName(g, r0) + ", " +
72 NameUtils.getSafeName(g, r1) + ", " +
73 NameUtils.getSafeName(g, r2) + ")"
75 // ITask task = ThreadLogger.getInstance().begin("g");
82 public IContextualModification deny(ReadGraph g, Object[] bindings) throws DatabaseException {
83 Resource r0 = (Resource)bindings[variable0];
84 Resource r1 = (Resource)bindings[variable1];
85 Resource r2 = (Resource)bindings[variable2];
86 if(g.hasStatement(r0, r1, r2))
87 return new IContextualModification() {
90 public void perform(WriteGraph g, Object[] bindings) throws DatabaseException {
91 Resource r0 = (Resource)bindings[variable0];
92 Resource r1 = (Resource)bindings[variable1];
93 Resource r2 = (Resource)bindings[variable2];
95 System.out.println("deny(" +
96 NameUtils.getSafeName(g, r0) + ", " +
97 NameUtils.getSafeName(g, r1) + ", " +
98 NameUtils.getSafeName(g, r2) + ")"
101 g.denyStatement(r0, r1, r2);
109 public void doDeny(WriteGraph g, Object[] bindings) throws DatabaseException {
110 Resource r0 = (Resource)bindings[variable0];
111 Resource r1 = (Resource)bindings[variable1];
112 Resource r2 = (Resource)bindings[variable2];
114 System.out.println("deny(" +
115 NameUtils.getSafeName(g, r0) + ", " +
116 NameUtils.getSafeName(g, r1) + ", " +
117 NameUtils.getSafeName(g, r2) + ")");
120 System.out.println("deny(" +
121 NameUtils.getSafeName(g, r0) + ", " +
122 NameUtils.getSafeName(g, r1) + ", " +
123 NameUtils.getSafeName(g, r2) + ")"
126 g.denyStatement(r0, r1, r2);
130 public Object next(ReadGraph g, Object[] bindings, Object continuation) throws DatabaseException {
131 return IInstruction.FAILURE;
135 public Object query(ReadGraph g, Object[] bindings) throws DatabaseException {
136 Resource r0 = (Resource)bindings[variable0];
137 Resource r1 = (Resource)bindings[variable1];
138 Resource r2 = (Resource)bindings[variable2];
140 System.out.print("hasStatement(" +
141 NameUtils.getSafeName(g, r0) + ", " +
142 NameUtils.getSafeName(g, r1) + ", " +
143 NameUtils.getSafeName(g, r2) + ")");
145 if(g.hasStatement(r0, r1, r2)) {
147 System.out.println(" -> true");
152 System.out.println(" -> false");
153 return IInstruction.FAILURE;
158 public void toString(StringBuilder b, int indent) {