You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-dev@xerces.apache.org by ne...@ca.ibm.com on 2002/01/16 00:26:53 UTC

[grammar caching]: re-revised interfaces

Hi folks,

FYI, I think I've incorporated all the changes we've agreed upon.  I've
prepended the package names whre each of these objects would live to make
discussion easier.

This exercise has pointed out to me that, if we locate these interfaces in
the xni package, we'll also have to have the Grammar superclass there.
Right now, the Grammar class we have in the impl.validation directory is
simply a placeholder, since when we wrote up the ASBuilder implementation
(very shortly before the Xerces2 beta 4 DCut) we weren't sure how to merge
the Grammar and DTDGrammar classes in the impl.dtd package.  Seems clear to
me that this needs doing; I guess now is as good a time as any.

So:  in addition to soliciting everyone's views of just where this stuff
can live, it would be great to hear (especially from folks who originally
developed DTD support in Xerces2) about what comonnality should exist in
the Grammar superclass, and how we should go about unifying the
impl.validation.Grammar and impl.validation.DTDGrammar classes.

Cheers,
Neil

// The Grammar Pool interface
public interface org.apache.xerces.xni.grammars.XMLGrammarPool {

    // we are trying to make this XMLGrammarPool work for all kinds of
    // grammars, so we have a parameter "grammarType" for each of the methods.
    // It could be "schema", "dtd, etc., or it could be recast into an
    // integer.

    // retrieve the initial known set of grammars. this method is
    // called by a validator before the validation starts. the application
    // can provide an initial set of grammars available to the current
    // validation attempt.
    public Grammar[] retrieveInitialGrammarSet(String grammarType);

    // return the final set of grammars that the validator ended up
    // with.
    // This method is called after the
    // validation finishes. The application may then choose to cache some
    // of the returned grammars.
    public void cacheGrammars(String grammarType, Grammar[] grammars);

    // This method requests that the application retrieve a grammar
    // corresponding to the given GrammarIdentifier from its cache.
    // If it cannot do so it must return null; the parser will then
    // call the EntityResolver.  An application must not call its
    // EntityResolver itself from this method.
    public Grammar retrieveGrammar(XMLGrammarIdentifier desc);

} // XMLGrammarPool

// This represents the basic physical description of the location of any
// XML resource (a Schema grammar, a DTD, a general entity etc.)
public interface org.apache.xerces.xni.XMLResourceIdentifier {

    /** Returns the public identifier. */
    public String getPublicId();

    /** Returns the expanded system identifier. */
    public String getSystemId();

    /** Returns the literal system identifier. */
    public String getLiteralSystemId();

    /** Returns the base system identifier. */
    public String getBaseSystemId();
} // XMLResourceIdentifier

// This interface describes basic attributes of XML grammars--their
// physical location and their type.
public interface org.apache.xerces.xni.grammars.XMLGrammarIdentifier  extends XMLResourceIdentifier {
    // returns the type of the grammar (e.g., DTD or XSD).
    public String getGrammarType();
} // XMLGrammarIdentifier

// All information specific to dTD grammars.
public class XMLDTDIdentifier implements XMLGrammarIdentifier {
    // return the root name of this DTD
    public String getRootName();

    // return the internal subset.  Entities should not be expanded;
    // this is simply the raw string representation of the stuff
    // between [ and ]>
    public String getInternalSubset ();
} // class XMLDTDIdentifier

// All information specific to XML Schema grammars.
public class XSDIdentifier implements XMLGrammarIdentifier {
    // used to indicate what triggered the call
    // we don't include xsi:schemaLocation/noNamespaceSchemaLocation
    // because we'll defer the loading of schema documents until
    // a component from that namespace is referenced from the instance
    public final static int CONTEXT_INCLUDE   = 0;
    public final static int CONTEXT_REDEFINE  = 1;
    public final static int CONTEXT_IMPORT    = 2;
    public final static int CONTEXT_ELEMENT   = 3;
    public final static int CONTEXT_ATTRIBUTE = 4;
    public final static int CONTEXT_XSITYPE   = 5;

    public int getContextType();

    // for include and redefine, the namespace will be the target
    // namespace of the enclosing document. (or empty string?)
    public String getTargetNamespace();

    // for import and xsi:location attributes, it's possible to have
    // multiple hints for one namespace. so it's an array whose first
    // element will derive from the noNamespaceSchemaLocation or
    // schemaLocation property as the case of the targetNamespace may
    // be:
    public String[] getLocationHints();

    // If it's triggered by the document, the name of the
    // triggering component: element, attribute or xsi:type
    public QName getTriggeringComponent();

    // More information about "other location hint":
    // everything about the enclosing element
    public QName getEnclosingElementName();
    public XMLAttributes getAttributes();
}

/**
 * This interface is used to resolve external parsed entities. The
 * application can register an object that implements this interface
 * with the parser configuration in order to intercept entities and
 * resolve them explicitly. If the registered entity resolver cannot
 * resolve the entity, it should return <code>null</code> so that the
 * parser will try to resolve the entity using a default mechanism.
 *
 * @see XMLParserConfiguration
 *
 * @author Andy Clark, IBM
 *
 * @version $Id: XMLEntityResolver.java,v 1.2 2001/08/23 00:35:37 lehors Exp $
 */
public interface org.apache.xerces.xni.XMLEntityResolver {

    //
    // XMLEntityResolver methods
    //

    /**
     * Resolves an external parsed entity. If the entity cannot be
     * resolved, this method should return null.
     *
     * @param desc:  contains a description for the type of entity
     *      (grammar, abstract schema) being sought.
     * @throws XNIException Thrown on general error.
     * @throws IOException  Thrown if resolved entity stream cannot be
     *                      opened or some other i/o error occurs.
     */
    public XMLInputSource resolveEntity(XMLResourceIdentifier desc)
        throws XNIException, IOException;

} // interface XMLEntityResolver


/**
 * Location information.
 * <p>In addition to storing information as to the physical location of
 *  a resource, provides a means for pointing to individual
 *  characters in the resource.</p>
 *
 * @author Andy Clark, IBM
 *
 * @version $Id: XMLLocator.java,v 1.2 2001/08/23 00:35:36 lehors Exp $
 */
public interface org.apache.xerces.xni.XMLLocator extends XMLResourceIdentifier {

    //
    // XMLLocator methods
    //

    /** Returns the line number. */
    public int getLineNumber();

    /** Returns the column number. */
    public int getColumnNumber();

} // interface XMLLocator


/*
 * The Apache Software License, Version 1.1
 *
 *
 * Copyright (c) 2000,2001 The Apache Software Foundation.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *
 * 3. The end-user documentation included with the redistribution,
 *    if any, must include the following acknowledgment:
 *       "This product includes software developed by the
 *        Apache Software Foundation (http://www.apache.org/)."
 *    Alternately, this acknowledgment may appear in the software itself,
 *    if and wherever such third-party acknowledgments normally appear.
 *
 * 4. The names "Xerces" and "Apache Software Foundation" must
 *    not be used to endorse or promote products derived from this
 *    software without prior written permission. For written
 *    permission, please contact apache@apache.org.
 *
 * 5. Products derived from this software may not be called "Apache",
 *    nor may "Apache" appear in their name, without prior written
 *    permission of the Apache Software Foundation.
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 * ====================================================================
 *
 * This software consists of voluntary contributions made by many
 * individuals on behalf of the Apache Software Foundation and was
 * originally based on software copyright (c) 1999, International
 * Business Machines, Inc., http://www.apache.org.  For more
 * information on the Apache Software Foundation, please see
 * <http://www.apache.org/>.
 */

package org.apache.xerces.impl.validation;

import java.lang.Integer;
import java.util.Hashtable;

import org.apache.xerces.impl.dtd.XMLAttributeDecl;
import org.apache.xerces.impl.dtd.XMLNotationDecl;
import org.apache.xerces.impl.dtd.XMLEntityDecl;
import org.apache.xerces.impl.dtd.XMLSimpleType;
import org.apache.xerces.impl.dtd.models.CMNode;
import org.apache.xerces.impl.dtd.models.CMAny;
import org.apache.xerces.impl.dtd.models.CMLeaf;
import org.apache.xerces.impl.dtd.models.CMUniOp;
import org.apache.xerces.impl.dtd.models.CMBinOp;
import org.apache.xerces.impl.dtd.models.DFAContentModel;
import org.apache.xerces.impl.dtd.models.MixedContentModel;
import org.apache.xerces.impl.dtd.models.SimpleContentModel;
import org.apache.xerces.impl.validation.EntityState;
import org.apache.xerces.impl.dv.dtd.DatatypeValidator;
import org.apache.xerces.impl.dtd.models.ContentModelValidator;
import org.apache.xerces.util.SymbolTable;

import org.apache.xerces.xni.QName;

/**
 * A generic grammar for use in validating XML documents. The Grammar
 * object stores the validation information in a compiled form. Specific
 * subclasses extend this class and "populate" the grammar by compiling
 * the specific syntax (DTD, Schema, etc) into the data structures used
 * by this object.
 * <p>
 * <strong>Note:</strong> The Grammar object is not useful as a generic
 * grammar access or query object. In other words, you cannot round-trip
 * specific grammar syntaxes with the compiled grammar information in
 * the Grammar object. You <em>can</em> create equivalent validation
 * rules in your choice of grammar syntax but there is no guarantee that
 * the input and output will be the same.
 *
 * Right now, this class is a shell; eventually, code
 * will be moved from dtd.Grammar here.
 *
 * @author Stubs generated by DesignDoc on Mon Sep 11 11:10:57 PDT 2000
 * @author Jeffrey Rodriguez, IBM
 * @author Eric Ye, IBM
 * @author Andy Clark, IBM
 * @author Neil Graham, IBM
 *
 * @version $Id: Grammar.java,v 1.6 2001/12/06 21:49:36 neilg Exp $
 */
public abstract class org.apache.xerces.xni.grammars.Grammar {

} // class Grammar
Neil Graham
XML Parser Development
IBM Toronto Lab
Phone:  905-413-3519, T/L 969-3519
E-mail:  neilg@ca.ibm.com


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-dev-help@xml.apache.org


Re: [grammar caching]: re-revised interfaces

Posted by "Theodore W. Leung" <tw...@sauria.com>.
On Tue, 2002-01-15 at 19:13, Andy Clark wrote:
> 3) I think the grammar interface (which is currently empty)
>    should add a method to return the grammar's type. That way
>    grammars can be thrown into a generic container and still
>    be queried later about their type without requiring an
>    instanceof operation.

So instead of instanceof, you do a String compare? Ew.


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-dev-help@xml.apache.org


Re: [grammar caching]: re-revised interfaces

Posted by Andy Clark <an...@apache.org>.
A few thoughts:

1) I'd rather make all of the get*SystemId method names be
   explicit in regards to their function. So I think we should
   change getSystemId to getExpandedSystemId as suggested by 
   Edwin.
2) Just because the base interface for specifying a resource
   location is called XMLResourceIdentifier doesn't mean that
   the "-Identifier" suffix applies to sub-interfaces. Case in
   point, the various grammar description interfaces hold more
   information that just the resource identifiers so they 
   should probably have a different suffix that makes sense.
   The "-Description" suffix is probably fine for the grammar
   description interfaces.
3) I think the grammar interface (which is currently empty)
   should add a method to return the grammar's type. That way
   grammars can be thrown into a generic container and still
   be queried later about their type without requiring an
   instanceof operation.

-- 
Andy Clark * andyc@apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-dev-help@xml.apache.org