Coverage Report

Created: 2025-06-13 07:02

/src/xerces-c/src/xercesc/framework/XMLElementDecl.cpp
Line
Count
Source (jump to first uncovered 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: XMLElementDecl.cpp 679359 2008-07-24 11:15:19Z borisk $
20
 */
21
22
23
// ---------------------------------------------------------------------------
24
//  Includes
25
// ---------------------------------------------------------------------------
26
#include <xercesc/framework/XMLElementDecl.hpp>
27
#include <xercesc/util/XMLUniDefs.hpp>
28
#include <xercesc/util/XMLUni.hpp>
29
30
#include <xercesc/validators/schema/SchemaElementDecl.hpp>
31
#include <xercesc/validators/DTD/DTDElementDecl.hpp>
32
33
XERCES_CPP_NAMESPACE_BEGIN
34
35
// ---------------------------------------------------------------------------
36
//  XMLElementDecl: Public, static data
37
// ---------------------------------------------------------------------------
38
const unsigned int  XMLElementDecl::fgInvalidElemId    = 0xFFFFFFFE;
39
const unsigned int  XMLElementDecl::fgPCDataElemId     = 0xFFFFFFFF;
40
const XMLCh         XMLElementDecl::fgPCDataElemName[] =
41
{
42
        chPound, chLatin_P, chLatin_C, chLatin_D, chLatin_A
43
    ,   chLatin_T, chLatin_A, chNull
44
};
45
46
47
48
// ---------------------------------------------------------------------------
49
//  XMLElementDecl: Destructor
50
// ---------------------------------------------------------------------------
51
XMLElementDecl::~XMLElementDecl()
52
84.8k
{
53
84.8k
    delete fElementName;
54
84.8k
}
55
56
// ---------------------------------------------------------------------------
57
//  XMLElementDecl: Setter Methods
58
// ---------------------------------------------------------------------------
59
void
60
XMLElementDecl::setElementName(const XMLCh* const       prefix
61
                            , const XMLCh* const        localPart
62
                            , const int                 uriId )
63
0
{
64
0
    if (fElementName)
65
0
        fElementName->setName(prefix, localPart, uriId);
66
0
    else
67
0
        fElementName = new (fMemoryManager) QName(prefix, localPart, uriId, fMemoryManager);
68
0
}
69
70
void
71
XMLElementDecl::setElementName(const XMLCh* const       rawName
72
                            , const int                 uriId )
73
89.7k
{
74
89.7k
    if (fElementName)
75
4.95k
        fElementName->setName(rawName, uriId);
76
84.8k
    else
77
84.8k
        fElementName = new (fMemoryManager) QName(rawName, uriId, fMemoryManager);
78
89.7k
}
79
80
void
81
XMLElementDecl::setElementName(const QName* const    elementName)
82
0
{
83
0
    if (fElementName)
84
0
        fElementName->setValues(*elementName);
85
0
    else
86
0
        fElementName = new (fMemoryManager) QName(*elementName);
87
0
}
88
89
// ---------------------------------------------------------------------------
90
//  ElementDecl: Hidden constructors
91
// ---------------------------------------------------------------------------
92
XMLElementDecl::XMLElementDecl(MemoryManager* const manager) :
93
94
84.8k
    fMemoryManager(manager)
95
84.8k
    , fElementName(0)
96
84.8k
    , fCreateReason(XMLElementDecl::NoReason)
97
84.8k
    , fId(XMLElementDecl::fgInvalidElemId)
98
84.8k
    , fExternalElement(false)
99
84.8k
{
100
84.8k
}
101
102
/***
103
 * Support for Serialization/De-serialization
104
 ***/
105
106
IMPL_XSERIALIZABLE_NOCREATE(XMLElementDecl)
107
108
void XMLElementDecl::serialize(XSerializeEngine& serEng)
109
0
{
110
111
0
    if (serEng.isStoring())
112
0
    {
113
0
        serEng<<fElementName;
114
0
        serEng<<(int) fCreateReason;
115
0
        serEng.writeSize (fId);
116
0
        serEng<<fExternalElement;
117
0
    }
118
0
    else
119
0
    {
120
0
        serEng>>fElementName;
121
122
0
        int i;
123
0
        serEng>>i;
124
0
        fCreateReason=(CreateReasons)i;
125
126
0
        serEng.readSize (fId);
127
0
        serEng>>fExternalElement;
128
0
    }
129
130
0
}
131
132
void
133
XMLElementDecl::storeElementDecl(XSerializeEngine&        serEng
134
                               , XMLElementDecl*    const element)
135
0
{
136
0
    if (element)
137
0
    {
138
0
        serEng<<(int) element->getObjectType();
139
0
        serEng<<element;
140
0
    }
141
0
    else
142
0
    {
143
0
        serEng<<(int) UnKnown;
144
0
    }
145
0
}
146
147
XMLElementDecl*
148
XMLElementDecl::loadElementDecl(XSerializeEngine& serEng)
149
0
{
150
0
    int type;
151
0
    serEng>>type;
152
153
0
    switch((XMLElementDecl::objectType)type)
154
0
    {
155
0
    case Schema:
156
0
        SchemaElementDecl* schemaElementDecl;
157
0
        serEng>>schemaElementDecl;
158
0
        return schemaElementDecl;
159
0
    case DTD:
160
0
        DTDElementDecl* dtdElementDecl;
161
0
        serEng>>dtdElementDecl;
162
0
        return dtdElementDecl;
163
0
    case UnKnown:
164
         //fall through
165
0
    default:
166
0
        return 0;
167
0
    }
168
0
}
169
170
XERCES_CPP_NAMESPACE_END