author | mkos |
Sun, 30 Dec 2012 00:00:00 +0100 | |
changeset 22678 | ac1ea46be942 |
parent 12009 | 4abb694f273a |
permissions | -rw-r--r-- |
12009 | 1 |
/* |
22678
ac1ea46be942
8029237: Update copyright year to match last edit in jaxws repository for 2012
mkos
parents:
12009
diff
changeset
|
2 |
* Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. |
12009 | 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.xjc.reader; |
|
27 |
||
28 |
import java.util.StringTokenizer; |
|
29 |
||
30 |
import com.sun.tools.internal.xjc.Options; |
|
31 |
||
32 |
import org.xml.sax.Attributes; |
|
33 |
import org.xml.sax.ErrorHandler; |
|
34 |
import org.xml.sax.SAXException; |
|
35 |
||
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 { |
|
59 |
||
60 |
/** |
|
61 |
* Number of the elements encountered. Used to detect the root element. |
|
62 |
*/ |
|
63 |
private int count=0; |
|
64 |
||
65 |
public ExtensionBindingChecker(String schemaLanguage, Options options, ErrorHandler handler) { |
|
66 |
super(schemaLanguage, options, handler); |
|
67 |
} |
|
68 |
||
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; |
|
80 |
||
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 |
} |
|
87 |
||
88 |
||
89 |
@Override |
|
90 |
public void startDocument() throws SAXException { |
|
91 |
super.startDocument(); |
|
92 |
count=0; |
|
93 |
} |
|
94 |
||
95 |
@Override |
|
96 |
public void startElement(String namespaceURI, String localName, String qName, Attributes atts) |
|
97 |
throws SAXException { |
|
98 |
||
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() ); |
|
105 |
||
106 |
if(!allowExtensions) |
|
107 |
error( Messages.ERR_VENDOR_EXTENSION_DISALLOWED_IN_STRICT_MODE.format() ); |
|
108 |
||
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 |
} |
|
121 |
||
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 |
} |
|
133 |
||
134 |
count++; |
|
135 |
super.startElement(namespaceURI, localName, qName, atts); |
|
136 |
} |
|
137 |
} |