src/share/jaxws_classes/com/sun/tools/internal/xjc/reader/ExtensionBindingChecker.java

Tue, 09 Apr 2013 14:51:13 +0100

author
alanb
date
Tue, 09 Apr 2013 14:51:13 +0100
changeset 368
0989ad8c0860
parent 0
373ffda63c9a
permissions
-rw-r--r--

8010393: Update JAX-WS RI to 2.2.9-b12941
Reviewed-by: alanb, erikj
Contributed-by: miroslav.kos@oracle.com, martin.grebac@oracle.com

     1 /*
     2  * Copyright (c) 1997, 2011, 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  */
    26 package com.sun.tools.internal.xjc.reader;
    28 import java.util.StringTokenizer;
    30 import com.sun.tools.internal.xjc.Options;
    32 import org.xml.sax.Attributes;
    33 import org.xml.sax.ErrorHandler;
    34 import org.xml.sax.SAXException;
    36 /**
    37  * This filter checks jaxb:extensionBindingPrefix and
    38  * pass/filter extension bindings.
    39  *
    40  * <p>
    41  * This filter also remembers enabled extension namespaces
    42  * and filters out any extension namespaces that doesn't belong
    43  * to those. The net effect is that disabled customizations
    44  * will never pass through this filter.
    45  *
    46  * <p>
    47  * Note that we can't just filter out all foreign namespaces,
    48  * as we need to use user-defined tags in documentations to generate javadoc.
    49  *
    50  * <p>
    51  * The class needs to know the list of extension binding namespaces
    52  * that the RI recognizes.
    53  * To add new URI, modify the isSupportedExtension method.
    54  *
    55  * @author
    56  *     Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
    57  */
    58 public final class ExtensionBindingChecker extends AbstractExtensionBindingChecker {
    60     /**
    61      * Number of the elements encountered. Used to detect the root element.
    62      */
    63     private int count=0;
    65     public ExtensionBindingChecker(String schemaLanguage, Options options, ErrorHandler handler) {
    66         super(schemaLanguage, options, handler);
    67     }
    69     /**
    70      * Returns true if the elements with the given namespace URI
    71      * should be blocked by this filter.
    72      */
    73     private boolean needsToBePruned( String uri ) {
    74         if( uri.equals(schemaLanguage) )
    75             return false;
    76         if( uri.equals(Const.JAXB_NSURI) )
    77             return false;
    78         if( enabledExtensions.contains(uri) )
    79             return false;
    81         // we don't need to prune something unless
    82         // the rest of the processor recognizes it as something special.
    83         // this allows us to send the documentation and other harmless
    84         // foreign XML fragments, which may be picked up as documents.
    85         return isRecognizableExtension(uri);
    86     }
    89     @Override
    90     public void startDocument() throws SAXException {
    91         super.startDocument();
    92         count=0;
    93     }
    95     @Override
    96     public void startElement(String namespaceURI, String localName, String qName, Attributes atts)
    97         throws SAXException {
    99         if(!isCutting()) {
   100             String v = atts.getValue(Const.JAXB_NSURI,"extensionBindingPrefixes");
   101             if(v!=null) {
   102                 if(count!=0)
   103                     // the binding attribute is allowed only at the root level.
   104                     error( Messages.ERR_UNEXPECTED_EXTENSION_BINDING_PREFIXES.format() );
   106                 if(!allowExtensions)
   107                     error( Messages.ERR_VENDOR_EXTENSION_DISALLOWED_IN_STRICT_MODE.format() );
   109                 // then remember the associated namespace URIs.
   110                 StringTokenizer tokens = new StringTokenizer(v);
   111                 while(tokens.hasMoreTokens()) {
   112                     String prefix = tokens.nextToken();
   113                     String uri = nsSupport.getURI(prefix);
   114                     if( uri==null )
   115                         // undeclared prefix
   116                         error( Messages.ERR_UNDECLARED_PREFIX.format(prefix) );
   117                     else
   118                         checkAndEnable(uri);
   119                 }
   120             }
   122             if( needsToBePruned(namespaceURI) ) {
   123                 // start pruning the tree. Call the super class method directly.
   124                 if( isRecognizableExtension(namespaceURI) ) {
   125                     // but this is a supported customization.
   126                     // isn't the user forgetting @jaxb:extensionBindingPrefixes?
   127                     warning( Messages.ERR_SUPPORTED_EXTENSION_IGNORED.format(namespaceURI) );
   128                 }
   129                 startCutting();
   130             } else
   131                 verifyTagName(namespaceURI, localName, qName);
   132         }
   134         count++;
   135         super.startElement(namespaceURI, localName, qName, atts);
   136     }
   137 }

mercurial