KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis2 > description > OperationDescription


1 package org.apache.axis2.description;
2
3 import org.apache.axis2.context.*;
4 import org.apache.axis2.engine.AxisError;
5 import org.apache.axis2.engine.AxisFault;
6 import org.apache.axis2.engine.MessageReceiver;
7 import org.apache.axis2.engine.Phase;
8 import org.apache.axis2.phaseresolver.PhaseMetadata;
9 import org.apache.axis2.phaseresolver.PhaseResolver;
10 import org.apache.wsdl.WSDLConstants;
11 import org.apache.wsdl.WSDLOperation;
12 import org.apache.wsdl.impl.WSDLOperationImpl;
13
14 import javax.xml.namespace.QName JavaDoc;
15 import java.util.ArrayList JavaDoc;
16 import java.util.Collection JavaDoc;
17 import java.util.Iterator JavaDoc;
18
19 /**
20  * @author chathura@opensource.lk
21  */

22 public class OperationDescription extends WSDLOperationImpl implements
23         ParameterInclude, WSDLOperation, DescriptionConstants,
24         WSDLConstants {
25
26     private MessageReceiver messageReceiver;
27     private ArrayList JavaDoc remainingPhasesInFlow;
28     private ArrayList JavaDoc phasesOutFlow;
29     private ArrayList JavaDoc phasesInFaultFlow;
30     private ArrayList JavaDoc phasesOutFaultFlow;
31
32     private int mep = MEP_CONSTANT_INVALID;
33
34     //To store deploytime module refs
35
private ArrayList JavaDoc modulerefs;
36
37     public OperationDescription() {
38         this.setMessageExchangePattern(MEP_URI_IN_OUT);
39         this.setComponentProperty(PARAMETER_KEY, new ParameterIncludeImpl());
40         this.setComponentProperty(MODULEREF_KEY, new ArrayList JavaDoc());
41
42         remainingPhasesInFlow = new ArrayList JavaDoc();
43         remainingPhasesInFlow.add(new Phase(PhaseMetadata.PHASE_POLICY_DETERMINATION));
44
45         phasesOutFlow = new ArrayList JavaDoc();
46         phasesOutFlow.add(new Phase(PhaseMetadata.PHASE_POLICY_DETERMINATION));
47         phasesOutFlow.add(new Phase(PhaseMetadata.PHASE_MESSAGE_OUT));
48
49         phasesInFaultFlow = new ArrayList JavaDoc();
50         phasesOutFaultFlow = new ArrayList JavaDoc();
51         modulerefs = new ArrayList JavaDoc();
52     }
53
54     public OperationDescription(QName JavaDoc name) {
55         this();
56         this.setName(name);
57     }
58
59     /**
60      * To ebgage a module it is reuired to use this method
61      *
62      * @param moduleref
63      * @throws AxisFault
64      */

65     public void engageModule(ModuleDescription moduleref) throws AxisFault {
66         if (moduleref == null) {
67             return;
68         }
69         if (moduleref != null) {
70             Collection JavaDoc collectionModule = (Collection JavaDoc) this.getComponentProperty(MODULEREF_KEY);
71             for (Iterator JavaDoc iterator = collectionModule.iterator(); iterator.hasNext();) {
72                 ModuleDescription modu = (ModuleDescription) iterator.next();
73                 if(modu.getName().equals(moduleref.getName())){
74                     throw new AxisFault(moduleref.getName().getLocalPart()+ " module has alredy engaged to the operation" +
75                             " operation terminated !!!");
76                 }
77
78             }
79         }
80         new PhaseResolver().engageModuleToOperation(this, moduleref);
81         Collection JavaDoc collectionModule = (Collection JavaDoc) this.getComponentProperty(MODULEREF_KEY);
82         collectionModule.add(moduleref);
83     }
84
85     public void addToEngageModuleList(ModuleDescription moduleName){
86         Collection JavaDoc collectionModule = (Collection JavaDoc) this.getComponentProperty(MODULEREF_KEY);
87         for (Iterator JavaDoc iterator = collectionModule.iterator(); iterator.hasNext();) {
88             ModuleDescription moduleDescription = (ModuleDescription) iterator.next();
89             if(moduleName.getName().equals(moduleDescription.getName())){
90                 return;
91             }
92         }
93         collectionModule.add(moduleName);
94     }
95
96
97
98
99     /*
100     * (non-Javadoc)
101     *
102     * @see org.apache.axis2.description.ServiceDescription#getEngadgedModules()
103     */

104
105     /**
106      * Method getEngadgedModules
107      *
108      * @return
109      */

110     public Collection JavaDoc getModules() {
111         return (Collection JavaDoc) this.getComponentProperty(MODULEREF_KEY);
112     }
113
114     /**
115      * Method addParameter
116      *
117      * @param param Parameter that will be added
118      */

119     public void addParameter(Parameter param) {
120         if (param == null) {
121             return;
122         }
123         ParameterIncludeImpl paramInclude = (ParameterIncludeImpl) this
124                 .getComponentProperty(PARAMETER_KEY);
125         paramInclude.addParameter(param);
126     }
127
128     /**
129      * Method getParameter
130      *
131      * @param name Name of the parameter
132      * @return
133      */

134     public Parameter getParameter(String JavaDoc name) {
135         ParameterIncludeImpl paramInclude = (ParameterIncludeImpl) this
136                 .getComponentProperty(PARAMETER_KEY);
137         return (Parameter) paramInclude.getParameter(name);
138     }
139
140     /**
141      * This method is responsible for finding a MEPContext for an incomming
142      * messages. An incomming message can be of two states.
143      * <p/>
144      * 1)This is a new incomming message of a given MEP. 2)This message is a
145      * part of an MEP which has already begun.
146      * <p/>
147      * The method is special cased for the two MEPs
148      * <p/>
149      * #IN_ONLY #IN_OUT
150      * <p/>
151      * for two reasons. First reason is the wide usage and the second being that
152      * the need for the MEPContext to be saved for further incomming messages.
153      * <p/>
154      * In the event that MEP of this operation is different from the two MEPs
155      * deafulted above the decession of creating a new or this message relates
156      * to a MEP which already in business is decided by looking at the WSA
157      * Relates TO of the incomming message.
158      *
159      * @param msgContext
160      * @return
161      */

162     public OperationContext findOperationContext(MessageContext msgContext,
163                                                  ServiceContext serviceContext) throws AxisFault {
164         OperationContext operationContext = null;
165
166         if (null == msgContext.getRelatesTo()) {
167             //Its a new incomming message so get the factory to create a new
168
// one
169
operationContext = OperationContextFactory.createMEPContext(getAxisSpecifMEPConstant(), this,
170                     serviceContext);
171
172         } else {
173             // So this message is part of an ongoing MEP
174
// operationContext =
175
ConfigurationContext configContext = msgContext.getSystemContext();
176             operationContext = configContext.getOperationContext(msgContext.getRelatesTo().getValue());
177
178             if (null == operationContext) {
179                 throw new AxisFault("Cannot relate the message in the operation :"
180                         + this.getName()
181                         + " :Unrelated RelatesTO value "
182                         + msgContext.getRelatesTo().getValue());
183             }
184
185         }
186
187         msgContext.getSystemContext().registerOperationContext(msgContext.getMessageID(), operationContext);
188         operationContext.addMessageContext(msgContext);
189         msgContext.setOperationContext(operationContext);
190         if (operationContext.isComplete()) {
191             operationContext.cleanup();
192         }
193
194         return operationContext;
195
196     }
197
198     public MessageReceiver getMessageReciever() {
199         return messageReceiver;
200     }
201
202     public void setMessageReciever(MessageReceiver messageReceiver) {
203         this.messageReceiver = messageReceiver;
204     }
205
206
207     /**
208      * This method will simply map the String URI of the Message exchange
209      * pattern to a integer. Further in the first lookup it will cash the looked
210      * up value so that the subsequent method calls will be extremely efficient.
211      *
212      * @return
213      */

214     public int getAxisSpecifMEPConstant() {
215         if (this.mep != MEP_CONSTANT_INVALID) {
216             return this.mep;
217         }
218
219         int temp = MEP_CONSTANT_INVALID;
220
221         if (MEP_URI_IN_OUT.equals(getMessageExchangePattern())) {
222             temp = MEP_CONSTANT_IN_OUT;
223         } else if (MEP_URI_IN_ONLY.equals(getMessageExchangePattern())) {
224             temp = MEP_CONSTANT_IN_ONLY;
225         } else if (MEP_URI_IN_OPTIONAL_OUT.equals(getMessageExchangePattern())) {
226             temp = MEP_CONSTANT_IN_OPTIONAL_OUT;
227         } else if (MEP_URI_OUT_IN.equals(getMessageExchangePattern())) {
228             temp = MEP_CONSTANT_OUT_IN;
229         } else if (MEP_URI_OUT_ONLY.equals(getMessageExchangePattern())) {
230             temp = MEP_CONSTANT_OUT_ONLY;
231         } else if (MEP_URI_OUT_OPTIONAL_IN.equals(getMessageExchangePattern())) {
232             temp = MEP_CONSTANT_OUT_OPTIONAL_IN;
233         } else if (MEP_URI_ROBUST_IN_ONLY.equals(getMessageExchangePattern())) {
234             temp = MEP_CONSTANT_ROBUST_IN_ONLY;
235         } else if (MEP_URI_ROBUST_OUT_ONLY.equals(getMessageExchangePattern())) {
236             temp = MEP_CONSTANT_ROBUST_OUT_ONLY;
237         }
238
239         if (temp == MEP_CONSTANT_INVALID) {
240             throw new AxisError("Could not Map the MEP URI to a axis MEP constant value");
241         }
242         this.mep = temp;
243         return this.mep;
244
245     }
246
247
248     /**
249      * @return
250      */

251     public ArrayList JavaDoc getPhasesInFaultFlow() {
252         return phasesInFaultFlow;
253     }
254
255     /**
256      * @return
257      */

258     public ArrayList JavaDoc getPhasesOutFaultFlow() {
259         return phasesOutFaultFlow;
260     }
261
262     /**
263      * @return
264      */

265     public ArrayList JavaDoc getPhasesOutFlow() {
266         return phasesOutFlow;
267     }
268
269     /**
270      * @return
271      */

272     public ArrayList JavaDoc getRemainingPhasesInFlow() {
273         return remainingPhasesInFlow;
274     }
275
276     /**
277      * @param list
278      */

279     public void setPhasesInFaultFlow(ArrayList JavaDoc list) {
280         phasesInFaultFlow = list;
281     }
282
283     /**
284      * @param list
285      */

286     public void setPhasesOutFaultFlow(ArrayList JavaDoc list) {
287         phasesOutFaultFlow = list;
288     }
289
290     /**
291      * @param list
292      */

293     public void setPhasesOutFlow(ArrayList JavaDoc list) {
294         phasesOutFlow = list;
295     }
296
297     /**
298      * @param list
299      */

300     public void setRemainingPhasesInFlow(ArrayList JavaDoc list) {
301         remainingPhasesInFlow = list;
302     }
303
304     public void addModule(QName JavaDoc moduleName) {
305         modulerefs.add(moduleName);
306     }
307
308     public ArrayList JavaDoc getModuleRefs() {
309         return modulerefs;
310     }
311
312
313 }
314
315
Popular Tags