[2674] | 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.hpp 568078 2007-08-21 11:43:25Z amassari $ |
---|
| 20 | */ |
---|
| 21 | |
---|
| 22 | |
---|
| 23 | #if !defined(SCHEMAATTDEFLIST_HPP) |
---|
| 24 | #define SCHEMAATTDEFLIST_HPP |
---|
| 25 | |
---|
| 26 | #include <xercesc/util/RefHash2KeysTableOf.hpp> |
---|
| 27 | #include <xercesc/validators/schema/SchemaElementDecl.hpp> |
---|
| 28 | |
---|
| 29 | XERCES_CPP_NAMESPACE_BEGIN |
---|
| 30 | |
---|
| 31 | // |
---|
| 32 | // This is a derivative of the framework abstract class which defines the |
---|
| 33 | // interface to a list of attribute defs that belong to a particular |
---|
| 34 | // element. The scanner needs to be able to get a list of the attributes |
---|
| 35 | // that an element supports, for use during the validation process and for |
---|
| 36 | // fixed/default attribute processing. |
---|
| 37 | // |
---|
| 38 | // For us, we just wrap the RefHash2KeysTableOf collection that the SchemaElementDecl |
---|
| 39 | // class uses to store the attributes that belong to it. |
---|
| 40 | // |
---|
| 41 | // This class does not adopt the hash table, it just references it. The |
---|
| 42 | // hash table is owned by the element decl it is a member of. |
---|
| 43 | // |
---|
| 44 | class VALIDATORS_EXPORT SchemaAttDefList : public XMLAttDefList |
---|
| 45 | { |
---|
| 46 | public : |
---|
| 47 | // ----------------------------------------------------------------------- |
---|
| 48 | // Constructors and Destructor |
---|
| 49 | // ----------------------------------------------------------------------- |
---|
| 50 | SchemaAttDefList |
---|
| 51 | ( |
---|
| 52 | RefHash2KeysTableOf<SchemaAttDef>* const listToUse, |
---|
| 53 | MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager |
---|
| 54 | ); |
---|
| 55 | |
---|
| 56 | ~SchemaAttDefList(); |
---|
| 57 | |
---|
| 58 | |
---|
| 59 | // ----------------------------------------------------------------------- |
---|
| 60 | // Implementation of the virtual interface |
---|
| 61 | // ----------------------------------------------------------------------- |
---|
| 62 | |
---|
| 63 | /** |
---|
| 64 | * @deprecated This method is not thread-safe. |
---|
| 65 | */ |
---|
| 66 | virtual bool hasMoreElements() const; |
---|
| 67 | |
---|
| 68 | virtual bool isEmpty() const; |
---|
| 69 | virtual XMLAttDef* findAttDef |
---|
| 70 | ( |
---|
| 71 | const unsigned long uriID |
---|
| 72 | , const XMLCh* const attName |
---|
| 73 | ); |
---|
| 74 | virtual const XMLAttDef* findAttDef |
---|
| 75 | ( |
---|
| 76 | const unsigned long uriID |
---|
| 77 | , const XMLCh* const attName |
---|
| 78 | ) const; |
---|
| 79 | virtual XMLAttDef* findAttDef |
---|
| 80 | ( |
---|
| 81 | const XMLCh* const attURI |
---|
| 82 | , const XMLCh* const attName |
---|
| 83 | ); |
---|
| 84 | virtual const XMLAttDef* findAttDef |
---|
| 85 | ( |
---|
| 86 | const XMLCh* const attURI |
---|
| 87 | , const XMLCh* const attName |
---|
| 88 | ) const; |
---|
| 89 | |
---|
| 90 | XMLAttDef* findAttDefLocalPart |
---|
| 91 | ( |
---|
| 92 | const unsigned long uriID |
---|
| 93 | , const XMLCh* const attLocalPart |
---|
| 94 | ); |
---|
| 95 | |
---|
| 96 | const XMLAttDef* findAttDefLocalPart |
---|
| 97 | ( |
---|
| 98 | const unsigned long uriID |
---|
| 99 | , const XMLCh* const attLocalPart |
---|
| 100 | ) const; |
---|
| 101 | |
---|
| 102 | /** |
---|
| 103 | * @deprecated This method is not thread-safe. |
---|
| 104 | */ |
---|
| 105 | virtual XMLAttDef& nextElement(); |
---|
| 106 | |
---|
| 107 | /** |
---|
| 108 | * @deprecated This method is not thread-safe. |
---|
| 109 | */ |
---|
| 110 | virtual void Reset(); |
---|
| 111 | |
---|
| 112 | /** |
---|
| 113 | * return total number of attributes in this list |
---|
| 114 | */ |
---|
| 115 | virtual unsigned int getAttDefCount() const ; |
---|
| 116 | |
---|
| 117 | /** |
---|
| 118 | * return attribute at the index-th position in the list. |
---|
| 119 | */ |
---|
| 120 | virtual XMLAttDef &getAttDef(unsigned int index) ; |
---|
| 121 | |
---|
| 122 | /** |
---|
| 123 | * return attribute at the index-th position in the list. |
---|
| 124 | */ |
---|
| 125 | virtual const XMLAttDef &getAttDef(unsigned int index) const ; |
---|
| 126 | |
---|
| 127 | /*** |
---|
| 128 | * Support for Serialization/De-serialization |
---|
| 129 | ***/ |
---|
| 130 | DECL_XSERIALIZABLE(SchemaAttDefList) |
---|
| 131 | |
---|
| 132 | SchemaAttDefList(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager); |
---|
| 133 | |
---|
| 134 | private : |
---|
| 135 | // ----------------------------------------------------------------------- |
---|
| 136 | // Unimplemented constructors and operators |
---|
| 137 | // ----------------------------------------------------------------------- |
---|
| 138 | SchemaAttDefList(const SchemaAttDefList&); |
---|
| 139 | SchemaAttDefList& operator=(const SchemaAttDefList&); |
---|
| 140 | |
---|
| 141 | void addAttDef(SchemaAttDef *toAdd); |
---|
| 142 | |
---|
| 143 | // ----------------------------------------------------------------------- |
---|
| 144 | // Private data members |
---|
| 145 | // |
---|
| 146 | // fEnum |
---|
| 147 | // This is an enumerator for the list that we use to do the enumerator |
---|
| 148 | // type methods of this class. |
---|
| 149 | // |
---|
| 150 | // fList |
---|
| 151 | // The list of SchemaAttDef objects that represent the attributes that |
---|
| 152 | // a particular element supports. |
---|
| 153 | // fArray |
---|
| 154 | // vector of pointers to the DTDAttDef objects contained in this list |
---|
| 155 | // fSize |
---|
| 156 | // size of fArray |
---|
| 157 | // fCount |
---|
| 158 | // number of DTDAttDef objects currently stored in this list |
---|
| 159 | // ----------------------------------------------------------------------- |
---|
| 160 | RefHash2KeysTableOfEnumerator<SchemaAttDef>* fEnum; |
---|
| 161 | RefHash2KeysTableOf<SchemaAttDef>* fList; |
---|
| 162 | SchemaAttDef** fArray; |
---|
| 163 | unsigned int fSize; |
---|
| 164 | unsigned int fCount; |
---|
| 165 | |
---|
| 166 | friend class ComplexTypeInfo; |
---|
| 167 | }; |
---|
| 168 | |
---|
| 169 | inline void SchemaAttDefList::addAttDef(SchemaAttDef *toAdd) |
---|
| 170 | { |
---|
| 171 | if(fCount == fSize) |
---|
| 172 | { |
---|
| 173 | // need to grow fArray |
---|
| 174 | fSize <<= 1; |
---|
| 175 | SchemaAttDef** newArray = (SchemaAttDef **)((getMemoryManager())->allocate( sizeof(SchemaAttDef*) * fSize )); |
---|
| 176 | memcpy(newArray, fArray, fCount * sizeof(SchemaAttDef *)); |
---|
| 177 | (getMemoryManager())->deallocate(fArray); |
---|
| 178 | fArray = newArray; |
---|
| 179 | } |
---|
| 180 | fArray[fCount++] = toAdd; |
---|
| 181 | } |
---|
| 182 | |
---|
| 183 | inline XMLAttDef* SchemaAttDefList::findAttDefLocalPart(const unsigned long uriID |
---|
| 184 | , const XMLCh* const attLocalPart) |
---|
| 185 | { |
---|
| 186 | return fList->get((void*)attLocalPart, uriID); |
---|
| 187 | } |
---|
| 188 | |
---|
| 189 | inline const XMLAttDef* SchemaAttDefList::findAttDefLocalPart(const unsigned long uriID |
---|
| 190 | , const XMLCh* const attLocalPart) const |
---|
| 191 | { |
---|
| 192 | return fList->get((void*)attLocalPart, uriID); |
---|
| 193 | } |
---|
| 194 | |
---|
| 195 | XERCES_CPP_NAMESPACE_END |
---|
| 196 | |
---|
| 197 | #endif |
---|