Tue, 09 Apr 2013 14:51:13 +0100
8010393: Update JAX-WS RI to 2.2.9-b12941
Reviewed-by: alanb, erikj
Contributed-by: miroslav.kos@oracle.com, martin.grebac@oracle.com
aoqi@0 | 1 | /* |
aoqi@0 | 2 | * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. |
aoqi@0 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
aoqi@0 | 4 | * |
aoqi@0 | 5 | * This code is free software; you can redistribute it and/or modify it |
aoqi@0 | 6 | * under the terms of the GNU General Public License version 2 only, as |
aoqi@0 | 7 | * published by the Free Software Foundation. Oracle designates this |
aoqi@0 | 8 | * particular file as subject to the "Classpath" exception as provided |
aoqi@0 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
aoqi@0 | 10 | * |
aoqi@0 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
aoqi@0 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
aoqi@0 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
aoqi@0 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
aoqi@0 | 15 | * accompanied this code). |
aoqi@0 | 16 | * |
aoqi@0 | 17 | * You should have received a copy of the GNU General Public License version |
aoqi@0 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
aoqi@0 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
aoqi@0 | 20 | * |
aoqi@0 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
aoqi@0 | 22 | * or visit www.oracle.com if you need additional information or have any |
aoqi@0 | 23 | * questions. |
aoqi@0 | 24 | */ |
aoqi@0 | 25 | |
aoqi@0 | 26 | package com.sun.tools.internal.xjc.reader; |
aoqi@0 | 27 | |
aoqi@0 | 28 | import java.util.StringTokenizer; |
aoqi@0 | 29 | |
aoqi@0 | 30 | import com.sun.tools.internal.xjc.Options; |
aoqi@0 | 31 | |
aoqi@0 | 32 | import org.xml.sax.Attributes; |
aoqi@0 | 33 | import org.xml.sax.ErrorHandler; |
aoqi@0 | 34 | import org.xml.sax.SAXException; |
aoqi@0 | 35 | |
aoqi@0 | 36 | /** |
aoqi@0 | 37 | * This filter checks jaxb:extensionBindingPrefix and |
aoqi@0 | 38 | * pass/filter extension bindings. |
aoqi@0 | 39 | * |
aoqi@0 | 40 | * <p> |
aoqi@0 | 41 | * This filter also remembers enabled extension namespaces |
aoqi@0 | 42 | * and filters out any extension namespaces that doesn't belong |
aoqi@0 | 43 | * to those. The net effect is that disabled customizations |
aoqi@0 | 44 | * will never pass through this filter. |
aoqi@0 | 45 | * |
aoqi@0 | 46 | * <p> |
aoqi@0 | 47 | * Note that we can't just filter out all foreign namespaces, |
aoqi@0 | 48 | * as we need to use user-defined tags in documentations to generate javadoc. |
aoqi@0 | 49 | * |
aoqi@0 | 50 | * <p> |
aoqi@0 | 51 | * The class needs to know the list of extension binding namespaces |
aoqi@0 | 52 | * that the RI recognizes. |
aoqi@0 | 53 | * To add new URI, modify the isSupportedExtension method. |
aoqi@0 | 54 | * |
aoqi@0 | 55 | * @author |
aoqi@0 | 56 | * Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com) |
aoqi@0 | 57 | */ |
aoqi@0 | 58 | public final class ExtensionBindingChecker extends AbstractExtensionBindingChecker { |
aoqi@0 | 59 | |
aoqi@0 | 60 | /** |
aoqi@0 | 61 | * Number of the elements encountered. Used to detect the root element. |
aoqi@0 | 62 | */ |
aoqi@0 | 63 | private int count=0; |
aoqi@0 | 64 | |
aoqi@0 | 65 | public ExtensionBindingChecker(String schemaLanguage, Options options, ErrorHandler handler) { |
aoqi@0 | 66 | super(schemaLanguage, options, handler); |
aoqi@0 | 67 | } |
aoqi@0 | 68 | |
aoqi@0 | 69 | /** |
aoqi@0 | 70 | * Returns true if the elements with the given namespace URI |
aoqi@0 | 71 | * should be blocked by this filter. |
aoqi@0 | 72 | */ |
aoqi@0 | 73 | private boolean needsToBePruned( String uri ) { |
aoqi@0 | 74 | if( uri.equals(schemaLanguage) ) |
aoqi@0 | 75 | return false; |
aoqi@0 | 76 | if( uri.equals(Const.JAXB_NSURI) ) |
aoqi@0 | 77 | return false; |
aoqi@0 | 78 | if( enabledExtensions.contains(uri) ) |
aoqi@0 | 79 | return false; |
aoqi@0 | 80 | |
aoqi@0 | 81 | // we don't need to prune something unless |
aoqi@0 | 82 | // the rest of the processor recognizes it as something special. |
aoqi@0 | 83 | // this allows us to send the documentation and other harmless |
aoqi@0 | 84 | // foreign XML fragments, which may be picked up as documents. |
aoqi@0 | 85 | return isRecognizableExtension(uri); |
aoqi@0 | 86 | } |
aoqi@0 | 87 | |
aoqi@0 | 88 | |
aoqi@0 | 89 | @Override |
aoqi@0 | 90 | public void startDocument() throws SAXException { |
aoqi@0 | 91 | super.startDocument(); |
aoqi@0 | 92 | count=0; |
aoqi@0 | 93 | } |
aoqi@0 | 94 | |
aoqi@0 | 95 | @Override |
aoqi@0 | 96 | public void startElement(String namespaceURI, String localName, String qName, Attributes atts) |
aoqi@0 | 97 | throws SAXException { |
aoqi@0 | 98 | |
aoqi@0 | 99 | if(!isCutting()) { |
aoqi@0 | 100 | String v = atts.getValue(Const.JAXB_NSURI,"extensionBindingPrefixes"); |
aoqi@0 | 101 | if(v!=null) { |
aoqi@0 | 102 | if(count!=0) |
aoqi@0 | 103 | // the binding attribute is allowed only at the root level. |
aoqi@0 | 104 | error( Messages.ERR_UNEXPECTED_EXTENSION_BINDING_PREFIXES.format() ); |
aoqi@0 | 105 | |
aoqi@0 | 106 | if(!allowExtensions) |
aoqi@0 | 107 | error( Messages.ERR_VENDOR_EXTENSION_DISALLOWED_IN_STRICT_MODE.format() ); |
aoqi@0 | 108 | |
aoqi@0 | 109 | // then remember the associated namespace URIs. |
aoqi@0 | 110 | StringTokenizer tokens = new StringTokenizer(v); |
aoqi@0 | 111 | while(tokens.hasMoreTokens()) { |
aoqi@0 | 112 | String prefix = tokens.nextToken(); |
aoqi@0 | 113 | String uri = nsSupport.getURI(prefix); |
aoqi@0 | 114 | if( uri==null ) |
aoqi@0 | 115 | // undeclared prefix |
aoqi@0 | 116 | error( Messages.ERR_UNDECLARED_PREFIX.format(prefix) ); |
aoqi@0 | 117 | else |
aoqi@0 | 118 | checkAndEnable(uri); |
aoqi@0 | 119 | } |
aoqi@0 | 120 | } |
aoqi@0 | 121 | |
aoqi@0 | 122 | if( needsToBePruned(namespaceURI) ) { |
aoqi@0 | 123 | // start pruning the tree. Call the super class method directly. |
aoqi@0 | 124 | if( isRecognizableExtension(namespaceURI) ) { |
aoqi@0 | 125 | // but this is a supported customization. |
aoqi@0 | 126 | // isn't the user forgetting @jaxb:extensionBindingPrefixes? |
aoqi@0 | 127 | warning( Messages.ERR_SUPPORTED_EXTENSION_IGNORED.format(namespaceURI) ); |
aoqi@0 | 128 | } |
aoqi@0 | 129 | startCutting(); |
aoqi@0 | 130 | } else |
aoqi@0 | 131 | verifyTagName(namespaceURI, localName, qName); |
aoqi@0 | 132 | } |
aoqi@0 | 133 | |
aoqi@0 | 134 | count++; |
aoqi@0 | 135 | super.startElement(namespaceURI, localName, qName, atts); |
aoqi@0 | 136 | } |
aoqi@0 | 137 | } |