GME  13
PSVIItem.cpp
Go to the documentation of this file.
00001 /*
00002  * Licensed to the Apache Software Foundation (ASF) under one or more
00003  * contributor license agreements.  See the NOTICE file distributed with
00004  * this work for additional information regarding copyright ownership.
00005  * The ASF licenses this file to You under the Apache License, Version 2.0
00006  * (the "License"); you may not use this file except in compliance with
00007  * the License.  You may obtain a copy of the License at
00008  * 
00009  *      http://www.apache.org/licenses/LICENSE-2.0
00010  * 
00011  * Unless required by applicable law or agreed to in writing, software
00012  * distributed under the License is distributed on an "AS IS" BASIS,
00013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  * See the License for the specific language governing permissions and
00015  * limitations under the License.
00016  */
00017 
00018 /*
00019  * $Id: PSVIItem.cpp 471747 2006-11-06 14:31:56Z amassari $
00020  */
00021 
00022 #include <xercesc/framework/psvi/PSVIItem.hpp>
00023 #include <xercesc/framework/psvi/XSValue.hpp>
00024 #include <xercesc/framework/psvi/XSComplexTypeDefinition.hpp>
00025 #include <xercesc/validators/datatype/DatatypeValidatorFactory.hpp>
00026 
00027 XERCES_CPP_NAMESPACE_BEGIN
00028 
00029 PSVIItem::PSVIItem( MemoryManager* const manager ):  
00030         fMemoryManager(manager),
00031         fValidationContext(0),
00032         fNormalizedValue(0),
00033         fDefaultValue(0),
00034         fCanonicalValue(0),
00035         fValidityState(VALIDITY_NOTKNOWN),
00036         fAssessmentType(VALIDATION_FULL),
00037         fIsSpecified(false),
00038         fType(0),
00039         fMemberType(0)
00040 {
00041 }
00042 
00043 void PSVIItem::reset(
00044             const XMLCh* const validationContext
00045             , const XMLCh* const normalizedValue
00046             , const VALIDITY_STATE validityState
00047             , const ASSESSMENT_TYPE assessmentType
00048         )
00049 {
00050     // this is just a wrapper method; fValidationContext will
00051     // be valid as long as and no longer than the thing to which
00052     // validationContext points
00053     fValidationContext = validationContext;
00054     fNormalizedValue = normalizedValue;
00055     fValidityState = validityState;
00056     fAssessmentType = assessmentType;
00057 }
00058 
00059 void PSVIItem::setValidationAttempted(PSVIItem::ASSESSMENT_TYPE attemptType)
00060 {
00061     fAssessmentType = attemptType;
00062 }
00063  
00064 void PSVIItem::setValidity(PSVIItem::VALIDITY_STATE validity)
00065 {
00066     fValidityState = validity;
00067 }
00068 
00069 XSValue* PSVIItem::getActualValue() const
00070 {
00071     /***
00072      * assessment 
00073          *    VALIDATION_PARTIAL 
00074          *    VALIDATION_FULL 
00075      * validity
00076          *    VALIDITY_VALID
00077      ***/
00078     if ((fAssessmentType==VALIDATION_NONE) || (fValidityState!=VALIDITY_VALID))
00079         return 0;
00080     
00081     /***
00082      *  XSSimpleType or
00083      *  XSComplexType's CONTENTTYPE_SIMPLE
00084      *  allowed
00085      ***/
00086     if ((!fType) ||
00087         ((fType->getTypeCategory() == XSTypeDefinition::COMPLEX_TYPE) &&
00088          (((XSComplexTypeDefinition*)fType)->getContentType() != XSComplexTypeDefinition::CONTENTTYPE_SIMPLE)))
00089         return 0;
00090     
00091     /*** 
00092      * Resolve dv
00093      *
00094      * 1. If fMemberType is not null, use the fMemberType->fDataTypeValidator
00095      * 2. If fType is XSSimpleType, use fType->fDataTypeValidator
00096      * 3. If fType is XSComplexType, use fType->fXSSimpleTypeDefinition-> fDataTypeValidator
00097      *
00098     ***/
00099 
00100     DatatypeValidator *dv = 0;
00101 
00102      if (fMemberType)
00103      {
00104          /***
00105           *  Now that fType is either XSSimpleTypeDefinition or
00106           *  XSComlextTypeDefinition with CONTENTTYPE_SIMPLE, the
00107           *  fMemberType must be XSSimpleTypeDefinition if present
00108          ***/
00109          dv=((XSSimpleTypeDefinition*) fMemberType)->getDatatypeValidator();
00110      }
00111      else if (fType->getTypeCategory() == XSTypeDefinition::SIMPLE_TYPE)
00112      {
00113          dv=((XSSimpleTypeDefinition*) fType)->getDatatypeValidator();
00114      }
00115      else
00116      {
00117          XSSimpleTypeDefinition* simType = ((XSComplexTypeDefinition*)fType)->getSimpleType();
00118          if (simType)
00119              dv = simType->getDatatypeValidator();
00120      }
00121 
00122      if (!dv) return 0;
00123 
00124      /***
00125       * Get the ultimate base dv in the datatype registry
00126       ***/
00127      DatatypeValidator *basedv = DatatypeValidatorFactory::getBuiltInBaseValidator(dv);
00128 
00129      if (!basedv) return 0;
00130     
00131      XSValue::Status  status=XSValue::st_Init;
00132 
00133      return XSValue::getActualValue(fNormalizedValue
00134                                   , XSValue::getDataType(basedv->getTypeLocalName())
00135                                   , status
00136                                   , XSValue::ver_10
00137                                   , false
00138                                   , fMemoryManager);
00139 
00140 
00141 }
00142 
00143 XERCES_CPP_NAMESPACE_END
00144 
00145