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 2003/11/24 06:13:21 UTC

cvs commit: xml-xerces/c/src/xercesc/validators/schema SchemaValidator.cpp SchemaValidator.hpp

neilg       2003/11/23 21:13:21

  Modified:    c/src/xercesc/validators/schema SchemaValidator.cpp
                        SchemaValidator.hpp
  Log:
  expose validator that actually validated attribute.  Clean up union handling
  
  Revision  Changes    Path
  1.44      +77 -63    xml-xerces/c/src/xercesc/validators/schema/SchemaValidator.cpp
  
  Index: SchemaValidator.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/src/xercesc/validators/schema/SchemaValidator.cpp,v
  retrieving revision 1.43
  retrieving revision 1.44
  diff -u -r1.43 -r1.44
  --- SchemaValidator.cpp	20 Nov 2003 18:12:20 -0000	1.43
  +++ SchemaValidator.cpp	24 Nov 2003 05:13:20 -0000	1.44
  @@ -56,6 +56,9 @@
   
   /*
    * $Log$
  + * Revision 1.44  2003/11/24 05:13:20  neilg
  + * expose validator that actually validated attribute.  Clean up union handling
  + *
    * Revision 1.43  2003/11/20 18:12:20  knoaman
    * Use a bitwise operation to check the node type.
    *
  @@ -314,6 +317,7 @@
       , fDatatypeBuffer(1023, manager)
       , fNil(false)
       , fTypeStack(0)
  +    , fMostRecentAttrValidator(0)
   {
       fTypeStack = new (fMemoryManager) ValueStackOf<ComplexTypeInfo*>(8, fMemoryManager);
   }
  @@ -559,6 +563,8 @@
           , attName->getPrefix()
           , schemaAttDef->getValue()
           , schemaAttDef->getType()
  +        , getMostRecentAttrValidator()
  +        , true
       );
   }
   
  @@ -619,6 +625,8 @@
           emitError(XMLValid::InvalidEmptyAttValue, attDef->getFullName());
           ((SchemaElementDecl *)(elemDecl))->setValidity(PSVIDefs::INVALID);
           ((SchemaAttDef *)(attDef))->setValidity(PSVIDefs::INVALID);
  +        // accords with original DOMTypeInfo implementation, but this does not feel right.
  +        fMostRecentAttrValidator = DatatypeValidatorFactory::getBuiltInRegistry()->get(SchemaSymbols::fgDT_ANYSIMPLETYPE);
           return;
       }
   
  @@ -628,56 +636,11 @@
           valid = false;
       }
       else {
  +        DatatypeValidator::ValidatorType attDefDVType = attDefDV->getType();
  +        ValidationContext *context = getScanner()->getValidationContext();
           try {
  -            DatatypeValidator::ValidatorType attDefDVType = attDefDV->getType();
  -
  -            // set up the entitydeclpool in ENTITYDatatypeValidator
  -            // and the idreflist in ID/IDREFDatatypeValidator
  -
  -            // indicate if this attribute is of type ID
  -            bool thisIsAnId = false;
   
  -            if (attDefDVType == DatatypeValidator::List) {
  -                DatatypeValidator* itemDTV = ((ListDatatypeValidator*)attDefDV)->getItemTypeDTV();
  -                DatatypeValidator::ValidatorType itemDTVType = itemDTV->getType();
  -                if (itemDTVType == DatatypeValidator::ID) {
  -                    thisIsAnId = true;
  -                }
  -                else if (itemDTVType == DatatypeValidator::IDREF) {
  -                    // if in prevalidatoin, do not add attDef to IDREFList
  -                    if (preValidation)
  -                        //todo: when to setIdRefList back to non-null
  -                        getScanner()->getValidationContext()->toCheckIdRefList(false);
  -                }
  -            }
  -            else if (attDefDVType == DatatypeValidator::Union) {
  -                RefVectorOf<DatatypeValidator>* memberDTV = ((UnionDatatypeValidator*)attDefDV)->getMemberTypeValidators();
  -                unsigned int memberTypeNumber = memberDTV->size();
  -                for ( unsigned int memberIndex = 0; memberIndex < memberTypeNumber; ++memberIndex)
  -                {
  -                    DatatypeValidator::ValidatorType memberDTVType = memberDTV->elementAt(memberIndex)->getType();
  -                    if (memberDTVType == DatatypeValidator::ID) {
  -                        thisIsAnId = true;
  -                    }
  -                    else if (memberDTVType == DatatypeValidator::IDREF) {
  -                        // if in prevalidatoin, do not add attDef to IDREFList
  -                        if (preValidation)
  -                            getScanner()->getValidationContext()->toCheckIdRefList(false);
  -
  -                    }
  -                }
  -            }
  -            else if (attDefDVType == DatatypeValidator::ID) {
  -                thisIsAnId = true;
  -            }
  -            else if (attDefDVType == DatatypeValidator::IDREF) {
  -                // if in prevalidatoin, do not add attDef to IDREFList
  -                if (preValidation)
  -                    getScanner()->getValidationContext()->toCheckIdRefList(false);
  -            }
  -
  -            // now validate the attribute value
  -            // if notation, need to bind URI to notation first
  +            // first, if notation, need to bind URI to notation first
               if (attDefDVType == DatatypeValidator::NOTATION)
               {
                   //
  @@ -696,24 +659,13 @@
                   notationBuf.append(&attrValue[colonPos + 1]);
   
                   attDefDV->validate(notationBuf.getRawBuffer()
  -                                 , getScanner()->getValidationContext());
  +                                 , context);
               }
               else {
  -                if (thisIsAnId) {
  -                    if (fSeenId) {
  -                        emitError
  -                        (
  -                            XMLValid::MultipleIdAttrs
  -                            , elemDecl->getFullName()
  -                        );
  -                        valid = false;
  -                    }
  -                    else
  -                        fSeenId = true;
  -                }
                   attDefDV->validate(attrValue
  -                                 , getScanner()->getValidationContext());
  +                                 , context);
               }
  +
           }
           catch (XMLException& idve) {
               valid = false;
  @@ -727,15 +679,77 @@
               emitError(XMLValid::GenericError);
               ((SchemaElementDecl *)(elemDecl))->setValidity(PSVIDefs::INVALID);
               ((SchemaAttDef *)attDef)->setValidity(PSVIDefs::INVALID);
  +            fMostRecentAttrValidator = DatatypeValidatorFactory::getBuiltInRegistry()->get(SchemaSymbols::fgDT_ANYSIMPLETYPE);
               throw;
  +        } 
  +        fMostRecentAttrValidator = attDefDV;
  +        // now we can look for ID's, entities, ...
  +
  +        // set up the entitydeclpool in ENTITYDatatypeValidator
  +        // and the idreflist in ID/IDREFDatatypeValidator
  +
  +        // indicate if this attribute is of type ID
  +        bool thisIsAnId = false;
  +
  +        if (attDefDVType == DatatypeValidator::List) {
  +            DatatypeValidator* itemDTV = ((ListDatatypeValidator*)attDefDV)->getItemTypeDTV();
  +            DatatypeValidator::ValidatorType itemDTVType = itemDTV->getType();
  +            if (itemDTVType == DatatypeValidator::ID) {
  +                thisIsAnId = true;
  +            }
  +            else if (itemDTVType == DatatypeValidator::IDREF) {
  +                // if in prevalidatoin, do not add attDef to IDREFList
  +                if (preValidation)
  +                    //todo: when to setIdRefList back to non-null
  +                    getScanner()->getValidationContext()->toCheckIdRefList(false);
  +            }
           }
  +        else if (attDefDVType == DatatypeValidator::Union) {
  +            DatatypeValidator *memberDTV = context->getValidatingMemberType();
  +            // actual type for DOMTypeInfo is memberDTV
  +            fMostRecentAttrValidator = memberDTV;
  +            DatatypeValidator::ValidatorType memberDTVType = memberDTV->getType();
  +            if (memberDTVType == DatatypeValidator::ID) {
  +                thisIsAnId = true;
  +            }
  +            else if (memberDTVType == DatatypeValidator::IDREF) {
  +                // if in prevalidatoin, do not add attDef to IDREFList
  +                if (preValidation)
  +                    getScanner()->getValidationContext()->toCheckIdRefList(false);
  +
  +            }
  +        }
  +        else if (attDefDVType == DatatypeValidator::ID) {
  +            thisIsAnId = true;
  +        }
  +        else if (attDefDVType == DatatypeValidator::IDREF) {
  +            // if in prevalidation, do not add attDef to IDREFList
  +            if (preValidation)
  +                getScanner()->getValidationContext()->toCheckIdRefList(false);
  +        }
  +        if (thisIsAnId) {
  +            if (fSeenId) {
  +                emitError
  +                (
  +                    XMLValid::MultipleIdAttrs
  +                    , elemDecl->getFullName()
  +                );
  +                valid = false;
  +            }
  +            else
  +                fSeenId = true;
  +        }
  +
       }
   
       if(!valid) {
           ((SchemaElementDecl *)(elemDecl))->setValidity(PSVIDefs::INVALID);
           ((SchemaAttDef *)attDef)->setValidity(PSVIDefs::INVALID);
  +        fMostRecentAttrValidator = DatatypeValidatorFactory::getBuiltInRegistry()->get(SchemaSymbols::fgDT_ANYSIMPLETYPE);
       }
       else if(attDefDV && attDefDV->getType() == DatatypeValidator::Union) 
  +        // in a thread-safe world, this is entirely bogus;REVISIT and remove 
  +        // once the appropriate methods have been removed!
           ((SchemaAttDef *)attDef)->setMembertypeValidator(((UnionDatatypeValidator *)attDefDV)->getMemberTypeValidator());
       fTrailing = false;
   
  
  
  
  1.20      +12 -1     xml-xerces/c/src/xercesc/validators/schema/SchemaValidator.hpp
  
  Index: SchemaValidator.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/src/xercesc/validators/schema/SchemaValidator.hpp,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- SchemaValidator.hpp	5 Oct 2003 02:09:37 -0000	1.19
  +++ SchemaValidator.hpp	24 Nov 2003 05:13:20 -0000	1.20
  @@ -56,6 +56,9 @@
   
   /*
    * $Log$
  + * Revision 1.20  2003/11/24 05:13:20  neilg
  + * expose validator that actually validated attribute.  Clean up union handling
  + *
    * Revision 1.19  2003/10/05 02:09:37  neilg
    * the validator now keeps track of the current complex and simple type (including if this is an xsi:type).  This allows both the validator and the scanner to know what the current type is, without the need to modify the element declaration each time an xsi:type is seen
    *
  @@ -260,6 +263,7 @@
       // -----------------------------------------------------------------------
       ComplexTypeInfo* getCurrentTypeInfo() const;
       DatatypeValidator *getCurrentDatatypeValidator() const;
  +    DatatypeValidator *getMostRecentAttrValidator() const;
   
   private:
       // -----------------------------------------------------------------------
  @@ -391,6 +395,8 @@
       //
       //  fTypeStack
       //      Stack of complex type declarations.
  +    //  fMostRecentAttrValidator
  +    //      DatatypeValidator that validated attribute most recently processed
       // -----------------------------------------------------------------------
       MemoryManager*                  fMemoryManager;
       SchemaGrammar*                  fSchemaGrammar;
  @@ -404,6 +410,7 @@
       bool                            fSeenId;
       XSDErrorReporter                fSchemaErrorReporter;
       ValueStackOf<ComplexTypeInfo*>* fTypeStack;
  +    DatatypeValidator *             fMostRecentAttrValidator;
   };
   
   
  @@ -448,6 +455,10 @@
   inline DatatypeValidator * SchemaValidator::getCurrentDatatypeValidator() const 
   {
       return fCurrentDatatypeValidator;
  +}
  +inline DatatypeValidator *SchemaValidator::getMostRecentAttrValidator() const
  +{
  +    return fMostRecentAttrValidator;
   }
   
   // ---------------------------------------------------------------------------
  
  
  

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