View Javadoc
1   /*
2    * Copyright (c) 1997, 2012, 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.tools.internal.ws.wsdl.parser;
27  
28  import com.sun.tools.internal.ws.api.wsdl.TWSDLExtensible;
29  import com.sun.tools.internal.ws.api.wsdl.TWSDLExtensionHandler;
30  import com.sun.tools.internal.ws.api.wsdl.TWSDLParserContext;
31  import com.sun.tools.internal.ws.util.xml.XmlUtil;
32  import com.sun.xml.internal.ws.policy.sourcemodel.wspolicy.NamespaceVersion;
33  import com.sun.xml.internal.ws.policy.sourcemodel.wspolicy.XmlToken;
34  
35  import org.w3c.dom.Element;
36  
37  /**
38   * Policies are evaluated at runtime. This class makes sure that wscompile/wsimport
39   * ignores all policy elements at tooltime.
40   *
41   * @author Jakub Podlesak (jakub.podlesak at sun.com)
42   * @author Fabian Ritzmann
43   */
44  
45  public class Policy15ExtensionHandler extends TWSDLExtensionHandler {
46  
47      @Override
48      public String getNamespaceURI() {
49          return NamespaceVersion.v1_5.toString();
50      }
51  
52      @Override
53      public boolean handlePortTypeExtension(TWSDLParserContext context, TWSDLExtensible parent, Element e) {
54          return handleExtension(context, parent, e);
55      }
56  
57      @Override
58      public boolean handleDefinitionsExtension(TWSDLParserContext context, TWSDLExtensible parent, Element e) {
59          return handleExtension(context, parent, e);
60      }
61  
62      @Override
63      public boolean handleBindingExtension(TWSDLParserContext context, TWSDLExtensible parent, Element e) {
64          return handleExtension(context, parent, e);
65      }
66  
67      @Override
68      public boolean handleOperationExtension(TWSDLParserContext context, TWSDLExtensible parent, Element e) {
69          return handleExtension(context, parent, e);
70      }
71  
72      @Override
73      public boolean handleInputExtension(TWSDLParserContext context, TWSDLExtensible parent, Element e) {
74          return handleExtension(context, parent, e);
75      }
76  
77      @Override
78      public boolean handleOutputExtension(TWSDLParserContext context, TWSDLExtensible parent, Element e) {
79          return handleExtension(context, parent, e);
80      }
81  
82      @Override
83      public boolean handleFaultExtension(TWSDLParserContext context, TWSDLExtensible parent, Element e) {
84          return handleExtension(context, parent, e);
85      }
86  
87      @Override
88      public boolean handleServiceExtension(TWSDLParserContext context, TWSDLExtensible parent, Element e) {
89          return handleExtension(context, parent, e);
90      }
91  
92      @Override
93      public boolean handlePortExtension(TWSDLParserContext context, TWSDLExtensible parent, Element e) {
94          return handleExtension(context, parent, e);
95      }
96  
97      /**
98       * Only skip the element if it is a <wsp:Policy/>, <wsp:PolicyReference/> or
99       * <wsp:UsingPolicy> element.
100      */
101     private boolean handleExtension(TWSDLParserContext context, TWSDLExtensible parent, Element e) {
102         return XmlUtil.matchesTagNS(e, NamespaceVersion.v1_5.asQName(XmlToken.Policy))
103                || XmlUtil.matchesTagNS(e,NamespaceVersion.v1_5.asQName(XmlToken.PolicyReference))
104                || XmlUtil.matchesTagNS(e, NamespaceVersion.v1_5.asQName(XmlToken.UsingPolicy));
105     }
106 
107 }