001: /**
002: * $Id: DefinitionDescriptorImpl.java,v 1.5 2003/06/03 10:49:23 sy131129 Exp $
003: * Copyright 2002-2003 Sun Microsystems, Inc. All
004: * rights reserved. Use of this product is subject
005: * to license terms. Federal Acquisitions:
006: * Commercial Software -- Government Users
007: * Subject to Standard License Terms and
008: * Conditions.
009: *
010: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
011: * are trademarks or registered trademarks of Sun Microsystems,
012: * Inc. in the United States and other countries.
013: */package com.sun.portal.providers.simplewebservice.wsdl.impl;
014:
015: import java.util.Map;
016: import java.util.Set;
017: import java.util.HashMap;
018: import java.util.Iterator;
019:
020: import com.sun.portal.providers.simplewebservice.wsdl.TypeDescriptor;
021: import com.sun.portal.providers.simplewebservice.wsdl.MessageDescriptor;
022: import com.sun.portal.providers.simplewebservice.wsdl.PortTypeDescriptor;
023: import com.sun.portal.providers.simplewebservice.wsdl.BindingDescriptor;
024: import com.sun.portal.providers.simplewebservice.wsdl.ServiceDescriptor;
025: import com.sun.portal.providers.simplewebservice.wsdl.DefinitionDescriptor;
026:
027: /**
028: * This class represents a WSDL definition.
029: *
030: */
031: public class DefinitionDescriptorImpl implements DefinitionDescriptor {
032:
033: private String name = null;
034: private String targetNamespace = null;
035: private Map namespaces = new HashMap();
036: private Map typeDescriptors = new HashMap();
037: private Map messageDescriptors = new HashMap();
038: private Map bindingDescriptors = new HashMap();
039: private Map portTypeDescriptors = new HashMap();
040: private Map serviceDescriptors = new HashMap();
041:
042: /**
043: * Default Constructor.
044: *
045: * @param name the name of the DefinitionDescriptor.
046: * @param targetNamespace the targetNamespace of the DefinitionDescriptor.
047: * @param namespaces the namespaces that are part of the DefinitionDescriptor.
048: * @param typeDescriptors the TypeDescriptors that are part of the DefinitionDescriptor.
049: * @param messageDescriptors the MessageDescriptors that are part of the DefinitionDescriptor.
050: * @param bindingDescriptors the BindingDescriptors that are part of the DefinitionDescriptor.
051: * @param portTypeDescriptors the PortTypeDescriptors that are part of the DefinitionDescriptor.
052: * @param serviceDescriptors the ServiceDescriptors that are part of the DefinitionDescriptor.
053: */
054: public DefinitionDescriptorImpl(String name,
055: String targetNamespace, Map namespaces,
056: Map typeDescriptors, Map messageDescriptors,
057: Map bindingDescriptors, Map portTypeDescriptors,
058: Map serviceDescriptors) {
059: this .name = name;
060: this .targetNamespace = targetNamespace;
061: this .namespaces = namespaces;
062: this .typeDescriptors = typeDescriptors;
063: this .messageDescriptors = messageDescriptors;
064: this .bindingDescriptors = bindingDescriptors;
065: this .portTypeDescriptors = portTypeDescriptors;
066: this .serviceDescriptors = serviceDescriptors;
067: }
068:
069: /**
070: * Get the name of this definition.
071: *
072: * @return the definition name
073: */
074: public String getName() {
075: return name;
076: }
077:
078: /**
079: * Get the target namespace in which the WSDL elements
080: * are defined.
081: *
082: * @return the target namespace
083: */
084: public String getTargetNamespace() {
085: return targetNamespace;
086: }
087:
088: /**
089: * Get the namespace URI associated with this prefix. Or null if
090: * there is no namespace URI associated with this prefix.
091: *
092: * @param prefix the prefix for which to fetch the namespace URI for.
093: *
094: * @return the target namespace.
095: */
096: public String getNamespace(String prefix) {
097: return (String) namespaces.get(prefix);
098: }
099:
100: /**
101: * Get a prefix associated with this namespace URI. Or null if
102: * there are no prefixes associated with this namespace URI.
103: *
104: * @param namespaceURI the namespace URI for which to fetch the prefix for.
105: *
106: * @return the target prefix.
107: */
108: public String getPrefix(String namespaceURI) {
109: String value = null;
110:
111: if (namespaceURI != null) {
112: Iterator entryIterator = namespaces.entrySet().iterator();
113:
114: while (entryIterator.hasNext()) {
115: Map.Entry entry = (Map.Entry) entryIterator.next();
116: String prefix = (String) entry.getKey();
117: String assocNamespaceURI = (String) entry.getValue();
118:
119: if (namespaceURI.equals(assocNamespaceURI)) {
120: value = prefix;
121: break;
122: }
123: }
124: }
125:
126: return value;
127: }
128:
129: /**
130: * Get all namespace associations in this definition. The keys are
131: * the prefixes, and the namespace URIs are the values.
132: *
133: * @return all the Namespaces
134: */
135: public Map getNamespaces() {
136: return namespaces;
137: }
138:
139: /**
140: * Get the specified TypeDescriptor.
141: *
142: * @param name the name of the desired TypeDescriptor.
143: *
144: * @return the corresponding TypeDescriptor, or null if there wasn't
145: * any matching TypeDescriptor.
146: */
147: public TypeDescriptor getTypeDescriptor(String name) {
148: TypeDescriptor typeDescriptor = (TypeDescriptor) typeDescriptors
149: .get(name);
150:
151: return typeDescriptor;
152: }
153:
154: /**
155: * Get all the TypeDescriptors defined here.
156: *
157: * @return all the TypeDescriptors.
158: */
159: public Map getTypeDescriptors() {
160: return typeDescriptors;
161: }
162:
163: /**
164: * Get the specified MessageDescriptor.
165: *
166: * @param name the name of the desired MessageDescriptor.
167: *
168: * @return the corresponding MessageDescriptor, or null if there wasn't
169: * any matching MessageDescriptor.
170: */
171: public MessageDescriptor getMessageDescriptor(String name) {
172: MessageDescriptor messageDescriptor = (MessageDescriptor) messageDescriptors
173: .get(name);
174:
175: return messageDescriptor;
176: }
177:
178: /**
179: * Get all the MessageDescriptors defined here.
180: *
181: * @return all the MessageDescriptors.
182: */
183: public Map getMessageDescriptors() {
184: return messageDescriptors;
185: }
186:
187: /**
188: * Get the specified PortTypeDescriptor.
189: *
190: * @param name the name of the desired PortTypeDescriptor.
191: *
192: * @return the corresponding PortTypeDescriptor, or null if there wasn't
193: * any matching PortTypeDescriptor
194: */
195: public PortTypeDescriptor getPortTypeDescriptor(String name) {
196: PortTypeDescriptor portTypeDescriptor = (PortTypeDescriptor) portTypeDescriptors
197: .get(name);
198:
199: return portTypeDescriptor;
200: }
201:
202: /**
203: * Get all the PortTypeDescriptors defined here.
204: *
205: * @return all the PortTypeDescriptors.
206: */
207: public Map getPortTypeDescriptors() {
208: return portTypeDescriptors;
209: }
210:
211: /**
212: * Get the specified BindingDescriptor.
213: *
214: * @param name the name of the desired BindingDescriptor.
215: *
216: * @return the corresponding BindingDescriptor, or null if there wasn't
217: * any matching BindingDescriptor.
218: */
219: public BindingDescriptor getBindingDescriptor(String name) {
220: BindingDescriptor bindingDescriptor = (BindingDescriptor) bindingDescriptors
221: .get(name);
222:
223: return bindingDescriptor;
224: }
225:
226: /**
227: * Get all the BindingDescriptor defined here.
228: *
229: * @return all the BindingDesciptors.
230: */
231: public Map getBindingDescriptors() {
232: return bindingDescriptors;
233: }
234:
235: /**
236: * Get the specified ServiceDescriptor.
237: *
238: * @param name the name of the desired ServiceDescriptor.
239: *
240: * @return the corresponding ServiceDescriptor, or null if there wasn't
241: * any matching ServiceDescriptor.
242: */
243: public ServiceDescriptor getServiceDescriptor(String name) {
244: ServiceDescriptor serviceDescriptor = (ServiceDescriptor) serviceDescriptors
245: .get(name);
246:
247: return serviceDescriptor;
248: }
249:
250: /**
251: * Get all the ServiceDescriptor defined here.
252: *
253: * @return all the ServiceDescriptors.
254: */
255: public Map getServiceDescriptors() {
256: return serviceDescriptors;
257: }
258:
259: /**
260: * Get the String representation of this DefinitionDescriptor.
261: *
262: * @return the String representation of this DefinitionDescriptor.
263: */
264: public String toString() {
265: StringBuffer strBuf = new StringBuffer();
266:
267: strBuf.append("\nDefinitionDescriptor: name=" + name
268: + " targetNamespace=" + targetNamespace);
269:
270: if (namespaces != null) {
271: Set keySet = namespaces.keySet();
272: Iterator keyIterator = keySet.iterator();
273:
274: strBuf.append("\nNamespaces: ");
275: while (keyIterator.hasNext()) {
276: String key = (String) keyIterator.next();
277: strBuf.append("\n" + key + "=" + namespaces.get(key));
278: }
279: }
280:
281: if (typeDescriptors != null) {
282: Iterator typeDescriptorIterator = typeDescriptors.values()
283: .iterator();
284:
285: while (typeDescriptorIterator.hasNext()) {
286: strBuf.append("\n" + typeDescriptorIterator.next());
287: }
288: }
289:
290: if (messageDescriptors != null) {
291: Iterator messageDescriptorIterator = messageDescriptors
292: .values().iterator();
293:
294: while (messageDescriptorIterator.hasNext()) {
295: strBuf.append("\n" + messageDescriptorIterator.next());
296: }
297: }
298:
299: if (portTypeDescriptors != null) {
300: Iterator portTypeDescriptorIterator = portTypeDescriptors
301: .values().iterator();
302:
303: while (portTypeDescriptorIterator.hasNext()) {
304: strBuf.append("\n" + portTypeDescriptorIterator.next());
305: }
306: }
307:
308: if (bindingDescriptors != null) {
309: Iterator bindingDescriptorIterator = bindingDescriptors
310: .values().iterator();
311:
312: while (bindingDescriptorIterator.hasNext()) {
313: strBuf.append("\n" + bindingDescriptorIterator.next());
314: }
315: }
316:
317: if (serviceDescriptors != null) {
318: Iterator serviceDescriptorIterator = serviceDescriptors
319: .values().iterator();
320:
321: while (serviceDescriptorIterator.hasNext()) {
322: strBuf.append("\n" + serviceDescriptorIterator.next());
323: }
324: }
325:
326: return strBuf.toString();
327: }
328: }
|