source: icXML/icXML-devel/src/xercesc/validators/schema/SchemaAttDefList.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: 5.8 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: SchemaAttDefList.cpp 679359 2008-07-24 11:15:19Z borisk $
20 */
21
22
23// ---------------------------------------------------------------------------
24//  Includes
25// ---------------------------------------------------------------------------
26#include <xercesc/validators/schema/SchemaAttDefList.hpp>
27
28#include <xercesc/internal/XTemplateSerializer.hpp>
29#include <xercesc/util/ArrayIndexOutOfBoundsException.hpp>
30
31XERCES_CPP_NAMESPACE_BEGIN
32
33// ---------------------------------------------------------------------------
34//  SchemaAttDefList: Constructors and Destructor
35// ---------------------------------------------------------------------------
36SchemaAttDefList::SchemaAttDefList(RefHash2KeysTableOf<SchemaAttDef>* const listToUse, MemoryManager* const manager)
37: XMLAttDefList(manager)
38,fEnum(0)
39,fList(listToUse)
40,fArray(0)
41,fSize(0)
42,fCount(0)
43{
44    fEnum = new (getMemoryManager()) RefHash2KeysTableOfEnumerator<SchemaAttDef>(listToUse, false, getMemoryManager());
45    fArray = (SchemaAttDef **)((getMemoryManager())->allocate( sizeof(SchemaAttDef*) << 1));
46    fSize = 2;
47}
48
49SchemaAttDefList::~SchemaAttDefList()
50{
51    delete fEnum;
52    (getMemoryManager())->deallocate(fArray);
53}
54
55
56// ---------------------------------------------------------------------------
57//  SchemaAttDefList: Implementation of the virtual interface
58// ---------------------------------------------------------------------------
59
60bool SchemaAttDefList::isEmpty() const
61{
62    return fList->isEmpty();
63}
64
65
66XMLAttDef* SchemaAttDefList::findAttDef(const  unsigned int uriID
67                                    , const XMLCh* const    attName)
68{
69   const int colonInd = XMLString::indexOf(attName, chColon);
70
71   // An index of 0 is really an error, but the QName class doesn't check for
72   // that case either...
73   const XMLCh* const localPart = colonInd >= 0 ? attName + colonInd + 1 : attName;
74
75   return fList->get((void*)localPart, uriID);
76}
77
78
79const XMLAttDef*
80SchemaAttDefList::findAttDef( const   unsigned int   uriID
81                            , const XMLCh* const    attName) const
82{
83   const int colonInd = XMLString::indexOf(attName, chColon);
84
85   // An index of 0 is really an error, but the QName class doesn't check for
86   // that case either...
87   const XMLCh* const localPart = colonInd >= 0 ? attName + colonInd + 1 : attName;
88
89   return fList->get((void*)localPart, uriID);
90}
91
92
93XMLAttDef* SchemaAttDefList::findAttDef(   const   XMLCh* const
94                                        , const XMLCh* const)
95{
96   //need numeric URI id to locate the attribute, that's how it was stored
97   ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::Pool_InvalidId, getMemoryManager());
98   return 0;
99}
100
101
102const XMLAttDef*
103SchemaAttDefList::findAttDef( const   XMLCh* const
104                            , const XMLCh* const) const
105{
106   //need numeric URI id to locate the attribute, that's how it was stored
107   ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::Pool_InvalidId, getMemoryManager());
108   return 0;
109}
110
111/**
112 * return total number of attributes in this list
113 */
114XMLSize_t SchemaAttDefList::getAttDefCount() const
115{
116    return fCount;
117}
118
119/**
120 * return attribute at the index-th position in the list.
121 */
122XMLAttDef &SchemaAttDefList::getAttDef(XMLSize_t index)
123{
124    if(index >= fCount)
125        ThrowXMLwithMemMgr(ArrayIndexOutOfBoundsException, XMLExcepts::AttrList_BadIndex, getMemoryManager());
126    return *(fArray[index]);
127}
128
129/**
130 * return attribute at the index-th position in the list.
131 */
132const XMLAttDef &SchemaAttDefList::getAttDef(XMLSize_t index) const
133{
134    if(index >= fCount)
135        ThrowXMLwithMemMgr(ArrayIndexOutOfBoundsException, XMLExcepts::AttrList_BadIndex, getMemoryManager());
136    return *(fArray[index]);
137}
138
139/***
140 * Support for Serialization/De-serialization
141 ***/
142
143IMPL_XSERIALIZABLE_TOCREATE(SchemaAttDefList)
144
145void SchemaAttDefList::serialize(XSerializeEngine& serEng)
146{
147
148    XMLAttDefList::serialize(serEng);
149
150    if (serEng.isStoring())
151    {
152        /***
153         *
154         * Serialize RefHash2KeysTableOf<SchemaAttDef>
155         *
156         ***/
157        XTemplateSerializer::storeObject(fList, serEng);
158        serEng.writeSize (fCount);
159
160        // do not serialize fEnum
161    }
162    else
163    {
164        /***
165         *
166         * Deserialize RefHash2KeysTableOf<SchemaAttDef>
167         *
168         ***/
169        XTemplateSerializer::loadObject(&fList, 29, true, serEng);
170
171        // assume empty so we can size fArray just right
172        serEng.readSize (fSize);
173        if (!fEnum && fList)
174        {
175            fEnum = new (getMemoryManager()) RefHash2KeysTableOfEnumerator<SchemaAttDef>(fList, false, getMemoryManager());
176        }
177        if(fSize)
178        {
179            (getMemoryManager())->deallocate(fArray);
180            fArray = (SchemaAttDef **)((getMemoryManager())->allocate( sizeof(SchemaAttDef*) * fSize));
181            fCount = 0;
182            while(fEnum->hasMoreElements())
183            {
184                fArray[fCount++] = &fEnum->nextElement();
185            }
186        }
187    }
188
189}
190
191SchemaAttDefList::SchemaAttDefList(MemoryManager* const manager)
192: XMLAttDefList(manager)
193,fEnum(0)
194,fList(0)
195,fArray(0)
196,fSize(0)
197,fCount(0)
198{
199}
200
201XERCES_CPP_NAMESPACE_END
Note: See TracBrowser for help on using the repository browser.