001: /*
002: * BEGIN_HEADER - DO NOT EDIT
003: *
004: * The contents of this file are subject to the terms
005: * of the Common Development and Distribution License
006: * (the "License"). You may not use this file except
007: * in compliance with the License.
008: *
009: * You can obtain a copy of the license at
010: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
011: * See the License for the specific language governing
012: * permissions and limitations under the License.
013: *
014: * When distributing Covered Code, include this CDDL
015: * HEADER in each file and include the License file at
016: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
017: * If applicable add the following below this CDDL HEADER,
018: * with the fields enclosed by brackets "[]" replaced with
019: * your own identifying information: Portions Copyright
020: * [year] [name of copyright owner]
021: */
022:
023: /*
024: * @(#)WsdlDocument.java
025: * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026: *
027: * END_HEADER - DO NOT EDIT
028: */
029: package com.sun.jbi.messaging;
030:
031: import com.sun.jbi.wsdl2.*;
032: import com.sun.jbi.wsdl2.impl.WsdlFactory;
033: import java.io.File;
034: import javax.xml.namespace.QName;
035: import javax.xml.parsers.DocumentBuilder;
036: import javax.xml.parsers.DocumentBuilderFactory;
037:
038: import org.w3c.dom.Document;
039:
040: /** This class generates the default WSDL definition used by NMR tests.
041: * Constants are supplied to protect individual tests from name changes
042: * in the underlying WSDL document.
043: * @author Sun Microsystems, Inc.
044: */
045: public class WsdlDocument {
046: /** Path to default WSDL definition. */
047: public static final String WSDL_20_DEFINITION = System
048: .getProperty("junit.srcroot")
049: + "/nms/regress/regress20.wsdl";
050:
051: public static final String WSDL_11_DEFINITION = System
052: .getProperty("junit.srcroot")
053: + "/nms/regress/regress11.wsdl";
054:
055: public static final String NS_URI = "http://example.com/wsdl";
056: /** NCNames */
057: public static final String HELLO_C_INTERFACE = "hellocity";
058: public static final String HELLO_W_INTERFACE = "helloworld";
059: public static final String HELLO_C_OPERATION_1 = "helloPhoenix";
060: public static final String HELLO_C_OPERATION_2 = "helloTempe";
061: public static final String HELLO_W_OPERATION = "helloEarth";
062: public static final String HELLO_BINDING = "hellobinding";
063: public static final String HELLO_SERVICE = "helloservice";
064: public static final String HELLO_ENDPOINT_1 = "helloendpoint1";
065: public static final String HELLO_ENDPOINT_2 = "helloendpoint2";
066:
067: public static final String STOCK_INTERFACE = "StockQuote";
068: public static final String STOCK_OPERATION = "GetLastTradePrice";
069: public static final String STOCK_BINDING = "StockQuoteBinding";
070: public static final String STOCK_SERVICE = "StockQuoteService";
071: public static final String STOCK_ENDPOINT = "StockQuotePort";
072:
073: /** QNames */
074: public static final QName HELLO_C_INTERFACE_Q = new QName(NS_URI,
075: HELLO_C_INTERFACE);
076: public static final QName HELLO_W_INTERFACE_Q = new QName(NS_URI,
077: HELLO_W_INTERFACE);
078: public static final QName STOCK_INTERFACE_Q = new QName(NS_URI,
079: STOCK_INTERFACE);
080: public static final QName HELLO_C_OPERATION_1_Q = new QName(NS_URI,
081: HELLO_C_OPERATION_1);
082: public static final QName HELLO_C_OPERATION_2_Q = new QName(NS_URI,
083: HELLO_C_OPERATION_2);
084: public static final QName HELLO_W_OPERATION_Q = new QName(NS_URI,
085: HELLO_W_OPERATION);
086: public static final QName STOCK_OPERATION_Q = new QName(NS_URI,
087: STOCK_OPERATION);
088: public static final QName HELLO_SERVICE_Q = new QName(NS_URI,
089: HELLO_SERVICE);
090: public static final QName STOCK_SERVICE_Q = new QName(NS_URI,
091: STOCK_SERVICE);
092:
093: public static void main(String[] args) throws Exception {
094: WsdlFactory factory;
095: Description defs;
096:
097: factory = WsdlFactory.newInstance();
098:
099: defs = createDefinition(factory);
100:
101: if (args.length == 1) {
102: writeDefinition(factory, defs, args[0]);
103: } else {
104: writeDefinition(factory, defs, WSDL_20_DEFINITION);
105: }
106:
107: /*
108: defs = readDefinition(factory, args[0]);
109: System.out.println(defs.getService(0).getQName());
110: */
111: }
112:
113: public static Description createDefinition(WsdlFactory wf)
114: throws Exception {
115: Description d;
116: Interface hellocity;
117: Interface helloworld;
118: Interface stockquote;
119: InterfaceOperation hellocity1;
120: InterfaceOperation hellocity2;
121: InterfaceOperation helloworld1;
122: InterfaceOperation stockquote1;
123: com.sun.jbi.wsdl2.Binding hellobinding;
124: com.sun.jbi.wsdl2.Binding stockbinding;
125: Service helloservice;
126: Service stockservice;
127: Endpoint helloendpoint1;
128: Endpoint helloendpoint2;
129: Endpoint stockendpoint1;
130:
131: d = wf.newDescription(NS_URI);
132:
133: /**
134: * INTERFACES
135: */
136: hellocity = d.addNewInterface(HELLO_C_INTERFACE);
137: helloworld = d.addNewInterface(HELLO_W_INTERFACE);
138: stockquote = d.addNewInterface(STOCK_INTERFACE);
139: /** The next line doesn't seem to work, so I just edit the output by hand. */
140: //helloworld.appendInterface(hellocity);
141: /**
142: * BINDINGS
143: */
144: hellobinding = d.addNewBinding(HELLO_BINDING);
145: stockbinding = d.addNewBinding(STOCK_BINDING);
146: hellobinding.setType(HELLO_BINDING);
147: stockbinding.setType(STOCK_BINDING);
148:
149: /**
150: * OPERATIONS
151: */
152: hellocity1 = hellocity.addNewOperation();
153: hellocity2 = hellocity.addNewOperation();
154: helloworld1 = helloworld.addNewOperation();
155: stockquote1 = stockquote.addNewOperation();
156: hellocity1.setPattern(ExchangePattern.IN_ONLY.toString());
157: hellocity2.setPattern(ExchangePattern.IN_OUT.toString());
158: helloworld1.setPattern(ExchangePattern.IN_OPTIONAL_OUT
159: .toString());
160: stockquote1.setPattern(ExchangePattern.ROBUST_IN_ONLY
161: .toString());
162: hellocity1.setName(HELLO_C_OPERATION_1);
163: hellocity2.setName(HELLO_C_OPERATION_2);
164: helloworld1.setName(HELLO_W_OPERATION);
165: stockquote1.setName(STOCK_OPERATION);
166:
167: /**
168: * SERVICES
169: */
170: helloservice = d.addNewService(HELLO_SERVICE);
171: stockservice = d.addNewService(STOCK_SERVICE);
172: helloservice.setInterface(helloworld);
173: stockservice.setInterface(stockquote);
174:
175: /**
176: * ENDPOINTS
177: */
178: helloendpoint1 = helloservice.addNewEndpoint(HELLO_ENDPOINT_1,
179: hellobinding);
180: helloendpoint2 = helloservice.addNewEndpoint(HELLO_ENDPOINT_2,
181: hellobinding);
182: stockendpoint1 = stockservice.addNewEndpoint(STOCK_ENDPOINT,
183: stockbinding);
184: helloendpoint1.setBinding(hellobinding);
185: helloendpoint2.setBinding(hellobinding);
186: stockendpoint1.setBinding(stockbinding);
187:
188: return d;
189: }
190:
191: public static void writeDefinition(WsdlFactory wf, Description def,
192: String path) throws Exception {
193: WsdlWriter ww = wf.newWsdlWriter();
194: ww.writeDescription(def, new java.io.FileOutputStream(path));
195: }
196:
197: public static Description readDefinition(WsdlFactory wf, String path)
198: throws Exception {
199: WsdlReader wr = wf.newWsdlReader();
200: return wr
201: .readDescription("c:/development/jbi/nms/bld/regress/regress.wsdl");
202: }
203:
204: public static Document readDocument(String path) throws Exception {
205: DocumentBuilderFactory dbf;
206: DocumentBuilder db;
207: Document d;
208:
209: dbf = DocumentBuilderFactory.newInstance();
210: dbf.setNamespaceAware(true);
211: db = dbf.newDocumentBuilder();
212: d = db.parse(new File(path));
213:
214: return d;
215: }
216:
217: public static Document readDefaultDocument() throws Exception {
218: return readDocument(WSDL_20_DEFINITION);
219: }
220: }
|