1   /*
2    * Copyright (c) 2005, The K-Wf Grid Consortium
3    * Fraunhofer Institute for Computer Architecture and Software Technology
4    * See http://www.kwfgrid.eu and http://www.first.fraunhofer.de for more details.
5    */
6   package net.kwfgrid.gworkflowdl.protocol.structure;
7   
8   import net.kwfgrid.gworkflowdl.structure.*;
9   
10  /***
11     Support class for <code>TestXUpdate</code>.
12   */
13  public class MyCreator extends DefaultProtocolCreator {	
14      public MyCreator(Creator delegate) {
15  	super(delegate);
16      }
17      
18      public Token newToken() { 	    
19  	Token t = super.newToken();
20  	Place p = newPlace();
21  	try {
22  	    p.addToken(t);
23  	} catch (Exception x) {
24  	    throw new IllegalArgumentException("Could not add token to place.");
25  	}
26  	return t;
27      }
28      
29      public Token newToken(boolean value) { 
30  	Token t = super.newToken(value);
31  	Place p = newPlace();
32  	try {
33  	    p.addToken(t);
34  	} catch (Exception x) {
35  	    throw new IllegalArgumentException("Could not add token to place.");
36  	}
37  	return t;
38      }
39  
40      public Token newToken(boolean value, GenericProperties properties) {
41          Token t = super.newToken(value,properties);
42          Place p = newPlace();
43          try {
44              p.addToken(t);
45          } catch (Exception x) {
46              throw new IllegalArgumentException("Could not add token to place.");
47          }
48          return t;
49      }
50  
51      public Token newToken(String id, boolean value, GenericProperties properties) {
52          Token t = super.newToken(id,value,properties);
53          Place p = newPlace();
54          try {
55              p.addToken(t);
56          } catch (Exception x) {
57              throw new IllegalArgumentException("Could not add token to place.");
58          }
59          return t;
60      }
61  
62      public Token newToken(Data data) {
63  	Token t = super.newToken(data);
64  	Place p = newPlace();
65  	try {
66  	    p.addToken(t);
67  	} catch (Exception x) {
68  	    throw new IllegalArgumentException("Could not add token to place.");
69  	}
70  	return t;
71      }
72  
73      public Token newToken(Data data, GenericProperties properties) {
74          Token t = super.newToken(data,properties);
75          Place p = newPlace();
76          try {
77              p.addToken(t);
78          } catch (Exception x) {
79              throw new IllegalArgumentException("Could not add token to place.");
80          }
81          return t;
82      }
83  
84      public Token newToken(String id, Data data, GenericProperties properties) {
85          Token t = super.newToken(id,data,properties);
86          Place p = newPlace();
87          try {
88              p.addToken(t);
89          } catch (Exception x) {
90              throw new IllegalArgumentException("Could not add token to place.");
91          }
92          return t;
93      }
94  
95      public Place newPlace() {
96  	Place pl = super.newPlace();
97  	pl.setID("placeID");
98  	Workflow wf = super.newWorkflow();
99  	wf.addPlace(pl);
100 	return pl;
101     }
102 
103     public OperationCandidate newOperationCandidate() {
104 	OperationCandidate o = super.newOperationCandidate();
105 	OperationClass oo = newOperationClass();
106 	oo.setOperationCandidates(new OperationCandidate[] { o } );
107 	return o;
108     }
109     
110     public OperationClass newOperationClass() {
111 	OperationClass o = super.newOperationClass();
112 	Operation oo = newOperation();
113 	oo.set(o);
114 	return o;
115     }
116 
117     public Operation newOperation() {
118 	Operation o = super.newOperation();
119 	Transition t = newTransition();
120 	t.setOperation(o);
121 	return o;
122     }
123     
124     public Transition newTransition() { 
125 	Transition t = super.newTransition();
126 	t.setID("transitionID");
127 	Workflow wf = super.newWorkflow();
128 	wf.addTransition(t);
129 	return t;
130     }
131     
132     public Edge newEdge() { 
133 	Edge e = super.newEdge();
134 	Transition t = newTransition();
135 	Place p = super.newPlace();
136 	p.setID("theplaceid");
137 	e.setPlace(p);
138 	t.addInEdge(e);
139 	return e;
140     }
141     
142     public GenericProperties newProperties() { 
143 	Workflow wf = super.newWorkflow();
144 	return wf.getProperties();
145     }
146     
147     public Property newProperty(String key, String value) { 
148 	GenericProperties gp = newProperties();
149 	Property p = super.newProperty(key, value);
150 	gp.addProperty(p);
151 	return p;
152     }
153     
154     public Property newProperty() { 
155 	GenericProperties gp = newProperties();
156 	Property p = super.newProperty("", "");
157 	gp.addProperty(p);
158 	return p;
159     }
160 }