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.ArrayList;
021: import java.util.Collections;
022: import java.util.LinkedHashMap;
023: import java.util.List;
024: import java.util.Map;
025:
026: import javax.xml.namespace.QName;
027:
028: public abstract class AbstractMessageContainer extends
029: AbstractPropertiesHolder {
030: protected QName mName;
031: private OperationInfo operation;
032: private Map<QName, MessagePartInfo> messageParts = new LinkedHashMap<QName, MessagePartInfo>(
033: 4);
034:
035: /**
036: * Initializes a new instance of the <code>MessagePartContainer</code>.
037: * @param operation the operation.
038: * @param nm
039: */
040: AbstractMessageContainer(OperationInfo op, QName nm) {
041: operation = op;
042: mName = nm;
043: }
044:
045: public QName getName() {
046: return mName;
047: }
048:
049: /**
050: * Returns the operation of this container.
051: *
052: * @return the operation.
053: */
054: public OperationInfo getOperation() {
055: return operation;
056: }
057:
058: /**
059: * Adds a message part to this container.
060: *
061: * @param name the qualified name of the message part
062: * @return name the newly created <code>MessagePartInfo</code> object
063: */
064: public MessagePartInfo addMessagePart(QName name) {
065: if (name == null) {
066: throw new IllegalArgumentException("Invalid name [" + name
067: + "]");
068: }
069:
070: MessagePartInfo part = new MessagePartInfo(name, this );
071: addMessagePart(part);
072: return part;
073: }
074:
075: public QName getMessagePartQName(String name) {
076: return new QName(this .getOperation().getInterface()
077: .getService().getTargetNamespace(), name);
078: }
079:
080: public MessagePartInfo addMessagePart(String name) {
081: return addMessagePart(getMessagePartQName(name));
082: }
083:
084: /**
085: * Adds a message part to this container.
086: *
087: * @param part the message part.
088: */
089: public void addMessagePart(MessagePartInfo part) {
090: part.setIndex(messageParts.size());
091: messageParts.put(part.getName(), part);
092: }
093:
094: public int getMessagePartIndex(MessagePartInfo part) {
095: int i = 0;
096: for (MessagePartInfo p : messageParts.values()) {
097: if (part == p) {
098: return i;
099: }
100: i++;
101: }
102: return -1;
103: }
104:
105: public MessagePartInfo getMessagePartByIndex(int i) {
106: for (MessagePartInfo p : messageParts.values()) {
107: if (p.getIndex() == i) {
108: return p;
109: }
110: }
111: return null;
112: }
113:
114: /**
115: * Removes an message part from this container.
116: *
117: * @param name the qualified message part name.
118: */
119: public void removeMessagePart(QName name) {
120: MessagePartInfo messagePart = getMessagePart(name);
121: if (messagePart != null) {
122: messageParts.remove(name);
123: }
124: }
125:
126: /**
127: * Returns the message part with the given name, if found.
128: *
129: * @param name the qualified name.
130: * @return the message part; or <code>null</code> if not found.
131: */
132: public MessagePartInfo getMessagePart(QName name) {
133: return messageParts.get(name);
134: }
135:
136: /**
137: * Returns all message parts for this message.
138: *
139: * @return all message parts.
140: */
141: public List<MessagePartInfo> getMessageParts() {
142: return Collections
143: .unmodifiableList(new ArrayList<MessagePartInfo>(
144: messageParts.values()));
145: }
146:
147: public int size() {
148: return messageParts.size();
149: }
150:
151: }
|