View Javadoc

1   /*
2    * Copyright 2010 Fraunhofer Gesellschaft, Munich, Germany,
3    * for its Fraunhofer Institute for Computer Architecture and Software
4    * Technology (FIRST), Berlin, Germany. All rights reserved.
5    * http://www.first.fraunhofer.de/
6    */
7   
8   package net.kwfgrid.gworkflowdl.structure;
9   
10  /***
11   * Factory class to achieve independence of implementation classes.
12   * The factory uses a <code>Creator</code> as delegate for the actual object creation. The creator implementation can be
13   * changed by calling the static method <code>setCreator</code>. The default implementation used is a <code>DefaultCreator</code>.
14   */
15  public final class Factory {
16      private static Creator _creator;
17  
18      static {
19  	_creator = new DefaultCreator();
20  	// ToDo: read this from a config file??
21      }
22  
23      private Factory() {
24      }
25  
26      /***
27         Configure the factory to use the specified creator for object creation.
28         @param creator The creator the Factory shall use for object creation.
29       */
30      public static void setCreator(Creator creator) {
31  	_creator = creator;
32      }
33  
34      /***
35         Create a new workflow with the specified ID and the specified GWorkflowDL description.
36         The ID must begin with a letter ( a-z, A-Z ) or the underscore ( _ ) due to the
37         XML datatype 'NCName'.
38         @param id The ID of the new workflow.
39         @param xml The GWorkflowDL-Description used to initialize the Workflow.
40         @exception IllegalArgumentException If the ID does not begin with a letter or the underscore.
41       */
42      public static Workflow newWorkflow(String id, String xml) throws WorkflowFormatException, CapacityException, IllegalArgumentException {
43  	Workflow wf = newWorkflow(id);
44  	wf.fromXML(xml);
45  	return wf;
46      }
47  
48      /***
49         Create a new workflow with the specified ID.
50         The ID must begin with a letter ( a-z, A-Z ) or the underscore ( _ ) due to the
51         XML datatype 'NCName'.
52         The actual implementation depends on the creator used by the factory.
53         @exception IllegalArgumentException If the ID does not begin with a letter or the underscore.
54      */
55      public static Workflow newWorkflow(String id) throws IllegalArgumentException {
56  	return _creator.newWorkflow(id);
57      }
58  
59      /***
60         Create a new workflow.
61         The actual implementation depends on the creator used by the factory.
62         The creator is also responsible to create the ID of the workflow.
63       */
64      public static Workflow newWorkflow() {
65  	return _creator.newWorkflow();
66      }
67  
68      /***
69         Create a new token.
70         The actual implementation depends on the creator used by the factory.
71       */
72      public static Token newToken() {
73          return _creator.newToken();
74      }
75  
76      /***
77         Create a new control-token representing the specified boolean value.
78         The actual implementation depends on the creator used by the factory.
79         @param value The value of the new control token.
80       */
81      public static Token newToken(boolean value) {
82  	return _creator.newToken(value);
83      }
84  
85      /***
86         Create a new control-token representing the specified boolean value and properties.
87         The actual implementation depends on the creator used by the factory.
88         @param value The value of the new control token.
89         @param properties The properties of the new control token.
90       */
91      public static Token newToken(boolean value, GenericProperties properties) {
92  	return _creator.newToken(value,properties);
93      }
94  
95      /***
96         Create a new control-token representing the specified boolean value and properties.
97         The actual implementation depends on the creator used by the factory.
98         @param id The unique identifier of the token.
99         @param value The value of the new control token.
100        @param properties The properties of the new control token.
101      */
102     public static Token newToken(String id, boolean value, GenericProperties properties) {
103 	return _creator.newToken(id,value,properties);
104     }
105 
106     /***
107        Create a new data-token representing the specified data object.
108        The actual implementation depends on the creator used by the factory.
109        @param value The value of the new data token.
110      */
111     public static Token newToken(Data data) {
112 	return _creator.newToken(data);
113     }
114 
115     /***
116        Create a new data-token representing the specified data object and properties.
117        The actual implementation depends on the creator used by the factory.
118        @param value The value of the new data token.
119        @param properties The properties of the new data token.
120      */
121     public static Token newToken(Data data, GenericProperties properties) {
122 	return _creator.newToken(data,properties);
123     }
124 
125     /***
126        Create a new data-token representing the specified data object and properties.
127        The actual implementation depends on the creator used by the factory.
128        @param id The unique identifier of the token.
129        @param value The value of the new data token.
130        @param properties The properties of the new data token.
131      */
132     public static Token newToken(String id, Data data, GenericProperties properties) {
133 	return _creator.newToken(id,data,properties);
134     }
135 
136     /***
137        Create a new empty data Object.
138        The actual implementation depends on the creator used by the factory.
139      */
140     public static Data newData() {
141 	return _creator.newData();
142     }
143 
144     /***
145      * Create a new data Object representing the specified data object.
146      * The actual implementation depends on the creator used by the factory.
147      * @param o The object which contains the data.
148      * @return The data which encapsulates the object.
149      */
150     public static Data newData(Object o) throws WorkflowFormatException {
151         return _creator.newData(o);
152     }
153 
154     /***
155        Create a new place.
156        The actual implementation depends on the creator used by the factory.
157      */
158     public static Place newPlace() {
159 	return _creator.newPlace();
160     }
161 
162     /***
163        Create a new transition.
164        The actual implementation depends on the creator used by the factory.
165      */
166     public static Transition newTransition() {
167 	return _creator.newTransition();
168     }
169 
170     /***
171        Create a new operation.
172        The actual implementation depends on the creator used by the factory.
173      */
174     public static Operation newOperation() {
175         return _creator.newOperation();
176     }
177 
178     /***
179        Create a new operation class.
180        The actual implementation depends on the creator used by the factory.
181      */
182     public static OperationClass newOperationClass() {
183 	return _creator.newOperationClass();
184     }
185 
186     /***
187        Create a new StdOperationCandidate
188        The actual implementation depends on the creator used by the factory.
189      */
190     public static OperationCandidate newOperationCandidate() {
191 	return _creator.newOperationCandidate();
192     }
193 
194     /***
195        Create a new edge.
196        The actual implementation depends on the creator used by the factory.
197      */
198     public static Edge newEdge() {
199 	return _creator.newEdge();
200     }
201 
202     /***
203        Create new generic-properties .
204        The actual implementation depends on the creator used by the factory.
205      */
206     public static GenericProperties newProperties() {
207 	return _creator.newProperties();
208     }
209     
210     /***
211        Create a new property with the specified key and value.
212        The actual implementation depends on the creator used by the factory.
213        @param key The key of the new property.
214        @param value The value of the new property.
215      */
216     public static Property newProperty(String key, String value) {
217 	return _creator.newProperty(key, value);
218     }
219 
220     /***
221        Create a new property.
222        The actual implementation depends on the creator used by the factory.
223      */
224     public static Property newProperty() {
225 	return _creator.newProperty();
226     }
227 
228 }