1 /*
   2  * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.xml.internal.ws.api.model.wsdl;
  27 
  28 
  29 import com.sun.istack.internal.NotNull;
  30 import com.sun.xml.internal.ws.api.server.Container;
  31 import com.sun.xml.internal.ws.api.wsdl.parser.WSDLParserExtension;
  32 import com.sun.xml.internal.ws.api.wsdl.parser.XMLEntityResolver;
  33 import com.sun.xml.internal.ws.api.policy.PolicyResolver;
  34 import com.sun.xml.internal.ws.api.policy.PolicyResolverFactory;
  35 import com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser;
  36 import com.sun.xml.internal.ws.policy.PolicyMap;
  37 import org.xml.sax.SAXException;
  38 
  39 import javax.xml.namespace.QName;
  40 import javax.xml.stream.XMLStreamException;
  41 import java.io.IOException;
  42 import java.util.Map;
  43 
  44 /**
  45  * Provides abstraction of wsdl:definitions.
  46  *
  47  * @author Vivek Pandey
  48  */
  49 public interface WSDLModel extends WSDLExtensible {
  50     /**
  51      * Gets {@link WSDLPortType} that models <code>wsdl:portType</code>
  52      *
  53      * @param name non-null quaified name of wsdl:message, where the localName is the value of <code>wsdl:portType@name</code> and
  54      *             the namespaceURI is the value of wsdl:definitions@targetNamespace
  55      * @return A {@link com.sun.xml.internal.ws.api.model.wsdl.WSDLPortType} or null if no wsdl:portType found.
  56      */
  57     WSDLPortType getPortType(@NotNull QName name);
  58 
  59     /**
  60      * Gets {@link WSDLBoundPortType} that models <code>wsdl:binding</code>
  61      *
  62      * @param name non-null quaified name of wsdl:binding, where the localName is the value of <code>wsdl:binding@name</code> and
  63      *             the namespaceURI is the value of wsdl:definitions@targetNamespace
  64      * @return A {@link WSDLBoundPortType} or null if no wsdl:binding found
  65      */
  66     WSDLBoundPortType getBinding(@NotNull QName name);
  67 
  68     /**
  69      * Give a {@link WSDLBoundPortType} for the given wsdl:service and wsdl:port names.
  70      *
  71      * @param serviceName service QName
  72      * @param portName    port QName
  73      * @return A {@link WSDLBoundPortType}. null if the Binding for the given wsd:service and wsdl:port name are not
  74      *         found.
  75      */
  76     WSDLBoundPortType getBinding(@NotNull QName serviceName, @NotNull QName portName);
  77 
  78     /**
  79      * Gets {@link WSDLService} that models <code>wsdl:service</code>
  80      *
  81      * @param name non-null quaified name of wsdl:service, where the localName is the value of <code>wsdl:service@name</code> and
  82      *             the namespaceURI is the value of wsdl:definitions@targetNamespace
  83      * @return A {@link WSDLService} or null if no wsdl:service found
  84      */
  85     WSDLService getService(@NotNull QName name);
  86 
  87     /**
  88      * Gives a {@link Map} of wsdl:portType {@link QName} and {@link WSDLPortType}
  89      *
  90      * @return an empty Map if the wsdl document has no wsdl:portType
  91      */
  92     @NotNull Map<QName, ? extends WSDLPortType> getPortTypes();
  93 
  94     /**
  95      * Gives a {@link Map} of wsdl:binding {@link QName} and {@link WSDLBoundPortType}
  96      *
  97      * @return an empty Map if the wsdl document has no wsdl:binding
  98      */
  99     @NotNull Map<QName, WSDLBoundPortType> getBindings();
 100 
 101     /**
 102      * Gives a {@link Map} of wsdl:service qualified name and {@link com.sun.xml.internal.ws.api.model.wsdl.WSDLService}
 103      *
 104      * @return an empty Map if the wsdl document has no wsdl:service
 105      */
 106     @NotNull Map<QName, ? extends WSDLService> getServices();
 107 
 108     /**
 109      * Gives the PolicyMap associated with the WSDLModel
 110      *
 111      * @return PolicyMap
 112      *
 113      * @deprecated
 114      * Do not use this method as the PolicyMap API is not final yet and might change in next few months.
 115      */
 116     public PolicyMap getPolicyMap();
 117 
 118 
 119     /**
 120      * Main purpose of this class is to  parsing of a WSDL and get the {@link WSDLModel} from it.
 121      */
 122     public class WSDLParser{
 123        /**
 124          * Parses WSDL from the given wsdlLoc and gives a {@link WSDLModel} built from it.
 125          *
 126          * @param wsdlEntityParser  Works like an entityResolver to resolve WSDLs
 127          * @param resolver  {@link XMLEntityResolver}, works at XML infoset level
 128          * @param isClientSide  true - its invoked on the client, false means its invoked on the server
 129          * @param extensions var args of {@link com.sun.xml.internal.ws.api.wsdl.parser.WSDLParserExtension}s
 130          * @return A {@link WSDLModel} built from the given wsdlLocation}
 131          * @throws java.io.IOException
 132          * @throws javax.xml.stream.XMLStreamException
 133          * @throws org.xml.sax.SAXException
 134          */
 135         public static @NotNull WSDLModel parse(XMLEntityResolver.Parser wsdlEntityParser, XMLEntityResolver resolver, boolean isClientSide, WSDLParserExtension... extensions) throws IOException, XMLStreamException, SAXException {
 136             return parse(wsdlEntityParser, resolver, isClientSide, Container.NONE, extensions);
 137         }
 138 
 139         /**
 140          * Parses WSDL from the given wsdlLoc and gives a {@link WSDLModel} built from it.
 141          *
 142          * @param wsdlEntityParser  Works like an entityResolver to resolve WSDLs
 143          * @param resolver  {@link XMLEntityResolver}, works at XML infoset level
 144          * @param isClientSide  true - its invoked on the client, false means its invoked on the server
 145          * @param container - container in which the parser is run
 146          * @param extensions var args of {@link com.sun.xml.internal.ws.api.wsdl.parser.WSDLParserExtension}s
 147          * @return A {@link WSDLModel} built from the given wsdlLocation}
 148          * @throws java.io.IOException
 149          * @throws javax.xml.stream.XMLStreamException
 150          * @throws org.xml.sax.SAXException
 151          */
 152         public static @NotNull WSDLModel parse(XMLEntityResolver.Parser wsdlEntityParser, XMLEntityResolver resolver, boolean isClientSide, @NotNull Container container, WSDLParserExtension... extensions) throws IOException, XMLStreamException, SAXException {
 153             return parse(wsdlEntityParser, resolver, isClientSide, container, PolicyResolverFactory.create(),extensions);
 154         }
 155 
 156 
 157         /**
 158          * Parses WSDL from the given wsdlLoc and gives a {@link WSDLModel} built from it.
 159          *
 160          * @param wsdlEntityParser  Works like an entityResolver to resolve WSDLs
 161          * @param resolver  {@link XMLEntityResolver}, works at XML infoset level
 162          * @param isClientSide  true - its invoked on the client, false means its invoked on the server
 163          * @param container - container in which the parser is run
 164          * @param policyResolver - PolicyResolver for resolving effective Policy
 165          * @param extensions var args of {@link com.sun.xml.internal.ws.api.wsdl.parser.WSDLParserExtension}s
 166          * @return A {@link WSDLModel} built from the given wsdlLocation}
 167          * @throws java.io.IOException
 168          * @throws javax.xml.stream.XMLStreamException
 169          * @throws org.xml.sax.SAXException
 170          */
 171         public static @NotNull WSDLModel parse(XMLEntityResolver.Parser wsdlEntityParser, XMLEntityResolver resolver, boolean isClientSide, @NotNull Container container, PolicyResolver policyResolver,  WSDLParserExtension... extensions) throws IOException, XMLStreamException, SAXException {
 172             return RuntimeWSDLParser.parse(wsdlEntityParser, resolver, isClientSide, container, policyResolver, extensions);
 173         }
 174 
 175     }
 176 }