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$
20  */
21 
22 #include <xercesc/framework/psvi/XSAttributeDeclaration.hpp>
23 #include <xercesc/framework/psvi/XSModel.hpp>
24 #include <xercesc/framework/psvi/XSNamespaceItem.hpp>
25 #include <xercesc/framework/psvi/XSAnnotation.hpp>
26 #include <xercesc/util/StringPool.hpp>
27 #include <xercesc/validators/schema/SchemaGrammar.hpp>
28 #include <xercesc/validators/schema/SchemaAttDef.hpp>
29 
30 XERCES_CPP_NAMESPACE_BEGIN
31 
32 // ---------------------------------------------------------------------------
33 //  XSAttributeDeclaration: Constructors and Destructor
34 // ---------------------------------------------------------------------------
XSAttributeDeclaration(SchemaAttDef * const attDef,XSSimpleTypeDefinition * const typeDef,XSAnnotation * const annot,XSModel * const xsModel,XSConstants::SCOPE scope,XSComplexTypeDefinition * enclosingCTDefinition,MemoryManager * const manager)35 XSAttributeDeclaration::XSAttributeDeclaration(SchemaAttDef* const           attDef,
36                                                XSSimpleTypeDefinition* const typeDef,
37                                                XSAnnotation* const           annot,
38                                                XSModel* const                xsModel,
39                                                XSConstants::SCOPE            scope,
40                                                XSComplexTypeDefinition*      enclosingCTDefinition,
41                                                MemoryManager * const         manager)
42     : XSObject(XSConstants::ATTRIBUTE_DECLARATION, xsModel, manager)
43     , fAttDef(attDef)
44     , fTypeDefinition(typeDef)
45     , fAnnotation(annot)
46     , fScope(scope)
47     , fEnclosingCTDefinition(enclosingCTDefinition)
48 {
49 }
50 
~XSAttributeDeclaration()51 XSAttributeDeclaration::~XSAttributeDeclaration()
52 {
53     // don't delete fTypeDefinition - deleted by XSModel
54 }
55 
56 // ---------------------------------------------------------------------------
57 //  XSAttributeDeclaration: XSObject virtual methods
58 // ---------------------------------------------------------------------------
getName() const59 const XMLCh *XSAttributeDeclaration::getName() const
60 {
61     return fAttDef->getAttName()->getLocalPart();
62 }
63 
getNamespace() const64 const XMLCh *XSAttributeDeclaration::getNamespace() const
65 {
66     return fXSModel->getURIStringPool()->getValueForId(fAttDef->getAttName()->getURI());
67 }
68 
getNamespaceItem()69 XSNamespaceItem *XSAttributeDeclaration::getNamespaceItem()
70 {
71     return fXSModel->getNamespaceItem(getNamespace());
72 }
73 
74 // ---------------------------------------------------------------------------
75 //  XSAttributeDeclaration: access methods
76 // ---------------------------------------------------------------------------
77 
getConstraintType() const78 XSConstants::VALUE_CONSTRAINT XSAttributeDeclaration::getConstraintType() const
79 {
80     if (fScope != XSConstants::SCOPE_GLOBAL)
81         return XSConstants::VALUE_CONSTRAINT_NONE;
82 
83     if (fAttDef->getDefaultType() == XMLAttDef::Default)
84         return XSConstants::VALUE_CONSTRAINT_DEFAULT;
85 
86     if ((fAttDef->getDefaultType() == XMLAttDef::Fixed) ||
87         (fAttDef->getDefaultType() == XMLAttDef::Required_And_Fixed))
88         return XSConstants::VALUE_CONSTRAINT_FIXED;
89 
90     return XSConstants::VALUE_CONSTRAINT_NONE;
91 }
92 
getConstraintValue()93 const XMLCh *XSAttributeDeclaration::getConstraintValue()
94 {
95     if (fScope == XSConstants::SCOPE_GLOBAL)
96         return fAttDef->getValue();
97 
98     return 0;
99 }
100 
getRequired() const101 bool XSAttributeDeclaration::getRequired() const
102 {
103     if (fAttDef->getDefaultType() == XMLAttDef::Required ||
104         fAttDef->getDefaultType() == XMLAttDef::Required_And_Fixed)
105         return true;
106 
107     return false;
108 }
109 
110 XERCES_CPP_NAMESPACE_END
111 
112 
113