001: /**
002: * $Id: WSDLReader.java,v 1.10 2003/12/01 10:47:45 vv138407 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.io.File;
016: import java.io.InputStream;
017: import java.io.IOException;
018: import java.io.ByteArrayOutputStream;
019:
020: import java.util.Map;
021: import java.util.List;
022: import java.util.HashMap;
023: import java.util.Iterator;
024: import java.util.ArrayList;
025: import java.util.Properties;
026:
027: import java.net.URL;
028: import java.net.URLConnection;
029:
030: import javax.xml.parsers.DocumentBuilder;
031: import javax.xml.parsers.DocumentBuilderFactory;
032:
033: import org.w3c.dom.Document;
034: import org.w3c.dom.Element;
035: import org.w3c.dom.Node;
036: import org.w3c.dom.Attr;
037: import org.w3c.dom.Text;
038: import org.w3c.dom.NodeList;
039: import org.w3c.dom.NamedNodeMap;
040:
041: import com.sun.portal.providers.simplewebservice.wsdl.DefinitionDescriptor;
042: import com.sun.portal.providers.simplewebservice.wsdl.TypeDescriptor;
043: import com.sun.portal.providers.simplewebservice.wsdl.TypeElementDescriptor;
044: import com.sun.portal.providers.simplewebservice.wsdl.MessageDescriptor;
045: import com.sun.portal.providers.simplewebservice.wsdl.PortTypeDescriptor;
046: import com.sun.portal.providers.simplewebservice.wsdl.BindingDescriptor;
047: import com.sun.portal.providers.simplewebservice.wsdl.ServiceDescriptor;
048: import com.sun.portal.providers.simplewebservice.wsdl.PartDescriptor;
049: import com.sun.portal.providers.simplewebservice.wsdl.PortDescriptor;
050: import com.sun.portal.providers.simplewebservice.wsdl.OperationDescriptor;
051: import com.sun.portal.providers.simplewebservice.wsdl.BindingOperationDescriptor;
052: import com.sun.portal.providers.simplewebservice.wsdl.BindingOperationInputDescriptor;
053: import com.sun.portal.providers.simplewebservice.wsdl.BindingOperationOutputDescriptor;
054: import com.sun.xml.rpc.processor.model.Model;
055: import com.sun.xml.rpc.processor.util.ClientProcessorEnvironment;
056: import com.sun.xml.rpc.processor.config.WSDLModelInfo;
057: import com.sun.xml.rpc.processor.config.Configuration;
058: import com.sun.xml.rpc.processor.ProcessorOptions;
059:
060: /**
061: * The WSDLReader Singleton class reads in a WSDL file.
062: * v 1.10 vv138407 : Modified the WSDLReader to use the WSDLModeler in
063: * jwsdp -1.3 for RFE: 4954276
064: *
065: */
066: public class WSDLReader implements WSDLReaderConstants {
067:
068: private static WSDLReader wsdlReader = new WSDLReader();
069:
070: /*
071: * Obtains the WSDL Reader singleton
072: *
073: * @return the WSDL Singleton.
074: */
075: public static WSDLReader getWSDLReader() {
076: return wsdlReader;
077: }
078:
079: public Model getWSDLModel(String urlString) throws WSDLException {
080: Model model = null;
081: ClientProcessorEnvironment env = null;
082: WSDLModelInfo modelInfo = null;
083: Configuration config = null;
084: Properties options = new Properties();
085:
086: env = new CustomClientProcessorEnvironment(
087: new ByteArrayOutputStream(), null, null);
088: modelInfo = new WSDLModelInfo();
089: config = new Configuration(env);
090: config.setModelInfo(modelInfo);
091: modelInfo.setParent(config);
092: modelInfo.setLocation(urlString);
093:
094: options.put(ProcessorOptions.VALIDATE_WSDL_PROPERTY,
095: new Boolean(true));
096: options.put(ProcessorOptions.EXPLICIT_SERVICE_CONTEXT_PROPERTY,
097: new Boolean(false));
098: options.put(ProcessorOptions.USE_WSI_BASIC_PROFILE, "true");
099: options.put(ProcessorOptions.STRICT_COMPLIANCE, "true");
100:
101: //if doc/lit need to run model with this set
102: //options.put(ProcessorOptions.USE_DOCUMENT_LITERAL_ENCODING, new Boolean(true));
103: //kw - need to set wsiBasic profile if wsi - check properties -
104:
105: try {
106: model = modelInfo.buildModel(options);
107: } catch (Exception e) {
108: throw new WSDLException(WSDLException.PARSER_ERROR, e
109: .getMessage());
110: }
111:
112: if (null == model) {
113: throw new WSDLException(WSDLException.PARSER_ERROR,
114: "Error in Parsing WSDL Document");
115: }
116:
117: return model;
118: }
119:
120: /**
121: * Builds Definition Descriptor for the WSDL Document
122: * using the WSDLModeler from JWSDP-1.2
123: * @param wsdlURL
124: * @return DefinitionDescriptor
125: *
126: */
127: private DefinitionDescriptor internalBuildWSDLDefinitionDescriptor(
128: String wsdlURL) throws Exception {
129:
130: Model model = null;
131: DefinitionDescriptor definitionsDescriptor = null;
132: try {
133: model = getWSDLModel(wsdlURL);
134: DefinitionDescriptorBuilder descriptorBuilder = new DefinitionDescriptorBuilder();
135: definitionsDescriptor = descriptorBuilder
136: .getDefinitionDescriptor(model);
137: } catch (Exception exception) {
138: throw exception;
139: }
140:
141: return definitionsDescriptor;
142: }
143:
144: /**
145: * Reads in the WSDL file
146: *
147: * @param urlString of the WSDL file.
148: *
149: * @throws WSDLException thrown if an error occured while
150: * parsing and loading the WSDL file.
151: *
152: */
153: public DefinitionDescriptor getWSDLDefinitionDescriptor(
154: String urlString) throws WSDLException {
155:
156: DefinitionDescriptor definitionDescriptor = null;
157:
158: try {
159:
160: definitionDescriptor = internalBuildWSDLDefinitionDescriptor(urlString);
161: } catch (IOException ioex) {
162: throw new WSDLException(WSDLException.INVALID_URL, ioex
163: .getMessage(), ioex);
164: } catch (WSDLException wsdlex) {
165: throw wsdlex;
166: } catch (Exception ex) {
167: throw new WSDLException(WSDLException.OTHER_ERROR, ex
168: .getMessage(), ex);
169: }
170: return definitionDescriptor;
171: }
172:
173: // for testing purposes only
174: public static void main(String[] argv) {
175:
176: System.out.println("In Main!");
177:
178: try {
179: WSDLReader wsdlReader = WSDLReader.getWSDLReader();
180: DefinitionDescriptor dd = wsdlReader
181: .getWSDLDefinitionDescriptor(argv[0]);
182: System.out.println("DefinitionDescriptor is-" + dd);
183: } catch (Exception e) {
184: e.printStackTrace();
185: }
186:
187: }
188:
189: }
|