| /* |
| * Portions Copyright 2006 Sun Microsystems, Inc. All Rights Reserved. |
| * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| * |
| * This code is free software; you can redistribute it and/or modify it |
| * under the terms of the GNU General Public License version 2 only, as |
| * published by the Free Software Foundation. Sun designates this |
| * particular file as subject to the "Classpath" exception as provided |
| * by Sun in the LICENSE file that accompanied this code. |
| * |
| * This code is distributed in the hope that it will be useful, but WITHOUT |
| * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| * version 2 for more details (a copy is included in the LICENSE file that |
| * accompanied this code). |
| * |
| * You should have received a copy of the GNU General Public License version |
| * 2 along with this work; if not, write to the Free Software Foundation, |
| * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| * |
| * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
| * CA 95054 USA or visit www.sun.com if you need additional information or |
| * have any questions. |
| */ |
| |
| package com.sun.tools.internal.ws.wsdl.document; |
| |
| import java.util.ArrayList; |
| import java.util.HashMap; |
| import java.util.Iterator; |
| import java.util.List; |
| import java.util.Map; |
| |
| import javax.xml.namespace.QName; |
| |
| import com.sun.tools.internal.ws.wsdl.framework.Defining; |
| import com.sun.tools.internal.ws.wsdl.framework.Entity; |
| import com.sun.tools.internal.ws.wsdl.framework.EntityAction; |
| import com.sun.tools.internal.ws.wsdl.framework.GlobalEntity; |
| import com.sun.tools.internal.ws.wsdl.framework.Kind; |
| import com.sun.tools.internal.ws.wsdl.framework.ValidationException; |
| |
| /** |
| * Entity corresponding to the "message" WSDL element. |
| * |
| * @author WS Development Team |
| */ |
| public class Message extends GlobalEntity { |
| |
| public Message(Defining defining) { |
| super(defining); |
| _parts = new ArrayList<MessagePart>(); |
| _partsByName = new HashMap<String, MessagePart>(); |
| } |
| |
| public void add(MessagePart part) { |
| if (_partsByName.get(part.getName()) != null) |
| throw new ValidationException( |
| "validation.duplicateName", |
| part.getName()); |
| _partsByName.put(part.getName(), part); |
| _parts.add(part); |
| } |
| |
| public Iterator<MessagePart> parts() { |
| return _parts.iterator(); |
| } |
| |
| public List<MessagePart> getParts(){ |
| return _parts; |
| } |
| |
| public MessagePart getPart(String name) { |
| return _partsByName.get(name); |
| } |
| |
| public int numParts() { |
| return _parts.size(); |
| } |
| |
| public Kind getKind() { |
| return Kinds.MESSAGE; |
| } |
| |
| public QName getElementName() { |
| return WSDLConstants.QNAME_MESSAGE; |
| } |
| |
| public Documentation getDocumentation() { |
| return _documentation; |
| } |
| |
| public void setDocumentation(Documentation d) { |
| _documentation = d; |
| } |
| |
| public void withAllSubEntitiesDo(EntityAction action) { |
| super.withAllSubEntitiesDo(action); |
| |
| for (Iterator iter = _parts.iterator(); iter.hasNext();) { |
| action.perform((Entity) iter.next()); |
| } |
| } |
| |
| public void accept(WSDLDocumentVisitor visitor) throws Exception { |
| visitor.preVisit(this); |
| for (Iterator<MessagePart> iter = _parts.iterator(); iter.hasNext();) { |
| iter.next().accept(visitor); |
| } |
| visitor.postVisit(this); |
| } |
| |
| public void validateThis() { |
| if (getName() == null) { |
| failValidation("validation.missingRequiredAttribute", "name"); |
| } |
| } |
| |
| private Documentation _documentation; |
| private List<MessagePart> _parts; |
| private Map<String, MessagePart> _partsByName; |
| } |