GME  13
DOMTypeInfoImpl.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 #include "DOMTypeInfoImpl.hpp"
00019 #include "DOMDocumentImpl.hpp"
00020 #include <xercesc/framework/psvi/PSVIItem.hpp>
00021 #include <xercesc/framework/psvi/XSTypeDefinition.hpp>
00022 
00023 XERCES_CPP_NAMESPACE_BEGIN
00024 
00025 /*static*/ DOMTypeInfoImpl DOMTypeInfoImpl::g_DtdValidatedElement;
00026 /*static*/ DOMTypeInfoImpl DOMTypeInfoImpl::g_DtdNotValidatedAttribute;
00027 /*static*/ DOMTypeInfoImpl DOMTypeInfoImpl::g_DtdValidatedCDATAAttribute(XMLUni::fgInfosetURIName, XMLUni::fgCDATAString);
00028 /*static*/ DOMTypeInfoImpl DOMTypeInfoImpl::g_DtdValidatedIDAttribute(XMLUni::fgInfosetURIName, XMLUni::fgIDString);
00029 /*static*/ DOMTypeInfoImpl DOMTypeInfoImpl::g_DtdValidatedIDREFAttribute(XMLUni::fgInfosetURIName, XMLUni::fgIDRefString);
00030 /*static*/ DOMTypeInfoImpl DOMTypeInfoImpl::g_DtdValidatedIDREFSAttribute(XMLUni::fgInfosetURIName, XMLUni::fgIDRefsString);
00031 /*static*/ DOMTypeInfoImpl DOMTypeInfoImpl::g_DtdValidatedENTITYAttribute(XMLUni::fgInfosetURIName, XMLUni::fgEntityString);
00032 /*static*/ DOMTypeInfoImpl DOMTypeInfoImpl::g_DtdValidatedENTITIESAttribute(XMLUni::fgInfosetURIName, XMLUni::fgEntitiesString);
00033 /*static*/ DOMTypeInfoImpl DOMTypeInfoImpl::g_DtdValidatedNMTOKENAttribute(XMLUni::fgInfosetURIName, XMLUni::fgNmTokenString);
00034 /*static*/ DOMTypeInfoImpl DOMTypeInfoImpl::g_DtdValidatedNMTOKENSAttribute(XMLUni::fgInfosetURIName, XMLUni::fgNmTokensString);
00035 /*static*/ DOMTypeInfoImpl DOMTypeInfoImpl::g_DtdValidatedNOTATIONAttribute(XMLUni::fgInfosetURIName, XMLUni::fgNotationString);
00036 /*static*/ DOMTypeInfoImpl DOMTypeInfoImpl::g_DtdValidatedENUMERATIONAttribute(XMLUni::fgInfosetURIName, XMLUni::fgEnumerationString);
00037 
00038 DOMTypeInfoImpl::DOMTypeInfoImpl(const XMLCh* namespaceUri/*=0*/, const XMLCh* name/*=0*/)
00039 : fBitFields(0),
00040   fTypeName(name),
00041   fTypeNamespace(namespaceUri),
00042   fMemberTypeName(0),
00043   fMemberTypeNamespace(0),
00044   fDefaultValue(0),
00045   fNormalizedValue(0)
00046 {
00047     // by setting the fBitField to 0 we are also setting:
00048     //  - [validity]=VALIDITY_NOTKNOWN
00049     //  - [validitation attempted]=VALIDATION_NONE
00050     //  - [schema specified]=false
00051 }
00052 
00053 DOMTypeInfoImpl::DOMTypeInfoImpl(DOMDocumentImpl* ownerDoc, const DOMPSVITypeInfo* sourcePSVI)
00054 : fBitFields(0),
00055   fTypeName(0),
00056   fTypeNamespace(0),
00057   fMemberTypeName(0),
00058   fMemberTypeNamespace(0),
00059   fDefaultValue(0),
00060   fNormalizedValue(0)
00061 {
00062     setNumericProperty(DOMPSVITypeInfo::PSVI_Validity,
00063         sourcePSVI->getNumericProperty(DOMPSVITypeInfo::PSVI_Validity));
00064     setNumericProperty(DOMPSVITypeInfo::PSVI_Validation_Attempted,
00065         sourcePSVI->getNumericProperty(DOMPSVITypeInfo::PSVI_Validation_Attempted));
00066     setNumericProperty(DOMPSVITypeInfo::PSVI_Type_Definition_Type,
00067         sourcePSVI->getNumericProperty(DOMPSVITypeInfo::PSVI_Type_Definition_Type));
00068     setNumericProperty(DOMPSVITypeInfo::PSVI_Type_Definition_Anonymous,
00069         sourcePSVI->getNumericProperty(DOMPSVITypeInfo::PSVI_Type_Definition_Anonymous));
00070     setNumericProperty(DOMPSVITypeInfo::PSVI_Nil,
00071         sourcePSVI->getNumericProperty(DOMPSVITypeInfo::PSVI_Nil));
00072     setNumericProperty(DOMPSVITypeInfo::PSVI_Member_Type_Definition_Anonymous,
00073         sourcePSVI->getNumericProperty(DOMPSVITypeInfo::PSVI_Member_Type_Definition_Anonymous));
00074     setNumericProperty(DOMPSVITypeInfo::PSVI_Schema_Specified,
00075         sourcePSVI->getNumericProperty(DOMPSVITypeInfo::PSVI_Schema_Specified));
00076 
00077     setStringProperty(DOMPSVITypeInfo::PSVI_Type_Definition_Name,
00078         ownerDoc->getPooledString(sourcePSVI->getStringProperty(DOMPSVITypeInfo::PSVI_Type_Definition_Name)));
00079     setStringProperty(DOMPSVITypeInfo::PSVI_Type_Definition_Namespace,
00080         ownerDoc->getPooledString(sourcePSVI->getStringProperty(DOMPSVITypeInfo::PSVI_Type_Definition_Namespace)));
00081     setStringProperty(DOMPSVITypeInfo::PSVI_Member_Type_Definition_Name,
00082         ownerDoc->getPooledString(sourcePSVI->getStringProperty(DOMPSVITypeInfo::PSVI_Member_Type_Definition_Name)));
00083     setStringProperty(DOMPSVITypeInfo::PSVI_Member_Type_Definition_Namespace,
00084         ownerDoc->getPooledString(sourcePSVI->getStringProperty(DOMPSVITypeInfo::PSVI_Member_Type_Definition_Namespace)));
00085     setStringProperty(DOMPSVITypeInfo::PSVI_Schema_Default,
00086         ownerDoc->getPooledString(sourcePSVI->getStringProperty(DOMPSVITypeInfo::PSVI_Schema_Default)));
00087     setStringProperty(DOMPSVITypeInfo::PSVI_Schema_Normalized_Value,
00088         ownerDoc->getPooledString(sourcePSVI->getStringProperty(DOMPSVITypeInfo::PSVI_Schema_Normalized_Value)));
00089 }
00090 
00091 const XMLCh* DOMTypeInfoImpl::getTypeName() const {
00092     // if it's a DTD, return the data that was stored
00093     if(!getNumericProperty(PSVI_Schema_Specified))
00094         return fTypeName;
00095     // if [validity] is "invalid" or "notKnown", the {target namespace} and {name} properties of the declared type if available, otherwise null.
00096     if(!getNumericProperty(PSVI_Validity))
00097         return fTypeName;
00098     if(fMemberTypeName)
00099         return fMemberTypeName;
00100     return fTypeName;
00101 }
00102 
00103 const XMLCh* DOMTypeInfoImpl::getTypeNamespace() const {
00104     // if it's a DTD, return the data that was stored
00105     if(!getNumericProperty(PSVI_Schema_Specified))
00106         return fTypeNamespace;
00107     // if [validity] is "invalid" or "notKnown", the {target namespace} and {name} properties of the declared type if available, otherwise null.
00108     if(!getNumericProperty(PSVI_Validity))
00109         return fTypeNamespace;
00110     if(fMemberTypeName)     // we check on the name, as the URI can be NULL
00111         return fMemberTypeNamespace;
00112     return fTypeNamespace;
00113 }
00114 
00115 bool DOMTypeInfoImpl::isDerivedFrom(const XMLCh* typeNamespaceArg, const XMLCh* typeNameArg, DerivationMethods) const
00116 {
00117     // if it's a DTD, return false
00118     if(!getNumericProperty(PSVI_Schema_Specified))
00119         return false;
00120     if(XMLString::equals(typeNamespaceArg, getTypeNamespace()) && XMLString::equals(typeNameArg, getTypeName()))
00121         return true;
00122     // TODO: need a pointer to the Grammar object
00123     return false;
00124 }
00125 
00126 const XMLCh* DOMTypeInfoImpl::getStringProperty(PSVIProperty prop) const {
00127     switch(prop)
00128     {
00129     case PSVI_Type_Definition_Name:             return fTypeName;
00130     case PSVI_Type_Definition_Namespace:        return fTypeNamespace;
00131     case PSVI_Member_Type_Definition_Name:      return fMemberTypeName;
00132     case PSVI_Member_Type_Definition_Namespace: return fMemberTypeNamespace;
00133     case PSVI_Schema_Default:                   return fDefaultValue;
00134     case PSVI_Schema_Normalized_Value:          return fNormalizedValue;
00135     default:                                    assert(false); /* it's not a string property */
00136     }
00137     return 0;
00138 }
00139 
00140 int DOMTypeInfoImpl::getNumericProperty(PSVIProperty prop) const {
00141     switch(prop)
00142     {
00143     case PSVI_Validity:                         return (PSVIItem::VALIDITY_STATE)(fBitFields & 0x0003);
00144     case PSVI_Validation_Attempted:             return (PSVIItem::ASSESSMENT_TYPE)((fBitFields >> 2) & 0x0003);
00145     case PSVI_Type_Definition_Type:             return (fBitFields & (1 << 5))?XSTypeDefinition::COMPLEX_TYPE:XSTypeDefinition::SIMPLE_TYPE;
00146     case PSVI_Type_Definition_Anonymous:        return (fBitFields & (1 << 6))?true:false;
00147     case PSVI_Nil:                              return (fBitFields & (1 << 7))?true:false;
00148     case PSVI_Member_Type_Definition_Anonymous: return (fBitFields & (1 << 8))?true:false;
00149     case PSVI_Schema_Specified:                 return (fBitFields & (1 << 9))?true:false;
00150     default:                                    assert(false); /* it's not a numeric property */
00151     }
00152     return 0;
00153 }
00154 
00155 void DOMTypeInfoImpl::setStringProperty(PSVIProperty prop, const XMLCh* value) {
00156     switch(prop)
00157     {
00158     case PSVI_Type_Definition_Name:             fTypeName=value; break;
00159     case PSVI_Type_Definition_Namespace:        fTypeNamespace=value; break;
00160     case PSVI_Member_Type_Definition_Name:      fMemberTypeName=value; break;
00161     case PSVI_Member_Type_Definition_Namespace: fMemberTypeNamespace=value; break;
00162     case PSVI_Schema_Default:                   fDefaultValue=value; break;
00163     case PSVI_Schema_Normalized_Value:          fNormalizedValue=value; break;
00164     default:                                    assert(false); /* it's not a string property */
00165     }
00166 }
00167 
00168 void DOMTypeInfoImpl::setNumericProperty(PSVIProperty prop, int value) {
00169     switch(prop)
00170     {
00171     case PSVI_Validity:                         fBitFields |= (value & 0x0003); break;
00172     case PSVI_Validation_Attempted:             fBitFields |= ((value & 0x0003) << 2); break;
00173     case PSVI_Type_Definition_Type:             fBitFields |= (value==XSTypeDefinition::COMPLEX_TYPE)?(1 << 5):0; break;
00174     case PSVI_Type_Definition_Anonymous:        fBitFields |= (value!=0)?(1 << 6):0; break;
00175     case PSVI_Nil:                              fBitFields |= (value!=0)?(1 << 7):0; break;
00176     case PSVI_Member_Type_Definition_Anonymous: fBitFields |= (value!=0)?(1 << 8):0; break;
00177     case PSVI_Schema_Specified:                 fBitFields |= (value!=0)?(1 << 9):0; break;
00178     default:                                    assert(false); /* it's not a numeric property */
00179     }
00180 }
00181 
00182 
00183 XERCES_CPP_NAMESPACE_END