001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common Development
008: * and Distribution License("CDDL") (collectively, the "License"). You
009: * may not use this file except in compliance with the License. You can obtain
010: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
011: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
012: * language governing permissions and limitations under the License.
013: *
014: * When distributing the software, include this License Header Notice in each
015: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
016: * Sun designates this particular file as subject to the "Classpath" exception
017: * as provided by Sun in the GPL Version 2 section of the License file that
018: * accompanied this code. If applicable, add the following below the License
019: * Header, with the fields enclosed by brackets [] replaced by your own
020: * identifying information: "Portions Copyrighted [year]
021: * [name of copyright owner]"
022: *
023: * Contributor(s):
024: *
025: * If you wish your version of this file to be governed by only the CDDL or
026: * only the GPL Version 2, indicate your decision by adding "[Contributor]
027: * elects to include this software in this distribution under the [CDDL or GPL
028: * Version 2] license." If you don't indicate a single choice of license, a
029: * recipient has the option to distribute your version of this file under
030: * either the CDDL, the GPL Version 2 or to extend the choice of license to
031: * its licensees as provided above. However, if you add GPL Version 2 code
032: * and therefore, elected the GPL Version 2 license, then the option applies
033: * only if the new code is made subject to such option by the copyright
034: * holder.
035: */
036:
037: package com.sun.tools.ws.processor.model;
038:
039: import com.sun.tools.ws.wsdl.framework.Entity;
040: import com.sun.tools.ws.wscompile.ErrorReceiver;
041: import com.sun.tools.ws.wscompile.AbortException;
042: import com.sun.tools.ws.resources.ModelMessages;
043:
044: import javax.xml.namespace.QName;
045: import java.util.*;
046:
047: /**
048: *
049: * @author WS Development Team
050: */
051: public abstract class Message extends ModelObject {
052: protected Message(com.sun.tools.ws.wsdl.document.Message entity,
053: ErrorReceiver receiver) {
054: super (entity);
055: setErrorReceiver(receiver);
056: }
057:
058: public void addBodyBlock(Block b) {
059: if (_bodyBlocks.containsKey(b.getName())) {
060: errorReceiver
061: .error(
062: getEntity().getLocator(),
063: ModelMessages
064: .MODEL_PART_NOT_UNIQUE(
065: ((com.sun.tools.ws.wsdl.document.Message) getEntity())
066: .getName(), b
067: .getName()));
068: throw new AbortException();
069: }
070: _bodyBlocks.put(b.getName(), b);
071: b.setLocation(Block.BODY);
072: }
073:
074: public Iterator<Block> getBodyBlocks() {
075: return _bodyBlocks.values().iterator();
076: }
077:
078: public int getBodyBlockCount() {
079: return _bodyBlocks.size();
080: }
081:
082: /* serialization */
083: public Map<QName, Block> getBodyBlocksMap() {
084: return _bodyBlocks;
085: }
086:
087: /* serialization */
088: public void setBodyBlocksMap(Map<QName, Block> m) {
089: _bodyBlocks = m;
090: }
091:
092: public boolean isBodyEmpty() {
093: return getBodyBlocks().hasNext();
094: }
095:
096: public boolean isBodyEncoded() {
097: boolean isEncoded = false;
098: for (Iterator iter = getBodyBlocks(); iter.hasNext();) {
099: Block bodyBlock = (Block) iter.next();
100: if (bodyBlock.getType().isSOAPType()) {
101: isEncoded = true;
102: }
103: }
104: return isEncoded;
105: }
106:
107: public void addHeaderBlock(Block b) {
108: if (_headerBlocks.containsKey(b.getName())) {
109: errorReceiver
110: .error(
111: getEntity().getLocator(),
112: ModelMessages
113: .MODEL_PART_NOT_UNIQUE(
114: ((com.sun.tools.ws.wsdl.document.Message) getEntity())
115: .getName(), b
116: .getName()));
117: throw new AbortException();
118: }
119: _headerBlocks.put(b.getName(), b);
120: b.setLocation(Block.HEADER);
121: }
122:
123: public Iterator<Block> getHeaderBlocks() {
124: return _headerBlocks.values().iterator();
125: }
126:
127: public Collection<Block> getHeaderBlockCollection() {
128: return _headerBlocks.values();
129: }
130:
131: public int getHeaderBlockCount() {
132: return _headerBlocks.size();
133: }
134:
135: /* serialization */
136: public Map<QName, Block> getHeaderBlocksMap() {
137: return _headerBlocks;
138: }
139:
140: /* serialization */
141: public void setHeaderBlocksMap(Map<QName, Block> m) {
142: _headerBlocks = m;
143: }
144:
145: /** attachment block */
146: public void addAttachmentBlock(Block b) {
147: if (_attachmentBlocks.containsKey(b.getName())) {
148: errorReceiver
149: .error(
150: getEntity().getLocator(),
151: ModelMessages
152: .MODEL_PART_NOT_UNIQUE(
153: ((com.sun.tools.ws.wsdl.document.Message) getEntity())
154: .getName(), b
155: .getName()));
156: throw new AbortException();
157: }
158: _attachmentBlocks.put(b.getName(), b);
159: b.setLocation(Block.ATTACHMENT);
160: }
161:
162: public void addUnboundBlock(Block b) {
163: if (_unboundBlocks.containsKey(b.getName())) {
164: return;
165: }
166: _unboundBlocks.put(b.getName(), b);
167: b.setLocation(Block.UNBOUND);
168: }
169:
170: public Iterator<Block> getUnboundBlocks() {
171: return _unboundBlocks.values().iterator();
172: }
173:
174: /* serialization */
175: public Map<QName, Block> getUnboundBlocksMap() {
176: return _unboundBlocks;
177: }
178:
179: public int getUnboundBlocksCount() {
180: return _unboundBlocks.size();
181: }
182:
183: /* serialization */
184: public void setUnboundBlocksMap(Map<QName, Block> m) {
185: _unboundBlocks = m;
186: }
187:
188: public Iterator<Block> getAttachmentBlocks() {
189: return _attachmentBlocks.values().iterator();
190: }
191:
192: public int getAttachmentBlockCount() {
193: return _attachmentBlocks.size();
194: }
195:
196: /* serialization */
197: public Map<QName, Block> getAttachmentBlocksMap() {
198: return _attachmentBlocks;
199: }
200:
201: /* serialization */
202: public void setAttachmentBlocksMap(Map<QName, Block> m) {
203: _attachmentBlocks = m;
204: }
205:
206: public void addParameter(Parameter p) {
207: if (_parametersByName.containsKey(p.getName())) {
208: errorReceiver.error(getEntity().getLocator(),
209: ModelMessages.MODEL_PARAMETER_NOTUNIQUE(
210: p.getName(), p.getName()));
211: throw new AbortException();
212: }
213: _parameters.add(p);
214: _parametersByName.put(p.getName(), p);
215: }
216:
217: public Parameter getParameterByName(String name) {
218: if (_parametersByName.size() != _parameters.size()) {
219: initializeParametersByName();
220: }
221: return _parametersByName.get(name);
222: }
223:
224: public Iterator<Parameter> getParameters() {
225: return _parameters.iterator();
226: }
227:
228: /* serialization */
229: public List<Parameter> getParametersList() {
230: return _parameters;
231: }
232:
233: /* serialization */
234: public void setParametersList(List<Parameter> l) {
235: _parameters = l;
236: }
237:
238: private void initializeParametersByName() {
239: _parametersByName = new HashMap();
240: if (_parameters != null) {
241: for (Iterator iter = _parameters.iterator(); iter.hasNext();) {
242: Parameter param = (Parameter) iter.next();
243: if (param.getName() != null
244: && _parametersByName.containsKey(param
245: .getName())) {
246: errorReceiver.error(getEntity().getLocator(),
247: ModelMessages.MODEL_PARAMETER_NOTUNIQUE(
248: param.getName(), param.getName()));
249: throw new AbortException();
250: }
251: _parametersByName.put(param.getName(), param);
252: }
253: }
254: }
255:
256: public Set<Block> getAllBlocks() {
257: Set<Block> blocks = new HashSet<Block>();
258: blocks.addAll(_bodyBlocks.values());
259: blocks.addAll(_headerBlocks.values());
260: blocks.addAll(_attachmentBlocks.values());
261: return blocks;
262: }
263:
264: private Map<QName, Block> _attachmentBlocks = new HashMap<QName, Block>();
265: private Map<QName, Block> _bodyBlocks = new HashMap<QName, Block>();
266: private Map<QName, Block> _headerBlocks = new HashMap<QName, Block>();
267: private Map<QName, Block> _unboundBlocks = new HashMap<QName, Block>();
268: private List<Parameter> _parameters = new ArrayList<Parameter>();
269: private Map<String, Parameter> _parametersByName = new HashMap<String, Parameter>();
270: }
|