001: /*
002: * Portions Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025: package com.sun.tools.internal.ws.processor.config.parser;
026:
027: import java.net.URL;
028: import java.util.*;
029:
030: import org.w3c.dom.Element;
031: import org.w3c.dom.NodeList;
032: import org.w3c.dom.Document;
033: import org.xml.sax.InputSource;
034: import org.xml.sax.EntityResolver;
035:
036: import com.sun.tools.internal.ws.processor.ProcessorOptions;
037: import com.sun.tools.internal.ws.processor.config.Configuration;
038: import com.sun.tools.internal.ws.processor.config.WSDLModelInfo;
039: import com.sun.tools.internal.ws.processor.util.ProcessorEnvironment;
040: import com.sun.xml.internal.ws.streaming.XMLStreamReaderFactory;
041: import com.sun.xml.internal.ws.streaming.XMLStreamReaderUtil;
042: import com.sun.xml.internal.ws.util.JAXWSUtils;
043: import com.sun.tools.internal.ws.wsdl.document.jaxws.JAXWSBindingsConstants;
044:
045: import javax.xml.stream.XMLStreamReader;
046:
047: /**
048: * @author Vivek Pandey
049: *
050: */
051: public class CustomizationParser extends InputParser {
052:
053: /**
054: * @param entityResolver
055: * @param env
056: * @param options
057: */
058: public CustomizationParser(EntityResolver entityResolver,
059: ProcessorEnvironment env, Properties options) {
060: super (env, options);
061: this .entityResolver = entityResolver;
062: }
063:
064: /* (non-Javadoc)
065: * @see com.sun.xml.internal.ws.processor.config.parser.InputParser#parse(java.io.File[], java.lang.String)
066: */
067: protected Configuration parse(List<String> inputFiles)
068: throws Exception {
069: //File wsdlFile = inputFiles[0];
070: Configuration configuration = new Configuration(getEnv());
071: wsdlModelInfo = new WSDLModelInfo();
072: wsdlModelInfo.setLocation(inputFiles.get(0));
073: if (_options.get(ProcessorOptions.WSDL_LOCATION) == null)
074: _options.setProperty(ProcessorOptions.WSDL_LOCATION,
075: inputFiles.get(0));
076:
077: //modelInfoParser = (JAXWSBindingInfoParser)getModelInfoParsers().get(JAXWSBindingsConstants.JAXWS_BINDINGS);
078: modelInfoParser = new JAXWSBindingInfoParser(getEnv());
079:
080: //get the jaxws bindingd file and add it to the modelInfo
081: Set<String> bindingFiles = (Set<String>) _options
082: .get(ProcessorOptions.BINDING_FILES);
083: for (String bindingFile : bindingFiles) {
084: addBinding(bindingFile);
085: }
086:
087: for (InputSource jaxwsBinding : jaxwsBindings) {
088: Document doc = modelInfoParser.parse(jaxwsBinding);
089: if (doc != null) {
090: wsdlModelInfo.putJAXWSBindings(jaxwsBinding
091: .getSystemId(), doc);
092: }
093: }
094:
095: //copy jaxb binding sources in modelInfo
096: for (InputSource jaxbBinding : jaxbBindings) {
097: wsdlModelInfo.addJAXBBIndings(jaxbBinding);
098: }
099:
100: addHandlerChainInfo();
101: configuration.setModelInfo(wsdlModelInfo);
102: return configuration;
103: }
104:
105: private void addBinding(String bindingLocation) throws Exception {
106: JAXWSUtils.checkAbsoluteness(bindingLocation);
107: InputSource is = null;
108: if (entityResolver != null) {
109: is = entityResolver.resolveEntity(null, bindingLocation);
110: }
111: if (is == null)
112: is = new InputSource(bindingLocation);
113:
114: XMLStreamReader reader = XMLStreamReaderFactory
115: .createFreshXMLStreamReader(is, true);
116: XMLStreamReaderUtil.nextElementContent(reader);
117: if (reader.getName().equals(
118: JAXWSBindingsConstants.JAXWS_BINDINGS)) {
119: jaxwsBindings.add(is);
120: } else if (reader.getName().equals(
121: JAXWSBindingsConstants.JAXB_BINDINGS)) {
122: jaxbBindings.add(is);
123: } else {
124: warn("configuration.notBindingFile");
125: }
126: }
127:
128: private void addHandlerChainInfo() throws Exception {
129: //setup handler chain info
130: for (Map.Entry<String, Document> entry : wsdlModelInfo
131: .getJAXWSBindings().entrySet()) {
132: Element e = entry.getValue().getDocumentElement();
133: NodeList nl = e.getElementsByTagNameNS(
134: "http://java.sun.com/xml/ns/javaee",
135: "handler-chains");
136: if (nl.getLength() == 0)
137: continue;
138: //take the first one, anyway its 1 handler-config per customization
139: Element hc = (Element) nl.item(0);
140: wsdlModelInfo.setHandlerConfig(hc);
141: return;
142: }
143: }
144:
145: private WSDLModelInfo wsdlModelInfo;
146: private JAXWSBindingInfoParser modelInfoParser;
147: private Set<InputSource> jaxwsBindings = new HashSet<InputSource>();
148: private Set<InputSource> jaxbBindings = new HashSet<InputSource>();
149: private EntityResolver entityResolver;
150:
151: }
|