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.HashSet;
030: import java.util.Iterator;
031: import java.util.List;
032: import java.util.Set;
033:
034: import javax.xml.namespace.QName;
035:
036: import com.sun.tools.internal.ws.wsdl.framework.AbstractDocument;
037: import com.sun.tools.internal.ws.wsdl.framework.Defining;
038: import com.sun.tools.internal.ws.wsdl.framework.DuplicateEntityException;
039: import com.sun.tools.internal.ws.wsdl.framework.Entity;
040: import com.sun.tools.internal.ws.wsdl.framework.EntityAction;
041: import com.sun.tools.internal.ws.wsdl.framework.ExtensibilityHelper;
042: import com.sun.tools.internal.ws.wsdl.framework.Extensible;
043: import com.sun.tools.internal.ws.wsdl.framework.Extension;
044:
045: /**
046: * Entity corresponding to the "definitions" WSDL element.
047: *
048: * @author WS Development Team
049: */
050: public class Definitions extends Entity implements Defining, Extensible {
051:
052: public Definitions(AbstractDocument document) {
053: _document = document;
054: _bindings = new ArrayList();
055: _imports = new ArrayList();
056: _messages = new ArrayList();
057: _portTypes = new ArrayList();
058: _services = new ArrayList();
059: _importedNamespaces = new HashSet();
060: _helper = new ExtensibilityHelper();
061: }
062:
063: public String getName() {
064: return _name;
065: }
066:
067: public void setName(String s) {
068: _name = s;
069: }
070:
071: public String getTargetNamespaceURI() {
072: return _targetNsURI;
073: }
074:
075: public void setTargetNamespaceURI(String s) {
076: _targetNsURI = s;
077: }
078:
079: public void setTypes(Types t) {
080: _types = t;
081: }
082:
083: public Types getTypes() {
084: return _types;
085: }
086:
087: public void add(Message m) {
088: _document.define(m);
089: _messages.add(m);
090: }
091:
092: public void add(PortType p) {
093: _document.define(p);
094: _portTypes.add(p);
095: }
096:
097: public void add(Binding b) {
098: _document.define(b);
099: _bindings.add(b);
100: }
101:
102: public void add(Service s) {
103: _document.define(s);
104: _services.add(s);
105: }
106:
107: public void addServiceOveride(Service s) {
108: _services.add(s);
109: }
110:
111: public void add(Import i) {
112: _imports.add(i);
113: _importedNamespaces.add(i.getNamespace());
114: }
115:
116: public Iterator imports() {
117: return _imports.iterator();
118: }
119:
120: public Iterator messages() {
121: return _messages.iterator();
122: }
123:
124: public Iterator portTypes() {
125: return _portTypes.iterator();
126: }
127:
128: public Iterator bindings() {
129: return _bindings.iterator();
130: }
131:
132: public Iterator<Service> services() {
133: return _services.iterator();
134: }
135:
136: public QName getElementName() {
137: return WSDLConstants.QNAME_DEFINITIONS;
138: }
139:
140: public Documentation getDocumentation() {
141: return _documentation;
142: }
143:
144: public void setDocumentation(Documentation d) {
145: _documentation = d;
146: }
147:
148: public void addExtension(Extension e) {
149: _helper.addExtension(e);
150: }
151:
152: public Iterator extensions() {
153: return _helper.extensions();
154: }
155:
156: public void withAllSubEntitiesDo(EntityAction action) {
157: if (_types != null) {
158: action.perform(_types);
159: }
160: for (Iterator iter = _messages.iterator(); iter.hasNext();) {
161: action.perform((Entity) iter.next());
162: }
163: for (Iterator iter = _portTypes.iterator(); iter.hasNext();) {
164: action.perform((Entity) iter.next());
165: }
166: for (Iterator iter = _bindings.iterator(); iter.hasNext();) {
167: action.perform((Entity) iter.next());
168: }
169: for (Iterator iter = _services.iterator(); iter.hasNext();) {
170: action.perform((Entity) iter.next());
171: }
172: for (Iterator iter = _imports.iterator(); iter.hasNext();) {
173: action.perform((Entity) iter.next());
174: }
175: _helper.withAllSubEntitiesDo(action);
176: }
177:
178: public void accept(WSDLDocumentVisitor visitor) throws Exception {
179: visitor.preVisit(this );
180:
181: for (Iterator iter = _imports.iterator(); iter.hasNext();) {
182: ((Import) iter.next()).accept(visitor);
183: }
184:
185: if (_types != null) {
186: _types.accept(visitor);
187: }
188:
189: for (Iterator iter = _messages.iterator(); iter.hasNext();) {
190: ((Message) iter.next()).accept(visitor);
191: }
192: for (Iterator iter = _portTypes.iterator(); iter.hasNext();) {
193: ((PortType) iter.next()).accept(visitor);
194: }
195: for (Iterator iter = _bindings.iterator(); iter.hasNext();) {
196: ((Binding) iter.next()).accept(visitor);
197: }
198: for (Iterator iter = _services.iterator(); iter.hasNext();) {
199: ((Service) iter.next()).accept(visitor);
200: }
201:
202: _helper.accept(visitor);
203: visitor.postVisit(this );
204: }
205:
206: public void validateThis() {
207: }
208:
209: private AbstractDocument _document;
210: private ExtensibilityHelper _helper;
211: private Documentation _documentation;
212: private String _name;
213: private String _targetNsURI;
214: private Types _types;
215: private List _messages;
216: private List _portTypes;
217: private List _bindings;
218: private List<Service> _services;
219: private List _imports;
220: private Set _importedNamespaces;
221: }
|