001: /*
002: * Portions Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package com.sun.tools.internal.ws.wsdl.document;
027:
028: import java.util.ArrayList;
029: import java.util.HashMap;
030: import java.util.Iterator;
031: import java.util.List;
032: import java.util.Map;
033:
034: import javax.xml.namespace.QName;
035:
036: import com.sun.tools.internal.ws.wsdl.framework.Defining;
037: import com.sun.tools.internal.ws.wsdl.framework.Entity;
038: import com.sun.tools.internal.ws.wsdl.framework.EntityAction;
039: import com.sun.tools.internal.ws.wsdl.framework.GlobalEntity;
040: import com.sun.tools.internal.ws.wsdl.framework.Kind;
041: import com.sun.tools.internal.ws.wsdl.framework.ValidationException;
042:
043: /**
044: * Entity corresponding to the "message" WSDL element.
045: *
046: * @author WS Development Team
047: */
048: public class Message extends GlobalEntity {
049:
050: public Message(Defining defining) {
051: super (defining);
052: _parts = new ArrayList<MessagePart>();
053: _partsByName = new HashMap<String, MessagePart>();
054: }
055:
056: public void add(MessagePart part) {
057: if (_partsByName.get(part.getName()) != null)
058: throw new ValidationException("validation.duplicateName",
059: part.getName());
060: _partsByName.put(part.getName(), part);
061: _parts.add(part);
062: }
063:
064: public Iterator<MessagePart> parts() {
065: return _parts.iterator();
066: }
067:
068: public List<MessagePart> getParts() {
069: return _parts;
070: }
071:
072: public MessagePart getPart(String name) {
073: return _partsByName.get(name);
074: }
075:
076: public int numParts() {
077: return _parts.size();
078: }
079:
080: public Kind getKind() {
081: return Kinds.MESSAGE;
082: }
083:
084: public QName getElementName() {
085: return WSDLConstants.QNAME_MESSAGE;
086: }
087:
088: public Documentation getDocumentation() {
089: return _documentation;
090: }
091:
092: public void setDocumentation(Documentation d) {
093: _documentation = d;
094: }
095:
096: public void withAllSubEntitiesDo(EntityAction action) {
097: super .withAllSubEntitiesDo(action);
098:
099: for (Iterator iter = _parts.iterator(); iter.hasNext();) {
100: action.perform((Entity) iter.next());
101: }
102: }
103:
104: public void accept(WSDLDocumentVisitor visitor) throws Exception {
105: visitor.preVisit(this );
106: for (Iterator<MessagePart> iter = _parts.iterator(); iter
107: .hasNext();) {
108: iter.next().accept(visitor);
109: }
110: visitor.postVisit(this );
111: }
112:
113: public void validateThis() {
114: if (getName() == null) {
115: failValidation("validation.missingRequiredAttribute",
116: "name");
117: }
118: }
119:
120: private Documentation _documentation;
121: private List<MessagePart> _parts;
122: private Map<String, MessagePart> _partsByName;
123: }
|