GME  13
XProtoType.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: XProtoType.cpp 834826 2009-11-11 10:03:53Z borisk $
00020  */
00021 
00022 // ---------------------------------------------------------------------------
00023 //  Includes
00024 // ---------------------------------------------------------------------------
00025 #include <xercesc/internal/XProtoType.hpp>
00026 #include <xercesc/internal/XSerializeEngine.hpp>
00027 #include <xercesc/util/XMLString.hpp>
00028 
00029 XERCES_CPP_NAMESPACE_BEGIN
00030 
00031 /***
00032  *
00033  *  write the length of the class name
00034  *  write the class name
00035  *
00036  ***/
00037 void XProtoType::store(XSerializeEngine& serEng) const
00038 {
00039     XMLSize_t strLen = XMLString::stringLen((char*)fClassName);
00040         serEng << (unsigned long)strLen;
00041         serEng.write(fClassName, strLen * sizeof(XMLByte));
00042 }
00043 
00044 /***
00045  *
00046  *  To verify that the content in the binary stream
00047  *  is the same as this class
00048  *
00049  ***/
00050 void XProtoType::load(XSerializeEngine& serEng
00051                     , XMLByte* const    inName
00052                     , MemoryManager* const manager)
00053 {
00054     if (!inName)
00055     {       
00056         ThrowXMLwithMemMgr(XSerializationException
00057                , XMLExcepts::XSer_ProtoType_Null_ClassName, manager);
00058     }
00059 
00060     // read and check class name length
00061     XMLSize_t inNameLen = XMLString::stringLen((char*)inName); 
00062     XMLSize_t classNameLen = 0;
00063     serEng >> (unsigned long&)classNameLen;
00064 
00065         if (classNameLen != inNameLen)
00066     {
00067         XMLCh value1[17];
00068         XMLCh value2[17];
00069         XMLString::sizeToText(inNameLen,    value1, 16, 10, manager);
00070         XMLString::sizeToText(classNameLen, value2, 16, 10, manager);
00071 
00072         ThrowXMLwithMemMgr2(XSerializationException
00073                 , XMLExcepts::XSer_ProtoType_NameLen_Dif
00074                 , value1
00075                 , value2
00076                 , manager);  
00077     }
00078 
00079     // read and check class name
00080         XMLByte  className[256];
00081     serEng.read(className, classNameLen*sizeof(XMLByte));
00082     className[classNameLen] = '\0';
00083 
00084     if ( !XMLString::equals((char*)className, (char*)inName))
00085     {
00086         //we don't have class name exceed this length in xerces
00087         XMLCh name1[256];
00088         XMLCh name2[256];
00089         XMLCh *tmp = XMLString::transcode((char*)inName, manager);
00090         XMLString::copyNString(name1, tmp, 255);
00091         manager->deallocate(tmp);
00092         tmp = XMLString::transcode((char*)className, manager);
00093         XMLString::copyNString(name2, tmp, 255);
00094         manager->deallocate(tmp);
00095 
00096         ThrowXMLwithMemMgr2(XSerializationException
00097                 , XMLExcepts::XSer_ProtoType_Name_Dif
00098                 , name1
00099                 , name2
00100                 , manager);
00101     }
00102 
00103     return;
00104 
00105 }
00106 
00107 XERCES_CPP_NAMESPACE_END
00108