View Javadoc

1   package net.kwfgrid.gworkflowdl.analysis;
2   
3   import net.kwfgrid.gworkflowdl.structure.*;
4   
5   /***
6    * Created by IntelliJ IDEA.
7    * User: hans
8    * Date: 26.10.2005
9    * Time: 15:20:50
10   * To change this template use File | Settings | File Templates.
11   */
12  public class SmartCopy {
13  
14      public static String newString(String s) {
15          if (s == null) {
16              return null;
17          } else {
18              return new String(s);
19          }
20      }
21  
22  
23      public static Workflow copy(Workflow wf) {
24  
25          //System.out.println("in SmartCopy wf " + ComplexityReducer.checkPlaces(wf));
26  
27          Workflow copy = Factory.newWorkflow();
28  
29          copy.setProperties(copy(wf.getProperties()));
30  
31          Place[] ps = wf.getPlaces();
32  
33          for (int i = 0; i < ps.length; i++) {
34              Place p = copy(ps[i]);
35              copy.addPlace(p);
36          }
37  
38          Transition[] ts = wf.getTransitions();
39          for (int i = 0; i < ts.length; i++) {
40              Transition t = copy(ts[i], copy);
41              copy.addTransition(t);
42          }
43  
44          //System.out.println("in SmartCopy " + ComplexityReducer.checkPlaces(copy));
45          return copy;
46      }
47  
48      public static GenericProperties copy(GenericProperties prop) {
49          GenericProperties p = Factory.newProperties();
50          String[] keys = prop.keys();
51          for (int i = 0; i < keys.length; i++) {
52              String val = prop.get(keys[i]);
53              p.put(newString(keys[i]), newString(val));
54          }
55          return p;
56      }
57  
58      public static Place copy(Place pl) {
59          Place p = Factory.newPlace();
60          p.setID(newString(pl.getID()));
61          p.setProperties(copy(pl.getProperties()));
62          try {
63              p.setCapacity(pl.getCapacity());
64              for (int i = 0; i < pl.getTokenNumber(); i++) {
65                  p.addToken(Factory.newToken(true));
66              }
67          } catch (CapacityException e) {
68          }
69          return p;
70      }
71  
72       public static Transition copy(Transition tr, Workflow wf) {
73  
74          Transition t = Factory.newTransition();
75          t.setID(newString(tr.getID()));
76          t.setProperties(copy(tr.getProperties()));
77  
78          Edge[] inEs = tr.getInEdges();
79          for (int i = 0; i < inEs.length; i++) {
80              String id  = inEs[i].getPlace().getID();
81              Edge e = Factory.newEdge();
82              e.setPlace(wf.getPlace(id));
83              t.addInEdge(e);
84          }
85          Edge[] outEs = tr.getOutEdges();
86          for (int i = 0; i < outEs.length; i++) {
87              String id  = outEs[i].getPlace().getID();
88              Edge e = Factory.newEdge();
89              e.setPlace(wf.getPlace(id));
90              t.addOutEdge(e);
91          }
92  
93          return t;
94      }
95  }