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  import org.apache.log4j.Logger;
11  import org.doomdark.uuid.UUIDGenerator;
12  
13  /***
14   * Default implementation of a creator.
15   */
16  public class DefaultCreator implements Creator {
17      private static final Logger logger = Logger.getLogger(DefaultCreator.class);
18  
19      /***
20         Generates a new workflow ID based on a random based UUID.
21         Due to datatype 'NCName' the workflow ID must begin with a letter or the underscore,
22         so this method prepends the prefix "WF_" to the UUID.
23       */
24      protected String newWorkflowID() {
25  	long t = System.currentTimeMillis();
26  	String id = "WF_"+UUIDGenerator.getInstance().generateRandomBasedUUID();
27  	if (logger.isDebugEnabled()) {
28          logger.debug("Workflow ID creation needed "+(System.currentTimeMillis()-t)+"ms.");
29      }
30  	return id;
31      }
32  
33      /***
34       * @return A new <code>StdToken</code>.
35       */
36      public Token newToken() {
37          return new StdToken();
38      }
39  
40      /***
41       * @return A new <code>StdToken</code> representing the specified boolean value.
42       */
43      public Token newToken(boolean value) {
44          return new StdToken(value);
45      }
46  
47      public Token newToken(boolean value, GenericProperties properties) {
48          return new StdToken(value,properties);
49      }
50  
51      public Token newToken(String id, boolean value, GenericProperties properties) {
52          return new StdToken(id,value,properties);
53      }
54  
55      /***
56       * @return A new <code>StdToken</code> representing the specified data.
57       */
58      public Token newToken(Data data) {
59          return new StdToken(data);
60      }
61  
62      public Token newToken(Data data, GenericProperties properties) {
63          return new StdToken(data,properties);
64      }
65  
66      public Token newToken(String id, Data data, GenericProperties properties) {
67          return new StdToken(id,data,properties);
68      }
69  
70      /***
71       * @return A new empty <code>JDOMData</code>.
72       */
73      public Data newData() {
74          return new JDOMData();
75      }
76  
77      /***
78       * @return A new <code>JDOMData</code> representing the specified data.
79       */
80      public Data newData(Object o) throws WorkflowFormatException {
81          return new JDOMData(o);
82      }
83  
84      /***
85       * @return A new <code>ArrayListPlace</code>.
86       */
87      public Place newPlace() {
88          return new ArrayListPlace();
89      }
90  
91      /***
92       * @return A new <code>StdOperation</code>.
93       */
94      public Operation newOperation() {
95          return new JDOMOperation();
96      }
97  
98      /***
99       * @return A new <code>ArrayListOperationClass</code>.
100      */
101     public OperationClass newOperationClass() {
102         return new ArrayListOperationClass();
103     }
104 
105     /***
106      * @return A new <code>StdCOperationCandidate</code>.
107      */
108     public OperationCandidate newOperationCandidate() {
109         return new StdOperationCandidate();
110     }
111 
112     /***
113      * @return A new <code>ArrayListTransition</code>.
114      */
115     public Transition newTransition() {
116         return new ArrayListTransition();
117     }
118 
119     /***
120      * @return A new <code>ArrayListWorkflow</code> with random based UUID.
121      */
122     public Workflow newWorkflow() {
123         return new ArrayListWorkflow(newWorkflowID());
124     }
125 
126     /***
127      * Creates a new instance of <code>ArrayListWorkflow</code> with the specified ID.
128      * The ID must begin with a letter ( a-z, A-Z ) or the underscore ( _ ) due to the
129      * XML datatype 'NCName'.
130      * @return A new <code>ArrayListWorkflow</code> with specified ID.
131      * @exception IllegalArgumentException If the ID does not begin with a letter or the underscore.
132      */
133     public Workflow newWorkflow(String ID) throws IllegalArgumentException {
134 	char c = ID.charAt(0);
135 	if (!(Character.isLetter(c) || c == '_'))
136 	    throw new IllegalArgumentException("Workflow ID must begin with letter or underscore.");
137         return new ArrayListWorkflow(ID);
138     }
139 
140     /***
141      * @return A new <code>StdEdge</code>.
142      */
143     public Edge newEdge() {
144         return new StdEdge();
145     }
146 
147     /***
148      * @return A new <code>ArrayListProperties</code>.
149      */
150     public GenericProperties newProperties() {
151          return new ArrayListProperties();
152     }
153     
154     /***
155      * @return A new <code>StdProperty</code> with the specified key and value.
156      */
157     public Property newProperty(String key, String value) {
158         return new StdProperty(key, value);
159     }
160 
161     /***
162      * @return A new <code>StdProperty</code>.
163      */
164     public Property newProperty() {
165         return new StdProperty();
166     }
167 }