0001: /*
0002: * Portions Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
0003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0004: *
0005: * This code is free software; you can redistribute it and/or modify it
0006: * under the terms of the GNU General Public License version 2 only, as
0007: * published by the Free Software Foundation. Sun designates this
0008: * particular file as subject to the "Classpath" exception as provided
0009: * by Sun in the LICENSE file that accompanied this code.
0010: *
0011: * This code is distributed in the hope that it will be useful, but WITHOUT
0012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0014: * version 2 for more details (a copy is included in the LICENSE file that
0015: * accompanied this code).
0016: *
0017: * You should have received a copy of the GNU General Public License version
0018: * 2 along with this work; if not, write to the Free Software Foundation,
0019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0020: *
0021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
0022: * CA 95054 USA or visit www.sun.com if you need additional information or
0023: * have any questions.
0024: */
0025:
0026: package com.sun.tools.internal.ws.wsdl.parser;
0027:
0028: import java.io.BufferedInputStream;
0029: import java.io.IOException;
0030: import java.io.InputStream;
0031: import java.io.OutputStream;
0032: import java.net.MalformedURLException;
0033: import java.net.URL;
0034: import java.util.ArrayList;
0035: import java.util.HashMap;
0036: import java.util.HashSet;
0037: import java.util.Iterator;
0038: import java.util.List;
0039: import java.util.Map;
0040: import java.util.Set;
0041:
0042: import javax.xml.namespace.QName;
0043: import javax.xml.parsers.DocumentBuilder;
0044: import javax.xml.parsers.DocumentBuilderFactory;
0045: import javax.xml.parsers.FactoryConfigurationError;
0046: import javax.xml.parsers.ParserConfigurationException;
0047: import javax.xml.transform.Transformer;
0048: import javax.xml.transform.TransformerException;
0049: import javax.xml.transform.stream.StreamResult;
0050: import javax.xml.transform.dom.DOMSource;
0051:
0052: import org.w3c.dom.Document;
0053: import org.w3c.dom.Element;
0054: import org.xml.sax.ErrorHandler;
0055: import org.xml.sax.InputSource;
0056: import org.xml.sax.SAXException;
0057: import org.xml.sax.SAXParseException;
0058: import org.xml.sax.EntityResolver;
0059:
0060: import com.sun.xml.internal.ws.util.localization.LocalizableMessageFactory;
0061: import com.sun.xml.internal.ws.util.localization.Localizer;
0062: import com.sun.xml.internal.ws.util.JAXWSUtils;
0063: import com.sun.tools.internal.ws.util.xml.NullEntityResolver;
0064: import com.sun.tools.internal.ws.wsdl.document.Binding;
0065: import com.sun.tools.internal.ws.wsdl.document.BindingFault;
0066: import com.sun.tools.internal.ws.wsdl.document.BindingInput;
0067: import com.sun.tools.internal.ws.wsdl.document.BindingOperation;
0068: import com.sun.tools.internal.ws.wsdl.document.BindingOutput;
0069: import com.sun.tools.internal.ws.wsdl.document.Definitions;
0070: import com.sun.tools.internal.ws.wsdl.document.Documentation;
0071: import com.sun.tools.internal.ws.wsdl.document.Fault;
0072: import com.sun.tools.internal.ws.wsdl.document.Import;
0073: import com.sun.tools.internal.ws.wsdl.document.Input;
0074: import com.sun.tools.internal.ws.wsdl.document.Message;
0075: import com.sun.tools.internal.ws.wsdl.document.MessagePart;
0076: import com.sun.tools.internal.ws.wsdl.document.Operation;
0077: import com.sun.tools.internal.ws.wsdl.document.OperationStyle;
0078: import com.sun.tools.internal.ws.wsdl.document.Output;
0079: import com.sun.tools.internal.ws.wsdl.document.Port;
0080: import com.sun.tools.internal.ws.wsdl.document.PortType;
0081: import com.sun.tools.internal.ws.wsdl.document.Service;
0082: import com.sun.tools.internal.ws.wsdl.document.Types;
0083: import com.sun.tools.internal.ws.wsdl.document.WSDLConstants;
0084: import com.sun.tools.internal.ws.wsdl.document.WSDLDocument;
0085: import com.sun.tools.internal.ws.wsdl.document.schema.SchemaConstants;
0086: import com.sun.tools.internal.ws.wsdl.document.schema.SchemaKinds;
0087: import com.sun.tools.internal.ws.wsdl.framework.Entity;
0088: import com.sun.tools.internal.ws.wsdl.framework.Extensible;
0089: import com.sun.tools.internal.ws.wsdl.framework.ParseException;
0090: import com.sun.tools.internal.ws.wsdl.framework.ParserContext;
0091: import com.sun.tools.internal.ws.wsdl.framework.ParserListener;
0092: import com.sun.tools.internal.ws.util.xml.XmlUtil;
0093: import com.sun.tools.internal.ws.processor.util.ProcessorEnvironment;
0094: import com.sun.tools.internal.ws.processor.config.WSDLModelInfo;
0095:
0096: /**
0097: * A parser for WSDL documents.
0098: *
0099: * @author WS Development Team
0100: */
0101: public class WSDLParser {
0102: private WSDLModelInfo modelInfo;
0103: private EntityResolver entityResolver;
0104: //all the wsdl:import system Ids
0105: private final Set<String> imports = new HashSet<String>();
0106: //Map which holds wsdl Document(s) for a given SystemId
0107: private final Map<String, Document> wsdlDocuments = new HashMap<String, Document>();
0108:
0109: private WSDLParser() {
0110: _extensionHandlers = new HashMap();
0111: hSet = new HashSet();
0112:
0113: // register handlers for default extensions
0114: register(new SOAPExtensionHandler());
0115: register(new HTTPExtensionHandler());
0116: register(new MIMEExtensionHandler());
0117: register(new SchemaExtensionHandler());
0118: register(new JAXWSBindingExtensionHandler());
0119: register(new SOAP12ExtensionHandler());
0120: }
0121:
0122: public WSDLParser(WSDLModelInfo modelInfo) {
0123: this ();
0124: assert (modelInfo != null);
0125: this .modelInfo = modelInfo;
0126: this .entityResolver = modelInfo.getEntityResolver();
0127: }
0128:
0129: public void register(ExtensionHandler h) {
0130: _extensionHandlers.put(h.getNamespaceURI(), h);
0131: h.setExtensionHandlers(_extensionHandlers);
0132: }
0133:
0134: public void unregister(ExtensionHandler h) {
0135: _extensionHandlers.put(h.getNamespaceURI(), null);
0136: h.setExtensionHandlers(null);
0137: }
0138:
0139: public void unregister(String uri) {
0140: _extensionHandlers.put(uri, null);
0141: }
0142:
0143: public boolean getFollowImports() {
0144: return _followImports;
0145: }
0146:
0147: public void setFollowImports(boolean b) {
0148: _followImports = b;
0149: }
0150:
0151: public void addParserListener(ParserListener l) {
0152: if (_listeners == null) {
0153: _listeners = new ArrayList();
0154: }
0155: _listeners.add(l);
0156: }
0157:
0158: public void removeParserListener(ParserListener l) {
0159: if (_listeners == null) {
0160: return;
0161: }
0162: _listeners.remove(l);
0163: }
0164:
0165: // public WSDLDocument parse(InputSource source) {
0166: // _messageFactory =
0167: // new LocalizableMessageFactory("com.sun.tools.internal.ws.resources.wsdl");
0168: // _localizer = new Localizer();
0169: //
0170: // WSDLDocument document = new WSDLDocument();
0171: // document.setSystemId(source.getSystemId());
0172: // ParserContext context = new ParserContext(document, _listeners);
0173: // context.setFollowImports(_followImports);
0174: // document.setDefinitions(parseDefinitions(context, source, null));
0175: // return document;
0176: // }
0177:
0178: public WSDLDocument parse() {
0179: String location = modelInfo.getLocation();
0180: assert (location != null);
0181: _messageFactory = new LocalizableMessageFactory(
0182: "com.sun.tools.internal.ws.resources.wsdl");
0183: _localizer = new Localizer();
0184:
0185: WSDLDocument document = new WSDLDocument();
0186: InputSource source = null;
0187: String wsdlLoc = JAXWSUtils.absolutize(JAXWSUtils
0188: .getFileOrURLName(location));
0189: if (entityResolver != null) {
0190: try {
0191: source = entityResolver.resolveEntity(null, wsdlLoc);
0192: } catch (SAXException e) {
0193: if (source.getSystemId() != null) {
0194: throw new ParseException(
0195: "parsing.saxExceptionWithSystemId", source
0196: .getSystemId(), e);
0197: } else {
0198: throw new ParseException("parsing.saxException", e);
0199: }
0200: } catch (IOException e) {
0201: if (source.getSystemId() != null) {
0202: throw new ParseException(
0203: "parsing.ioExceptionWithSystemId", source
0204: .getSystemId(), e);
0205: } else {
0206: throw new ParseException("parsing.ioException", e);
0207: }
0208: }
0209: }
0210: if (source == null) {
0211: //default resolution
0212: source = new InputSource(wsdlLoc);
0213: }
0214: document.setSystemId(wsdlLoc);
0215: ParserContext context = new ParserContext(document, _listeners);
0216: context.setFollowImports(_followImports);
0217: document
0218: .setDefinitions(parseDefinitions(context, source, null));
0219: return document;
0220: }
0221:
0222: protected Definitions parseDefinitions(ParserContext context,
0223: InputSource source, String expectedTargetNamespaceURI) {
0224: context.pushWSDLLocation();
0225: context.setWSDLLocation(context.getDocument().getSystemId());
0226: String sysId = context.getDocument().getSystemId();
0227: buildDocumentFromWSDL(sysId, source, expectedTargetNamespaceURI);
0228: Document root = wsdlDocuments.get(sysId);
0229:
0230: //Internalizer.transform takes Set of jaxws:bindings elements, this is to allow multiple external
0231: //bindings to be transformed.
0232: new Internalizer().transform(modelInfo.getJAXWSBindings(),
0233: wsdlDocuments, (ProcessorEnvironment) modelInfo
0234: .getParent().getEnvironment());
0235:
0236: //print the wsdl
0237: // try{
0238: // dump(System.out);
0239: // }catch(IOException e){
0240: // e.printStackTrace();
0241: // }
0242:
0243: Definitions definitions = parseDefinitionsNoImport(context,
0244: root, expectedTargetNamespaceURI);
0245: processImports(context, source, definitions);
0246: context.popWSDLLocation();
0247: return definitions;
0248: }
0249:
0250: /**
0251: * @param systemId
0252: * @param source
0253: * @param expectedTargetNamespaceURI
0254: */
0255: private void buildDocumentFromWSDL(String systemId,
0256: InputSource source, String expectedTargetNamespaceURI) {
0257: try {
0258: DocumentBuilderFactory builderFactory = DocumentBuilderFactory
0259: .newInstance();
0260: builderFactory.setNamespaceAware(true);
0261: builderFactory.setValidating(false);
0262: DocumentBuilder builder = builderFactory
0263: .newDocumentBuilder();
0264: builder.setErrorHandler(new ErrorHandler() {
0265: public void error(SAXParseException e)
0266: throws SAXParseException {
0267: throw e;
0268: }
0269:
0270: public void fatalError(SAXParseException e)
0271: throws SAXParseException {
0272: throw e;
0273: }
0274:
0275: public void warning(SAXParseException err)
0276: throws SAXParseException {
0277: // do nothing
0278: }
0279: });
0280: if (entityResolver != null)
0281: builder.setEntityResolver(entityResolver);
0282: else
0283: builder.setEntityResolver(new NullEntityResolver());
0284:
0285: try {
0286: Document document = builder.parse(source);
0287: wsdlDocuments.put(systemId, document);
0288: Element e = document.getDocumentElement();
0289: Util.verifyTagNSRootElement(e,
0290: WSDLConstants.QNAME_DEFINITIONS);
0291: String name = XmlUtil.getAttributeOrNull(e,
0292: Constants.ATTR_NAME);
0293:
0294: String _targetNamespaceURI = XmlUtil
0295: .getAttributeOrNull(e,
0296: Constants.ATTR_TARGET_NAMESPACE);
0297:
0298: if (expectedTargetNamespaceURI != null
0299: && !expectedTargetNamespaceURI
0300: .equals(_targetNamespaceURI)) {
0301: //TODO: throw an exception???
0302: }
0303:
0304: for (Iterator iter = XmlUtil.getAllChildren(e); iter
0305: .hasNext();) {
0306: Element e2 = Util.nextElement(iter);
0307: if (e2 == null)
0308: break;
0309:
0310: //check to see if it has imports
0311: if (XmlUtil.matchesTagNS(e2,
0312: WSDLConstants.QNAME_IMPORT)) {
0313: String namespace = Util.getRequiredAttribute(
0314: e2, Constants.ATTR_NAMESPACE);
0315: String location = Util.getRequiredAttribute(e2,
0316: Constants.ATTR_LOCATION);
0317: location = getAdjustedLocation(source, location);
0318: if (location != null && !location.equals("")) {
0319: if (!imports.contains(location)) {
0320: imports.add(location);
0321: InputSource impSource = null;
0322: if (entityResolver != null) {
0323: impSource = entityResolver
0324: .resolveEntity(null,
0325: location);
0326: }
0327:
0328: if (impSource == null)
0329: impSource = new InputSource(
0330: location); // default resolution{
0331:
0332: buildDocumentFromWSDL(location,
0333: impSource, namespace);
0334: }
0335: }
0336: }
0337: }
0338: } catch (IOException e) {
0339: if (source.getSystemId() != null) {
0340: throw new ParseException(
0341: "parsing.ioExceptionWithSystemId", source
0342: .getSystemId(), e);
0343: } else {
0344: throw new ParseException("parsing.ioException", e);
0345: }
0346: } catch (SAXException e) {
0347: if (source.getSystemId() != null) {
0348: throw new ParseException(
0349: "parsing.saxExceptionWithSystemId", source
0350: .getSystemId(), e);
0351: } else {
0352: throw new ParseException("parsing.saxException", e);
0353: }
0354: }
0355: } catch (ParserConfigurationException e) {
0356: throw new ParseException("parsing.parserConfigException", e);
0357: } catch (FactoryConfigurationError e) {
0358: throw new ParseException("parsing.factoryConfigException",
0359: e);
0360: }
0361: }
0362:
0363: private String getAdjustedLocation(InputSource source,
0364: String location) {
0365: return source.getSystemId() == null ? location
0366: : Util.processSystemIdWithBase(source.getSystemId(),
0367: location);
0368: }
0369:
0370: /**
0371: * Dumps the contents of the forest to the specified stream.
0372: *
0373: * This is a debug method. As such, error handling is sloppy.
0374: */
0375: public void dump(OutputStream out) throws IOException {
0376: try {
0377: // create identity transformer
0378: Transformer it = XmlUtil.newTransformer();
0379:
0380: for (Iterator itr = wsdlDocuments.entrySet().iterator(); itr
0381: .hasNext();) {
0382: Map.Entry e = (Map.Entry) itr.next();
0383:
0384: out.write(("---<< " + e.getKey() + "\n").getBytes());
0385:
0386: it.transform(new DOMSource((Document) e.getValue()),
0387: new StreamResult(out));
0388:
0389: out.write("\n\n\n".getBytes());
0390: }
0391: } catch (TransformerException e) {
0392: e.printStackTrace();
0393: }
0394: }
0395:
0396: /* (non-Javadoc)
0397: * @see WSDLParser#processImports(ParserContext, org.xml.sax.InputSource, Definitions)
0398: */
0399: protected void processImports(ParserContext context,
0400: InputSource source, Definitions definitions) {
0401: for (String location : imports) {
0402: if (!context.getDocument().isImportedDocument(location)) {
0403: Definitions importedDefinitions = parseDefinitionsNoImport(
0404: context, wsdlDocuments.get(location), location);
0405: if (importedDefinitions == null)
0406: continue;
0407: context.getDocument().addImportedEntity(
0408: importedDefinitions);
0409: context.getDocument().addImportedDocument(location);
0410: }
0411: }
0412: }
0413:
0414: protected Definitions parseDefinitionsNoImport(
0415: ParserContext context, InputSource source,
0416: String expectedTargetNamespaceURI) {
0417: try {
0418: DocumentBuilderFactory builderFactory = DocumentBuilderFactory
0419: .newInstance();
0420: builderFactory.setNamespaceAware(true);
0421: builderFactory.setValidating(false);
0422: DocumentBuilder builder = builderFactory
0423: .newDocumentBuilder();
0424: builder.setErrorHandler(new ErrorHandler() {
0425: public void error(SAXParseException e)
0426: throws SAXParseException {
0427: throw e;
0428: }
0429:
0430: public void fatalError(SAXParseException e)
0431: throws SAXParseException {
0432: throw e;
0433: }
0434:
0435: public void warning(SAXParseException err)
0436: throws SAXParseException {
0437: // do nothing
0438: }
0439: });
0440: builder.setEntityResolver(new NullEntityResolver());
0441:
0442: try {
0443: Document document = builder.parse(source);
0444: return parseDefinitionsNoImport(context, document,
0445: expectedTargetNamespaceURI);
0446: } catch (IOException e) {
0447: if (source.getSystemId() != null) {
0448: throw new ParseException(
0449: "parsing.ioExceptionWithSystemId", source
0450: .getSystemId(), e);
0451: } else {
0452: throw new ParseException("parsing.ioException", e);
0453: }
0454: } catch (SAXException e) {
0455: if (source.getSystemId() != null) {
0456: throw new ParseException(
0457: "parsing.saxExceptionWithSystemId", source
0458: .getSystemId(), e);
0459: } else {
0460: throw new ParseException("parsing.saxException", e);
0461: }
0462: }
0463: } catch (ParserConfigurationException e) {
0464: throw new ParseException("parsing.parserConfigException", e);
0465: } catch (FactoryConfigurationError e) {
0466: throw new ParseException("parsing.factoryConfigException",
0467: e);
0468: }
0469: }
0470:
0471: protected Definitions parseDefinitionsNoImport(
0472: ParserContext context, Document doc,
0473: String expectedTargetNamespaceURI) {
0474: _targetNamespaceURI = null;
0475: Element root = doc.getDocumentElement();
0476: Util.verifyTagNSRootElement(root,
0477: WSDLConstants.QNAME_DEFINITIONS);
0478: return parseDefinitionsNoImport(context, root,
0479: expectedTargetNamespaceURI);
0480: }
0481:
0482: protected Definitions parseDefinitionsNoImport(
0483: ParserContext context, Element e,
0484: String expectedTargetNamespaceURI) {
0485: context.push();
0486: context.registerNamespaces(e);
0487:
0488: Definitions definitions = new Definitions(context.getDocument());
0489: String name = XmlUtil
0490: .getAttributeOrNull(e, Constants.ATTR_NAME);
0491: definitions.setName(name);
0492:
0493: _targetNamespaceURI = XmlUtil.getAttributeOrNull(e,
0494: Constants.ATTR_TARGET_NAMESPACE);
0495:
0496: definitions.setTargetNamespaceURI(_targetNamespaceURI);
0497:
0498: boolean gotDocumentation = false;
0499: boolean gotTypes = false;
0500:
0501: for (Iterator iter = XmlUtil.getAllChildren(e); iter.hasNext();) {
0502: Element e2 = Util.nextElement(iter);
0503: if (e2 == null)
0504: break;
0505:
0506: if (XmlUtil.matchesTagNS(e2,
0507: WSDLConstants.QNAME_DOCUMENTATION)) {
0508: if (gotDocumentation) {
0509: Util.fail("parsing.onlyOneDocumentationAllowed", e
0510: .getLocalName());
0511: }
0512: gotDocumentation = true;
0513: if (definitions.getDocumentation() == null)
0514: definitions
0515: .setDocumentation(getDocumentationFor(e2));
0516: } else if (XmlUtil.matchesTagNS(e2,
0517: WSDLConstants.QNAME_TYPES)) {
0518: if (gotTypes) {
0519: Util.fail("parsing.onlyOneTypesAllowed",
0520: Constants.TAG_DEFINITIONS);
0521: }
0522: //add all the wsdl:type elements to latter make a list of all the schema elements
0523: // that will be needed to create jaxb model
0524: addSchemaElements(e2);
0525:
0526: //definitions.setTypes(parseTypes(context, definitions, e2));
0527: } else if (XmlUtil.matchesTagNS(e2,
0528: WSDLConstants.QNAME_MESSAGE)) {
0529: Message message = parseMessage(context, definitions, e2);
0530: definitions.add(message);
0531: } else if (XmlUtil.matchesTagNS(e2,
0532: WSDLConstants.QNAME_PORT_TYPE)) {
0533: PortType portType = parsePortType(context, definitions,
0534: e2);
0535: definitions.add(portType);
0536: } else if (XmlUtil.matchesTagNS(e2,
0537: WSDLConstants.QNAME_BINDING)) {
0538: Binding binding = parseBinding(context, definitions, e2);
0539: definitions.add(binding);
0540: } else if (XmlUtil.matchesTagNS(e2,
0541: WSDLConstants.QNAME_SERVICE)) {
0542: Service service = parseService(context, definitions, e2);
0543: definitions.add(service);
0544: } else if (XmlUtil.matchesTagNS(e2,
0545: WSDLConstants.QNAME_IMPORT)) {
0546: definitions.add(parseImport(context, definitions, e2));
0547: } else if ((_useWSIBasicProfile)
0548: && (XmlUtil.matchesTagNS(e2,
0549: SchemaConstants.QNAME_IMPORT))) {
0550: warn("warning.wsi.r2003");
0551: } else {
0552: // possible extensibility element -- must live outside the WSDL namespace
0553: checkNotWsdlElement(e2);
0554: if (!handleExtension(context, definitions, e2)) {
0555: checkNotWsdlRequired(e2);
0556: }
0557: }
0558: }
0559:
0560: context.pop();
0561: context.fireDoneParsingEntity(WSDLConstants.QNAME_DEFINITIONS,
0562: definitions);
0563: return definitions;
0564: }
0565:
0566: protected Message parseMessage(ParserContext context,
0567: Definitions definitions, Element e) {
0568: context.push();
0569: context.registerNamespaces(e);
0570: Message message = new Message(definitions);
0571: String name = Util.getRequiredAttribute(e, Constants.ATTR_NAME);
0572: message.setName(name);
0573:
0574: boolean gotDocumentation = false;
0575:
0576: for (Iterator iter = XmlUtil.getAllChildren(e); iter.hasNext();) {
0577: Element e2 = Util.nextElement(iter);
0578: if (e2 == null)
0579: break;
0580:
0581: if (XmlUtil.matchesTagNS(e2,
0582: WSDLConstants.QNAME_DOCUMENTATION)) {
0583: if (gotDocumentation) {
0584: Util.fail("parsing.onlyOneDocumentationAllowed", e
0585: .getLocalName());
0586: }
0587: gotDocumentation = true;
0588: message.setDocumentation(getDocumentationFor(e2));
0589: } else if (XmlUtil.matchesTagNS(e2,
0590: WSDLConstants.QNAME_PART)) {
0591: MessagePart part = parseMessagePart(context, e2);
0592: message.add(part);
0593: } else {
0594: Util.fail("parsing.invalidElement", e2.getTagName(), e2
0595: .getNamespaceURI());
0596: }
0597: }
0598:
0599: context.pop();
0600: context.fireDoneParsingEntity(WSDLConstants.QNAME_MESSAGE,
0601: message);
0602: return message;
0603: }
0604:
0605: protected MessagePart parseMessagePart(ParserContext context,
0606: Element e) {
0607: context.push();
0608: context.registerNamespaces(e);
0609: MessagePart part = new MessagePart();
0610: String partName = Util.getRequiredAttribute(e,
0611: Constants.ATTR_NAME);
0612: part.setName(partName);
0613:
0614: String elementAttr = XmlUtil.getAttributeOrNull(e,
0615: Constants.ATTR_ELEMENT);
0616: String typeAttr = XmlUtil.getAttributeOrNull(e,
0617: Constants.ATTR_TYPE);
0618:
0619: if (elementAttr != null) {
0620: if (typeAttr != null) {
0621: Util.fail("parsing.onlyOneOfElementOrTypeRequired",
0622: partName);
0623: }
0624:
0625: part.setDescriptor(context
0626: .translateQualifiedName(elementAttr));
0627: part.setDescriptorKind(SchemaKinds.XSD_ELEMENT);
0628: } else if (typeAttr != null) {
0629: part
0630: .setDescriptor(context
0631: .translateQualifiedName(typeAttr));
0632: part.setDescriptorKind(SchemaKinds.XSD_TYPE);
0633: } else {
0634: // XXX-NOTE - this is wrong; for extensibility purposes,
0635: // any attribute can be specified on a <part> element, so
0636: // we need to put an extensibility hook here
0637: Util.fail("parsing.elementOrTypeRequired", partName);
0638: }
0639:
0640: context.pop();
0641: context.fireDoneParsingEntity(WSDLConstants.QNAME_PART, part);
0642: return part;
0643: }
0644:
0645: protected PortType parsePortType(ParserContext context,
0646: Definitions definitions, Element e) {
0647: context.push();
0648: context.registerNamespaces(e);
0649: PortType portType = new PortType(definitions);
0650: String name = Util.getRequiredAttribute(e, Constants.ATTR_NAME);
0651: portType.setName(name);
0652:
0653: boolean gotDocumentation = false;
0654:
0655: for (Iterator iter = XmlUtil.getAllChildren(e); iter.hasNext();) {
0656: Element e2 = Util.nextElement(iter);
0657: if (e2 == null)
0658: break;
0659:
0660: if (XmlUtil.matchesTagNS(e2,
0661: WSDLConstants.QNAME_DOCUMENTATION)) {
0662: if (gotDocumentation) {
0663: Util.fail("parsing.onlyOneDocumentationAllowed", e
0664: .getLocalName());
0665: }
0666: gotDocumentation = true;
0667: if (portType.getDocumentation() == null)
0668: portType.setDocumentation(getDocumentationFor(e2));
0669: } else if (XmlUtil.matchesTagNS(e2,
0670: WSDLConstants.QNAME_OPERATION)) {
0671: Operation op = parsePortTypeOperation(context, e2);
0672: portType.add(op);
0673: } else {
0674: // possible extensibility element -- must live outside the WSDL namespace
0675: checkNotWsdlElement(e2);
0676: if (!handleExtension(context, portType, e2)) {
0677: checkNotWsdlRequired(e2);
0678: }
0679: }/*else {
0680: Util.fail(
0681: "parsing.invalidElement",
0682: e2.getTagName(),
0683: e2.getNamespaceURI());
0684: }*/
0685: }
0686:
0687: context.pop();
0688: context.fireDoneParsingEntity(WSDLConstants.QNAME_PORT_TYPE,
0689: portType);
0690: return portType;
0691: }
0692:
0693: protected Operation parsePortTypeOperation(ParserContext context,
0694: Element e) {
0695: context.push();
0696: context.registerNamespaces(e);
0697:
0698: Operation operation = new Operation();
0699: String name = Util.getRequiredAttribute(e, Constants.ATTR_NAME);
0700: operation.setName(name);
0701: String parameterOrderAttr = XmlUtil.getAttributeOrNull(e,
0702: Constants.ATTR_PARAMETER_ORDER);
0703: operation.setParameterOrder(parameterOrderAttr);
0704:
0705: boolean gotDocumentation = false;
0706:
0707: boolean gotInput = false;
0708: boolean gotOutput = false;
0709: boolean gotFault = false;
0710: boolean inputBeforeOutput = false;
0711:
0712: for (Iterator iter = XmlUtil.getAllChildren(e); iter.hasNext();) {
0713: Element e2 = Util.nextElement(iter);
0714: if (e2 == null)
0715: break;
0716:
0717: if (XmlUtil.matchesTagNS(e2,
0718: WSDLConstants.QNAME_DOCUMENTATION)) {
0719: if (gotDocumentation) {
0720: Util.fail("parsing.onlyOneDocumentationAllowed", e
0721: .getLocalName());
0722: }
0723: gotDocumentation = true;
0724: if (operation.getDocumentation() == null)
0725: operation.setDocumentation(getDocumentationFor(e2));
0726: } else if (XmlUtil.matchesTagNS(e2,
0727: WSDLConstants.QNAME_INPUT)) {
0728: if (gotInput) {
0729: Util.fail("parsing.tooManyElements", new Object[] {
0730: Constants.TAG_INPUT,
0731: Constants.TAG_OPERATION, name });
0732: }
0733:
0734: context.push();
0735: context.registerNamespaces(e2);
0736: Input input = new Input();
0737: String messageAttr = Util.getRequiredAttribute(e2,
0738: Constants.ATTR_MESSAGE);
0739: input.setMessage(context
0740: .translateQualifiedName(messageAttr));
0741: String nameAttr = XmlUtil.getAttributeOrNull(e2,
0742: Constants.ATTR_NAME);
0743: input.setName(nameAttr);
0744: operation.setInput(input);
0745: gotInput = true;
0746: if (gotOutput) {
0747: inputBeforeOutput = false;
0748: }
0749:
0750: // verify that there is at most one child element and it is a documentation element
0751: boolean gotDocumentation2 = false;
0752: for (Iterator iter2 = XmlUtil.getAllChildren(e2); iter2
0753: .hasNext();) {
0754: Element e3 = Util.nextElement(iter2);
0755: if (e3 == null)
0756: break;
0757:
0758: if (XmlUtil.matchesTagNS(e3,
0759: WSDLConstants.QNAME_DOCUMENTATION)) {
0760: if (gotDocumentation2) {
0761: Util
0762: .fail(
0763: "parsing.onlyOneDocumentationAllowed",
0764: e.getLocalName());
0765: }
0766: gotDocumentation2 = true;
0767: input.setDocumentation(getDocumentationFor(e3));
0768: } else {
0769: Util.fail("parsing.invalidElement", e3
0770: .getTagName(), e3.getNamespaceURI());
0771: }
0772: }
0773: context.pop();
0774: } else if (XmlUtil.matchesTagNS(e2,
0775: WSDLConstants.QNAME_OUTPUT)) {
0776: if (gotOutput) {
0777: Util.fail("parsing.tooManyElements", new Object[] {
0778: Constants.TAG_OUTPUT,
0779: Constants.TAG_OPERATION, name });
0780: }
0781:
0782: context.push();
0783: context.registerNamespaces(e2);
0784: Output output = new Output();
0785: String messageAttr = Util.getRequiredAttribute(e2,
0786: Constants.ATTR_MESSAGE);
0787: output.setMessage(context
0788: .translateQualifiedName(messageAttr));
0789: String nameAttr = XmlUtil.getAttributeOrNull(e2,
0790: Constants.ATTR_NAME);
0791: output.setName(nameAttr);
0792: operation.setOutput(output);
0793: gotOutput = true;
0794: if (gotInput) {
0795: inputBeforeOutput = true;
0796: }
0797:
0798: // verify that there is at most one child element and it is a documentation element
0799: boolean gotDocumentation2 = false;
0800: for (Iterator iter2 = XmlUtil.getAllChildren(e2); iter2
0801: .hasNext();) {
0802: Element e3 = Util.nextElement(iter2);
0803: if (e3 == null)
0804: break;
0805:
0806: if (XmlUtil.matchesTagNS(e3,
0807: WSDLConstants.QNAME_DOCUMENTATION)) {
0808: if (gotDocumentation2) {
0809: Util
0810: .fail(
0811: "parsing.onlyOneDocumentationAllowed",
0812: e.getLocalName());
0813: }
0814: gotDocumentation2 = true;
0815: output
0816: .setDocumentation(getDocumentationFor(e3));
0817: } else {
0818: Util.fail("parsing.invalidElement", e3
0819: .getTagName(), e3.getNamespaceURI());
0820: }
0821: }
0822: context.pop();
0823: } else if (XmlUtil.matchesTagNS(e2,
0824: WSDLConstants.QNAME_FAULT)) {
0825: context.push();
0826: context.registerNamespaces(e2);
0827: Fault fault = new Fault();
0828: String messageAttr = Util.getRequiredAttribute(e2,
0829: Constants.ATTR_MESSAGE);
0830: fault.setMessage(context
0831: .translateQualifiedName(messageAttr));
0832: String nameAttr = XmlUtil.getAttributeOrNull(e2,
0833: Constants.ATTR_NAME);
0834: fault.setName(nameAttr);
0835: operation.addFault(fault);
0836: gotFault = true;
0837:
0838: // verify that there is at most one child element and it is a documentation element
0839: boolean gotDocumentation2 = false;
0840: for (Iterator iter2 = XmlUtil.getAllChildren(e2); iter2
0841: .hasNext();) {
0842: Element e3 = Util.nextElement(iter2);
0843: if (e3 == null)
0844: break;
0845:
0846: if (XmlUtil.matchesTagNS(e3,
0847: WSDLConstants.QNAME_DOCUMENTATION)) {
0848: if (gotDocumentation2) {
0849: Util
0850: .fail(
0851: "parsing.onlyOneDocumentationAllowed",
0852: e.getLocalName());
0853: }
0854: gotDocumentation2 = true;
0855: if (fault.getDocumentation() == null)
0856: fault
0857: .setDocumentation(getDocumentationFor(e3));
0858: } else {
0859: // possible extensibility element -- must live outside the WSDL namespace
0860: checkNotWsdlElement(e3);
0861: if (!handleExtension(context, fault, e3)) {
0862: checkNotWsdlRequired(e3);
0863: }
0864: }/*else {
0865: Util.fail(
0866: "parsing.invalidElement",
0867: e3.getTagName(),
0868: e3.getNamespaceURI());
0869: }*/
0870: }
0871: context.pop();
0872: } else {
0873: // possible extensibility element -- must live outside the WSDL namespace
0874: checkNotWsdlElement(e2);
0875: if (!handleExtension(context, operation, e2)) {
0876: checkNotWsdlRequired(e2);
0877: }
0878: }/*else {
0879: Util.fail(
0880: "parsing.invalidElement",
0881: e2.getTagName(),
0882: e2.getNamespaceURI());
0883: }*/
0884: }
0885:
0886: if (gotInput && !gotOutput && !gotFault) {
0887: operation.setStyle(OperationStyle.ONE_WAY);
0888: } else if (gotInput && gotOutput && inputBeforeOutput) {
0889: operation.setStyle(OperationStyle.REQUEST_RESPONSE);
0890: } else if (gotInput && gotOutput && !inputBeforeOutput) {
0891: operation.setStyle(OperationStyle.SOLICIT_RESPONSE);
0892: } else if (gotOutput && !gotInput && !gotFault) {
0893: operation.setStyle(OperationStyle.NOTIFICATION);
0894: } else {
0895: Util.fail("parsing.invalidOperationStyle", name);
0896: }
0897:
0898: context.pop();
0899: context.fireDoneParsingEntity(WSDLConstants.QNAME_OPERATION,
0900: operation);
0901: return operation;
0902: }
0903:
0904: protected Binding parseBinding(ParserContext context,
0905: Definitions definitions, Element e) {
0906: context.push();
0907: context.registerNamespaces(e);
0908: Binding binding = new Binding(definitions);
0909: String name = Util.getRequiredAttribute(e, Constants.ATTR_NAME);
0910: binding.setName(name);
0911: String typeAttr = Util.getRequiredAttribute(e,
0912: Constants.ATTR_TYPE);
0913: binding.setPortType(context.translateQualifiedName(typeAttr));
0914:
0915: boolean gotDocumentation = false;
0916:
0917: for (Iterator iter = XmlUtil.getAllChildren(e); iter.hasNext();) {
0918: Element e2 = Util.nextElement(iter);
0919: if (e2 == null)
0920: break;
0921:
0922: if (XmlUtil.matchesTagNS(e2,
0923: WSDLConstants.QNAME_DOCUMENTATION)) {
0924: if (gotDocumentation) {
0925: Util.fail("parsing.onlyOneDocumentationAllowed", e
0926: .getLocalName());
0927: }
0928: gotDocumentation = true;
0929: binding.setDocumentation(getDocumentationFor(e2));
0930: } else if (XmlUtil.matchesTagNS(e2,
0931: WSDLConstants.QNAME_OPERATION)) {
0932: BindingOperation op = parseBindingOperation(context, e2);
0933: binding.add(op);
0934: } else {
0935: // possible extensibility element -- must live outside the WSDL namespace
0936: checkNotWsdlElement(e2);
0937: if (!handleExtension(context, binding, e2)) {
0938: checkNotWsdlRequired(e2);
0939: }
0940: }
0941: }
0942:
0943: context.pop();
0944: context.fireDoneParsingEntity(WSDLConstants.QNAME_BINDING,
0945: binding);
0946: return binding;
0947: }
0948:
0949: protected BindingOperation parseBindingOperation(
0950: ParserContext context, Element e) {
0951: context.push();
0952: context.registerNamespaces(e);
0953: BindingOperation operation = new BindingOperation();
0954: String name = Util.getRequiredAttribute(e, Constants.ATTR_NAME);
0955: operation.setName(name);
0956:
0957: boolean gotDocumentation = false;
0958:
0959: boolean gotInput = false;
0960: boolean gotOutput = false;
0961: boolean gotFault = false;
0962: boolean inputBeforeOutput = false;
0963:
0964: for (Iterator iter = XmlUtil.getAllChildren(e); iter.hasNext();) {
0965: Element e2 = Util.nextElement(iter);
0966: if (e2 == null)
0967: break;
0968: if (XmlUtil.matchesTagNS(e2,
0969: WSDLConstants.QNAME_DOCUMENTATION)) {
0970: if (gotDocumentation) {
0971: Util.fail("parsing.onlyOneDocumentationAllowed", e
0972: .getLocalName());
0973: }
0974: gotDocumentation = true;
0975: operation.setDocumentation(getDocumentationFor(e2));
0976: } else if (XmlUtil.matchesTagNS(e2,
0977: WSDLConstants.QNAME_INPUT)) {
0978: if (gotInput) {
0979: Util.fail("parsing.tooManyElements", new Object[] {
0980: Constants.TAG_INPUT,
0981: Constants.TAG_OPERATION, name });
0982: }
0983:
0984: /* Here we check for the use scenario */
0985: Iterator itere2 = XmlUtil.getAllChildren(e2);
0986: Element ee = Util.nextElement(itere2);
0987: if (hSet.isEmpty()) {
0988: hSet.add(ee.getAttribute("use"));
0989: } else {
0990: /* this codition will happen when the wsdl used has a mixture of
0991: literal and encoded style */
0992: if (!hSet.contains(ee.getAttribute("use"))
0993: && (ee.getAttribute("use") != "")) {
0994: hSet.add(ee.getAttribute("use"));
0995: }
0996: }
0997:
0998: context.push();
0999: context.registerNamespaces(e2);
1000: BindingInput input = new BindingInput();
1001: String nameAttr = XmlUtil.getAttributeOrNull(e2,
1002: Constants.ATTR_NAME);
1003: input.setName(nameAttr);
1004: operation.setInput(input);
1005: gotInput = true;
1006: if (gotOutput) {
1007: inputBeforeOutput = false;
1008: }
1009:
1010: // verify that there is at most one child element and it is a documentation element
1011: boolean gotDocumentation2 = false;
1012: for (Iterator iter2 = XmlUtil.getAllChildren(e2); iter2
1013: .hasNext();) {
1014: Element e3 = Util.nextElement(iter2);
1015: if (e3 == null)
1016: break;
1017:
1018: if (XmlUtil.matchesTagNS(e3,
1019: WSDLConstants.QNAME_DOCUMENTATION)) {
1020: if (gotDocumentation2) {
1021: Util
1022: .fail(
1023: "parsing.onlyOneDocumentationAllowed",
1024: e.getLocalName());
1025: }
1026: gotDocumentation2 = true;
1027: input.setDocumentation(getDocumentationFor(e3));
1028: } else {
1029: // possible extensibility element -- must live outside the WSDL namespace
1030: checkNotWsdlElement(e3);
1031: if (!handleExtension(context, input, e3)) {
1032: checkNotWsdlRequired(e3);
1033: }
1034: }
1035: }
1036: context.pop();
1037: } else if (XmlUtil.matchesTagNS(e2,
1038: WSDLConstants.QNAME_OUTPUT)) {
1039: if (gotOutput) {
1040: Util.fail("parsing.tooManyElements", new Object[] {
1041: Constants.TAG_OUTPUT,
1042: Constants.TAG_OPERATION, name });
1043: }
1044:
1045: context.push();
1046: context.registerNamespaces(e2);
1047: BindingOutput output = new BindingOutput();
1048: String nameAttr = XmlUtil.getAttributeOrNull(e2,
1049: Constants.ATTR_NAME);
1050: output.setName(nameAttr);
1051: operation.setOutput(output);
1052: gotOutput = true;
1053: if (gotInput) {
1054: inputBeforeOutput = true;
1055: }
1056:
1057: // verify that there is at most one child element and it is a documentation element
1058: boolean gotDocumentation2 = false;
1059: for (Iterator iter2 = XmlUtil.getAllChildren(e2); iter2
1060: .hasNext();) {
1061:
1062: Element e3 = Util.nextElement(iter2);
1063: if (e3 == null)
1064: break;
1065:
1066: if (XmlUtil.matchesTagNS(e3,
1067: WSDLConstants.QNAME_DOCUMENTATION)) {
1068: if (gotDocumentation2) {
1069: Util
1070: .fail(
1071: "parsing.onlyOneDocumentationAllowed",
1072: e.getLocalName());
1073: }
1074: gotDocumentation2 = true;
1075: output
1076: .setDocumentation(getDocumentationFor(e3));
1077: } else {
1078: // possible extensibility element -- must live outside the WSDL namespace
1079: checkNotWsdlElement(e3);
1080: if (!handleExtension(context, output, e3)) {
1081: checkNotWsdlRequired(e3);
1082: }
1083: }
1084: }
1085: context.pop();
1086: } else if (XmlUtil.matchesTagNS(e2,
1087: WSDLConstants.QNAME_FAULT)) {
1088: context.push();
1089: context.registerNamespaces(e2);
1090: BindingFault fault = new BindingFault();
1091: String nameAttr = Util.getRequiredAttribute(e2,
1092: Constants.ATTR_NAME);
1093: fault.setName(nameAttr);
1094: operation.addFault(fault);
1095: gotFault = true;
1096:
1097: // verify that there is at most one child element and it is a documentation element
1098: boolean gotDocumentation2 = false;
1099: for (Iterator iter2 = XmlUtil.getAllChildren(e2); iter2
1100: .hasNext();) {
1101: Element e3 = Util.nextElement(iter2);
1102: if (e3 == null)
1103: break;
1104:
1105: if (XmlUtil.matchesTagNS(e3,
1106: WSDLConstants.QNAME_DOCUMENTATION)) {
1107: if (gotDocumentation2) {
1108: Util
1109: .fail(
1110: "parsing.onlyOneDocumentationAllowed",
1111: e.getLocalName());
1112: }
1113: gotDocumentation2 = true;
1114: if (fault.getDocumentation() == null)
1115: fault
1116: .setDocumentation(getDocumentationFor(e3));
1117: } else {
1118: // possible extensibility element -- must live outside the WSDL namespace
1119: checkNotWsdlElement(e3);
1120: if (!handleExtension(context, fault, e3)) {
1121: checkNotWsdlRequired(e3);
1122: }
1123: }
1124: }
1125: context.pop();
1126: } else {
1127: // possible extensibility element -- must live outside the WSDL namespace
1128: checkNotWsdlElement(e2);
1129: if (!handleExtension(context, operation, e2)) {
1130: checkNotWsdlRequired(e2);
1131: }
1132: }
1133: }
1134:
1135: if (gotInput && !gotOutput && !gotFault) {
1136: operation.setStyle(OperationStyle.ONE_WAY);
1137: } else if (gotInput && gotOutput && inputBeforeOutput) {
1138: operation.setStyle(OperationStyle.REQUEST_RESPONSE);
1139: } else if (gotInput && gotOutput && !inputBeforeOutput) {
1140: operation.setStyle(OperationStyle.SOLICIT_RESPONSE);
1141: } else if (gotOutput && !gotInput && !gotFault) {
1142: operation.setStyle(OperationStyle.NOTIFICATION);
1143: } else {
1144: Util.fail("parsing.invalidOperationStyle", name);
1145: }
1146:
1147: context.pop();
1148: context.fireDoneParsingEntity(WSDLConstants.QNAME_OPERATION,
1149: operation);
1150: return operation;
1151: }
1152:
1153: protected Import parseImport(ParserContext context,
1154: Definitions definitions, Element e) {
1155: context.push();
1156: context.registerNamespaces(e);
1157: Import anImport = new Import();
1158: String namespace = Util.getRequiredAttribute(e,
1159: Constants.ATTR_NAMESPACE);
1160: anImport.setNamespace(namespace);
1161: String location = Util.getRequiredAttribute(e,
1162: Constants.ATTR_LOCATION);
1163: anImport.setLocation(location);
1164:
1165: // according to the schema in the WSDL 1.1 spec, an import can have a documentation element
1166: boolean gotDocumentation = false;
1167:
1168: for (Iterator iter = XmlUtil.getAllChildren(e); iter.hasNext();) {
1169: Element e2 = Util.nextElement(iter);
1170: if (e2 == null)
1171: break;
1172:
1173: if (XmlUtil.matchesTagNS(e2,
1174: WSDLConstants.QNAME_DOCUMENTATION)) {
1175: if (gotDocumentation) {
1176: Util.fail("parsing.onlyOneDocumentationAllowed", e
1177: .getLocalName());
1178: }
1179: gotDocumentation = true;
1180: anImport.setDocumentation(getDocumentationFor(e2));
1181: } else {
1182: Util.fail("parsing.invalidElement", e2.getTagName(), e2
1183: .getNamespaceURI());
1184: }
1185: }
1186: context.pop();
1187: context.fireDoneParsingEntity(WSDLConstants.QNAME_IMPORT,
1188: anImport);
1189: return anImport;
1190: }
1191:
1192: protected Service parseService(ParserContext context,
1193: Definitions definitions, Element e) {
1194: context.push();
1195: context.registerNamespaces(e);
1196: Service service = new Service(definitions);
1197: String name = Util.getRequiredAttribute(e, Constants.ATTR_NAME);
1198: service.setName(name);
1199:
1200: boolean gotDocumentation = false;
1201:
1202: for (Iterator iter = XmlUtil.getAllChildren(e); iter.hasNext();) {
1203: Element e2 = Util.nextElement(iter);
1204: if (e2 == null)
1205: break;
1206:
1207: if (XmlUtil.matchesTagNS(e2,
1208: WSDLConstants.QNAME_DOCUMENTATION)) {
1209: if (gotDocumentation) {
1210: Util.fail("parsing.onlyOneDocumentationAllowed", e
1211: .getLocalName());
1212: }
1213: gotDocumentation = true;
1214: if (service.getDocumentation() == null)
1215: service.setDocumentation(getDocumentationFor(e2));
1216: } else if (XmlUtil.matchesTagNS(e2,
1217: WSDLConstants.QNAME_PORT)) {
1218: Port port = parsePort(context, definitions, e2);
1219: service.add(port);
1220: } else {
1221: // possible extensibility element -- must live outside the WSDL namespace
1222: checkNotWsdlElement(e2);
1223: if (!handleExtension(context, service, e2)) {
1224: checkNotWsdlRequired(e2);
1225: }
1226: }
1227: }
1228:
1229: context.pop();
1230: context.fireDoneParsingEntity(WSDLConstants.QNAME_SERVICE,
1231: service);
1232: return service;
1233: }
1234:
1235: protected Port parsePort(ParserContext context,
1236: Definitions definitions, Element e) {
1237: context.push();
1238: context.registerNamespaces(e);
1239:
1240: Port port = new Port(definitions);
1241: String name = Util.getRequiredAttribute(e, Constants.ATTR_NAME);
1242: port.setName(name);
1243:
1244: String bindingAttr = Util.getRequiredAttribute(e,
1245: Constants.ATTR_BINDING);
1246: port.setBinding(context.translateQualifiedName(bindingAttr));
1247:
1248: boolean gotDocumentation = false;
1249:
1250: for (Iterator iter = XmlUtil.getAllChildren(e); iter.hasNext();) {
1251: Element e2 = Util.nextElement(iter);
1252: if (e2 == null)
1253: break;
1254:
1255: if (XmlUtil.matchesTagNS(e2,
1256: WSDLConstants.QNAME_DOCUMENTATION)) {
1257: if (gotDocumentation) {
1258: Util.fail("parsing.onlyOneDocumentationAllowed", e
1259: .getLocalName());
1260: }
1261: gotDocumentation = true;
1262: if (port.getDocumentation() == null)
1263: port.setDocumentation(getDocumentationFor(e2));
1264: } else {
1265: // possible extensibility element -- must live outside the WSDL namespace
1266: checkNotWsdlElement(e2);
1267: if (!handleExtension(context, port, e2)) {
1268: checkNotWsdlRequired(e2);
1269: }
1270: }
1271: }
1272:
1273: context.pop();
1274: context.fireDoneParsingEntity(WSDLConstants.QNAME_PORT, port);
1275: return port;
1276: }
1277:
1278: protected Types parseTypes(ParserContext context,
1279: Definitions definitions, Element e) {
1280: context.push();
1281: context.registerNamespaces(e);
1282: Types types = new Types();
1283:
1284: boolean gotDocumentation = false;
1285:
1286: for (Iterator iter = XmlUtil.getAllChildren(e); iter.hasNext();) {
1287: Element e2 = Util.nextElement(iter);
1288: if (e2 == null)
1289: break;
1290:
1291: if (XmlUtil.matchesTagNS(e2,
1292: WSDLConstants.QNAME_DOCUMENTATION)) {
1293: if (gotDocumentation) {
1294: Util.fail("parsing.onlyOneDocumentationAllowed", e
1295: .getLocalName());
1296: }
1297: gotDocumentation = true;
1298: types.setDocumentation(getDocumentationFor(e2));
1299: } //bug fix 4854004
1300: else if ((_useWSIBasicProfile)
1301: && (XmlUtil.matchesTagNS(e2,
1302: SchemaConstants.QNAME_IMPORT))) {
1303: warn("warning.wsi.r2003");
1304: } else {
1305: // possible extensibility element -- must live outside the WSDL namespace
1306: checkNotWsdlElement(e2);
1307: try {
1308: if (!handleExtension(context, types, e2)) {
1309: checkNotWsdlRequired(e2);
1310: }
1311: } catch (ParseException pe) {
1312: if (pe.getKey().equals(
1313: "parsing.incorrectRootElement")) {
1314: if (_useWSIBasicProfile) {
1315: warn("warning.wsi.r2004");
1316: }
1317: throw pe;
1318: }
1319: }
1320: }
1321: }
1322:
1323: context.pop();
1324: context.fireDoneParsingEntity(WSDLConstants.QNAME_TYPES, types);
1325: return types;
1326: }
1327:
1328: private List _elements = new ArrayList();
1329:
1330: public void addSchemaElements(Element typesElement) {
1331: for (Iterator iter = XmlUtil.getAllChildren(typesElement); iter
1332: .hasNext();) {
1333: Element e = Util.nextElement(iter);
1334: if (e == null)
1335: break;
1336:
1337: if (XmlUtil.matchesTagNS(e, SchemaConstants.QNAME_SCHEMA)) {
1338: _elements.add(e);
1339: } else {
1340: // possible extensibility element -- must live outside the WSDL namespace
1341: checkNotWsdlElement(e);
1342: }
1343: }
1344: }
1345:
1346: public List getSchemaElements() {
1347: return _elements;
1348: }
1349:
1350: protected boolean handleExtension(ParserContext context,
1351: Extensible entity, Element e) {
1352: ExtensionHandler h = (ExtensionHandler) _extensionHandlers
1353: .get(e.getNamespaceURI());
1354: if (h == null) {
1355: context.fireIgnoringExtension(new QName(
1356: e.getNamespaceURI(), e.getLocalName()),
1357: ((Entity) entity).getElementName());
1358: return false;
1359: } else {
1360: return h.doHandleExtension(context, entity, e);
1361: }
1362: }
1363:
1364: protected void checkNotWsdlElement(Element e) {
1365: // possible extensibility element -- must live outside the WSDL namespace
1366: if (e.getNamespaceURI().equals(Constants.NS_WSDL))
1367: Util.fail("parsing.invalidWsdlElement", e.getTagName());
1368: }
1369:
1370: protected void checkNotWsdlRequired(Element e) {
1371: // check the wsdl:required attribute, fail if set to "true"
1372: String required = XmlUtil.getAttributeNSOrNull(e,
1373: Constants.ATTR_REQUIRED, Constants.NS_WSDL);
1374: if (required != null && required.equals(Constants.TRUE)) {
1375: Util.fail("parsing.requiredExtensibilityElement", e
1376: .getTagName(), e.getNamespaceURI());
1377: }
1378: }
1379:
1380: protected Documentation getDocumentationFor(Element e) {
1381: String s = XmlUtil.getTextForNode(e);
1382: if (s == null) {
1383: return null;
1384: } else {
1385: return new Documentation(s);
1386: }
1387: }
1388:
1389: protected void error(String key) {
1390: System.err.println(_localizer.localize(_messageFactory
1391: .getMessage(key)));
1392: }
1393:
1394: public HashSet getUse() {
1395: return hSet;
1396: }
1397:
1398: protected void warn(String key) {
1399: System.err.println(_localizer.localize(_messageFactory
1400: .getMessage(key)));
1401: }
1402:
1403: protected void warn(String key, String arg) {
1404: System.err.println(_localizer.localize(_messageFactory
1405: .getMessage(key, arg)));
1406: }
1407:
1408: protected void warn(String key, Object[] args) {
1409: System.err.println(_localizer.localize(_messageFactory
1410: .getMessage(key, args)));
1411: }
1412:
1413: private boolean _followImports;
1414: private String _targetNamespaceURI;
1415: private Map _extensionHandlers;
1416: private ArrayList _listeners;
1417: private boolean _useWSIBasicProfile = true;
1418: private LocalizableMessageFactory _messageFactory = null;
1419: private Localizer _localizer;
1420: private HashSet hSet = null;
1421: }
|