source: icXML/icXML-devel/src/xercesc/framework/psvi/PSVIItem.cpp @ 2722

Last change on this file since 2722 was 2722, checked in by cameron, 6 years ago

Original Xerces files with import mods for icxercesc

File size: 4.4 KB
Line 
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements.  See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License.  You may obtain a copy of the License at
8 *
9 *      http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18/*
19 * $Id: PSVIItem.cpp 471747 2006-11-06 14:31:56Z amassari $
20 */
21
22#include <xercesc/framework/psvi/PSVIItem.hpp>
23#include <xercesc/framework/psvi/XSValue.hpp>
24#include <xercesc/framework/psvi/XSComplexTypeDefinition.hpp>
25#include <icxercesc/validators/datatype/DatatypeValidatorFactory.hpp>
26
27XERCES_CPP_NAMESPACE_BEGIN
28
29PSVIItem::PSVIItem( MemoryManager* const manager ): 
30        fMemoryManager(manager),
31        fValidationContext(0),
32        fNormalizedValue(0),
33        fDefaultValue(0),
34        fCanonicalValue(0),
35        fValidityState(VALIDITY_NOTKNOWN),
36        fAssessmentType(VALIDATION_FULL),
37        fIsSpecified(false),
38        fType(0),
39        fMemberType(0)
40{
41}
42
43void PSVIItem::reset(
44            const XMLCh* const validationContext
45            , const XMLCh* const normalizedValue
46            , const VALIDITY_STATE validityState
47            , const ASSESSMENT_TYPE assessmentType
48        )
49{
50    // this is just a wrapper method; fValidationContext will
51    // be valid as long as and no longer than the thing to which
52    // validationContext points
53    fValidationContext = validationContext;
54    fNormalizedValue = normalizedValue;
55    fValidityState = validityState;
56    fAssessmentType = assessmentType;
57}
58
59void PSVIItem::setValidationAttempted(PSVIItem::ASSESSMENT_TYPE attemptType)
60{
61    fAssessmentType = attemptType;
62}
63 
64void PSVIItem::setValidity(PSVIItem::VALIDITY_STATE validity)
65{
66    fValidityState = validity;
67}
68
69XSValue* PSVIItem::getActualValue() const
70{
71    /***
72     * assessment
73         *    VALIDATION_PARTIAL
74         *    VALIDATION_FULL
75     * validity
76         *    VALIDITY_VALID
77     ***/
78    if ((fAssessmentType==VALIDATION_NONE) || (fValidityState!=VALIDITY_VALID))
79        return 0;
80   
81    /***
82     *  XSSimpleType or
83     *  XSComplexType's CONTENTTYPE_SIMPLE
84     *  allowed
85     ***/
86    if ((!fType) ||
87        ((fType->getTypeCategory() == XSTypeDefinition::COMPLEX_TYPE) &&
88         (((XSComplexTypeDefinition*)fType)->getContentType() != XSComplexTypeDefinition::CONTENTTYPE_SIMPLE)))
89        return 0;
90   
91    /***
92     * Resolve dv
93     *
94     * 1. If fMemberType is not null, use the fMemberType->fDataTypeValidator
95     * 2. If fType is XSSimpleType, use fType->fDataTypeValidator
96     * 3. If fType is XSComplexType, use fType->fXSSimpleTypeDefinition-> fDataTypeValidator
97     *
98    ***/
99
100    DatatypeValidator *dv = 0;
101
102     if (fMemberType)
103     {
104         /***
105          *  Now that fType is either XSSimpleTypeDefinition or
106          *  XSComlextTypeDefinition with CONTENTTYPE_SIMPLE, the
107          *  fMemberType must be XSSimpleTypeDefinition if present
108         ***/
109         dv=((XSSimpleTypeDefinition*) fMemberType)->getDatatypeValidator();
110     }
111     else if (fType->getTypeCategory() == XSTypeDefinition::SIMPLE_TYPE)
112     {
113         dv=((XSSimpleTypeDefinition*) fType)->getDatatypeValidator();
114     }
115     else
116     {
117         XSSimpleTypeDefinition* simType = ((XSComplexTypeDefinition*)fType)->getSimpleType();
118         if (simType)
119             dv = simType->getDatatypeValidator();
120     }
121
122     if (!dv) return 0;
123
124     /***
125      * Get the ultimate base dv in the datatype registry
126      ***/
127     DatatypeValidator *basedv = DatatypeValidatorFactory::getBuiltInBaseValidator(dv);
128
129     if (!basedv) return 0;
130   
131     XSValue::Status  status=XSValue::st_Init;
132
133     return XSValue::getActualValue(fNormalizedValue
134                                  , XSValue::getDataType(basedv->getTypeLocalName())
135                                  , status
136                                  , XSValue::ver_10
137                                  , false
138                                  , fMemoryManager);
139
140
141}
142
143XERCES_CPP_NAMESPACE_END
144
145
Note: See TracBrowser for help on using the repository browser.