001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common Development
008: * and Distribution License("CDDL") (collectively, the "License"). You
009: * may not use this file except in compliance with the License. You can obtain
010: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
011: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
012: * language governing permissions and limitations under the License.
013: *
014: * When distributing the software, include this License Header Notice in each
015: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
016: * Sun designates this particular file as subject to the "Classpath" exception
017: * as provided by Sun in the GPL Version 2 section of the License file that
018: * accompanied this code. If applicable, add the following below the License
019: * Header, with the fields enclosed by brackets [] replaced by your own
020: * identifying information: "Portions Copyrighted [year]
021: * [name of copyright owner]"
022: *
023: * Contributor(s):
024: *
025: * If you wish your version of this file to be governed by only the CDDL or
026: * only the GPL Version 2, indicate your decision by adding "[Contributor]
027: * elects to include this software in this distribution under the [CDDL or GPL
028: * Version 2] license." If you don't indicate a single choice of license, a
029: * recipient has the option to distribute your version of this file under
030: * either the CDDL, the GPL Version 2 or to extend the choice of license to
031: * its licensees as provided above. However, if you add GPL Version 2 code
032: * and therefore, elected the GPL Version 2 license, then the option applies
033: * only if the new code is made subject to such option by the copyright
034: * holder.
035: */
036:
037: package com.sun.tools.xjc.reader.dtd.bindinfo;
038:
039: import com.sun.tools.xjc.Options;
040: import com.sun.tools.xjc.reader.AbstractExtensionBindingChecker;
041: import com.sun.tools.xjc.reader.Const;
042:
043: import org.xml.sax.Attributes;
044: import org.xml.sax.ErrorHandler;
045: import org.xml.sax.SAXException;
046: import org.xml.sax.XMLFilter;
047:
048: /**
049: * {@link XMLFilter} that checks the use of extension namespace URIs
050: * (to see if they have corresponding plugins), and otherwise report an error.
051: *
052: * <p>
053: * This code also masks the recognized extensions from the validator that
054: * will be plugged as the next component to this.
055: *
056: * @author Kohsuke Kawaguchi
057: */
058: final class DTDExtensionBindingChecker extends
059: AbstractExtensionBindingChecker {
060: public DTDExtensionBindingChecker(String schemaLanguage,
061: Options options, ErrorHandler handler) {
062: super (schemaLanguage, options, handler);
063: }
064:
065: /**
066: * Returns true if the elements with the given namespace URI
067: * should be blocked by this filter.
068: */
069: private boolean needsToBePruned(String uri) {
070: if (uri.equals(schemaLanguage))
071: return false;
072: if (uri.equals(Const.JAXB_NSURI))
073: return false;
074: if (uri.equals(Const.XJC_EXTENSION_URI))
075: return false;
076: // we don't want validator to see extensions that we understand ,
077: // because they will complain.
078: // OTOH, if this is an extension that we didn't understand,
079: // we want the validator to report an error
080: return enabledExtensions.contains(uri);
081: }
082:
083: public void startElement(String uri, String localName,
084: String qName, Attributes atts) throws SAXException {
085:
086: if (!isCutting()) {
087: if (!uri.equals("")) {
088: // "" is the standard namespace
089: checkAndEnable(uri);
090:
091: verifyTagName(uri, localName, qName);
092:
093: if (needsToBePruned(uri))
094: startCutting();
095: }
096: }
097:
098: super.startElement(uri, localName, qName, atts);
099: }
100: }
|