source: icXML/icXML-devel/src/xercesc/dom/impl/DOMTypeInfoImpl.cpp @ 2777

Last change on this file since 2777 was 2777, checked in by cameron, 7 years ago

Set up to use xercesc/icxercesc root-relative paths for all includes

File size: 9.7 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#include <xercesc/dom/impl/DOMTypeInfoImpl.hpp>
19#include <xercesc/dom/impl/DOMDocumentImpl.hpp>
20#include <xercesc/framework/psvi/PSVIItem.hpp>
21#include <xercesc/framework/psvi/XSTypeDefinition.hpp>
22
23XERCES_CPP_NAMESPACE_BEGIN
24
25/*static*/ DOMTypeInfoImpl DOMTypeInfoImpl::g_DtdValidatedElement;
26/*static*/ DOMTypeInfoImpl DOMTypeInfoImpl::g_DtdNotValidatedAttribute;
27/*static*/ DOMTypeInfoImpl DOMTypeInfoImpl::g_DtdValidatedCDATAAttribute(XMLUni::fgInfosetURIName, XMLUni::fgCDATAString);
28/*static*/ DOMTypeInfoImpl DOMTypeInfoImpl::g_DtdValidatedIDAttribute(XMLUni::fgInfosetURIName, XMLUni::fgIDString);
29/*static*/ DOMTypeInfoImpl DOMTypeInfoImpl::g_DtdValidatedIDREFAttribute(XMLUni::fgInfosetURIName, XMLUni::fgIDRefString);
30/*static*/ DOMTypeInfoImpl DOMTypeInfoImpl::g_DtdValidatedIDREFSAttribute(XMLUni::fgInfosetURIName, XMLUni::fgIDRefsString);
31/*static*/ DOMTypeInfoImpl DOMTypeInfoImpl::g_DtdValidatedENTITYAttribute(XMLUni::fgInfosetURIName, XMLUni::fgEntityString);
32/*static*/ DOMTypeInfoImpl DOMTypeInfoImpl::g_DtdValidatedENTITIESAttribute(XMLUni::fgInfosetURIName, XMLUni::fgEntitiesString);
33/*static*/ DOMTypeInfoImpl DOMTypeInfoImpl::g_DtdValidatedNMTOKENAttribute(XMLUni::fgInfosetURIName, XMLUni::fgNmTokenString);
34/*static*/ DOMTypeInfoImpl DOMTypeInfoImpl::g_DtdValidatedNMTOKENSAttribute(XMLUni::fgInfosetURIName, XMLUni::fgNmTokensString);
35/*static*/ DOMTypeInfoImpl DOMTypeInfoImpl::g_DtdValidatedNOTATIONAttribute(XMLUni::fgInfosetURIName, XMLUni::fgNotationString);
36/*static*/ DOMTypeInfoImpl DOMTypeInfoImpl::g_DtdValidatedENUMERATIONAttribute(XMLUni::fgInfosetURIName, XMLUni::fgEnumerationString);
37
38DOMTypeInfoImpl::DOMTypeInfoImpl(const XMLCh* namespaceUri/*=0*/, const XMLCh* name/*=0*/)
39: fBitFields(0),
40  fTypeName(name),
41  fTypeNamespace(namespaceUri),
42  fMemberTypeName(0),
43  fMemberTypeNamespace(0),
44  fDefaultValue(0),
45  fNormalizedValue(0)
46{
47    // by setting the fBitField to 0 we are also setting:
48    //  - [validity]=VALIDITY_NOTKNOWN
49    //  - [validitation attempted]=VALIDATION_NONE
50    //  - [schema specified]=false
51}
52
53DOMTypeInfoImpl::DOMTypeInfoImpl(DOMDocumentImpl* ownerDoc, const DOMPSVITypeInfo* sourcePSVI)
54: fBitFields(0),
55  fTypeName(0),
56  fTypeNamespace(0),
57  fMemberTypeName(0),
58  fMemberTypeNamespace(0),
59  fDefaultValue(0),
60  fNormalizedValue(0)
61{
62    setNumericProperty(DOMPSVITypeInfo::PSVI_Validity,
63        sourcePSVI->getNumericProperty(DOMPSVITypeInfo::PSVI_Validity));
64    setNumericProperty(DOMPSVITypeInfo::PSVI_Validation_Attempted,
65        sourcePSVI->getNumericProperty(DOMPSVITypeInfo::PSVI_Validation_Attempted));
66    setNumericProperty(DOMPSVITypeInfo::PSVI_Type_Definition_Type,
67        sourcePSVI->getNumericProperty(DOMPSVITypeInfo::PSVI_Type_Definition_Type));
68    setNumericProperty(DOMPSVITypeInfo::PSVI_Type_Definition_Anonymous,
69        sourcePSVI->getNumericProperty(DOMPSVITypeInfo::PSVI_Type_Definition_Anonymous));
70    setNumericProperty(DOMPSVITypeInfo::PSVI_Nil,
71        sourcePSVI->getNumericProperty(DOMPSVITypeInfo::PSVI_Nil));
72    setNumericProperty(DOMPSVITypeInfo::PSVI_Member_Type_Definition_Anonymous,
73        sourcePSVI->getNumericProperty(DOMPSVITypeInfo::PSVI_Member_Type_Definition_Anonymous));
74    setNumericProperty(DOMPSVITypeInfo::PSVI_Schema_Specified,
75        sourcePSVI->getNumericProperty(DOMPSVITypeInfo::PSVI_Schema_Specified));
76
77    setStringProperty(DOMPSVITypeInfo::PSVI_Type_Definition_Name,
78        ownerDoc->getPooledString(sourcePSVI->getStringProperty(DOMPSVITypeInfo::PSVI_Type_Definition_Name)));
79    setStringProperty(DOMPSVITypeInfo::PSVI_Type_Definition_Namespace,
80        ownerDoc->getPooledString(sourcePSVI->getStringProperty(DOMPSVITypeInfo::PSVI_Type_Definition_Namespace)));
81    setStringProperty(DOMPSVITypeInfo::PSVI_Member_Type_Definition_Name,
82        ownerDoc->getPooledString(sourcePSVI->getStringProperty(DOMPSVITypeInfo::PSVI_Member_Type_Definition_Name)));
83    setStringProperty(DOMPSVITypeInfo::PSVI_Member_Type_Definition_Namespace,
84        ownerDoc->getPooledString(sourcePSVI->getStringProperty(DOMPSVITypeInfo::PSVI_Member_Type_Definition_Namespace)));
85    setStringProperty(DOMPSVITypeInfo::PSVI_Schema_Default,
86        ownerDoc->getPooledString(sourcePSVI->getStringProperty(DOMPSVITypeInfo::PSVI_Schema_Default)));
87    setStringProperty(DOMPSVITypeInfo::PSVI_Schema_Normalized_Value,
88        ownerDoc->getPooledString(sourcePSVI->getStringProperty(DOMPSVITypeInfo::PSVI_Schema_Normalized_Value)));
89}
90
91const XMLCh* DOMTypeInfoImpl::getTypeName() const {
92    // if it's a DTD, return the data that was stored
93    if(!getNumericProperty(PSVI_Schema_Specified))
94        return fTypeName;
95    // if [validity] is "invalid" or "notKnown", the {target namespace} and {name} properties of the declared type if available, otherwise null.
96    if(!getNumericProperty(PSVI_Validity))
97        return fTypeName;
98    if(fMemberTypeName)
99        return fMemberTypeName;
100    return fTypeName;
101}
102
103const XMLCh* DOMTypeInfoImpl::getTypeNamespace() const {
104    // if it's a DTD, return the data that was stored
105    if(!getNumericProperty(PSVI_Schema_Specified))
106        return fTypeNamespace;
107    // if [validity] is "invalid" or "notKnown", the {target namespace} and {name} properties of the declared type if available, otherwise null.
108    if(!getNumericProperty(PSVI_Validity))
109        return fTypeNamespace;
110    if(fMemberTypeName)     // we check on the name, as the URI can be NULL
111        return fMemberTypeNamespace;
112    return fTypeNamespace;
113}
114
115bool DOMTypeInfoImpl::isDerivedFrom(const XMLCh* typeNamespaceArg, const XMLCh* typeNameArg, DerivationMethods) const
116{
117    // if it's a DTD, return false
118    if(!getNumericProperty(PSVI_Schema_Specified))
119        return false;
120    if(XMLString::equals(typeNamespaceArg, getTypeNamespace()) && XMLString::equals(typeNameArg, getTypeName()))
121        return true;
122    // TODO: need a pointer to the Grammar object
123    return false;
124}
125
126const XMLCh* DOMTypeInfoImpl::getStringProperty(PSVIProperty prop) const {
127    switch(prop)
128    {
129    case PSVI_Type_Definition_Name:             return fTypeName;
130    case PSVI_Type_Definition_Namespace:        return fTypeNamespace;
131    case PSVI_Member_Type_Definition_Name:      return fMemberTypeName;
132    case PSVI_Member_Type_Definition_Namespace: return fMemberTypeNamespace;
133    case PSVI_Schema_Default:                   return fDefaultValue;
134    case PSVI_Schema_Normalized_Value:          return fNormalizedValue;
135    default:                                    assert(false); /* it's not a string property */
136    }
137    return 0;
138}
139
140int DOMTypeInfoImpl::getNumericProperty(PSVIProperty prop) const {
141    switch(prop)
142    {
143    case PSVI_Validity:                         return (PSVIItem::VALIDITY_STATE)(fBitFields & 0x0003);
144    case PSVI_Validation_Attempted:             return (PSVIItem::ASSESSMENT_TYPE)((fBitFields >> 2) & 0x0003);
145    case PSVI_Type_Definition_Type:             return (fBitFields & (1 << 5))?XSTypeDefinition::COMPLEX_TYPE:XSTypeDefinition::SIMPLE_TYPE;
146    case PSVI_Type_Definition_Anonymous:        return (fBitFields & (1 << 6))?true:false;
147    case PSVI_Nil:                              return (fBitFields & (1 << 7))?true:false;
148    case PSVI_Member_Type_Definition_Anonymous: return (fBitFields & (1 << 8))?true:false;
149    case PSVI_Schema_Specified:                 return (fBitFields & (1 << 9))?true:false;
150    default:                                    assert(false); /* it's not a numeric property */
151    }
152    return 0;
153}
154
155void DOMTypeInfoImpl::setStringProperty(PSVIProperty prop, const XMLCh* value) {
156    switch(prop)
157    {
158    case PSVI_Type_Definition_Name:             fTypeName=value; break;
159    case PSVI_Type_Definition_Namespace:        fTypeNamespace=value; break;
160    case PSVI_Member_Type_Definition_Name:      fMemberTypeName=value; break;
161    case PSVI_Member_Type_Definition_Namespace: fMemberTypeNamespace=value; break;
162    case PSVI_Schema_Default:                   fDefaultValue=value; break;
163    case PSVI_Schema_Normalized_Value:          fNormalizedValue=value; break;
164    default:                                    assert(false); /* it's not a string property */
165    }
166}
167
168void DOMTypeInfoImpl::setNumericProperty(PSVIProperty prop, int value) {
169    switch(prop)
170    {
171    case PSVI_Validity:                         fBitFields |= (value & 0x0003); break;
172    case PSVI_Validation_Attempted:             fBitFields |= ((value & 0x0003) << 2); break;
173    case PSVI_Type_Definition_Type:             fBitFields |= (value==XSTypeDefinition::COMPLEX_TYPE)?(1 << 5):0; break;
174    case PSVI_Type_Definition_Anonymous:        fBitFields |= (value!=0)?(1 << 6):0; break;
175    case PSVI_Nil:                              fBitFields |= (value!=0)?(1 << 7):0; break;
176    case PSVI_Member_Type_Definition_Anonymous: fBitFields |= (value!=0)?(1 << 8):0; break;
177    case PSVI_Schema_Specified:                 fBitFields |= (value!=0)?(1 << 9):0; break;
178    default:                                    assert(false); /* it's not a numeric property */
179    }
180}
181
182
183XERCES_CPP_NAMESPACE_END
184/**
185 * End of file DOMTypeInfo.cpp
186 */
Note: See TracBrowser for help on using the repository browser.