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: package org.apache.axis2.description;
020:
021: import org.apache.axiom.om.util.UUIDGenerator;
022: import org.apache.axis2.AxisFault;
023: import org.apache.axis2.context.MessageContext;
024: import org.apache.axis2.context.OperationContext;
025: import org.apache.axis2.i18n.Messages;
026: import org.apache.axis2.wsdl.WSDLConstants;
027:
028: import javax.xml.namespace.QName;
029: import java.util.ArrayList;
030: import java.util.HashMap;
031:
032: /**
033: * This class is to keep common methods and properties in InOut and OutIn axisOperation
034: */
035: public abstract class TwoChannelAxisOperation extends AxisOperation {
036:
037: protected AxisMessage inFaultMessage;
038: protected AxisMessage outFaultMessage;
039: protected AxisMessage inMessage;
040: protected AxisMessage outMessage;
041:
042: public TwoChannelAxisOperation() {
043: super ();
044: //setup a temporary name
045: QName tmpName = new QName(this .getClass().getName() + "_"
046: + UUIDGenerator.getUUID());
047: this .setName(tmpName);
048: createMessages();
049: }
050:
051: public TwoChannelAxisOperation(QName name) {
052: super (name);
053: createMessages();
054: }
055:
056: private void createMessages() {
057: inMessage = new AxisMessage();
058: inMessage.setDirection(WSDLConstants.WSDL_MESSAGE_DIRECTION_IN);
059: inMessage.setParent(this );
060: addChild("inMessage", inMessage);
061:
062: inFaultMessage = new AxisMessage();
063: inFaultMessage.setParent(this );
064:
065: outFaultMessage = new AxisMessage();
066: outFaultMessage.setParent(this );
067:
068: outMessage = new AxisMessage();
069: outMessage
070: .setDirection(WSDLConstants.WSDL_MESSAGE_DIRECTION_OUT);
071: outMessage.setParent(this );
072: addChild("outMessage", outMessage);
073: }
074:
075: public void addMessage(AxisMessage message, String label) {
076: if (WSDLConstants.MESSAGE_LABEL_OUT_VALUE.equals(label)) {
077: addChild("outMessage", message);
078: } else if (WSDLConstants.MESSAGE_LABEL_IN_VALUE.equals(label)) {
079: addChild("inMessage", message);
080: } else if (WSDLConstants.MESSAGE_LABEL_FAULT_VALUE
081: .equals(label)) {
082: addChild("faultMessage", message);
083: } else {
084: throw new UnsupportedOperationException(
085: "Not yet implemented");
086: }
087: }
088:
089: public AxisMessage getMessage(String label) {
090: if (WSDLConstants.MESSAGE_LABEL_OUT_VALUE.equals(label)) {
091: return (AxisMessage) getChild("outMessage");
092: } else if (WSDLConstants.MESSAGE_LABEL_IN_VALUE.equals(label)) {
093: return (AxisMessage) getChild("inMessage");
094: } else {
095: throw new UnsupportedOperationException(
096: "Not yet implemented");
097: }
098: }
099:
100: public void addFaultMessageContext(MessageContext msgContext,
101: OperationContext opContext) throws AxisFault {
102: HashMap mep = opContext.getMessageContexts();
103: MessageContext faultMessageCtxt = (MessageContext) mep
104: .get(MESSAGE_LABEL_FAULT_VALUE);
105:
106: if (faultMessageCtxt != null) {
107: throw new AxisFault(Messages.getMessage("mepcompleted"));
108: } else {
109: mep.put(MESSAGE_LABEL_FAULT_VALUE, msgContext);
110: opContext.setComplete(true);
111: opContext.cleanup();
112: }
113:
114: }
115:
116: public ArrayList getPhasesInFaultFlow() {
117: return inFaultMessage.getMessageFlow();
118: }
119:
120: public ArrayList getPhasesOutFaultFlow() {
121: return outFaultMessage.getMessageFlow();
122: }
123:
124: public ArrayList getPhasesOutFlow() {
125: return outMessage.getMessageFlow();
126: }
127:
128: public ArrayList getRemainingPhasesInFlow() {
129: return inMessage.getMessageFlow();
130: }
131:
132: public void setPhasesInFaultFlow(ArrayList list) {
133: inFaultMessage.setMessageFlow(list);
134: }
135:
136: public void setPhasesOutFaultFlow(ArrayList list) {
137: outFaultMessage.setMessageFlow(list);
138: }
139:
140: public void setPhasesOutFlow(ArrayList list) {
141: outMessage.setMessageFlow(list);
142: }
143:
144: public void setRemainingPhasesInFlow(ArrayList list) {
145: inMessage.setMessageFlow(list);
146: }
147: }
|