src/share/jaxws_classes/com/sun/tools/internal/ws/processor/model/Message.java

Thu, 31 Aug 2017 15:18:52 +0800

author
aoqi
date
Thu, 31 Aug 2017 15:18:52 +0800
changeset 637
9c07ef4934dd
parent 534
6de45b31d047
parent 0
373ffda63c9a
permissions
-rw-r--r--

merge

     1 /*
     2  * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     8  * particular file as subject to the "Classpath" exception as provided
     9  * by Oracle in the LICENSE file that accompanied this code.
    10  *
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    14  * version 2 for more details (a copy is included in the LICENSE file that
    15  * accompanied this code).
    16  *
    17  * You should have received a copy of the GNU General Public License version
    18  * 2 along with this work; if not, write to the Free Software Foundation,
    19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    20  *
    21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    22  * or visit www.oracle.com if you need additional information or have any
    23  * questions.
    24  */
    26 package com.sun.tools.internal.ws.processor.model;
    28 import com.sun.tools.internal.ws.wsdl.framework.Entity;
    29 import com.sun.tools.internal.ws.wscompile.ErrorReceiver;
    30 import com.sun.tools.internal.ws.wscompile.AbortException;
    31 import com.sun.tools.internal.ws.resources.ModelMessages;
    33 import javax.xml.namespace.QName;
    34 import java.util.*;
    36 /**
    37  *
    38  * @author WS Development Team
    39  */
    40 public abstract class Message extends ModelObject {
    41     protected Message(com.sun.tools.internal.ws.wsdl.document.Message entity, ErrorReceiver receiver) {
    42         super(entity);
    43         setErrorReceiver(receiver);
    44     }
    46     public void addBodyBlock(Block b) {
    47         if (_bodyBlocks.containsKey(b.getName())) {
    48             errorReceiver.error(getEntity().getLocator(), ModelMessages.MODEL_PART_NOT_UNIQUE(((com.sun.tools.internal.ws.wsdl.document.Message)getEntity()).getName(), b.getName()));
    49             throw new AbortException();
    50         }
    51         _bodyBlocks.put(b.getName(), b);
    52         b.setLocation(Block.BODY);
    53     }
    55     public Iterator<Block> getBodyBlocks() {
    56         return _bodyBlocks.values().iterator();
    57     }
    59     public int getBodyBlockCount() {
    60         return _bodyBlocks.size();
    61     }
    63     /* serialization */
    64     public Map<QName, Block> getBodyBlocksMap() {
    65         return _bodyBlocks;
    66     }
    68     /* serialization */
    69     public void setBodyBlocksMap(Map<QName, Block> m) {
    70         _bodyBlocks = m;
    71     }
    73     public boolean isBodyEmpty() {
    74         return getBodyBlocks().hasNext();
    75     }
    77     public boolean isBodyEncoded() {
    78         boolean isEncoded = false;
    79         for (Iterator iter = getBodyBlocks(); iter.hasNext();) {
    80             Block bodyBlock = (Block) iter.next();
    81             if (bodyBlock.getType().isSOAPType()) {
    82                 isEncoded = true;
    83             }
    84         }
    85         return isEncoded;
    86     }
    88     public void addHeaderBlock(Block b) {
    89         if (_headerBlocks.containsKey(b.getName())) {
    90             errorReceiver.error(getEntity().getLocator(), ModelMessages.MODEL_PART_NOT_UNIQUE(((com.sun.tools.internal.ws.wsdl.document.Message)getEntity()).getName(), b.getName()));
    91             throw new AbortException();
    92         }
    93         _headerBlocks.put(b.getName(), b);
    94         b.setLocation(Block.HEADER);
    95     }
    97     public Iterator<Block> getHeaderBlocks() {
    98         return _headerBlocks.values().iterator();
    99     }
   101     public Collection<Block> getHeaderBlockCollection() {
   102         return _headerBlocks.values();
   103     }
   105     public int getHeaderBlockCount() {
   106         return _headerBlocks.size();
   107     }
   109     /* serialization */
   110     public Map<QName, Block> getHeaderBlocksMap() {
   111         return _headerBlocks;
   112     }
   114     /* serialization */
   115     public void setHeaderBlocksMap(Map<QName, Block> m) {
   116         _headerBlocks = m;
   117     }
   119     /** attachment block */
   120     public void addAttachmentBlock(Block b) {
   121         if (_attachmentBlocks.containsKey(b.getName())) {
   122             errorReceiver.error(getEntity().getLocator(), ModelMessages.MODEL_PART_NOT_UNIQUE(((com.sun.tools.internal.ws.wsdl.document.Message)getEntity()).getName(), b.getName()));
   123             throw new AbortException();
   124         }
   125         _attachmentBlocks.put(b.getName(), b);
   126         b.setLocation(Block.ATTACHMENT);
   127     }
   129     public void addUnboundBlock(Block b) {
   130         if (_unboundBlocks.containsKey(b.getName())) {
   131             return;
   132         }
   133         _unboundBlocks.put(b.getName(), b);
   134         b.setLocation(Block.UNBOUND);
   135     }
   137     public Iterator<Block> getUnboundBlocks() {
   138         return _unboundBlocks.values().iterator();
   139     }
   141     /* serialization */
   142     public Map<QName, Block> getUnboundBlocksMap() {
   143         return _unboundBlocks;
   144     }
   146     public int getUnboundBlocksCount() {
   147         return _unboundBlocks.size();
   148     }
   150     /* serialization */
   151     public void setUnboundBlocksMap(Map<QName, Block> m) {
   152         _unboundBlocks = m;
   153     }
   156     public Iterator<Block> getAttachmentBlocks() {
   157         return _attachmentBlocks.values().iterator();
   158     }
   160     public int getAttachmentBlockCount () {
   161         return _attachmentBlocks.size();
   162     }
   164         /* serialization */
   165     public Map<QName, Block> getAttachmentBlocksMap() {
   166         return _attachmentBlocks;
   167     }
   169     /* serialization */
   170     public void setAttachmentBlocksMap(Map<QName, Block> m) {
   171         _attachmentBlocks = m;
   172     }
   174     public void addParameter(Parameter p) {
   175         if (_parametersByName.containsKey(p.getName())) {
   176             errorReceiver.error(getEntity().getLocator(), ModelMessages.MODEL_PARAMETER_NOTUNIQUE(p.getName(), p.getName()));
   177             throw new AbortException();
   178         }
   179         _parameters.add(p);
   180         String name = p.getCustomName() != null ? p.getCustomName() : p.getName();
   181         _parametersByName.put(name, p);
   182     }
   184     public Parameter getParameterByName(String name) {
   185         if (_parametersByName.size() != _parameters.size()) {
   186             initializeParametersByName();
   187         }
   188         return _parametersByName.get(name);
   189     }
   191     public Iterator<Parameter> getParameters() {
   192         return _parameters.iterator();
   193     }
   195     /* serialization */
   196     public List<Parameter> getParametersList() {
   197         return _parameters;
   198     }
   200     /* serialization */
   201     public void setParametersList(List<Parameter> l) {
   202         _parameters = l;
   203     }
   205     private void initializeParametersByName() {
   206         _parametersByName = new HashMap();
   207         if (_parameters != null) {
   208             for (Iterator iter = _parameters.iterator(); iter.hasNext();) {
   209                 Parameter param = (Parameter) iter.next();
   210                 if (param.getName() != null &&
   211                     _parametersByName.containsKey(param.getName())) {
   212                     errorReceiver.error(getEntity().getLocator(), ModelMessages.MODEL_PARAMETER_NOTUNIQUE(param.getName(), param.getName()));
   213                     throw new AbortException();
   214                 }
   215                 _parametersByName.put(param.getName(), param);
   216             }
   217         }
   218     }
   220     public Set<Block> getAllBlocks(){
   221         Set<Block> blocks = new HashSet<Block>();
   222         blocks.addAll(_bodyBlocks.values());
   223         blocks.addAll(_headerBlocks.values());
   224         blocks.addAll(_attachmentBlocks.values());
   225         return blocks;
   226     }
   228     private Map<QName, Block> _attachmentBlocks = new HashMap<QName, Block>();
   229     private Map<QName, Block> _bodyBlocks = new HashMap<QName, Block>();
   230     private Map<QName, Block> _headerBlocks = new HashMap<QName, Block>();
   231     private Map<QName, Block> _unboundBlocks = new HashMap<QName, Block>();
   232     private List<Parameter> _parameters = new ArrayList<Parameter>();
   233     private Map<String, Parameter> _parametersByName = new HashMap<String, Parameter>();
   234 }

mercurial