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.gwes;
9   
10  import net.kwfgrid.gworkflowdl.structure.Token;
11  import net.kwfgrid.gworkflowdl.structure.Factory;
12  import net.kwfgrid.gworkflowdl.structure.WorkflowFormatException;
13  import net.kwfgrid.gworkflowdl.structure.Data;
14  import net.kwfgrid.gwes.util.HTMLFilter;
15  
16  import org.apache.log4j.Logger;
17  
18  /**
19   * @author Andreas Hoheisel
20   *         (<a href="http://www.andreas-hoheisel.de">www.andreas-hoheisel.de</a>)
21   * @version $Id: SOAPFault.java 1452 2010-12-22 16:09:58Z hoheisel $
22   */
23  public class SOAPFault {
24  
25      /**
26       * log4j logger.
27       */
28      final static Logger logger = Logger.getLogger(SOAPFault.class);
29  
30      /**
31       * mandatory Code.Value element information item
32       */
33      String codeValue;
34  
35      /**
36       * mandatory Reason element information item
37       */
38      String reason;
39  
40      /**
41       * optional Node element information item
42       */
43      String node;
44  
45      /**
46       * optional Role element information item
47       */
48      String role;
49  
50      /**
51       * optional Detail element information item
52       */
53      String detail;
54      
55      /**
56       *  exit Code of program which caused soap fault
57       */
58      Integer exitCode;
59      
60      private static final String ELEMENT_DATA_BEGIN = "<data xmlns=\"http://www.gridworkflow.org/gworkflowdl\">";
61      private static final String ELEMENT_FAULT_BEGIN = "<soapenv:Fault xmlns:soapenv=\"http://www.w3.org/2003/05/soap-envelope\">";
62      private static final String ELEMENT_CODE_BEGIN = "<soapenv:Code>";
63      private static final String ELEMENT_VALUE_BEGIN = "<soapenv:Value>";
64      private static final String ELEMENT_VALUE_END = "</soapenv:Value>";
65      private static final String ELEMENT_CODE_END = "</soapenv:Code>";
66      private static final String ELEMENT_REASON_TEXT_BEGIN = "<soapenv:Reason><soapenv:Text xml:lang=\"en\">";
67      private static final String ELEMENT_REASON_TEXT_END = "</soapenv:Text></soapenv:Reason>";
68      private static final String ELEMENT_NODE_BEGIN = "<soapenv:Node>";
69      private static final String ELEMENT_NODE_END = "</soapenv:Node>";
70      private static final String ELEMENT_ROLE_BEGIN = "<soapenv:Role>";
71      private static final String ELEMENT_ROLE_END = "</soapenv:Role>";
72      private static final String ELEMENT_DETAIL_BEGIN = "<soapenv:Detail>";
73      private static final String ELEMENT_EXIT_CODE_BEGIN = "<exitCode>";
74      private static final String ELEMENT_EXIT_CODE_END = "</exitCode>";
75      private static final String ELEMENT_DETAIL_END = "</soapenv:Detail>";
76      private static final String ELEMENT_FAULT_END = "</soapenv:Fault>";
77      private static final String ELEMENT_DATA_END = "</data>";
78  
79  
80      public SOAPFault(String codeValue, String reason) {
81          this.codeValue = HTMLFilter.filter(codeValue);
82          this.reason = HTMLFilter.filter(reason);
83      }
84  
85      public SOAPFault(String codeValue, String reason, int exitCode) {
86          this.codeValue = HTMLFilter.filter(codeValue);
87          this.reason = HTMLFilter.filter(reason);
88      	this.exitCode = exitCode;
89      }
90  
91      /**
92       * Converts this SOAPFault into a Token object.
93       * @return The corresponding Token.
94       */
95      public Token toToken() throws WorkflowFormatException {
96          Data data = Factory.newData();
97          data.fromXML(toTokenString());
98          Token token = Factory.newToken(data);
99          return token;
100     }
101 
102     /**
103      * Converts this SOAPFault into a token String, beginning with "&lt;data ..."
104      * @return The corresponding fault token as string.
105      */
106     public String toTokenString() {
107         StringBuffer xml = new StringBuffer()
108                 .append(ELEMENT_DATA_BEGIN)
109                 .append(ELEMENT_FAULT_BEGIN)
110                 .append(ELEMENT_CODE_BEGIN)
111                 .append(ELEMENT_VALUE_BEGIN)
112                 .append(codeValue)
113                 .append(ELEMENT_VALUE_END)
114                 .append(ELEMENT_CODE_END)
115                 .append(ELEMENT_REASON_TEXT_BEGIN)
116                 .append(reason)
117                 .append(ELEMENT_REASON_TEXT_END);
118         if (node!=null) {
119             xml.append(ELEMENT_NODE_BEGIN)
120                 .append(node)
121                 .append(ELEMENT_NODE_END);
122         }
123         if (role!=null) {
124             xml.append(ELEMENT_ROLE_BEGIN)
125                 .append(role)
126                 .append(ELEMENT_ROLE_END);
127         }
128         if (detail!=null) {
129             xml.append(ELEMENT_DETAIL_BEGIN)
130                 .append(detail);
131             if (exitCode != null) {
132             	xml.append(ELEMENT_EXIT_CODE_BEGIN)
133                 .append(exitCode.intValue())
134                 .append(ELEMENT_EXIT_CODE_END);
135             }
136                 xml.append(ELEMENT_DETAIL_END);
137         }
138         xml.append(ELEMENT_FAULT_END);
139         xml.append(ELEMENT_DATA_END);
140 
141         return xml.toString();
142     }
143 
144     public String getCodeValue() {
145         return codeValue;
146     }
147 
148     public void setCodeValue(String codeValue) {
149         this.codeValue = HTMLFilter.filter(codeValue);
150     }
151 
152     public String getReason() {
153         return reason;
154     }
155 
156     public void setReason(String reason) {
157         this.reason = HTMLFilter.filter(reason);
158     }
159 
160     public String getNode() {
161         return node;
162     }
163 
164     public void setNode(String node) {
165         this.node = HTMLFilter.filter(node);
166     }
167 
168     public String getRole() {
169         return role;
170     }
171 
172     public void setRole(String role) {
173         this.role = HTMLFilter.filter(role);
174     }
175 
176     public String getDetail() {
177         return detail;
178     }
179 
180     public void setDetail(String detail) {
181         this.detail = detail;
182     }
183 
184     public void setExitCode(int exitCode) {
185     	this.exitCode = exitCode;
186     }
187     
188     public int getExitCode() {
189     	return this.exitCode;
190     }
191 }