> I added some
> duplicate code which should probably be refactored, but I am not sure
> what future plans you all have for that file.  I've done some minimal
> testing and tried to get the code right.
>
> I'd appreciate any feedback anyone may have on the changes (including
> that the changes look OK).

The changes look good to me. My only comment is on the duplicate code you
mentioned.

> Note: Does passing in null for target namespace cause any problems?

The method parseSchemaJAXP() is not necessary. This JAXP property is very
similar to DOM3 schema-preparsing, where the target namespace of the
grammar is not known. So, similar to what's done in DOMASBuilderImpl, it's
ok to pass "null" as the expected target namespace, as long as you indicate
that "referType" is "pre-parse".

So you can simply remove this method, and change the two invocations to
  parseSchema(null, inputSource, XSDDescription.CONTEXT_PREPARSE);

>     * Can schemaNamespace be interned after call to constructTrees()?

Yes. XSDocumentInfo#fTargetNamespace is always interned, if it's not null.

Cheers,
Sandy Gao
Software Developer, IBM Canada
(1-905) 413-3255
[EMAIL PROTECTED]



                                                                                       
                       
                    Edwin Goei                                                         
                       
                    <[EMAIL PROTECTED]       To:     "[EMAIL PROTECTED]" 
<[EMAIL PROTECTED]>  
                    om>                  cc:                                           
                       
                                         Subject:     Committed JAXP 1.2 
"schemaSource" property code         
                    02/03/2002                                                         
                       
                    01:32 PM                                                           
                       
                    Please respond                                                     
                       
                    to                                                                 
                       
                    xerces-j-dev                                                       
                       
                                                                                       
                       
                                                                                       
                       



Hi all,

I just committed a first pass implementation to the proposed JAXP 1.2
"schemaSource" property in Xerces2.  (In the most recent draft, the
"schemaSource" property behaves similar to the JAXP "schemaLocation"
property described at
http://java.sun.com/xml/jaxp/change-requests-12.html (an older draft)).

This change should not affect the way Xerces behaves unless that prop is
set.  The code changes mainly affect XSDHandler.java.  I added some
duplicate code which should probably be refactored, but I am not sure
what future plans you all have for that file.  I've done some minimal
testing and tried to get the code right.

I'd appreciate any feedback anyone may have on the changes (including
that the changes look OK).

-Edwin
----- Message from [EMAIL PROTECTED] on 3 Feb 2002 18:07:47 -0000 -----
                                                                                     
       To: [EMAIL PROTECTED]                                                 
                                                                                     
  Subject: cvs commit: xml-xerces/java/src/org/apache/xerces/impl Constants.java     
                                                                                     

edwingo     02/02/03 10:07:47

  Modified:    java/src/org/apache/xerces/parsers
                        StandardParserConfiguration.java
               java/src/org/apache/xerces/impl/xs/traversers
                        XSDHandler.java
               java/src/org/apache/xerces/impl/xs XMLSchemaValidator.java
               java/src/org/apache/xerces/impl Constants.java
  Log:
  First pass implementation of proposed JAXP 1.2 "schemaSource" property.
  This code should not affect the way Xerces functions in any way unless a
  certain JAXP "schemaSource" property is set.  There is also duplicate
code
  in XSDHandler.java that needs to be cleaned up.

  Revision  Changes    Path
  1.19      +9 -1
xml-xerces/java/src/org/apache/xerces/parsers/StandardParserConfiguration.java


  Index: StandardParserConfiguration.java
  ===================================================================
  RCS file:
/home/cvs/xml-xerces/java/src/org/apache/xerces/parsers/StandardParserConfiguration.java,v

  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- StandardParserConfiguration.java         29 Jan 2002 23:16:43 -0000
      1.18
  +++ StandardParserConfiguration.java         3 Feb 2002 18:07:46 -0000
      1.19
  @@ -122,7 +122,7 @@
    * @author Arnaud  Le Hors, IBM
    * @author Andy Clark, IBM
    *
  - * @version $Id: StandardParserConfiguration.java,v 1.18 2002/01/29
23:16:43 sandygao Exp $
  + * @version $Id: StandardParserConfiguration.java,v 1.19 2002/02/03
18:07:46 edwingo Exp $
    */
   public class StandardParserConfiguration
       extends BasicParserConfiguration
  @@ -800,6 +800,14 @@
                   return;
               }
               if (property.equals(Constants.SCHEMA_NONS_LOCATION)) {
  +                return;
  +            }
  +        }
  +
  +        if (propertyId.startsWith(Constants.JAXP_PROPERTY_PREFIX)) {
  +            String property =
  +
propertyId.substring(Constants.JAXP_PROPERTY_PREFIX.length());
  +            if (property.equals(Constants.SCHEMA_SOURCE)) {
                   return;
               }
           }



  1.21      +169 -2
xml-xerces/java/src/org/apache/xerces/impl/xs/traversers/XSDHandler.java

  Index: XSDHandler.java
  ===================================================================
  RCS file:
/home/cvs/xml-xerces/java/src/org/apache/xerces/impl/xs/traversers/XSDHandler.java,v

  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- XSDHandler.java          29 Jan 2002 20:24:57 -0000          1.20
  +++ XSDHandler.java          3 Feb 2002 18:07:46 -0000           1.21
  @@ -69,11 +69,13 @@
   import org.apache.xerces.impl.xs.XSDDescription;
   import org.apache.xerces.impl.xs.XMLSchemaException;
   import org.apache.xerces.parsers.StandardParserConfiguration;
  +import org.apache.xerces.impl.Constants;
   import org.apache.xerces.impl.XMLErrorReporter;
   import org.apache.xerces.impl.XMLEntityManager;
   import org.apache.xerces.parsers.DOMParser;
   import org.apache.xerces.xni.QName;
   import org.apache.xerces.xni.XMLResourceIdentifier;
  +import org.apache.xerces.xni.parser.XMLConfigurationException;
   import org.apache.xerces.xni.parser.XMLEntityResolver;
   import org.apache.xerces.xni.parser.XMLInputSource;
   import org.apache.xerces.util.XMLResourceIdentifierImpl;
  @@ -86,11 +88,19 @@
   import org.w3c.dom.Attr;
   import org.w3c.dom.Element;

  +import org.xml.sax.InputSource;
  +
   import java.util.Hashtable;
   import java.util.Stack;
   import java.util.Vector;
   import java.util.StringTokenizer;
  +import java.io.BufferedInputStream;
  +import java.io.File;
  +import java.io.FileInputStream;
  +import java.io.FileNotFoundException;
  +import java.io.InputStream;
   import java.io.IOException;
  +import java.io.Reader;

   /**
    * The purpose of this class is to co-ordinate the construction of a
  @@ -101,7 +111,7 @@
    * schema, other grammars may be constructed as a side-effect.
    *
    * @author Neil Graham, IBM
  - * @version $Id: XSDHandler.java,v 1.20 2002/01/29 20:24:57 sandygao Exp
$
  + * @version $Id: XSDHandler.java,v 1.21 2002/02/03 18:07:46 edwingo Exp
$
    */

   public class XSDHandler {
  @@ -401,6 +411,57 @@
           return fGrammarBucket.getGrammar(schemaNamespace);
       } // end parseSchema

  +    /**
  +     * REVISIT: Common code needs to be factored out and cleaned up.
  +     * XXX Temporary duplicate code to get JAXP SchemaLocation working.
  +     * Note: Does passing in null for target namespace cause any
problems?
  +     * Can schemaNamespace be interned after call to constructTrees()?
  +     */
  +    public SchemaGrammar parseSchemaJAXP(XMLInputSource is) {
  +        short referType = XSDDescription.CONTEXT_PREPARSE;
  +
  +        // first phase:  construct trees.
  +        Document schemaRoot = getSchema(null, is, true, referType);
  +        if (schemaRoot == null) {
  +            // something went wrong right off the hop
  +            return null;
  +        }
  +
  +        fRoot = constructTrees(schemaRoot, is.getSystemId(), /* ns */
null,
  +                               referType);
  +
  +        if (fRoot == null) {
  +            // REVISIT:  something went wrong; print error about no
schema found
  +            return null;
  +        }
  +
  +        String schemaNamespace = fRoot.fTargetNamespace;
  +
  +        // handle empty string URI as null
  +        if (schemaNamespace != null) {
  +            schemaNamespace = fSymbolTable.addSymbol(schemaNamespace);
  +        }
  +
  +        // second phase:  fill global registries.
  +        buildGlobalNameRegistries();
  +
  +        // third phase:  call traversers
  +        traverseSchemas();
  +
  +        // fourth phase: handle local element decls
  +        traverseLocalElements();
  +
  +        // fifth phase:  handle Keyrefs
  +        resolveKeyRefs();
  +
  +        // sixth phase: validate attribute of non-schema namespaces
  +        // REVISIT: skip this for now. we reall don't want to do it.
  +        //fAttributeChecker.checkNonSchemaAttributes(fGrammarBucket);
  +
  +        // and return.
  +        return fGrammarBucket.getGrammar(schemaNamespace);
  +    }
  +
       // may wish to have setter methods for ErrorHandler,
       // EntityResolver...

  @@ -1247,7 +1308,8 @@
                         XMLEntityResolver entityResolver,
                         SymbolTable symbolTable,
                         String externalSchemaLocation,
  -                      String externalNoNSSchemaLocation) {
  +                      String externalNoNSSchemaLocation,
  +                      Object jaxpSchemaSource) {

           fErrorReporter = errorReporter;
           fSymbolTable = symbolTable;
  @@ -1308,7 +1370,112 @@

           fRedefinedRestrictedAttributeGroupRegistry.clear();
           fRedefinedRestrictedGroupRegistry.clear();
  +
  +        processJAXPSchemaSource(jaxpSchemaSource, entityResolver);
       } // reset(ErrorReporter, EntityResolver, SymbolTable)
  +
  +    /**
  +     * Translate the various JAXP SchemaSource property types to XNI
  +     * XMLInputSource.  Valid types are: String,
org.xml.sax.InputSource,
  +     * InputStream, File, or Object[] of any of previous types.
  +     */
  +    private void processJAXPSchemaSource(Object val, XMLEntityResolver
xer) {
  +        if (val == null) {
  +            return;
  +        }
  +
  +        Class componentType = val.getClass().getComponentType();
  +        if (componentType == null) {
  +            // Not an array
  +            parseSchemaJAXP(XSD2XMLInputSource(val, xer));
  +            return ;
  +        } else if (componentType != Object.class) {
  +            // Not an Object[]
  +            throw new XMLConfigurationException(
  +                XMLConfigurationException.NOT_SUPPORTED,
  +                Constants.JAXP_PROPERTY_PREFIX +
Constants.SCHEMA_SOURCE);
  +        }
  +
  +        Object[] objArr = (Object[]) val;
  +        for (int i = 0; i < objArr.length; i++) {
  +            parseSchemaJAXP(XSD2XMLInputSource(objArr[i], xer));
  +        }
  +    }
  +
  +    private XMLInputSource XSD2XMLInputSource(
  +            Object val, XMLEntityResolver entityResolver)
  +    {
  +        if (val instanceof String) {
  +            // String value is treated as a URI that is passed through
the
  +            // EntityResolver
  +            String loc = (String) val;
  +            if (entityResolver != null) {
  +                String expandedLoc =
XMLEntityManager.expandSystemId(loc);
  +                fResourceIdentifier.setValues(null, loc, null,
expandedLoc);
  +                XMLInputSource xis = null;
  +                try {
  +                    xis =
entityResolver.resolveEntity(fResourceIdentifier);
  +                } catch (IOException ex) {
  +                    short referType = XSDDescription.CONTEXT_PREPARSE;
  +                    fErrorReporter.reportError(
  +                        XSMessageFormatter.SCHEMA_DOMAIN,
  +                        DOC_ERROR_CODES[referType],
  +                        new Object[] { loc },
  +                        XMLErrorReporter.SEVERITY_ERROR);
  +                }
  +                if (xis == null) {
  +                    // REVISIT: can this happen?
  +                    // Treat value as a URI and pass in as systemId
  +                    return new XMLInputSource(null, loc, null);
  +                }
  +                return xis;
  +            }
  +        } else if (val instanceof InputSource) {
  +            return SAX2XMLInputSource((InputSource) val);
  +        } else if (val instanceof InputStream) {
  +            return new XMLInputSource(null, null, null,
  +                                      (InputStream) val, null);
  +        } else if (val instanceof File) {
  +            File file = (File) val;
  +            InputStream is = null;
  +            try {
  +                is = new BufferedInputStream(new FileInputStream(file));
  +            } catch (FileNotFoundException ex) {
  +                short referType = XSDDescription.CONTEXT_PREPARSE;
  +                fErrorReporter.reportError(
  +                    XSMessageFormatter.SCHEMA_DOMAIN,
  +                    DOC_ERROR_CODES[referType],
  +                    new Object[] { file.toString() },
  +                    XMLErrorReporter.SEVERITY_ERROR);
  +            }
  +            return new XMLInputSource(null, null, null, is, null);
  +        }
  +        throw new XMLConfigurationException(
  +            XMLConfigurationException.NOT_SUPPORTED,
  +            Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_SOURCE);
  +    }
  +
  +    /**
  +     * Convert a SAX InputSource to an equivalent XNI XMLInputSource
  +     */
  +    private static XMLInputSource SAX2XMLInputSource(InputSource sis) {
  +        String publicId = sis.getPublicId();
  +        String systemId = sis.getSystemId();
  +
  +        Reader charStream = sis.getCharacterStream();
  +        if (charStream != null) {
  +            return new XMLInputSource(publicId, systemId, null,
charStream,
  +                                      null);
  +        }
  +
  +        InputStream byteStream = sis.getByteStream();
  +        if (byteStream != null) {
  +            return new XMLInputSource(publicId, systemId, null,
byteStream,
  +                                      sis.getEncoding());
  +        }
  +
  +        return new XMLInputSource(publicId, systemId, null);
  +    }

       /**
        * Traverse all the deferred local elements. This method should be
called



  1.41      +13 -3
xml-xerces/java/src/org/apache/xerces/impl/xs/XMLSchemaValidator.java

  Index: XMLSchemaValidator.java
  ===================================================================
  RCS file:
/home/cvs/xml-xerces/java/src/org/apache/xerces/impl/xs/XMLSchemaValidator.java,v

  retrieving revision 1.40
  retrieving revision 1.41
  diff -u -r1.40 -r1.41
  --- XMLSchemaValidator.java       29 Jan 2002 01:15:14 -0000
1.40
  +++ XMLSchemaValidator.java       3 Feb 2002 18:07:46 -0000
1.41
  @@ -130,7 +130,7 @@
    * @author Elena Litani IBM
    * @author Andy Clark IBM
    * @author Neeraj Bajaj, Sun Microsystems, inc.
  - * @version $Id: XMLSchemaValidator.java,v 1.40 2002/01/29 01:15:14
lehors Exp $
  + * @version $Id: XMLSchemaValidator.java,v 1.41 2002/02/03 18:07:46
edwingo Exp $
    */
   public class XMLSchemaValidator
                implements XMLComponent, XMLDocumentFilter, FieldActivator
{
  @@ -205,6 +205,10 @@
       protected static final String SCHEMA_NONS_LOCATION =
       Constants.XERCES_PROPERTY_PREFIX + Constants.SCHEMA_NONS_LOCATION;

  +    /** Property identifier: JAXP schema source. */
  +    protected static final String JAXP_SCHEMA_SOURCE =
  +    Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_SOURCE;
  +
       // recognized features and properties

       /** Recognized features. */
  @@ -223,7 +227,8 @@
           ENTITY_RESOLVER,
           VALIDATION_MANAGER,
           SCHEMA_LOCATION,
  -        SCHEMA_NONS_LOCATION
  +        SCHEMA_NONS_LOCATION,
  +        JAXP_SCHEMA_SOURCE
       };

       //
  @@ -1150,6 +1155,10 @@
           fExternalSchemas
= (String)componentManager.getProperty(SCHEMA_LOCATION);
           fExternalNoNamespaceSchema
= (String)componentManager.getProperty(SCHEMA_NONS_LOCATION);

  +        // get JAXP schema source property
  +        Object jaxpSchemaSource = componentManager.getProperty(
  +                JAXP_SCHEMA_SOURCE);
  +
           // clear grammars, and put the one for schema namespace there
           fGrammarBucket.reset();
           fGrammarPool
= (XMLGrammarPool)componentManager.getProperty(XMLGRAMMAR_POOL);
  @@ -1167,7 +1176,8 @@
           // reset schema handler and all traversal objects
           fSchemaHandler.reset(fXSIErrorReporter.fErrorReporter,
                                fEntityResolver, fSymbolTable,
  -                             fExternalSchemas,
fExternalNoNamespaceSchema);
  +                             fExternalSchemas,
fExternalNoNamespaceSchema,
  +                             jaxpSchemaSource);

           // initialize state
           fCurrentElemDecl = null;



  1.12      +14 -1
xml-xerces/java/src/org/apache/xerces/impl/Constants.java

  Index: Constants.java
  ===================================================================
  RCS file:
/home/cvs/xml-xerces/java/src/org/apache/xerces/impl/Constants.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- Constants.java           29 Jan 2002 01:15:09 -0000          1.11
  +++ Constants.java           3 Feb 2002 18:07:46 -0000           1.12
  @@ -65,7 +65,7 @@
    *
    * @author Andy Clark, IBM
    *
  - * @version $Id: Constants.java,v 1.11 2002/01/29 01:15:09 lehors Exp $
  + * @version $Id: Constants.java,v 1.12 2002/02/03 18:07:46 edwingo Exp $
    */
   public final class Constants {

  @@ -112,6 +112,19 @@

       /** XML string property ("xml-string"). */
       public static final String XML_STRING_PROPERTY = "xml-string";
  +
  +
  +    //
  +    // JAXP properties
  +    //
  +
  +    /** JAXP property prefix ("http://xml.org/sax/properties/";). */
  +    public static final String JAXP_PROPERTY_PREFIX =
  +            "http://java.sun.com/xml/jaxp/properties/";;
  +
  +    /** JAXP schemaSource property */
  +    public static final String SCHEMA_SOURCE = "schemaSource";
  +

       //
       // DOM features




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]





---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to