GME
13
|
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 00023 // --------------------------------------------------------------------------- 00024 // Includes 00025 // --------------------------------------------------------------------------- 00026 #include <xercesc/framework/XMLElementDecl.hpp> 00027 #include <xercesc/util/XMLUniDefs.hpp> 00028 #include <xercesc/util/XMLUni.hpp> 00029 00030 #include <xercesc/validators/schema/SchemaElementDecl.hpp> 00031 #include <xercesc/validators/DTD/DTDElementDecl.hpp> 00032 00033 XERCES_CPP_NAMESPACE_BEGIN 00034 00035 // --------------------------------------------------------------------------- 00036 // XMLElementDecl: Public, static data 00037 // --------------------------------------------------------------------------- 00038 const unsigned int XMLElementDecl::fgInvalidElemId = 0xFFFFFFFE; 00039 const unsigned int XMLElementDecl::fgPCDataElemId = 0xFFFFFFFF; 00040 const XMLCh XMLElementDecl::fgPCDataElemName[] = 00041 { 00042 chPound, chLatin_P, chLatin_C, chLatin_D, chLatin_A 00043 , chLatin_T, chLatin_A, chNull 00044 }; 00045 00046 00047 00048 // --------------------------------------------------------------------------- 00049 // XMLElementDecl: Destructor 00050 // --------------------------------------------------------------------------- 00051 XMLElementDecl::~XMLElementDecl() 00052 { 00053 delete fElementName; 00054 } 00055 00056 // --------------------------------------------------------------------------- 00057 // XMLElementDecl: Setter Methods 00058 // --------------------------------------------------------------------------- 00059 void 00060 XMLElementDecl::setElementName(const XMLCh* const prefix 00061 , const XMLCh* const localPart 00062 , const int uriId ) 00063 { 00064 if (fElementName) 00065 fElementName->setName(prefix, localPart, uriId); 00066 else 00067 fElementName = new (fMemoryManager) QName(prefix, localPart, uriId, fMemoryManager); 00068 } 00069 00070 void 00071 XMLElementDecl::setElementName(const XMLCh* const rawName 00072 , const int uriId ) 00073 { 00074 if (fElementName) 00075 fElementName->setName(rawName, uriId); 00076 else 00077 fElementName = new (fMemoryManager) QName(rawName, uriId, fMemoryManager); 00078 } 00079 00080 void 00081 XMLElementDecl::setElementName(const QName* const elementName) 00082 { 00083 if (fElementName) 00084 fElementName->setValues(*elementName); 00085 else 00086 fElementName = new (fMemoryManager) QName(*elementName); 00087 } 00088 00089 // --------------------------------------------------------------------------- 00090 // ElementDecl: Hidden constructors 00091 // --------------------------------------------------------------------------- 00092 XMLElementDecl::XMLElementDecl(MemoryManager* const manager) : 00093 00094 fMemoryManager(manager) 00095 , fElementName(0) 00096 , fCreateReason(XMLElementDecl::NoReason) 00097 , fId(XMLElementDecl::fgInvalidElemId) 00098 , fExternalElement(false) 00099 { 00100 } 00101 00102 /*** 00103 * Support for Serialization/De-serialization 00104 ***/ 00105 00106 IMPL_XSERIALIZABLE_NOCREATE(XMLElementDecl) 00107 00108 void XMLElementDecl::serialize(XSerializeEngine& serEng) 00109 { 00110 00111 if (serEng.isStoring()) 00112 { 00113 serEng<<fElementName; 00114 serEng<<(int) fCreateReason; 00115 serEng.writeSize (fId); 00116 serEng<<fExternalElement; 00117 } 00118 else 00119 { 00120 serEng>>fElementName; 00121 00122 int i; 00123 serEng>>i; 00124 fCreateReason=(CreateReasons)i; 00125 00126 serEng.readSize (fId); 00127 serEng>>fExternalElement; 00128 } 00129 00130 } 00131 00132 void 00133 XMLElementDecl::storeElementDecl(XSerializeEngine& serEng 00134 , XMLElementDecl* const element) 00135 { 00136 if (element) 00137 { 00138 serEng<<(int) element->getObjectType(); 00139 serEng<<element; 00140 } 00141 else 00142 { 00143 serEng<<(int) UnKnown; 00144 } 00145 } 00146 00147 XMLElementDecl* 00148 XMLElementDecl::loadElementDecl(XSerializeEngine& serEng) 00149 { 00150 int type; 00151 serEng>>type; 00152 00153 switch((XMLElementDecl::objectType)type) 00154 { 00155 case Schema: 00156 SchemaElementDecl* schemaElementDecl; 00157 serEng>>schemaElementDecl; 00158 return schemaElementDecl; 00159 case DTD: 00160 DTDElementDecl* dtdElementDecl; 00161 serEng>>dtdElementDecl; 00162 return dtdElementDecl; 00163 case UnKnown: 00164 //fall through 00165 default: 00166 return 0; 00167 } 00168 } 00169 00170 XERCES_CPP_NAMESPACE_END