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.Map;
023: import java.util.concurrent.ConcurrentHashMap;
024: import java.util.logging.Logger;
025:
026: import javax.xml.namespace.QName;
027:
028: import org.apache.cxf.common.i18n.Message;
029: import org.apache.cxf.common.logging.LogUtils;
030:
031: public class BindingInfo extends AbstractDescriptionElement {
032:
033: private static final Logger LOG = LogUtils
034: .getL7dLogger(BindingInfo.class);
035:
036: QName name;
037: ServiceInfo service;
038: final String bindingId;
039:
040: Map<QName, BindingOperationInfo> operations = new ConcurrentHashMap<QName, BindingOperationInfo>(
041: 4);
042:
043: public BindingInfo(ServiceInfo service, String bindingId) {
044: this .service = service;
045: this .bindingId = bindingId;
046: }
047:
048: public InterfaceInfo getInterface() {
049: return service.getInterface();
050: }
051:
052: public ServiceInfo getService() {
053: return service;
054: }
055:
056: public String getBindingId() {
057: return bindingId;
058: }
059:
060: public void setName(QName n) {
061: name = n;
062: }
063:
064: public QName getName() {
065: return name;
066: }
067:
068: private boolean nameEquals(String a, String b) {
069: if (a == null) {
070: // in case of input/output itself is empty
071: return true;
072: } else {
073: return "".equals(a) ? "".equals(b) : a.equals(b);
074: }
075: }
076:
077: public BindingOperationInfo buildOperation(QName opName,
078: String inName, String outName) {
079: for (OperationInfo op : getInterface().getOperations()) {
080: if (opName.equals(op.getName())
081: && nameEquals(inName, op.getInputName())
082: && nameEquals(outName, op.getOutputName())) {
083:
084: return new BindingOperationInfo(this , op);
085: }
086: }
087: return null;
088: }
089:
090: /**
091: * Adds an operation to this service.
092: *
093: * @param operation the operation.
094: */
095: public void addOperation(BindingOperationInfo operation) {
096: if (operation.getName() == null) {
097: throw new NullPointerException(new Message(
098: "BINDING.OPERATION.NAME.NOT.NULL", LOG).toString());
099: }
100: if (operations.containsKey(operation.getName())) {
101: throw new IllegalArgumentException(new Message(
102: "DUPLICATED.OPERATION.NAME", LOG,
103: new Object[] { operation.getName() }).toString());
104: }
105:
106: operations.put(operation.getName(), operation);
107: }
108:
109: /**
110: * Returns the operation info with the given name, if found.
111: *
112: * @param oname the name.
113: * @return the operation; or <code>null</code> if not found.
114: */
115: public BindingOperationInfo getOperation(QName oname) {
116: return operations.get(oname);
117: }
118:
119: /**
120: * Returns all operations for this service.
121: *
122: * @return all operations.
123: */
124: public Collection<BindingOperationInfo> getOperations() {
125: return Collections.unmodifiableCollection(operations.values());
126: }
127:
128: public BindingOperationInfo getOperation(OperationInfo oi) {
129: for (BindingOperationInfo b : operations.values()) {
130: if (b.getOperationInfo() == oi
131: || (b.isUnwrappedCapable() && b
132: .getUnwrappedOperation().getOperationInfo() == oi)) {
133: return b;
134: }
135: }
136:
137: return null;
138: }
139: }
|