]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.mapping/src/org/simantics/mapping/constraint/instructions/TypedBracketInstruction.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.mapping / src / org / simantics / mapping / constraint / instructions / TypedBracketInstruction.java
index b56284e57d089e3a6bc56afcf280b9217dccede3..8669e530c82b88a63239402b37eaa9725bfb0c62 100644 (file)
-/*******************************************************************************\r
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
- * in Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- *     VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.mapping.constraint.instructions;\r
-\r
-import gnu.trove.map.hash.TIntIntHashMap;\r
-import gnu.trove.set.hash.TIntHashSet;\r
-\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.WriteGraph;\r
-import org.simantics.db.common.utils.NameUtils;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.mapping.IContextualModification;\r
-\r
-public class TypedBracketInstruction implements IInstruction {\r
-\r
-       public static abstract class CreationInstruction {\r
-               protected int variableId;\r
-               \r
-               public CreationInstruction(int variableId) {\r
-                       this.variableId = variableId;\r
-               }\r
-\r
-               public abstract Resource create(WriteGraph g, Object[] bindings) throws DatabaseException;\r
-\r
-               public void mapVariables(TIntIntHashMap map) {\r
-                       variableId = map.get(variableId);                       \r
-               }\r
-               \r
-               public void collectVariables(TIntHashSet reads, TIntHashSet writes) {                   \r
-               }\r
-       }\r
-       \r
-       IInstruction instruction;\r
-       CreationInstruction[] variables;        \r
-       \r
-       public TypedBracketInstruction(IInstruction instruction, CreationInstruction ... variables) {\r
-               this.instruction = instruction;\r
-               this.variables = variables;\r
-       }       \r
-\r
-       @Override\r
-       public void collectVariables(TIntHashSet reads, TIntHashSet writes) {\r
-               instruction.collectVariables(reads, writes);\r
-               for(CreationInstruction var : variables)\r
-                       var.collectVariables(reads, writes);\r
-       }\r
-       \r
-       class Claim implements IContextualModification {\r
-                       \r
-               public Claim() {\r
-               }\r
-\r
-               @Override\r
-               public void perform(WriteGraph g, Object[] bindings) throws DatabaseException {\r
-                       for(CreationInstruction var : variables) {\r
-                               bindings[var.variableId] = var.create(g, bindings);\r
-                               if(DEBUG)\r
-                                   System.out.println("@ newResource " + NameUtils.getSafeName(g, (Resource)bindings[var.variableId]));\r
-                       }\r
-                       instruction.doClaim(g, bindings);       \r
-               }\r
-       }\r
-       \r
-       @Override\r
-       public IContextualModification claim(ReadGraph g, Object[] bindings) throws DatabaseException {\r
-               if(instruction.query(g, bindings)==IInstruction.FAILURE)\r
-                       return new Claim();\r
-               return null;\r
-       }\r
-       \r
-       class Deny implements IContextualModification {\r
-               Object continuation;\r
-               \r
-               public Deny(Object continuation) {\r
-                       this.continuation = continuation;\r
-               }\r
-\r
-               @Override\r
-               public void perform(WriteGraph g, Object[] bindings) throws DatabaseException {\r
-                       do {\r
-                               for(CreationInstruction var : variables)\r
-                                       g.deny((Resource)bindings[var.variableId]);\r
-                               continuation = instruction.next(g, bindings, continuation);\r
-                       } while(continuation != null && continuation != IInstruction.FAILURE);  \r
-               }\r
-       }\r
-       \r
-       @Override\r
-       public IContextualModification deny(ReadGraph g, Object[] bindings) throws DatabaseException {\r
-               Object continuation = instruction.query(g, bindings);\r
-               if(continuation != IInstruction.FAILURE)\r
-                       return new Deny(continuation);\r
-               return null;\r
-       }\r
-\r
-       @Override\r
-       public void doClaim(WriteGraph g, Object[] bindings) throws DatabaseException {\r
-               if(instruction.query(g, bindings)==IInstruction.FAILURE) {\r
-                       for(CreationInstruction var : variables) {\r
-                               bindings[var.variableId] = var.create(g, bindings);\r
-                               if(DEBUG)\r
-                                   System.out.println("@ newResource " + NameUtils.getSafeName(g, (Resource)bindings[var.variableId]));\r
-                       }\r
-                       instruction.doClaim(g, bindings);\r
-               }               \r
-       }\r
-\r
-       @Override\r
-       public void doDeny(WriteGraph g, Object[] bindings) throws DatabaseException {\r
-               Object continuation = instruction.query(g, bindings);\r
-               if(continuation != IInstruction.FAILURE)\r
-                       do {\r
-                               for(CreationInstruction var : variables)\r
-                                       g.deny((Resource)bindings[var.variableId]);\r
-                               continuation = instruction.next(g, bindings, continuation);\r
-                       } while(continuation != null && continuation != IInstruction.FAILURE);          \r
-       }\r
-\r
-       @Override\r
-       public void mapVariables(TIntIntHashMap map) {\r
-               instruction.mapVariables(map);\r
-               for(int i=0;i<variables.length;++i)\r
-                       variables[i].mapVariables(map);\r
-       }\r
-\r
-       @Override\r
-       public Object next(ReadGraph g, Object[] bindings, Object continuation) throws DatabaseException {\r
-               return instruction.next(g, bindings, continuation);\r
-       }\r
-\r
-       @Override\r
-       public Object query(ReadGraph g, Object[] bindings) throws DatabaseException {\r
-               return instruction.query(g, bindings);\r
-       }\r
-\r
-    @Override\r
-    public void toString(StringBuilder b, int indent) {\r
-        b.append('[');\r
-        b.append(']');\r
-    }\r
-\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.mapping.constraint.instructions;
+
+import gnu.trove.map.hash.TIntIntHashMap;
+import gnu.trove.set.hash.TIntHashSet;
+
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.WriteGraph;
+import org.simantics.db.common.utils.NameUtils;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.mapping.IContextualModification;
+
+public class TypedBracketInstruction implements IInstruction {
+
+       public static abstract class CreationInstruction {
+               protected int variableId;
+               
+               public CreationInstruction(int variableId) {
+                       this.variableId = variableId;
+               }
+
+               public abstract Resource create(WriteGraph g, Object[] bindings) throws DatabaseException;
+
+               public void mapVariables(TIntIntHashMap map) {
+                       variableId = map.get(variableId);                       
+               }
+               
+               public void collectVariables(TIntHashSet reads, TIntHashSet writes) {                   
+               }
+       }
+       
+       IInstruction instruction;
+       CreationInstruction[] variables;        
+       
+       public TypedBracketInstruction(IInstruction instruction, CreationInstruction ... variables) {
+               this.instruction = instruction;
+               this.variables = variables;
+       }       
+
+       @Override
+       public void collectVariables(TIntHashSet reads, TIntHashSet writes) {
+               instruction.collectVariables(reads, writes);
+               for(CreationInstruction var : variables)
+                       var.collectVariables(reads, writes);
+       }
+       
+       class Claim implements IContextualModification {
+                       
+               public Claim() {
+               }
+
+               @Override
+               public void perform(WriteGraph g, Object[] bindings) throws DatabaseException {
+                       for(CreationInstruction var : variables) {
+                               bindings[var.variableId] = var.create(g, bindings);
+                               if(DEBUG)
+                                   System.out.println("@ newResource " + NameUtils.getSafeName(g, (Resource)bindings[var.variableId]));
+                       }
+                       instruction.doClaim(g, bindings);       
+               }
+       }
+       
+       @Override
+       public IContextualModification claim(ReadGraph g, Object[] bindings) throws DatabaseException {
+               if(instruction.query(g, bindings)==IInstruction.FAILURE)
+                       return new Claim();
+               return null;
+       }
+       
+       class Deny implements IContextualModification {
+               Object continuation;
+               
+               public Deny(Object continuation) {
+                       this.continuation = continuation;
+               }
+
+               @Override
+               public void perform(WriteGraph g, Object[] bindings) throws DatabaseException {
+                       do {
+                               for(CreationInstruction var : variables)
+                                       g.deny((Resource)bindings[var.variableId]);
+                               continuation = instruction.next(g, bindings, continuation);
+                       } while(continuation != null && continuation != IInstruction.FAILURE);  
+               }
+       }
+       
+       @Override
+       public IContextualModification deny(ReadGraph g, Object[] bindings) throws DatabaseException {
+               Object continuation = instruction.query(g, bindings);
+               if(continuation != IInstruction.FAILURE)
+                       return new Deny(continuation);
+               return null;
+       }
+
+       @Override
+       public void doClaim(WriteGraph g, Object[] bindings) throws DatabaseException {
+               if(instruction.query(g, bindings)==IInstruction.FAILURE) {
+                       for(CreationInstruction var : variables) {
+                               bindings[var.variableId] = var.create(g, bindings);
+                               if(DEBUG)
+                                   System.out.println("@ newResource " + NameUtils.getSafeName(g, (Resource)bindings[var.variableId]));
+                       }
+                       instruction.doClaim(g, bindings);
+               }               
+       }
+
+       @Override
+       public void doDeny(WriteGraph g, Object[] bindings) throws DatabaseException {
+               Object continuation = instruction.query(g, bindings);
+               if(continuation != IInstruction.FAILURE)
+                       do {
+                               for(CreationInstruction var : variables)
+                                       g.deny((Resource)bindings[var.variableId]);
+                               continuation = instruction.next(g, bindings, continuation);
+                       } while(continuation != null && continuation != IInstruction.FAILURE);          
+       }
+
+       @Override
+       public void mapVariables(TIntIntHashMap map) {
+               instruction.mapVariables(map);
+               for(int i=0;i<variables.length;++i)
+                       variables[i].mapVariables(map);
+       }
+
+       @Override
+       public Object next(ReadGraph g, Object[] bindings, Object continuation) throws DatabaseException {
+               return instruction.next(g, bindings, continuation);
+       }
+
+       @Override
+       public Object query(ReadGraph g, Object[] bindings) throws DatabaseException {
+               return instruction.query(g, bindings);
+       }
+
+    @Override
+    public void toString(StringBuilder b, int indent) {
+        b.append('[');
+        b.append(']');
+    }
+
+}