All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.xerces.parsers.DOMASBuilderImpl Maven / Gradle / Ivy

Go to download

Xerces2 is the next generation of high performance, fully compliant XML parsers in the Apache Xerces family. This new version of Xerces introduces the Xerces Native Interface (XNI), a complete framework for building parser components and configurations that is extremely modular and easy to program. The Apache Xerces2 parser is the reference implementation of XNI but other parser components, configurations, and parsers can be written using the Xerces Native Interface. For complete design and implementation documents, refer to the XNI Manual. Xerces2 is a fully conforming XML Schema 1.0 processor. A partial experimental implementation of the XML Schema 1.1 Structures and Datatypes Working Drafts (December 2009) and an experimental implementation of the XML Schema Definition Language (XSD): Component Designators (SCD) Candidate Recommendation (January 2010) are provided for evaluation. For more information, refer to the XML Schema page. Xerces2 also provides a complete implementation of the Document Object Model Level 3 Core and Load/Save W3C Recommendations and provides a complete implementation of the XML Inclusions (XInclude) W3C Recommendation. It also provides support for OASIS XML Catalogs v1.1. Xerces2 is able to parse documents written according to the XML 1.1 Recommendation, except that it does not yet provide an option to enable normalization checking as described in section 2.13 of this specification. It also handles namespaces according to the XML Namespaces 1.1 Recommendation, and will correctly serialize XML 1.1 documents if the DOM level 3 load/save APIs are in use.

There is a newer version: 2.12.2
Show newest version
/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.apache.xerces.parsers;

import java.util.Vector;

import org.apache.xerces.dom.ASModelImpl;
import org.apache.xerces.dom3.as.ASModel;
import org.apache.xerces.dom3.as.DOMASBuilder;
import org.apache.xerces.dom3.as.DOMASException;
import org.apache.xerces.impl.Constants;
import org.apache.xerces.impl.xs.SchemaGrammar;
import org.apache.xerces.impl.xs.XSGrammarBucket;
import org.apache.xerces.util.SymbolTable;
import org.apache.xerces.util.XMLGrammarPoolImpl;
import org.apache.xerces.xni.XNIException;
import org.apache.xerces.xni.grammars.Grammar;
import org.apache.xerces.xni.grammars.XMLGrammarPool;
import org.apache.xerces.xni.parser.XMLInputSource;
import org.w3c.dom.ls.LSInput;

/**
 * This is Abstract Schema DOM Builder class. It extends the DOMParserImpl
 * class. Provides support for preparsing schemas.
 *
 * @deprecated
 * @author Pavani Mukthipudi, Sun Microsystems Inc.
 * @author Neil Graham, IBM
 * @version $Id: DOMASBuilderImpl.java 447239 2006-09-18 05:08:26Z mrglavas $
 *
 */

public class DOMASBuilderImpl
    extends DOMParserImpl implements DOMASBuilder {

    //
    // Constants
    //

    // Feature ids

    protected static final String SCHEMA_FULL_CHECKING =
        Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_FULL_CHECKING;

    // Property ids

    protected static final String ERROR_REPORTER =
        Constants.XERCES_PROPERTY_PREFIX + Constants.ERROR_REPORTER_PROPERTY;

    protected static final String SYMBOL_TABLE =
        Constants.XERCES_PROPERTY_PREFIX + Constants.SYMBOL_TABLE_PROPERTY;

    protected static final String ENTITY_MANAGER =
        Constants.XERCES_PROPERTY_PREFIX + Constants.ENTITY_MANAGER_PROPERTY;


    //
    // Data
    //

    protected XSGrammarBucket fGrammarBucket;

    protected ASModelImpl fAbstractSchema;

    //
    // Constructors
    //

    /**
     * Constructs a DOM Builder using the dtd/xml schema parser configuration.
     */
    public DOMASBuilderImpl() {
        super(new XMLGrammarCachingConfiguration());
    } // 

    /**
     * Constructs a DOM Builder using the specified parser configuration.
     * We must demand that the configuration extend XMLGrammarCachingConfiguration to make
     * sure all relevant methods/features are available.
     */
    public DOMASBuilderImpl(XMLGrammarCachingConfiguration config) {
        super(config);
    } // (XMLParserConfiguration)

    /**
     * Constructs a DOM Builder using the specified symbol table.
     */
    public DOMASBuilderImpl(SymbolTable symbolTable) {
        super(new XMLGrammarCachingConfiguration(symbolTable));
    } // (SymbolTable)


    /**
     * Constructs a DOM Builder using the specified symbol table and
     * grammar pool.
     * The grammarPool implementation should extent the default
     * implementation; otherwise, correct functioning of this class may
     * not occur.
     */
    public DOMASBuilderImpl(SymbolTable symbolTable, XMLGrammarPool grammarPool) {
        super(new XMLGrammarCachingConfiguration(symbolTable, grammarPool));
    }

    //
    // DOMASBuilder methods
    //

    /**
     * Associate an ASModel with a document instance. This
     * ASModel will be used by the "
     * validate-if-schema" and "
     * datatype-normalization" options during the load of a new
     * Document.
     */
    public ASModel getAbstractSchema() {
        return fAbstractSchema;
    }

    /**
     * Associate an ASModel with a document instance. This
     * ASModel will be used by the "
     * validate-if-schema" and "
     * datatype-normalization" options during the load of a new
     * Document.
     */
    public void setAbstractSchema(ASModel abstractSchema) {

        // since the ASModel associated with this object is an attribute
        // according to the DOM IDL, we must obliterate anything
        // that was set before, rather than adding to it.
        // REVISIT:  so shouldn't we attempt to clear the
        // grammarPool before adding stuff to it?  - NG
        fAbstractSchema = (ASModelImpl)abstractSchema;

        // make sure the GrammarPool is properly initialized.
        XMLGrammarPool grammarPool = (XMLGrammarPool)fConfiguration.getProperty(StandardParserConfiguration.XMLGRAMMAR_POOL);
        // if there is no grammar pool, create one
        // REVISIT: ASBuilder should always create one.
        if (grammarPool == null) {
            // something's not right in this situation...
            grammarPool = new XMLGrammarPoolImpl();
            fConfiguration.setProperty(StandardParserConfiguration.XMLGRAMMAR_POOL,
                                       grammarPool);
        }
        if (fAbstractSchema != null) {
            initGrammarPool(fAbstractSchema, grammarPool);
        }
    }

    /**
     * Parse a Abstract Schema from a location identified by an URI.
     *
     * @param uri The location of the Abstract Schema to be read.
     * @return The newly created Abstract Schema.
     * @exception DOMASException
     *   Exceptions raised by parseASURI() originate with the
     *   installed ErrorHandler, and thus depend on the implementation of
     *   the DOMErrorHandler interfaces. The default error
     *   handlers will raise a DOMASException if any form of
     *   Abstract Schema inconsistencies or warning occurs during the parse,
     *   but application defined errorHandlers are not required to do so.
     *   
WRONG_MIME_TYPE_ERR: Raised when mimeTypeCheck is * true and the inputsource has an incorrect MIME Type. * See attribute mimeTypeCheck. * @exception DOMSystemException * Exceptions raised by parseURI() originate with the * installed ErrorHandler, and thus depend on the implementation of * the DOMErrorHandler interfaces. The default error * handlers will raise a DOMSystemException if any form I/O or other * system error occurs during the parse, but application defined error * handlers are not required to do so. */ public ASModel parseASURI(String uri) throws DOMASException, Exception { XMLInputSource source = new XMLInputSource(null, uri, null); return parseASInputSource(source); } /** * Parse a Abstract Schema from a location identified by an * LSInput. * * @param is The LSInput from which the source * Abstract Schema is to be read. * @return The newly created ASModel. * @exception DOMASException * Exceptions raised by parseASURI() originate with the * installed ErrorHandler, and thus depend on the implementation of * the DOMErrorHandler interfaces. The default error * handlers will raise a DOMASException if any form of * Abstract Schema inconsistencies or warning occurs during the parse, * but application defined errorHandlers are not required to do so. *
WRONG_MIME_TYPE_ERR: Raised when mimeTypeCheck is * true and the inputsource has an incorrect MIME Type. See attribute * mimeTypeCheck. * @exception DOMSystemException * Exceptions raised by parseURI() originate with the * installed ErrorHandler, and thus depend on the implementation of * the DOMErrorHandler interfaces. The default error * handlers will raise a DOMSystemException if any form I/O or other * system error occurs during the parse, but application defined error * handlers are not required to do so. */ public ASModel parseASInputSource(LSInput is) throws DOMASException, Exception { // need to wrap the LSInput with an XMLInputSource XMLInputSource xis = this.dom2xmlInputSource(is); try { return parseASInputSource(xis); } catch (XNIException e) { Exception ex = e.getException(); throw ex; } } ASModel parseASInputSource(XMLInputSource is) throws Exception { if (fGrammarBucket == null) { fGrammarBucket = new XSGrammarBucket(); } initGrammarBucket(); // actually do the parse: // save some casting XMLGrammarCachingConfiguration gramConfig = (XMLGrammarCachingConfiguration)fConfiguration; // ensure grammarPool doesn't absorb grammars while it's parsing gramConfig.lockGrammarPool(); SchemaGrammar grammar = gramConfig.parseXMLSchema(is); gramConfig.unlockGrammarPool(); ASModelImpl newAsModel = null; if (grammar != null) { newAsModel = new ASModelImpl(); fGrammarBucket.putGrammar (grammar, true); addGrammars(newAsModel, fGrammarBucket); } return newAsModel; } // put all the grammars we have access to in the GrammarBucket private void initGrammarBucket() { fGrammarBucket.reset(); if (fAbstractSchema != null) initGrammarBucketRecurse(fAbstractSchema); } private void initGrammarBucketRecurse(ASModelImpl currModel) { if(currModel.getGrammar() != null) { fGrammarBucket.putGrammar(currModel.getGrammar()); } for(int i = 0; i < currModel.getInternalASModels().size(); i++) { ASModelImpl nextModel = (ASModelImpl)(currModel.getInternalASModels().elementAt(i)); initGrammarBucketRecurse(nextModel); } } private void addGrammars(ASModelImpl model, XSGrammarBucket grammarBucket) { SchemaGrammar [] grammarList = grammarBucket.getGrammars(); for(int i=0; i




© 2015 - 2024 Weber Informatics LLC | Privacy Policy