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.List;
029: import java.util.Properties;
030:
031: import com.sun.tools.internal.ws.processor.config.Configuration;
032: import com.sun.tools.internal.ws.processor.util.ProcessorEnvironment;
033: import com.sun.xml.internal.ws.util.JAXWSUtils;
034: import com.sun.tools.internal.ws.wsdl.document.WSDLConstants;
035: import com.sun.xml.internal.ws.streaming.XMLStreamReaderFactory;
036: import com.sun.xml.internal.ws.streaming.XMLStreamReaderUtil;
037:
038: import javax.xml.stream.XMLStreamReader;
039:
040: import org.xml.sax.EntityResolver;
041:
042: /**
043: * @author Vivek Pandey
044: *
045: * Main entry point from CompileTool
046: */
047: public class Reader {
048:
049: /**
050: *
051: */
052: public Reader(ProcessorEnvironment env, Properties options) {
053: this ._env = env;
054: this ._options = options;
055: }
056:
057: public Configuration parse(EntityResolver entityResolver,
058: List<String> inputSources) throws Exception {
059: //reset the input type flags before parsing
060: isClassFile = false;
061:
062: InputParser parser = null;
063: //now its just the first file. do we expect more than one input files?
064: validateInput(inputSources.get(0));
065:
066: if (isClassFile) {
067: parser = new ClassModelParser(_env, _options);
068: } else {
069: parser = new CustomizationParser(entityResolver, _env,
070: _options);
071: }
072: return parser.parse(inputSources);
073: }
074:
075: protected void validateInput(String file) throws Exception {
076: if (isClass(file)) {
077: isClassFile = true;
078: return;
079: }
080:
081: // JAXWSUtils.checkAbsoluteness(file);
082: // URL url = new URL(file);
083: //
084: // XMLStreamReader reader =
085: // XMLStreamReaderFactory.createXMLStreamReader(url.openStream(), true);
086: //
087: // XMLStreamReaderUtil.nextElementContent(reader);
088: // if(!reader.getName().equals(WSDLConstants.QNAME_DEFINITIONS)){
089: // //we are here, means invalid element
090: // ParserUtil.failWithFullName("configuration.invalidElement", file, reader);
091: // }
092: }
093:
094: public boolean isClass(String className) {
095: try {
096: _env.getClassLoader().loadClass(className);
097: } catch (ClassNotFoundException e) {
098: return false;
099: } catch (Exception e) {
100: e.printStackTrace();
101: }
102: return true;
103: }
104:
105: private boolean isClassFile;
106:
107: protected ProcessorEnvironment _env;
108:
109: protected Properties _options;
110: }
|