[prev in list] [next in list] [prev in thread] [next in thread] 

List:       xerces-cvs
Subject:    cvs commit: xml-xerces/java/src/org/apache/xerces/validators/datatype UnionDatatypeValidator.java
From:       neilg () apache ! org
Date:       2001-03-29 21:13:39
[Download RAW message or body]

neilg       01/03/29 13:13:39

  Modified:    java/src/org/apache/xerces/validators/schema
                        TraverseSchema.java
               java/src/org/apache/xerces/validators/datatype
                        UnionDatatypeValidator.java
  Log:
  added a couple of missing aspects of "final".  Thanks to Khaled Noaman for pointing \
out one of the things I had missed.  
  Revision  Changes    Path
  1.119     +105 -26   \
xml-xerces/java/src/org/apache/xerces/validators/schema/TraverseSchema.java  
  Index: TraverseSchema.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/validators/schema/TraverseSchema.java,v
  retrieving revision 1.118
  retrieving revision 1.119
  diff -u -r1.118 -r1.119
  --- TraverseSchema.java	2001/03/28 21:42:36	1.118
  +++ TraverseSchema.java	2001/03/29 21:13:34	1.119
  @@ -125,7 +125,7 @@
    *  
    * @see org.apache.xerces.validators.common.Grammar
    *
  - * @version $Id: TraverseSchema.java,v 1.118 2001/03/28 21:42:36 neilg Exp $
  + * @version $Id: TraverseSchema.java,v 1.119 2001/03/29 21:13:34 neilg Exp $
    */
   public class TraverseSchema implements 
                               NamespacesScope.NamespacesHandler{
  @@ -412,10 +412,18 @@
               root.getAttribute(SchemaSymbols.ATT_ELEMENTFORMDEFAULT).equals(SchemaSymbols.ATTVAL_QUALIFIED);
  fAttributeDefaultQualified = 
               root.getAttribute(SchemaSymbols.ATT_ATTRIBUTEFORMDEFAULT).equals(SchemaSymbols.ATTVAL_QUALIFIED);
                
  -        fBlockDefault = 
  -            parseBlockSet(root.getAttribute(SchemaSymbols.ATT_BLOCKDEFAULT));
  -        fFinalDefault = 
  -            parseFinalSet(root.getAttribute(SchemaSymbols.ATT_FINALDEFAULT));
  +        Attr blockAttr = root.getAttributeNode(SchemaSymbols.ATT_BLOCKDEFAULT);
  +        if (blockAttr == null) 
  +            fBlockDefault = 0;
  +        else
  +            fBlockDefault = 
  +                parseBlockSet(blockAttr.getValue());
  +        Attr finalAttr = root.getAttributeNode(SchemaSymbols.ATT_FINALDEFAULT);
  +        if (finalAttr == null) 
  +            fFinalDefault = 0;
  +        else
  +            fFinalDefault = 
  +                parseFinalSet(finalAttr.getValue());
           
           //REVISIT, really sticky when noTargetNamesapce, for now, we assume \
everyting is in the same name space);  if (fTargetNSURI == StringPool.EMPTY_STRING) {
  @@ -743,10 +751,18 @@
               root.getAttribute(SchemaSymbols.ATT_ELEMENTFORMDEFAULT).equals(SchemaSymbols.ATTVAL_QUALIFIED);
  fAttributeDefaultQualified = 
               root.getAttribute(SchemaSymbols.ATT_ATTRIBUTEFORMDEFAULT).equals(SchemaSymbols.ATTVAL_QUALIFIED);
                
  -        fBlockDefault = 
  -            parseBlockSet(root.getAttribute(SchemaSymbols.ATT_BLOCKDEFAULT));
  -        fFinalDefault = 
  -            parseFinalSet(root.getAttribute(SchemaSymbols.ATT_FINALDEFAULT));
  +        Attr blockAttr = root.getAttributeNode(SchemaSymbols.ATT_BLOCKDEFAULT);
  +        if (blockAttr == null) 
  +            fBlockDefault = 0;
  +        else
  +            fBlockDefault = 
  +                parseBlockSet(blockAttr.getValue());
  +        Attr finalAttr = root.getAttributeNode(SchemaSymbols.ATT_FINALDEFAULT);
  +        if (finalAttr == null) 
  +            fFinalDefault = 0;
  +        else
  +            fFinalDefault = 
  +                parseFinalSet(finalAttr.getValue());
           
           //REVISIT, really sticky when noTargetNamesapce, for now, we assume \
everyting is in the same name space);  if (fTargetNSURI == StringPool.EMPTY_STRING) {
  @@ -1489,7 +1505,10 @@
               return fStringPool.addSymbol(qualifiedName);
           }
           
  -        int finalProperty = \
parseFinalSet(simpleTypeDecl.getAttribute(SchemaSymbols.ATT_FINAL));  +        Attr \
finalAttr = simpleTypeDecl.getAttributeNode(SchemaSymbols.ATT_FINAL);  +        int \
finalProperty = 0;  +        if(finalAttr != null) 
  +            finalProperty = parseFinalSet(finalAttr.getValue());
           // REVISIT:  is "extension" allowed???
           
           // if we have a nonzero final , store it in the hash...
  @@ -2132,8 +2151,14 @@
           // Get the attributes of the type
           // ------------------------------------------------------------------
           String isAbstract = complexTypeDecl.getAttribute( \
                SchemaSymbols.ATT_ABSTRACT );
  -        String blockSet = complexTypeDecl.getAttribute( SchemaSymbols.ATT_BLOCK );
  -        String finalSet = complexTypeDecl.getAttribute( SchemaSymbols.ATT_FINAL );
  +        String blockSet = null;
  +        Attr blockAttr = complexTypeDecl.getAttributeNode( SchemaSymbols.ATT_BLOCK \
);  +        if (blockAttr != null)
  +            blockSet = blockAttr.getValue();
  +        String finalSet = null;
  +        Attr finalAttr = complexTypeDecl.getAttributeNode( SchemaSymbols.ATT_FINAL \
);  +        if (finalAttr != null)
  +            finalSet = finalAttr.getValue();
           String typeId = complexTypeDecl.getAttribute( SchemaSymbols.ATTVAL_ID );
           String typeName = complexTypeDecl.getAttribute(SchemaSymbols.ATT_NAME); 
           String mixed = complexTypeDecl.getAttribute(SchemaSymbols.ATT_MIXED);
  @@ -2225,7 +2250,7 @@
             }
             typeInfo.blockSet = parseBlockSet(blockSet); 
             // make sure block's value was absent, #all or in {extension, \
                restriction}
  -          if( !blockSet.equals("") &&
  +          if( (blockSet != null ) && !blockSet.equals("") &&
                   (!blockSet.equals(SchemaSymbols.ATTVAL_POUNDALL) &&
                   (((typeInfo.blockSet & SchemaSymbols.RESTRICTION) == 0) && 
                   ((typeInfo.blockSet & SchemaSymbols.EXTENSION) == 0))))  
  @@ -2233,7 +2258,7 @@
   
             typeInfo.finalSet = parseFinalSet(finalSet); 
             // make sure final's value was absent, #all or in {extension, \
                restriction}
  -          if( !finalSet.equals("") &&
  +          if( (finalSet != null ) && !finalSet.equals("") &&
                   (!finalSet.equals(SchemaSymbols.ATTVAL_POUNDALL) &&
                   (((typeInfo.finalSet & SchemaSymbols.RESTRICTION) == 0) && 
                   ((typeInfo.finalSet & SchemaSymbols.EXTENSION) == 0))))  
  @@ -4093,17 +4118,23 @@
           }
           
           // parse out 'block', 'final', 'nullable', 'abstract'
  -        String blockSetStr = elementDecl.getAttribute(SchemaSymbols.ATT_BLOCK);
  +        String blockSetStr = null;
  +        Attr blockAttr = elementDecl.getAttributeNode( SchemaSymbols.ATT_BLOCK );
  +        if (blockAttr != null)
  +            blockSetStr = blockAttr.getValue();
           int blockSet = parseBlockSet(blockSetStr);
  -        if( !blockSetStr.equals("") &&
  +        if( (blockSetStr != null) && !blockSetStr.equals("") &&
                   (!blockSetStr.equals(SchemaSymbols.ATTVAL_POUNDALL) &&
                   (((blockSet & SchemaSymbols.RESTRICTION) == 0) && 
                   (((blockSet & SchemaSymbols.EXTENSION) == 0) &&
                   ((blockSet & SchemaSymbols.SUBSTITUTION) == 0)))))  
               reportGenericSchemaError("The values of the 'block' attribute of an \
element must be either #all or a list of 'substitution', 'restriction' and \
                'extension'; " + blockSetStr + " was found");
  -        String finalSetStr = elementDecl.getAttribute(SchemaSymbols.ATT_FINAL);
  +        String finalSetStr = null;
  +        Attr finalAttr = elementDecl.getAttributeNode( SchemaSymbols.ATT_FINAL );
  +        if (finalAttr != null)
  +            finalSetStr = finalAttr.getValue();
           int finalSet = parseFinalSet(finalSetStr);
  -        if( !finalSetStr.equals("") &&
  +        if( (finalSetStr != null) && !finalSetStr.equals("") &&
                   (!finalSetStr.equals(SchemaSymbols.ATTVAL_POUNDALL) &&
                   (((finalSet & SchemaSymbols.RESTRICTION) == 0) && 
                   ((finalSet & SchemaSymbols.EXTENSION) == 0))))  
  @@ -4983,9 +5014,31 @@
                           if(dTemp == substitutionGroupEltDV) break;
                       }
                       if (dTemp == null) {
  -                        // REVISIT:  localize
  -                        reportGenericSchemaError("Element " + \
elementDecl.getAttribute(SchemaSymbols.ATT_NAME) + " has a type which does not derive \
                from the type of the element at the head of the substitution group");
  -                        noErrorSoFar = false;
  +                        if(typeInfo.baseDataTypeValidator instanceof \
UnionDatatypeValidator) {  +                            // dv must derive from one of \
its members...  +                            Vector subUnionMemberDV = \
((UnionDatatypeValidator)typeInfo.baseDataTypeValidator).getBaseValidators();  +      \
int subUnionSize = subUnionMemberDV.size();  +                            boolean \
found = false;  +                            for (int i=0; i<subUnionSize && !found; \
i++) {  +                                DatatypeValidator dTempSub = \
(DatatypeValidator)subUnionMemberDV.elementAt(i);   +                                \
for(; dTempSub != null; dTempSub = dTempSub.getBaseValidator()) {  +                  \
// WARNING!!!  This uses comparison by reference andTemp is thus inherently suspect!  \
+                                    if(dTempSub == typeInfo.baseDataTypeValidator) { \
+                                        found = true;  +                             \
break;  +                                    }
  +                                }
  +                            }
  +                            if(!found) {
  +                                // REVISIT:  localize
  +                                reportGenericSchemaError("Element " + \
elementDecl.getAttribute(SchemaSymbols.ATT_NAME) + " has a type which does not derive \
from the type of the element at the head of the substitution group");  +              \
noErrorSoFar = false;  +                            }
  +                        } else {
  +                            // REVISIT:  localize
  +                            reportGenericSchemaError("Element " + \
elementDecl.getAttribute(SchemaSymbols.ATT_NAME) + " has a type which does not derive \
from the type of the element at the head of the substitution group");  +              \
noErrorSoFar = false;  +                        }
                       } else { // now let's see if substitutionGroup element allows \
                this:
                           if((derivationMethod & \
fSchemaGrammar.getElementDeclFinalSet(substitutionGroupElementDeclIndex)) != 0) {  \
noErrorSoFar = false;  @@ -5026,9 +5079,31 @@
                   if(dTemp == substitutionGroupEltDV) break;
               }
               if (dTemp == null) {
  -                // REVISIT:  localize
  -                reportGenericSchemaError("Element " + \
elementDecl.getAttribute(SchemaSymbols.ATT_NAME) + " has a type which does not derive \
                from the type of the element at the head of the substitution group");
  -                noErrorSoFar = false;
  +                if(substitutionGroupEltDV instanceof UnionDatatypeValidator) {
  +                    // dv must derive from one of its members...
  +                    Vector subUnionMemberDV = \
((UnionDatatypeValidator)substitutionGroupEltDV).getBaseValidators();  +              \
int subUnionSize = subUnionMemberDV.size();  +                    boolean found = \
false;  +                    for (int i=0; i<subUnionSize && !found; i++) {
  +                        DatatypeValidator dTempSub = \
(DatatypeValidator)subUnionMemberDV.elementAt(i);   +                        for(; \
dTempSub != null; dTempSub = dTempSub.getBaseValidator()) {  +                        \
// WARNING!!!  This uses comparison by reference andTemp is thus inherently suspect!  \
+                            if(dTempSub == substitutionGroupEltDV) {  +              \
found = true;  +                                break;
  +                            }
  +                        }
  +                    }
  +                    if(!found) {
  +                        // REVISIT:  localize
  +                        reportGenericSchemaError("Element " + \
elementDecl.getAttribute(SchemaSymbols.ATT_NAME) + " has a type which does not derive \
from the type of the element at the head of the substitution group");  +              \
noErrorSoFar = false;  +                    }
  +                } else {
  +                    // REVISIT:  localize
  +                    reportGenericSchemaError("Element " + \
elementDecl.getAttribute(SchemaSymbols.ATT_NAME) + " has a type which does not derive \
from the type of the element at the head of the substitution group");  +              \
noErrorSoFar = false;  +                }
               } else { // now let's see if substitutionGroup element allows this:
                   if((SchemaSymbols.RESTRICTION & \
fSchemaGrammar.getElementDeclFinalSet(substitutionGroupElementDeclIndex)) != 0) {  \
noErrorSoFar = false;  @@ -5984,7 +6059,9 @@
   
       private int parseBlockSet (String blockString)  throws Exception
       {
  -            if ( blockString.equals (SchemaSymbols.ATTVAL_POUNDALL) ) {
  +            if( blockString == null) 
  +                return fBlockDefault;
  +            else if ( blockString.equals (SchemaSymbols.ATTVAL_POUNDALL) ) {
                       return \
SchemaSymbols.SUBSTITUTION+SchemaSymbols.EXTENSION+SchemaSymbols.LIST+SchemaSymbols.RESTRICTION+SchemaSymbols.UNION;
  } else {
                       int extend = 0;
  @@ -6045,7 +6122,9 @@
   
       private int parseFinalSet (String finalString)  throws Exception
       {
  -            if ( finalString.equals (SchemaSymbols.ATTVAL_POUNDALL) ) {
  +            if( finalString == null) 
  +                return fFinalDefault;
  +            else if ( finalString.equals (SchemaSymbols.ATTVAL_POUNDALL) ) {
                       return \
SchemaSymbols.EXTENSION+SchemaSymbols.LIST+SchemaSymbols.RESTRICTION+SchemaSymbols.UNION;
  } else {
                       int extend = 0;
  
  
  
  1.6       +5 -0      \
xml-xerces/java/src/org/apache/xerces/validators/datatype/UnionDatatypeValidator.java \
  Index: UnionDatatypeValidator.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/validators/datatype/UnionDatatypeValidator.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- UnionDatatypeValidator.java	2001/03/28 21:42:39	1.5
  +++ UnionDatatypeValidator.java	2001/03/29 21:13:38	1.6
  @@ -212,6 +212,11 @@
   
       }
   
  +    // returns the fBaseValidators Vector; added so that
  +    // 2.2.4 of SchemaStructures spec section 3.14.6 can be implemented.
  +    public Vector getBaseValidators() {
  +        return fBaseValidators;
  +    }
   
       /**
       * check if enum is subset of fEnumeration
  
  
  

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


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic