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