View Javadoc

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.gwui.workflow;
7   
8   import net.kwfgrid.gworkflowdl.structure.*;
9   import net.kwfgrid.gworkflowdl.protocol.xml.GWDLNamespace;
10  
11  /***
12     Some constants from the XML schema and utility methods.
13   */
14  public class XMLUtilities implements GWDLNamespace {
15      ///
16      /// Constants in the XML document.
17      /// ....................................................................................................
18  
19      /*** Type string of an effect place */
20      public static final String EFFECT = "effect";
21      /*** Type string of a data place */
22      public static final String DATA = "data";
23      /*** Key of a property containing status information. */
24      public static final String STATUS = "status";
25      /*** Possible value of the status property of a workflow. */
26      public static final String WORKFLOW_STATUS_UNDEFINED = "UNDEFINED";
27      /*** Possible value of the status property of a workflow. */
28      public static final String WORKFLOW_STATUS_INITIATED = "INITIATED";
29      /*** Possible value of the status property of a workflow. */
30      public static final String WORKFLOW_STATUS_ACTIVE = "ACTIVE";
31      /*** Possible value of the status property of a workflow. */
32      public static final String WORKFLOW_STATUS_RUNNING = "RUNNING";
33      /*** Possible value of the status property of a workflow. */
34      public static final String WORKFLOW_STATUS_TERMINATED = "TERMINATED";
35      /*** Possible value of the status property of a workflow. */
36      public static final String WORKFLOW_STATUS_COMPLETED = "COMPLETED";
37      /*** Possible value of the status property of a workflow. */
38      public static final String WORKFLOW_STATUS_SUSPENDED = "SUSPENDED";
39  
40      ///
41      /// String representation of tag & attribute names.
42      /// ....................................................................................................
43  
44      public static final String CONDITION = "condition";
45      public static final String TOKEN = "token";
46      public static final String PROPERTY = "property";
47      public static final String WORKFLOW = "workflow";
48      public static final String TRANSITION = "transition";
49      public static final String PLACE = "place";
50      public static final String READ_PLACE = "readPlace";
51      public static final String WRITE_PLACE = "writePlace";
52      public static final String INPUT_PLACE = "inputPlace";
53      public static final String OUTPUT_PLACE = "outputPlace";
54  
55      ///
56      /// Utility methods.
57      /// ....................................................................................................
58  
59      public static boolean needsDecision(Transition t) {
60  	Property[] props = t.getProperties().getProperties();;
61  	for (int i=0; i<props.length; i++) {
62  	    if (props[i].getKey().indexOf("decision")==0) {
63  		return true;
64  	    }
65  	}
66  	return false;
67      }
68  
69      public static boolean equalNamespace(String ns1, String ns2) {
70  	return
71  	    (ns1 == null && ns2 == null) ||
72  	    (ns1 != null && ns1.equals(ns2));
73      }
74  
75      public static boolean isGWorkflowDLNamespace(String ns) {
76  	return
77  	    (GWDL_NS == null && ns == null) ||
78  	    (GWDL_NS != null && GWDL_NS.equals(ns));
79      }
80      
81      public static boolean isEffectPlace(Place p) {
82  	return EFFECT.equals(p.getTokenType());	
83      }
84  
85      public static boolean isControlPlace(Place p) {
86  	return p.getTokenType()==null;
87      }
88  
89      public static boolean isDataPlace(Place p) {
90  	return DATA.equals(p.getTokenType());	
91      }
92  
93      /***
94         Parse a human readable name from an owl String.
95         @return a human readable name included in <code>owl</code> or "unknown" if a name could not be parsed.
96      */
97      public static String parseName(String owl) {
98  	if (owl==null) return "unknown";
99  	if (owl.lastIndexOf("#")>=0) {
100 	    String part1 = owl.substring(owl.lastIndexOf("/")+1, owl.lastIndexOf("#"));
101 	    String part2 = owl.substring(owl.lastIndexOf("#")+1);
102 	    return part1+": "+part2;
103 	} else {
104 	    return owl.substring(owl.lastIndexOf("/")+1);
105 	}
106     }      
107 
108     private static final String BLACK = "control Transition";
109     private static final String RED = "abstract Transition";
110     private static final String YELLOW = "Transition with defined Operation Class";
111     private static final String BLUE = "Transition with Operation Candidates";
112     private static final String GREEN = "executable Transition";
113 
114     public static String getAbstractionLevelDescription(Transition t) {
115 	int level = t.getAbstractionLevel();
116 	if (Operation.RED == level) {
117 	    return RED;
118 	} else if (Operation.BLUE == level) {
119 	    return BLUE;
120 	} else if (Operation.GREEN == level) {
121 	    return GREEN;
122 	} else if (Operation.YELLOW == level) {
123 	    return YELLOW;
124 	} else { 
125 	    return BLACK;
126 	}
127     } 
128 }