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: */package org.apache.cxf.service.model;
019:
020: import java.util.Collection;
021: import java.util.Collections;
022: import java.util.List;
023: import java.util.Map;
024: import java.util.concurrent.ConcurrentHashMap;
025: import java.util.logging.Logger;
026:
027: import javax.xml.namespace.QName;
028:
029: import org.apache.cxf.common.i18n.Message;
030: import org.apache.cxf.common.logging.LogUtils;
031:
032: public class OperationInfo extends AbstractPropertiesHolder {
033: private static final Logger LOG = LogUtils
034: .getL7dLogger(OperationInfo.class);
035: InterfaceInfo intf;
036: QName opName;
037: String inName;
038: MessageInfo inputMessage;
039: String outName;
040: MessageInfo outputMessage;
041: Map<QName, FaultInfo> faults;
042: OperationInfo unwrappedOperation;
043: List<String> parameterOrdering;
044:
045: public OperationInfo() {
046: }
047:
048: OperationInfo(InterfaceInfo it, QName n) {
049: intf = it;
050: setName(n);
051: }
052:
053: OperationInfo(OperationInfo op) {
054: intf = op.getInterface();
055: setName(op.getName());
056: }
057:
058: /**
059: * Returns the name of the Operation.
060: * @return the name of the Operation
061: */
062: public QName getName() {
063: return opName;
064: }
065:
066: /**
067: * Sets the name of the operation.
068: * @param name the new name of the operation
069: */
070: public final void setName(QName name) {
071: if (name == null) {
072: throw new NullPointerException(
073: "Operation Name cannot be null.");
074: }
075: opName = name;
076: }
077:
078: public InterfaceInfo getInterface() {
079: return intf;
080: }
081:
082: public MessageInfo createMessage(QName nm) {
083: return new MessageInfo(this , nm);
084: }
085:
086: public MessageInfo getOutput() {
087: return outputMessage;
088: }
089:
090: public String getOutputName() {
091: return outName;
092: }
093:
094: public void setOutput(String nm, MessageInfo out) {
095: outName = nm;
096: outputMessage = out;
097: }
098:
099: public boolean hasOutput() {
100: return outputMessage != null;
101: }
102:
103: public MessageInfo getInput() {
104: return inputMessage;
105: }
106:
107: public String getInputName() {
108: return inName;
109: }
110:
111: public void setInput(String nm, MessageInfo in) {
112: inName = nm;
113: inputMessage = in;
114: }
115:
116: public boolean hasInput() {
117: return inputMessage != null;
118: }
119:
120: public boolean isOneWay() {
121: return inputMessage != null && outputMessage == null;
122: }
123:
124: public boolean isUnwrappedCapable() {
125: return unwrappedOperation != null;
126: }
127:
128: public OperationInfo getUnwrappedOperation() {
129: return unwrappedOperation;
130: }
131:
132: public void setUnwrappedOperation(OperationInfo op) {
133: unwrappedOperation = op;
134: }
135:
136: public boolean isUnwrapped() {
137: return false;
138: }
139:
140: /**
141: * Adds an fault to this operation.
142: *
143: * @param name the fault name.
144: */
145: public FaultInfo addFault(QName name, QName message) {
146: if (name == null) {
147: throw new NullPointerException(new Message(
148: "FAULT.NAME.NOT.NULL", LOG).toString());
149: }
150: if (faults != null && faults.containsKey(name)) {
151: throw new IllegalArgumentException(
152: new Message("DUPLICATED.FAULT.NAME", LOG,
153: new Object[] { name }).toString());
154: }
155: FaultInfo fault = new FaultInfo(name, message, this );
156: addFault(fault);
157: return fault;
158: }
159:
160: /**
161: * Adds a fault to this operation.
162: *
163: * @param fault the fault.
164: */
165: public synchronized void addFault(FaultInfo fault) {
166: if (faults == null) {
167: faults = new ConcurrentHashMap<QName, FaultInfo>(4);
168: }
169: faults.put(fault.getFaultName(), fault);
170: }
171:
172: /**
173: * Removes a fault from this operation.
174: *
175: * @param name the qualified fault name.
176: */
177: public void removeFault(QName name) {
178: if (faults != null) {
179: faults.remove(name);
180: }
181: }
182:
183: /**
184: * Returns the fault with the given name, if found.
185: *
186: * @param name the name.
187: * @return the fault; or <code>null</code> if not found.
188: */
189: public FaultInfo getFault(QName name) {
190: if (faults != null) {
191: return faults.get(name);
192: }
193: return null;
194: }
195:
196: /**
197: * Returns all faults for this operation.
198: *
199: * @return all faults.
200: */
201: public Collection<FaultInfo> getFaults() {
202: if (faults == null) {
203: return Collections.emptyList();
204: }
205: return Collections.unmodifiableCollection(faults.values());
206: }
207:
208: public void setParameterOrdering(List<String> o) {
209: this .parameterOrdering = o;
210: }
211:
212: public List<String> getParameterOrdering() {
213: return parameterOrdering;
214: }
215:
216: @Override
217: public String toString() {
218: return new StringBuilder().append("[OperationInfo: ").append(
219: opName).append("]").toString();
220: }
221: }
|