001: /*
002: Copyright (c) 2004-2005, Dennis M. Sosnoski.
003: All rights reserved.
004:
005: Redistribution and use in source and binary forms, with or without modification,
006: are permitted provided that the following conditions are met:
007:
008: * Redistributions of source code must retain the above copyright notice, this
009: list of conditions and the following disclaimer.
010: * Redistributions in binary form must reproduce the above copyright notice,
011: this list of conditions and the following disclaimer in the documentation
012: and/or other materials provided with the distribution.
013: * Neither the name of JiBX nor the names of its contributors may be used
014: to endorse or promote products derived from this software without specific
015: prior written permission.
016:
017: THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
018: ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
019: WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
020: DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
021: ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
022: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
023: LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
024: ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
025: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
026: SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
027: */
028:
029: package org.jibx.ws.wsdl;
030:
031: import java.util.ArrayList;
032: import java.util.HashMap;
033: import java.util.List;
034: import java.util.Map;
035: import java.util.Set;
036:
037: /**
038: * Top-level component of WSDL definition. Note that using this (including
039: * marshalling it out as XML) is not threadsafe, since the DOM representation
040: * used for the schema may not be threadsafe for reading (including in the case
041: * of the Xerces implementation shipped with recent JVMs).
042: *
043: * @author Dennis M. Sosnoski
044: */
045: public class Definitions {
046: /** Transport specification for SOAP over HTTP. */
047: public static final String HTTP_TRANSPORT = "http://schemas.xmlsoap.org/soap/http";
048:
049: /** Supported style value. */
050: public static final String STYLE_DOCUMENT = "document";
051:
052: /** Prefix for WSDL target namespace. */
053: private final String m_wsdlPrefix;
054:
055: /** Target namespace for WSDL. */
056: private final String m_wsdlNamespace;
057:
058: /** Name for port type. */
059: private final String m_portTypeName;
060:
061: /** Name for binding. */
062: private final String m_bindingName;
063:
064: /** Name for service. */
065: private final String m_serviceName;
066:
067: /** Name for port. */
068: private final String m_portName;
069:
070: /** Schema definition holders. */
071: private final ArrayList m_schemas;
072:
073: /** Map from namespace URIs to prefixes. */
074: private final Map m_uriPrefixMap;
075:
076: /** Message definitions. */
077: private final ArrayList m_messages;
078:
079: /** Operation definitions. */
080: private final ArrayList m_operations;
081:
082: /** Documentation for the portType. */
083: private List m_portTypeDocumentation;
084:
085: /** Service location URL.*/
086: private String m_serviceLocation;
087:
088: /**
089: * Standard constructor.
090: *
091: * @param tname port type name
092: * @param bname binding name
093: * @param sname service name
094: * @param pname port name
095: * @param wpfx prefix for WSDL target namespace
096: * @param wuri WSDL target namespace
097: * @param spfx prefix for schema target namespace
098: * @param suri schema target namespace
099: */
100: public Definitions(String tname, String bname, String sname,
101: String pname, String wpfx, String wuri, String spfx,
102: String suri) {
103: m_portTypeName = tname;
104: m_bindingName = bname;
105: m_serviceName = sname;
106: m_portName = pname;
107: m_wsdlPrefix = wpfx;
108: m_wsdlNamespace = wuri;
109: m_schemas = new ArrayList();
110: m_uriPrefixMap = new HashMap();
111: m_messages = new ArrayList();
112: m_operations = new ArrayList();
113: m_uriPrefixMap.put(wuri, wpfx);
114: if (!wuri.equals(suri)) {
115: m_uriPrefixMap.put(suri, spfx);
116: }
117: }
118:
119: /**
120: * Set service location.
121: *
122: * @param sloc service location URL string
123: */
124: public void setServiceLocation(String sloc) {
125: m_serviceLocation = sloc;
126: }
127:
128: /**
129: * Add message definition.
130: *
131: * @param msg message definition
132: */
133: public void addMessage(Message msg) {
134: m_messages.add(msg);
135: }
136:
137: /**
138: * Add operation definition.
139: *
140: * @param op operation definition
141: */
142: public void addOperation(Operation op) {
143: m_operations.add(op);
144: }
145:
146: /**
147: * Get port type name.
148: *
149: * @return port type name
150: */
151: public String getPortTypeName() {
152: return m_portTypeName;
153: }
154:
155: /**
156: * Get binding name.
157: *
158: * @return binding name
159: */
160: public String getBindingName() {
161: return m_bindingName;
162: }
163:
164: /**
165: * Get service name.
166: *
167: * @return service name
168: */
169: public String getServiceName() {
170: return m_serviceName;
171: }
172:
173: /**
174: * Get port name.
175: *
176: * @return port name
177: */
178: public String getPortName() {
179: return m_portTypeName;
180: }
181:
182: /**
183: * Get WSDL target namespace prefix.
184: *
185: * @return target namespace prefix
186: */
187: public String getWsdlPrefix() {
188: return m_wsdlPrefix;
189: }
190:
191: /**
192: * Get WSDL target namespace URI.
193: *
194: * @return target namespace
195: */
196: public String getWsdlNamespace() {
197: return m_wsdlNamespace;
198: }
199:
200: /**
201: * Get schema definition holders.
202: *
203: * @return schemas
204: */
205: public ArrayList getSchemas() {
206: return m_schemas;
207: }
208:
209: /**
210: * Get service location.
211: *
212: * @return service location URL string
213: */
214: public String getServiceLocation() {
215: return m_serviceLocation;
216: }
217:
218: /**
219: * Get portType documentation.
220: *
221: * @return list of nodes
222: */
223: public List getPortTypeDocumentation() {
224: return m_portTypeDocumentation;
225: }
226:
227: /**
228: * Set portType documentation.
229: *
230: * @param nodes list of nodes
231: */
232: public void setPortTypeDocumentation(List nodes) {
233: m_portTypeDocumentation = nodes;
234: }
235:
236: /**
237: * Get messages.
238: *
239: * @return list of messages
240: */
241: public ArrayList getMessages() {
242: return m_messages;
243: }
244:
245: /**
246: * Get operations.
247: *
248: * @return list of operations
249: */
250: public ArrayList getOperations() {
251: return m_operations;
252: }
253:
254: /**
255: * Get the prefix for a namespace URI. The first time this is called for a
256: * particular namespace URI a prefix is assigned and returned.
257: *
258: * @param uri
259: * @return prefix
260: */
261: public String getPrefix(String uri) {
262: String prefix = (String) m_uriPrefixMap.get(uri);
263: if (prefix == null) {
264: prefix = "ns" + (m_uriPrefixMap.size() - 1);
265: m_uriPrefixMap.put(uri, prefix);
266: }
267: return prefix;
268: }
269:
270: /**
271: * Get the complete set of namespace URIs used by this definition.
272: *
273: * @return set of URIs
274: */
275: public Set getNamespaces() {
276: return m_uriPrefixMap.keySet();
277: }
278: }
|