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.processor.model;
027:
028: import java.util.ArrayList;
029: import java.util.Collection;
030: import java.util.HashMap;
031: import java.util.HashSet;
032: import java.util.Iterator;
033: import java.util.List;
034: import java.util.Map;
035: import java.util.Set;
036:
037: import javax.xml.namespace.QName;
038:
039: /**
040: *
041: * @author WS Development Team
042: */
043: public abstract class Message extends ModelObject {
044:
045: public void addBodyBlock(Block b) {
046: if (_bodyBlocks.containsKey(b.getName())) {
047: throw new ModelException("model.uniqueness");
048: }
049: _bodyBlocks.put(b.getName(), b);
050: b.setLocation(Block.BODY);
051: }
052:
053: public Iterator<Block> getBodyBlocks() {
054: return _bodyBlocks.values().iterator();
055: }
056:
057: public int getBodyBlockCount() {
058: return _bodyBlocks.size();
059: }
060:
061: /* serialization */
062: public Map<QName, Block> getBodyBlocksMap() {
063: return _bodyBlocks;
064: }
065:
066: /* serialization */
067: public void setBodyBlocksMap(Map<QName, Block> m) {
068: _bodyBlocks = m;
069: }
070:
071: public boolean isBodyEmpty() {
072: return getBodyBlocks().hasNext();
073: }
074:
075: public boolean isBodyEncoded() {
076: boolean isEncoded = false;
077: for (Iterator iter = getBodyBlocks(); iter.hasNext();) {
078: Block bodyBlock = (Block) iter.next();
079: if (bodyBlock.getType().isSOAPType()) {
080: isEncoded = true;
081: }
082: }
083: return isEncoded;
084: }
085:
086: public void addHeaderBlock(Block b) {
087: if (_headerBlocks.containsKey(b.getName())) {
088: throw new ModelException("model.uniqueness");
089: }
090: _headerBlocks.put(b.getName(), b);
091: b.setLocation(Block.HEADER);
092: }
093:
094: public Iterator<Block> getHeaderBlocks() {
095: return _headerBlocks.values().iterator();
096: }
097:
098: public Collection<Block> getHeaderBlockCollection() {
099: return _headerBlocks.values();
100: }
101:
102: public int getHeaderBlockCount() {
103: return _headerBlocks.size();
104: }
105:
106: /* serialization */
107: public Map<QName, Block> getHeaderBlocksMap() {
108: return _headerBlocks;
109: }
110:
111: /* serialization */
112: public void setHeaderBlocksMap(Map<QName, Block> m) {
113: _headerBlocks = m;
114: }
115:
116: /** attachment block */
117: public void addAttachmentBlock(Block b) {
118: if (_attachmentBlocks.containsKey(b.getName())) {
119: throw new ModelException("model.uniqueness");
120: }
121: _attachmentBlocks.put(b.getName(), b);
122: b.setLocation(Block.ATTACHMENT);
123: }
124:
125: public void addUnboundBlock(Block b) {
126: if (_unboundBlocks.containsKey(b.getName())) {
127: return;
128: }
129: _unboundBlocks.put(b.getName(), b);
130: b.setLocation(Block.UNBOUND);
131: }
132:
133: public Iterator<Block> getUnboundBlocks() {
134: return _unboundBlocks.values().iterator();
135: }
136:
137: /* serialization */
138: public Map<QName, Block> getUnboundBlocksMap() {
139: return _unboundBlocks;
140: }
141:
142: public int getUnboundBlocksCount() {
143: return _unboundBlocks.size();
144: }
145:
146: /* serialization */
147: public void setUnboundBlocksMap(Map<QName, Block> m) {
148: _unboundBlocks = m;
149: }
150:
151: public Iterator<Block> getAttachmentBlocks() {
152: return _attachmentBlocks.values().iterator();
153: }
154:
155: public int getAttachmentBlockCount() {
156: return _attachmentBlocks.size();
157: }
158:
159: /* serialization */
160: public Map<QName, Block> getAttachmentBlocksMap() {
161: return _attachmentBlocks;
162: }
163:
164: /* serialization */
165: public void setAttachmentBlocksMap(Map<QName, Block> m) {
166: _attachmentBlocks = m;
167: }
168:
169: public void addParameter(Parameter p) {
170: if (_parametersByName.containsKey(p.getName())) {
171: throw new ModelException("model.uniqueness");
172: }
173: _parameters.add(p);
174: _parametersByName.put(p.getName(), p);
175: }
176:
177: public Parameter getParameterByName(String name) {
178: if (_parametersByName.size() != _parameters.size()) {
179: initializeParametersByName();
180: }
181: return (Parameter) _parametersByName.get(name);
182: }
183:
184: public Iterator<Parameter> getParameters() {
185: return _parameters.iterator();
186: }
187:
188: /* serialization */
189: public List<Parameter> getParametersList() {
190: return _parameters;
191: }
192:
193: /* serialization */
194: public void setParametersList(List<Parameter> l) {
195: _parameters = l;
196: }
197:
198: private void initializeParametersByName() {
199: _parametersByName = new HashMap();
200: if (_parameters != null) {
201: for (Iterator iter = _parameters.iterator(); iter.hasNext();) {
202: Parameter param = (Parameter) iter.next();
203: if (param.getName() != null
204: && _parametersByName.containsKey(param
205: .getName())) {
206:
207: throw new ModelException("model.uniqueness");
208: }
209: _parametersByName.put(param.getName(), param);
210: }
211: }
212: }
213:
214: public Set<Block> getAllBlocks() {
215: Set<Block> blocks = new HashSet<Block>();
216: blocks.addAll(_bodyBlocks.values());
217: blocks.addAll(_headerBlocks.values());
218: blocks.addAll(_attachmentBlocks.values());
219: return blocks;
220: }
221:
222: private Map<QName, Block> _attachmentBlocks = new HashMap<QName, Block>();
223: private Map<QName, Block> _bodyBlocks = new HashMap<QName, Block>();
224: private Map<QName, Block> _headerBlocks = new HashMap<QName, Block>();
225: private Map<QName, Block> _unboundBlocks = new HashMap<QName, Block>();
226: private List<Parameter> _parameters = new ArrayList<Parameter>();
227: private Map<String, Parameter> _parametersByName = new HashMap<String, Parameter>();
228: }
|