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.phaseresolver;
021:
022: import org.apache.axis2.description.*;
023: import org.apache.axis2.engine.AxisConfiguration;
024: import org.apache.axis2.engine.Phase;
025: import org.apache.axis2.wsdl.WSDLConstants;
026:
027: import java.util.ArrayList;
028: import java.util.Iterator;
029: import java.util.List;
030:
031: /**
032: * Class PhaseResolver
033: */
034: public class PhaseResolver {
035:
036: private static final int IN_FLOW = 1;
037: private static final int OUT_FAULT_FLOW = 5;
038:
039: /**
040: * Field axisConfig
041: */
042: private AxisConfiguration axisConfig;
043:
044: /**
045: * Field phaseHolder
046: */
047: private PhaseHolder phaseHolder;
048:
049: /**
050: * default constructor , to obuild chains for GlobalDescription
051: *
052: * @param axisconfig
053: */
054: public PhaseResolver(AxisConfiguration axisconfig) {
055: this .axisConfig = axisconfig;
056: }
057:
058: private void engageModuleToFlow(Flow flow, List handlerChain)
059: throws PhaseException {
060: phaseHolder = new PhaseHolder(handlerChain);
061: if (flow != null) {
062: for (int j = 0; j < flow.getHandlerCount(); j++) {
063: HandlerDescription metadata = flow.getHandler(j);
064: phaseHolder.addHandler(metadata);
065: }
066: }
067: }
068:
069: private void engageModuleToOperation(AxisOperation axisOperation,
070: AxisModule axisModule, int flowType) throws PhaseException {
071: List phases = new ArrayList();
072: Flow flow = null;
073: switch (flowType) {
074: case PhaseMetadata.IN_FLOW: {
075: phases.addAll(axisConfig.getInFlowPhases());
076: phases.addAll(axisOperation.getRemainingPhasesInFlow());
077: flow = axisModule.getInFlow();
078: break;
079: }
080: case PhaseMetadata.OUT_FLOW: {
081: phases.addAll(axisOperation.getPhasesOutFlow());
082: phases.addAll(axisConfig.getOutFlowPhases());
083: flow = axisModule.getOutFlow();
084: break;
085: }
086: case PhaseMetadata.FAULT_OUT_FLOW: {
087: phases.addAll(axisOperation.getPhasesOutFaultFlow());
088: phases.addAll(axisConfig.getOutFaultFlowPhases());
089: flow = axisModule.getFaultOutFlow();
090: break;
091: }
092: case PhaseMetadata.FAULT_IN_FLOW: {
093: phases.addAll(axisOperation.getPhasesInFaultFlow());
094: phases.addAll(axisConfig.getInFaultFlowPhases());
095: flow = axisModule.getFaultInFlow();
096: break;
097: }
098: }
099: engageModuleToFlow(flow, phases);
100: }
101:
102: public void engageModuleToOperation(AxisOperation axisOperation,
103: AxisModule module) throws PhaseException {
104: for (int type = IN_FLOW; type < OUT_FAULT_FLOW; type++) {
105: engageModuleToOperation(axisOperation, module, type);
106: }
107: }
108:
109: /**
110: * To remove handlers from global chians this method can be used , first it take inflow
111: * of the module and then take handler one by one and then remove those handlers from
112: * global inchain ,
113: * the same procedure will be carry out for all the other flows as well.
114: *
115: * @param module
116: */
117: public void disengageModuleFromGlobalChains(AxisModule module) {
118: //INFLOW
119: Flow flow = module.getInFlow();
120: if (flow != null) {
121: for (int j = 0; j < flow.getHandlerCount(); j++) {
122: HandlerDescription handler = flow.getHandler(j);
123: removeHandlerfromaPhase(handler, axisConfig
124: .getInFlowPhases());
125: }
126: }
127: //OUTFLOW
128: flow = module.getOutFlow();
129: if (flow != null) {
130: for (int j = 0; j < flow.getHandlerCount(); j++) {
131: HandlerDescription handler = flow.getHandler(j);
132: removeHandlerfromaPhase(handler, axisConfig
133: .getOutFlowPhases());
134: }
135: }
136: //INFAULTFLOW
137: flow = module.getFaultInFlow();
138: if (flow != null) {
139: for (int j = 0; j < flow.getHandlerCount(); j++) {
140: HandlerDescription handler = flow.getHandler(j);
141: removeHandlerfromaPhase(handler, axisConfig
142: .getInFaultFlowPhases());
143: }
144: }
145: //OUTFAULTFLOW
146: flow = module.getFaultOutFlow();
147: if (flow != null) {
148: for (int j = 0; j < flow.getHandlerCount(); j++) {
149: HandlerDescription handler = flow.getHandler(j);
150: removeHandlerfromaPhase(handler, axisConfig
151: .getOutFaultFlowPhases());
152: }
153: }
154: }
155:
156: /**
157: * To remove handlers from operations chians this method can be used , first it take inflow
158: * of the module and then take handler one by one and then remove those handlers from
159: * global inchain ,
160: * the same procedure will be carry out for all the other flows as well.
161: *
162: * @param module
163: */
164: public void disengageModuleFromOperationChain(AxisModule module,
165: AxisOperation operation) {
166: //INFLOW
167: Flow flow = module.getInFlow();
168: if (flow != null) {
169: for (int j = 0; j < flow.getHandlerCount(); j++) {
170: HandlerDescription handler = flow.getHandler(j);
171: removeHandlerfromaPhase(handler, operation
172: .getRemainingPhasesInFlow());
173: }
174: }
175: //OUTFLOW
176: flow = module.getOutFlow();
177: if (flow != null) {
178: for (int j = 0; j < flow.getHandlerCount(); j++) {
179: HandlerDescription handler = flow.getHandler(j);
180: removeHandlerfromaPhase(handler, operation
181: .getPhasesOutFlow());
182: }
183: }
184: //INFAULTFLOW
185: flow = module.getFaultInFlow();
186: if (flow != null) {
187: for (int j = 0; j < flow.getHandlerCount(); j++) {
188: HandlerDescription handler = flow.getHandler(j);
189: removeHandlerfromaPhase(handler, operation
190: .getPhasesInFaultFlow());
191: }
192: }
193: //OUTFAULTFLOW
194: flow = module.getFaultOutFlow();
195: if (flow != null) {
196: for (int j = 0; j < flow.getHandlerCount(); j++) {
197: HandlerDescription handler = flow.getHandler(j);
198: removeHandlerfromaPhase(handler, operation
199: .getPhasesOutFaultFlow());
200: }
201: }
202: }
203:
204: /**
205: * To remove a single handler from a given list of phases
206: *
207: * @param handler
208: * @param phaseList
209: */
210: private void removeHandlerfromaPhase(HandlerDescription handler,
211: ArrayList phaseList) {
212: String phaseName = handler.getRules().getPhaseName();
213: Iterator phaseItr = phaseList.iterator();
214: while (phaseItr.hasNext()) {
215: Phase phase = (Phase) phaseItr.next();
216: if (phase.getPhaseName().equals(phaseName)) {
217: phase.removeHandler(handler);
218: break;
219: }
220: }
221: }
222:
223: public void engageModuleToMessage(AxisMessage axisMessage,
224: AxisModule axisModule) throws PhaseException {
225: String direction = axisMessage.getDirection();
226: AxisOperation axisOperation = axisMessage.getAxisOperation();
227: if (WSDLConstants.MESSAGE_LABEL_OUT_VALUE
228: .equalsIgnoreCase(direction)) {
229: engageModuleToOperation(axisOperation, axisModule,
230: PhaseMetadata.OUT_FLOW);
231: } else if (WSDLConstants.MESSAGE_LABEL_IN_VALUE
232: .equalsIgnoreCase(direction)) {
233: engageModuleToOperation(axisOperation, axisModule,
234: PhaseMetadata.IN_FLOW);
235: } else if (WSDLConstants.MESSAGE_LABEL_FAULT_VALUE
236: .equals(direction)) {
237: //TODO : Need to handle fault correctly
238: }
239: }
240: }
|