You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by ne...@apache.org on 2001/09/18 23:51:58 UTC

cvs commit: xml-xerces/java/src/org/apache/xerces/impl/v2 SchemaNamespaceSupport.java SchemaGrammar.java XSAttributeChecker.java XSDElementTraverser.java XSDHandler.java XSDocumentInfo.java

neilg       01/09/18 14:51:58

  Modified:    java/src/org/apache/xerces/impl/v2 SchemaGrammar.java
                        XSAttributeChecker.java XSDElementTraverser.java
                        XSDHandler.java XSDocumentInfo.java
  Added:       java/src/org/apache/xerces/impl/v2
                        SchemaNamespaceSupport.java
  Log:
  As well as fixing a problem with identity constraint handling in the grammar, this moves local element traversal in to XSDHandler.  It should also take care of the case where a local element declaration contains a type which itself contains a local element declaration.  Finally, I have implemented a class which subclasses NamespaceSupport in an attempt to find an efficient way for keeping track of local namespaces; this should be useful not only in deferred local element traversal but also in keyref handling.
  
  Revision  Changes    Path
  1.19      +7 -3      xml-xerces/java/src/org/apache/xerces/impl/v2/SchemaGrammar.java
  
  Index: SchemaGrammar.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/v2/SchemaGrammar.java,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- SchemaGrammar.java	2001/09/18 18:35:10	1.18
  +++ SchemaGrammar.java	2001/09/18 21:51:57	1.19
  @@ -72,7 +72,7 @@
    * 
    * @author Sandy Gao, IBM
    * @author Elena Litani, IBM
  - * @version $Id: SchemaGrammar.java,v 1.18 2001/09/18 18:35:10 elena Exp $
  + * @version $Id: SchemaGrammar.java,v 1.19 2001/09/18 21:51:57 neilg Exp $
    */
   
   public class SchemaGrammar {
  @@ -597,15 +597,19 @@
               if(fElementDeclKeyRef[chunk][index].length == 0) {
                   fElementDeclKeyRef[chunk][index][0] = icIndex;
               } else {
  +                int[] tempReg = new int[fElementDeclKeyRef[chunk][index].length+1];
                   System.arraycopy(fElementDeclKeyRef[chunk][index], 0, 
  -                    fElementDeclKeyRef[chunk][index], 0, fElementDeclKeyRef.length);
  +                    tempReg, 0, fElementDeclKeyRef.length);
  +                fElementDeclKeyRef[chunk][index] = tempReg;
               }
           } else { // must be unique or key...
               if(fElementDeclUniqueOrKey[chunk][index].length == 0) {
                   fElementDeclUniqueOrKey[chunk][index][0] = icIndex;
               } else {
  +                int[] tempReg = new int[fElementDeclUniqueOrKey[chunk][index].length+1];
                   System.arraycopy(fElementDeclUniqueOrKey[chunk][index], 0, 
  -                    fElementDeclUniqueOrKey[chunk][index], 0, fElementDeclUniqueOrKey.length);
  +                    tempReg, 0, fElementDeclUniqueOrKey.length);
  +                fElementDeclUniqueOrKey[chunk][index] = tempReg;
               }
           }
           // update fGlobalIDConstraintDecl registry
  
  
  
  1.16      +6 -7      xml-xerces/java/src/org/apache/xerces/impl/v2/XSAttributeChecker.java
  
  Index: XSAttributeChecker.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/v2/XSAttributeChecker.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- XSAttributeChecker.java	2001/09/13 22:17:24	1.15
  +++ XSAttributeChecker.java	2001/09/18 21:51:57	1.16
  @@ -66,7 +66,6 @@
   import org.apache.xerces.util.XInt;
   import org.apache.xerces.util.XIntPool;
   import org.apache.xerces.xni.QName;
  -import org.apache.xerces.util.NamespaceSupport;
   
   /**
    * Class <code>XSAttributeCheck</code> is used to check the validity of attributes
  @@ -90,7 +89,7 @@
    *
    * @author Sandy Gao, IBM
    * 
  - * @version $Id: XSAttributeChecker.java,v 1.15 2001/09/13 22:17:24 sandygao Exp $
  + * @version $Id: XSAttributeChecker.java,v 1.16 2001/09/18 21:51:57 neilg Exp $
    */
   
   public class XSAttributeChecker {
  @@ -984,7 +983,7 @@
        * @return: Hashtable - list of attributes and values
        */
       public Object[] checkAttributes(Element element, boolean isGlobal,
  -                                    NamespaceSupport nsSupport) {
  +                                    SchemaNamespaceSupport nsSupport) {
           if (element == null)
               return null;
   
  @@ -1172,7 +1171,7 @@
       }
   
       private Object validate(String attr, String value, int dvIndex,
  -                            NamespaceSupport nsSupport) throws InvalidDatatypeValueException {
  +                            SchemaNamespaceSupport nsSupport) throws InvalidDatatypeValueException {
           if (value == null)
               return null;
   
  @@ -1515,7 +1514,7 @@
       }
   
       //REVISIT: how to resolver qname?
  -    protected QName resolveQName (String attrVal, NamespaceSupport nsSupport) {
  +    protected QName resolveQName (String attrVal, SchemaNamespaceSupport nsSupport) {
           String prefix = XSDHandler.EMPTY_STRING;
           String localpart = attrVal;
           int colonptr = attrVal.indexOf(":");
  @@ -1569,7 +1568,7 @@
       }
       
       // return an array back to the pool
  -    public void returnAttrArray(Object[] attrArray, NamespaceSupport nsSupport) {
  +    public void returnAttrArray(Object[] attrArray, SchemaNamespaceSupport nsSupport) {
           // pop the namespace context
           nsSupport.popContext();
           
  @@ -1589,7 +1588,7 @@
           fArrayPool[--fPoolPos] = attrArray;
       }
   
  -    public void resolveNamespace(Element element, NamespaceSupport nsSupport) {
  +    public void resolveNamespace(Element element, SchemaNamespaceSupport nsSupport) {
           // push the namespace context
           nsSupport.pushContext();
   
  
  
  
  1.12      +20 -54    xml-xerces/java/src/org/apache/xerces/impl/v2/XSDElementTraverser.java
  
  Index: XSDElementTraverser.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/v2/XSDElementTraverser.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- XSDElementTraverser.java	2001/09/13 22:17:24	1.11
  +++ XSDElementTraverser.java	2001/09/18 21:51:57	1.12
  @@ -89,7 +89,7 @@
    * 
    * @author Sandy Gao, IBM
    *
  - * @version $Id: XSDElementTraverser.java,v 1.11 2001/09/13 22:17:24 sandygao Exp $
  + * @version $Id: XSDElementTraverser.java,v 1.12 2001/09/18 21:51:57 neilg Exp $
    */
   class XSDElementTraverser extends XSDAbstractTraverser{
   
  @@ -101,20 +101,11 @@
       protected XSElementDecl  fTempElementDecl  = new XSElementDecl();
       protected XSParticleDecl fTempParticleDecl = new XSParticleDecl();
       
  -    // the initial size of the array to store deferred local elements
  -    static final int INIT_STACK_SIZE = 30;
  -    // the incremental size of the array to store deferred local elements
  -    static final int INC_STACK_SIZE  = 10;
  -    // current position of the array (# of deferred local elements)
  -    int fStackPos = 0;
  -
  -    private int[] fParticleIdx = new int[INIT_STACK_SIZE];
  -    private Element[] fElementDecl = new Element[INIT_STACK_SIZE];
  -    private XSDocumentInfo[] fSchemaDoc = new XSDocumentInfo[INIT_STACK_SIZE];
  -    private SchemaGrammar[] fGrammar = new SchemaGrammar[INIT_STACK_SIZE];
  -    private int[] fAllContext = new int[INIT_STACK_SIZE];
  -    
       SubstitutionGroupHandler fSubGroupHandler;
  +
  +    // this controls what happens when a local element is encountered.
  +    // We may not encounter all local elements when first parsing.
  +    boolean fDeferTraversingLocalElements;
       
       XSDElementTraverser (XSDHandler handler,
                            XMLErrorReporter errorReporter,
  @@ -127,9 +118,10 @@
       /**
        * Traverse a locally declared element (or an element reference).
        *
  -     * To handle the recursive cases effeciently, we delay the traversal
  +     * To handle the recursive cases efficiently, we delay the traversal
        * and return an empty particle node. We'll fill in this particle node
        * later after we've done with all the global declarations.
  +     * This method causes a number of data structures in the schema handler to be filled in.
        *
        * @param  elmDecl
        * @param  schemaDoc
  @@ -141,45 +133,18 @@
                         SchemaGrammar grammar,
                         int allContextFlags) {
   
  -        // if the stack is full, increase the size
  -        if (fParticleIdx.length == fStackPos) {
  -            // increase size
  -            int[] newStackI = new int[fStackPos+INC_STACK_SIZE];
  -            System.arraycopy(fParticleIdx, 0, newStackI, 0, fStackPos);
  -            Element[] newStackE = new Element[fStackPos+INC_STACK_SIZE];
  -            System.arraycopy(fElementDecl, 0, newStackE, 0, fStackPos);
  -            XSDocumentInfo[] newStackX = new XSDocumentInfo[fStackPos+INC_STACK_SIZE];
  -            System.arraycopy(fSchemaDoc, 0, newStackX, 0, fStackPos);
  -            SchemaGrammar[] newStackS = new SchemaGrammar[fStackPos+INC_STACK_SIZE];
  -            System.arraycopy(fGrammar, 0, newStackS, 0, fStackPos);
  -            newStackI = new int[fStackPos+INC_STACK_SIZE];
  -            System.arraycopy(fAllContext, 0, newStackI, 0, fStackPos);
  -        }
  -
           fTempParticleDecl.clear();
           fTempParticleDecl.type = XSParticleDecl.PARTICLE_EMPTY;
           int particleIdx = grammar.addParticleDecl(fTempParticleDecl);
  -
  -        fParticleIdx[fStackPos] = particleIdx;
  -        fElementDecl[fStackPos] = elmDecl;
  -        fSchemaDoc[fStackPos] = schemaDoc;
  -        fGrammar[fStackPos] = grammar;
  -        fAllContext[fStackPos] = allContextFlags;
  -
  +        if(fDeferTraversingLocalElements) { 
  +            fSchemaHandler.fillInLocalElemInfo(elmDecl, schemaDoc, allContextFlags, particleIdx);
  +        } else {
  +            traverseLocal(particleIdx, elmDecl, schemaDoc, grammar, allContextFlags); 
  +        }
           return particleIdx;
       }
   
       /**
  -     * Traverse all the deferred local elements. This method should be called
  -     * by the handler after we've done with all the global declarations.
  -     */
  -    void traverseLocalElements() {
  -        for (int i = 0; i < fStackPos; i++) {
  -            traverseLocal(i);
  -        }
  -    }
  -    
  -    /**
        * Traverse a locally declared element (or an element reference).
        *
        * This is the real traversal method. It's called after we've done with
  @@ -187,13 +152,10 @@
        *
        * @param  index
        */
  -    private void traverseLocal(int index) {
  -
  -        int particleIdx = fParticleIdx[index];
  -        Element elmDecl = fElementDecl[index];
  -        XSDocumentInfo schemaDoc = fSchemaDoc[index];
  -        SchemaGrammar grammar = fGrammar[index];
  -        int allContextFlags = fAllContext[index];
  +    private void traverseLocal(int particleIdx, Element elmDecl,
  +                      XSDocumentInfo schemaDoc,
  +                      SchemaGrammar grammar,
  +                      int allContextFlags) {
   
           // General Attribute Checking
           Object[] attrValues = fAttrChecker.checkAttributes(elmDecl, false, schemaDoc.fNamespaceSupport);
  @@ -565,5 +527,9 @@
           
           return ret;
       }
  +
  +    void reset() {
  +        fDeferTraversingLocalElements = true;
  +    } // reset()
   
   }
  
  
  
  1.23      +74 -10    xml-xerces/java/src/org/apache/xerces/impl/v2/XSDHandler.java
  
  Index: XSDHandler.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/v2/XSDHandler.java,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- XSDHandler.java	2001/09/13 21:25:59	1.22
  +++ XSDHandler.java	2001/09/18 21:51:57	1.23
  @@ -65,7 +65,6 @@
   import org.apache.xerces.xni.parser.XMLEntityResolver;
   import org.apache.xerces.xni.parser.XMLInputSource;
   import org.apache.xerces.util.SymbolTable;
  -import org.apache.xerces.util.NamespaceSupport;
   import org.apache.xerces.util.DOMUtil;
   
   import org.w3c.dom.Document;
  @@ -96,7 +95,7 @@
    * schema, other grammars may be constructed as a side-effect.
    *
    * @author Neil Graham, IBM
  - * @version $Id: XSDHandler.java,v 1.22 2001/09/13 21:25:59 neilg Exp $
  + * @version $Id: XSDHandler.java,v 1.23 2001/09/18 21:51:57 neilg Exp $
    */
   
   class XSDHandler {
  @@ -207,6 +206,22 @@
       XSDUniqueOrKeyTraverser fUniqueOrKeyTraverser;
       XSDWildcardTraverser fWildCardTraverser;
   
  +    // these data members are needed for the deferred traversal
  +    // of local elements.  
  +
  +    // the initial size of the array to store deferred local elements
  +    private static final int INIT_STACK_SIZE = 30;
  +    // the incremental size of the array to store deferred local elements
  +    private static final int INC_STACK_SIZE  = 10;
  +    // current position of the array (# of deferred local elements)
  +    private int fLocalElemStackPos;
  +
  +    private int[] fParticleIdx;
  +    private Element[] fLocalElementDecl;
  +    private int[] fAllContext;
  +    private String [][] fLocalElemNamespaceContext;
  +    
  +
       // Constructors
   
       // it should be possible to use the same XSDHandler to parse
  @@ -251,7 +266,7 @@
           traverseSchemas();
   
           // fourth:  handle local element decls
  -        // traverseLocalElements(...)
  +        traverseLocalElements();
   
           // fifth phase:  handle Keyrefs
   //        resolveKeyRefs();
  @@ -659,7 +674,7 @@
               
               DOMUtil.setHidden(decl);
   
  -            // back up the current NamespaceSupport, because we need to provide
  +            // back up the current SchemaNamespaceSupport, because we need to provide
               // a fresh one to the traverGlobal methods.
               schemaWithDecl.backupNSSupport();
               
  @@ -683,7 +698,7 @@
                       retIndex = fSimpleTypeTraverser.traverseGlobal(decl, schemaWithDecl, sGrammar);
               }
           
  -            // restore the previous NamespaceSupport, so that the caller can get
  +            // restore the previous SchemaNamespaceSupport, so that the caller can get
               // proper namespace binding.
               schemaWithDecl.restoreNSSupport();
           }
  @@ -810,6 +825,13 @@
           fRedefine2XSDMap.clear();
           fRoot = null;
   
  +        fLocalElemStackPos = 0; 
  +        fParticleIdx = new int[INIT_STACK_SIZE];
  +        fLocalElementDecl = new Element[INIT_STACK_SIZE];
  +        fAllContext = new int[INIT_STACK_SIZE];
  +        // err on the small side for num. of local namespaces declared...
  +        fLocalElemNamespaceContext = new String [INIT_STACK_SIZE][1];
  +    
           // reset traversers
           fAttributeChecker.reset();
           fAttributeGroupTraverser.reset();
  @@ -825,6 +847,48 @@
   
       } // reset
   
  +    /**
  +     * Traverse all the deferred local elements. This method should be called
  +     * by traverseSchemas after we've done with all the global declarations.
  +     */
  +    void traverseLocalElements() {
  +        fElementTraverser.fDeferTraversingLocalElements = false;
  +        for (int i = 0; i < fLocalElemStackPos; i++) {
  +            Element currElem = fLocalElementDecl[i]; 
  +            XSDocumentInfo currSchema = (XSDocumentInfo)fDoc2XSDocumentMap.get(DOMUtil.getDocument(currElem));
  +            SchemaGrammar currGrammar = fGrammarResolver.getGrammar(currSchema.fTargetNamespace);
  +            fElementTraverser.traverseLocal (currElem, currSchema, currGrammar, fAllContext[i]); 
  +        }
  +    }
  +    
  +    // the purpose of this method is to keep up-to-date structures
  +    // we'll need for the feferred traversal of local elements.
  +    void fillInLocalElemInfo(Element elmDecl,
  +                      XSDocumentInfo schemaDoc,
  +                      int allContextFlags, int particleIndex) {
  +
  +        // if the stack is full, increase the size
  +        if (fParticleIdx.length == fLocalElemStackPos) {
  +            // increase size
  +            int[] newStackI = new int[fLocalElemStackPos+INC_STACK_SIZE];
  +            System.arraycopy(fParticleIdx, 0, newStackI, 0, fLocalElemStackPos);
  +            fParticleIdx = newStackI;
  +            Element[] newStackE = new Element[fLocalElemStackPos+INC_STACK_SIZE];
  +            System.arraycopy(fLocalElementDecl, 0, newStackE, 0, fLocalElemStackPos);
  +            fLocalElementDecl = newStackE;
  +            newStackI = new int[fLocalElemStackPos+INC_STACK_SIZE];
  +            System.arraycopy(fAllContext, 0, newStackI, 0, fLocalElemStackPos);
  +            String [][] newStackN = new String [fLocalElemStackPos+INC_STACK_SIZE][];
  +            System.arraycopy(fLocalElemNamespaceContext, 0, newStackN, 0, fLocalElemStackPos); 
  +            fLocalElemNamespaceContext = newStackN;
  +        }
  +
  +        fParticleIdx[fLocalElemStackPos] = particleIndex;
  +        fLocalElementDecl[fLocalElemStackPos] = elmDecl;
  +        fAllContext[fLocalElemStackPos] = allContextFlags;
  +        fLocalElemNamespaceContext[fLocalElemStackPos] = schemaDoc.fNamespaceSupport.getEffectiveLocalContext();
  +    } // end fillInLocalElemInfo(...)
  +
       /** This method makes sure that
        * if this component is being redefined that it lives in the
        * right schema.  It then renames the component correctly.  If it
  @@ -880,7 +944,7 @@
               Element child, String componentType, 
               String oldName, String newName) {
   
  -        NamespaceSupport currNSMap = currSchema.fNamespaceSupport;
  +        SchemaNamespaceSupport currNSMap = currSchema.fNamespaceSupport;
           if (componentType.equals(SchemaSymbols.ELT_SIMPLETYPE)) {
               String processedTypeName = currSchema.fTargetNamespace+","+oldName;
   			Element grandKid = DOMUtil.getFirstChildElement(child);
  @@ -1013,10 +1077,10 @@
       } // renameRedefiningComponents(XSDocumentInfo, Element, String, String, String):void
   
       // this method takes a name of the form a:b, determines the URI mapped
  -    // to by a in the current NamespaceSupport object, and returns this
  +    // to by a in the current SchemaNamespaceSupport object, and returns this
       // information in the form (nsURI,b) suitable for lookups in the global
       // decl Hashtables.
  -    private String findQName(String name, NamespaceSupport currNSMap) {
  +    private String findQName(String name, SchemaNamespaceSupport currNSMap) {
           int colonPtr = name.indexOf(':');
           String prefix = "";
           if (colonPtr > 0)
  @@ -1024,7 +1088,7 @@
           String uri = currNSMap.getURI(prefix);
           String localpart = (colonPtr == 0)?name:name.substring(colonPtr);
           return uri+","+localpart;
  -    } // findQName(String, NamespaceSupport):  String
  +    } // findQName(String, SchemaNamespaceSupport):  String
   
   	// This function looks among the children of curr for an element of type elementSought.
   	// If it finds one, it evaluates whether its ref attribute contains a reference
  @@ -1034,7 +1098,7 @@
   	// It also resets the value of ref so that it will refer to the renamed type from the schema
   	// being redefined.
   	private int changeRedefineGroup(String originalQName, String elementSought, 
  -            String newName, Element curr, NamespaceSupport currNSMap) {
  +            String newName, Element curr, SchemaNamespaceSupport currNSMap) {
   		int result = 0;
   		for (Element child = DOMUtil.getFirstChildElement(curr);
   				child != null; child = DOMUtil.getNextSiblingElement(child)) {
  
  
  
  1.8       +9 -10     xml-xerces/java/src/org/apache/xerces/impl/v2/XSDocumentInfo.java
  
  Index: XSDocumentInfo.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/v2/XSDocumentInfo.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- XSDocumentInfo.java	2001/09/12 22:33:48	1.7
  +++ XSDocumentInfo.java	2001/09/18 21:51:57	1.8
  @@ -57,7 +57,6 @@
   
   package org.apache.xerces.impl.v2;
   
  -import org.apache.xerces.util.NamespaceSupport;
   import org.apache.xerces.util.DOMUtil;
   import org.apache.xerces.util.XInt;
   import org.apache.xerces.util.XIntPool;
  @@ -73,15 +72,15 @@
    * affect the contents of that schema document alone.
    *
    * @author Neil Graham, IBM
  - * @version $Id: XSDocumentInfo.java,v 1.7 2001/09/12 22:33:48 sandygao Exp $
  + * @version $Id: XSDocumentInfo.java,v 1.8 2001/09/18 21:51:57 neilg Exp $
    */
   
   class XSDocumentInfo {
   
       // Data
  -    protected NamespaceSupport fNamespaceSupport;
  -    protected NamespaceSupport fNamespaceSupportRoot;
  -    protected Stack NamespaceSupportStack = new Stack();
  +    protected SchemaNamespaceSupport fNamespaceSupport;
  +    protected SchemaNamespaceSupport fNamespaceSupportRoot;
  +    protected Stack SchemaNamespaceSupportStack = new Stack();
   
       // schema's attributeFormDefault
       protected boolean fAreLocalAttributesQualified;
  @@ -101,7 +100,7 @@
   
       XSDocumentInfo (Document schemaDoc, XSAttributeChecker attrChecker) {
           fSchemaDoc = schemaDoc;
  -        fNamespaceSupport = new NamespaceSupport();
  +        fNamespaceSupport = new SchemaNamespaceSupport();
           
           if(schemaDoc != null) {
               Element root = DOMUtil.getRoot(schemaDoc); 
  @@ -119,7 +118,7 @@
               if (fTargetNamespace == null)
                   fTargetNamespace = XSDHandler.EMPTY_STRING; 
   
  -            fNamespaceSupportRoot = new NamespaceSupport(fNamespaceSupport);
  +            fNamespaceSupportRoot = new SchemaNamespaceSupport(fNamespaceSupport);
   
               // REVISIT: we can't return, becaues we can't pop fNamespaceSupport
               //attrChecker.returnAttrArray(schemaAttrs, fNamespaceSupport);
  @@ -127,12 +126,12 @@
       }
   
       void backupNSSupport() {
  -        NamespaceSupportStack.push(fNamespaceSupport);
  -        fNamespaceSupport = new NamespaceSupport(fNamespaceSupportRoot);
  +        SchemaNamespaceSupportStack.push(fNamespaceSupport);
  +        fNamespaceSupport = new SchemaNamespaceSupport(fNamespaceSupportRoot);
       }
   
       void restoreNSSupport() {
  -        fNamespaceSupport = (NamespaceSupport)NamespaceSupportStack.pop();
  +        fNamespaceSupport = (SchemaNamespaceSupport)SchemaNamespaceSupportStack.pop();
       }
       
   } // XSDocumentInfo
  
  
  
  1.1                  xml-xerces/java/src/org/apache/xerces/impl/v2/SchemaNamespaceSupport.java
  
  Index: SchemaNamespaceSupport.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 2000 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.v2;
  
  import org.apache.xerces.util.NamespaceSupport;
  
  /**
   * This class customizes the behaviour of the util.NamespaceSupport
   * class in order to easily implement some features that we need for
   * efficient schema handling.  It will not be generally useful.  
   *
   * @author Neil Graham, IBM
   *
   * @version $Id: SchemaNamespaceSupport.java,v 1.1 2001/09/18 21:51:57 neilg Exp $
   */
  public class SchemaNamespaceSupport 
      extends NamespaceSupport {
  
      SchemaNamespaceSupport () {
          super();
      } // constructor
  
      SchemaNamespaceSupport(SchemaNamespaceSupport nSupport) {
          super(nSupport);
      } // end constructor
      
      /**
       * This method takes a set of Strings, as stored in a
       * NamespaceSupport object, and "fools" the object into thinking
       * that this is one unified context.  This is meant to be used in
       * conjunction with things like local elements, whose declarations
       * may be deeply nested but which for all practical purposes may
       * be regarded as being one level below the global <schema>
       * element--at least with regard to namespace declarations.
       * It's worth noting that the context from which the strings are
       * being imported had better be using the same SymbolTable.
       */
      void setEffectiveContext (String [] namespaceDecls) {
          if(fCurrentContext == fContext.length) {
              // expand size of fContext
              int[] newContext = new int[fContext.length*2];
              System.arraycopy(fContext, 0, newContext, 0, fContext.length);
              fContext = newContext;
          }
          fContext[++fCurrentContext] = fNamespaceSize;
          while(fNamespace.length > fNamespaceSize + namespaceDecls.length) {
              // expand namespace's size...
              String[] tempNSArray = new String[fNamespace.length*2];
              System.arraycopy(fNamespace, 0, tempNSArray, 0,
                      fNamespace.length);
              fNamespace = tempNSArray;
          }
          System.arraycopy(namespaceDecls, 0, fNamespace, fNamespaceSize,
          namespaceDecls.length);
          fNamespaceSize += namespaceDecls.length;
      } // setEffectiveContext(String):void
  
      /** 
       * This method returns an array of Strings, as would be stored in
       * a NamespaceSupport object.  This array contains all
       * declarations except those at the global level.
       */
      String [] getEffectiveLocalContext() {
          // the trick here is to recognize that all local contexts
          // happen to start at fContext[2].
          int topLocalContext = (fCurrentContext >= 2) ? fContext[2]:-1;
          if (topLocalContext == -1) {
              // no local decls!
              return null;
          }
          String [] returnVal = new String[fNamespaceSize-topLocalContext+1];
          System.arraycopy(fNamespace, 0, returnVal, 0,
                  topLocalContext);
          return returnVal;
      } // getEffectiveLocalContext():String
  
      // This method removes from this object all the namespaces
      // returned by getEffectiveLocalContext. 
      void makeGlobal() {
          int topLocalContext = (fCurrentContext >= 2) ? fContext[2]:-1;
          if(topLocalContext == -1) {
              return; // nothing to do!
          }
          fCurrentContext = 1;
          fNamespaceSize = fContext[fCurrentContext];
      } // makeGlobal
  } // class NamespaceSupport
  
  
  

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