001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */
019:
020: package org.apache.axis2.deployment.util;
021:
022: import org.apache.axiom.om.OMElement;
023: import org.apache.axis2.AxisFault;
024: import org.apache.axis2.deployment.DeploymentErrorMsgs;
025: import org.apache.axis2.deployment.DeploymentException;
026: import org.apache.axis2.description.AxisOperation;
027: import org.apache.axis2.description.HandlerDescription;
028: import org.apache.axis2.engine.Handler;
029: import org.apache.axis2.engine.Phase;
030: import org.apache.axis2.i18n.Messages;
031: import org.apache.axis2.phaseresolver.PhaseException;
032: import org.apache.axis2.phaseresolver.PhaseMetadata;
033:
034: import javax.xml.namespace.QName;
035: import java.util.ArrayList;
036: import java.util.Iterator;
037:
038: public class PhasesInfo {
039: private ArrayList INPhases;
040: private ArrayList IN_FaultPhases;
041: private ArrayList OUTPhases;
042: private ArrayList OUT_FaultPhases;
043:
044: public PhasesInfo() {
045: INPhases = new ArrayList();
046: IN_FaultPhases = new ArrayList();
047: OUTPhases = new ArrayList();
048: OUT_FaultPhases = new ArrayList();
049: }
050:
051: /**
052: * To copy phase information from one to another
053: *
054: * @param phase
055: */
056: private Phase copyPhase(Phase phase) throws DeploymentException {
057: Phase newPhase = new Phase(phase.getPhaseName());
058: Iterator handlers = phase.getHandlers().iterator();
059:
060: while (handlers.hasNext()) {
061: try {
062: Handler handlerDescription = (Handler) handlers.next();
063:
064: newPhase
065: .addHandler(handlerDescription.getHandlerDesc());
066: } catch (PhaseException e) {
067: throw new DeploymentException(e);
068: }
069: }
070:
071: return newPhase;
072: }
073:
074: HandlerDescription makeHandler(OMElement handlerElement) {
075: String name = handlerElement
076: .getAttributeValue(new QName("name"));
077: QName qname = handlerElement.resolveQName(name);
078: HandlerDescription desc = new HandlerDescription(qname
079: .getLocalPart());
080: String className = handlerElement.getAttributeValue(new QName(
081: "class"));
082:
083: desc.setClassName(className);
084:
085: return desc;
086: }
087:
088: public Phase makePhase(OMElement phaseElement)
089: throws PhaseException {
090: String phaseName = phaseElement.getAttributeValue(new QName(
091: "name"));
092: Phase phase = new Phase(phaseName);
093: Iterator children = phaseElement.getChildElements();
094:
095: while (children.hasNext()) {
096: OMElement handlerElement = (OMElement) children.next();
097: HandlerDescription handlerDesc = makeHandler(handlerElement);
098:
099: phase.addHandler(handlerDesc);
100: }
101:
102: return phase;
103: }
104:
105: public ArrayList getGlobalInflow() throws DeploymentException {
106: ArrayList globalphase = new ArrayList();
107: boolean foundDispatchPhase = false;
108: for (int i = 0; i < INPhases.size(); i++) {
109: Phase phase = (Phase) INPhases.get(i);
110: String phaseName = phase.getPhaseName();
111: if (!foundDispatchPhase) {
112: if (PhaseMetadata.PHASE_DISPATCH.equals(phaseName)) {
113: foundDispatchPhase = true;
114: }
115: globalphase.add(phase);
116: }
117: }
118: if (!foundDispatchPhase) {
119: throw new DeploymentException(
120: Messages
121: .getMessage(DeploymentErrorMsgs.DISPATCH_PHASE_NOT_FOUND));
122: }
123: return globalphase;
124: }
125:
126: public ArrayList getGlobalOutPhaseList() throws DeploymentException {
127: /**
128: * I have assumed that PolicyDetermination and MessageProcessing are global out phase
129: */
130: ArrayList globalPhaseList = new ArrayList();
131:
132: boolean messageOut = false;
133: for (int i = 0; i < OUTPhases.size(); i++) {
134: Phase phase = (Phase) OUTPhases.get(i);
135: String phaseName = phase.getPhaseName();
136: if (!messageOut) {
137: if (PhaseMetadata.PHASE_MESSAGE_OUT.equals(phaseName)) {
138: messageOut = true;
139: globalPhaseList.add(copyPhase(phase));
140: }
141: } else {
142: globalPhaseList.add(copyPhase(phase));
143: }
144: }
145: return globalPhaseList;
146: }
147:
148: public ArrayList getINPhases() {
149: return INPhases;
150: }
151:
152: public ArrayList getIN_FaultPhases() {
153: return IN_FaultPhases;
154: }
155:
156: public ArrayList getOUTPhases() {
157: return OUTPhases;
158: }
159:
160: public ArrayList getOUT_FaultPhases() throws DeploymentException {
161: ArrayList globalPhaseList = new ArrayList();
162: boolean messageOut = false;
163: for (int i = 0; i < OUT_FaultPhases.size(); i++) {
164: Phase phase = (Phase) OUT_FaultPhases.get(i);
165: String phaseName = phase.getPhaseName();
166: if (!messageOut) {
167: if (PhaseMetadata.PHASE_MESSAGE_OUT.equals(phaseName)) {
168: messageOut = true;
169: globalPhaseList.add(copyPhase(phase));
170: }
171: } else {
172: globalPhaseList.add(copyPhase(phase));
173: }
174: }
175: return globalPhaseList;
176: }
177:
178: public ArrayList getOperationInFaultPhases()
179: throws DeploymentException {
180: ArrayList operationINPhases = new ArrayList();
181: boolean foundDispathPhase = false;
182: for (int i = 0; i < IN_FaultPhases.size(); i++) {
183: Phase phase = (Phase) IN_FaultPhases.get(i);
184: String phaseName = phase.getPhaseName();
185: if (foundDispathPhase) {
186: operationINPhases.add(copyPhase(phase));
187: }
188: if (PhaseMetadata.PHASE_DISPATCH.equals(phaseName)) {
189: foundDispathPhase = true;
190: }
191: }
192: return operationINPhases;
193: }
194:
195: public ArrayList getGlobalInFaultPhases()
196: throws DeploymentException {
197: ArrayList globalInfaultphase = new ArrayList();
198: boolean foundDispatchPhase = false;
199: for (int i = 0; i < IN_FaultPhases.size(); i++) {
200: Phase phase = (Phase) IN_FaultPhases.get(i);
201: String phaseName = phase.getPhaseName();
202: if (!foundDispatchPhase) {
203: if (PhaseMetadata.PHASE_DISPATCH.equals(phaseName)) {
204: foundDispatchPhase = true;
205: }
206: globalInfaultphase.add(phase);
207: }
208: }
209: if (!foundDispatchPhase) {
210: throw new DeploymentException(
211: Messages
212: .getMessage(DeploymentErrorMsgs.DISPATCH_PHASE_NOT_FOUND));
213: }
214: return globalInfaultphase;
215: }
216:
217: public ArrayList getOperationInPhases() throws DeploymentException {
218: ArrayList operationINPhases = new ArrayList();
219: boolean foundDispathPhase = false;
220: for (int i = 0; i < INPhases.size(); i++) {
221: Phase phase = (Phase) INPhases.get(i);
222: String phaseName = phase.getPhaseName();
223: if (foundDispathPhase) {
224: operationINPhases.add(copyPhase(phase));
225: }
226: if (PhaseMetadata.PHASE_DISPATCH.equals(phaseName)) {
227: foundDispathPhase = true;
228: }
229: }
230: return operationINPhases;
231: }
232:
233: public ArrayList getOperationOutFaultPhases()
234: throws DeploymentException {
235: ArrayList operationFaultOutPhases = new ArrayList();
236: for (int i = 0; i < OUT_FaultPhases.size(); i++) {
237: Phase phase = (Phase) OUT_FaultPhases.get(i);
238: String phaseName = phase.getPhaseName();
239: if (PhaseMetadata.PHASE_MESSAGE_OUT.equals(phaseName)) {
240: break;
241: }
242: operationFaultOutPhases.add(copyPhase(phase));
243:
244: }
245: return operationFaultOutPhases;
246: }
247:
248: public ArrayList getOperationOutPhases() throws DeploymentException {
249: ArrayList oprationOUTPhases = new ArrayList();
250:
251: for (int i = 0; i < OUTPhases.size(); i++) {
252: Phase phase = (Phase) OUTPhases.get(i);
253: String phaseName = phase.getPhaseName();
254: if (PhaseMetadata.PHASE_MESSAGE_OUT.equals(phaseName)) {
255: break;
256: }
257: oprationOUTPhases.add(copyPhase(phase));
258: }
259:
260: return oprationOUTPhases;
261: }
262:
263: public void setINPhases(ArrayList INPhases) {
264: this .INPhases = INPhases;
265: }
266:
267: public void setIN_FaultPhases(ArrayList IN_FaultPhases) {
268: this .IN_FaultPhases = IN_FaultPhases;
269: }
270:
271: public void setOUTPhases(ArrayList OUTPhases) {
272: this .OUTPhases = OUTPhases;
273: }
274:
275: public void setOUT_FaultPhases(ArrayList OUT_FaultPhases) {
276: this .OUT_FaultPhases = OUT_FaultPhases;
277: }
278:
279: public void setOperationPhases(AxisOperation axisOperation)
280: throws AxisFault {
281: if (axisOperation != null) {
282: try {
283: axisOperation
284: .setRemainingPhasesInFlow(getOperationInPhases());
285: axisOperation.setPhasesOutFlow(getOperationOutPhases());
286: axisOperation
287: .setPhasesInFaultFlow(getOperationInFaultPhases());
288: axisOperation
289: .setPhasesOutFaultFlow(getOperationOutFaultPhases());
290: } catch (DeploymentException e) {
291: throw AxisFault.makeFault(e);
292: }
293: }
294: }
295: }
|