source: icXML/icXML-devel/src/xercesc/internal/XProtoType.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: 3.3 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: XProtoType.cpp 834826 2009-11-11 10:03:53Z borisk $
20 */
21
22// ---------------------------------------------------------------------------
23//  Includes
24// ---------------------------------------------------------------------------
25#include <xercesc/internal/XProtoType.hpp>
26#include <xercesc/internal/XSerializeEngine.hpp>
27#include <icxercesc/util/XMLString.hpp>
28
29XERCES_CPP_NAMESPACE_BEGIN
30
31/***
32 *
33 *  write the length of the class name
34 *  write the class name
35 *
36 ***/
37void XProtoType::store(XSerializeEngine& serEng) const
38{
39    XMLSize_t strLen = XMLString::stringLen((char*)fClassName);
40        serEng << (unsigned long)strLen;
41        serEng.write(fClassName, strLen * sizeof(XMLByte));
42}
43
44/***
45 *
46 *  To verify that the content in the binary stream
47 *  is the same as this class
48 *
49 ***/
50void XProtoType::load(XSerializeEngine& serEng
51                    , XMLByte* const    inName
52                    , MemoryManager* const manager)
53{
54    if (!inName)
55    {       
56        ThrowXMLwithMemMgr(XSerializationException
57               , XMLExcepts::XSer_ProtoType_Null_ClassName, manager);
58    }
59
60    // read and check class name length
61    XMLSize_t inNameLen = XMLString::stringLen((char*)inName); 
62    XMLSize_t classNameLen = 0;
63    serEng >> (unsigned long&)classNameLen;
64
65        if (classNameLen != inNameLen)
66    {
67        XMLCh value1[17];
68        XMLCh value2[17];
69        XMLString::sizeToText(inNameLen,    value1, 16, 10, manager);
70        XMLString::sizeToText(classNameLen, value2, 16, 10, manager);
71
72        ThrowXMLwithMemMgr2(XSerializationException
73                , XMLExcepts::XSer_ProtoType_NameLen_Dif
74                , value1
75                , value2
76                , manager); 
77    }
78
79    // read and check class name
80        XMLByte  className[256];
81    serEng.read(className, classNameLen*sizeof(XMLByte));
82    className[classNameLen] = '\0';
83
84    if ( !XMLString::equals((char*)className, (char*)inName))
85    {
86        //we don't have class name exceed this length in xerces
87        XMLCh name1[256];
88        XMLCh name2[256];
89        XMLCh *tmp = XMLString::transcode((char*)inName, manager);
90        XMLString::copyNString(name1, tmp, 255);
91        manager->deallocate(tmp);
92        tmp = XMLString::transcode((char*)className, manager);
93        XMLString::copyNString(name2, tmp, 255);
94        manager->deallocate(tmp);
95
96        ThrowXMLwithMemMgr2(XSerializationException
97                , XMLExcepts::XSer_ProtoType_Name_Dif
98                , name1
99                , name2
100                , manager);
101    }
102
103    return;
104
105}
106
107XERCES_CPP_NAMESPACE_END
108
Note: See TracBrowser for help on using the repository browser.