GME  13
XSAttributeDeclaration.cpp
Go to the documentation of this file.
00001 /*
00002  * Licensed to the Apache Software Foundation (ASF) under one or more
00003  * contributor license agreements.  See the NOTICE file distributed with
00004  * this work for additional information regarding copyright ownership.
00005  * The ASF licenses this file to You under the Apache License, Version 2.0
00006  * (the "License"); you may not use this file except in compliance with
00007  * the License.  You may obtain a copy of the License at
00008  * 
00009  *      http://www.apache.org/licenses/LICENSE-2.0
00010  * 
00011  * Unless required by applicable law or agreed to in writing, software
00012  * distributed under the License is distributed on an "AS IS" BASIS,
00013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  * See the License for the specific language governing permissions and
00015  * limitations under the License.
00016  */
00017 
00018 /*
00019  * $Id: XSAttributeDeclaration.cpp 471747 2006-11-06 14:31:56Z amassari $
00020  */
00021 
00022 #include <xercesc/framework/psvi/XSAttributeDeclaration.hpp>
00023 #include <xercesc/framework/psvi/XSModel.hpp>
00024 #include <xercesc/framework/psvi/XSNamespaceItem.hpp>
00025 #include <xercesc/framework/psvi/XSAnnotation.hpp>
00026 #include <xercesc/util/StringPool.hpp>
00027 #include <xercesc/validators/schema/SchemaGrammar.hpp>
00028 #include <xercesc/validators/schema/SchemaAttDef.hpp>
00029 
00030 XERCES_CPP_NAMESPACE_BEGIN
00031 
00032 // ---------------------------------------------------------------------------
00033 //  XSAttributeDeclaration: Constructors and Destructor
00034 // ---------------------------------------------------------------------------
00035 XSAttributeDeclaration::XSAttributeDeclaration(SchemaAttDef* const           attDef,
00036                                                XSSimpleTypeDefinition* const typeDef,
00037                                                XSAnnotation* const           annot,
00038                                                XSModel* const                xsModel,
00039                                                XSConstants::SCOPE            scope,
00040                                                XSComplexTypeDefinition*      enclosingCTDefinition,
00041                                                MemoryManager * const         manager)
00042     : XSObject(XSConstants::ATTRIBUTE_DECLARATION, xsModel, manager)
00043     , fAttDef(attDef)
00044     , fTypeDefinition(typeDef)
00045     , fAnnotation(annot) 
00046     , fScope(scope)
00047     , fEnclosingCTDefinition(enclosingCTDefinition)        
00048 {
00049 }
00050 
00051 XSAttributeDeclaration::~XSAttributeDeclaration() 
00052 {
00053     // don't delete fTypeDefinition - deleted by XSModel
00054 }
00055 
00056 // ---------------------------------------------------------------------------
00057 //  XSAttributeDeclaration: XSObject virtual methods
00058 // ---------------------------------------------------------------------------
00059 const XMLCh *XSAttributeDeclaration::getName() const
00060 {
00061     return fAttDef->getAttName()->getLocalPart();
00062 }
00063 
00064 const XMLCh *XSAttributeDeclaration::getNamespace() 
00065 {
00066     return fXSModel->getURIStringPool()->getValueForId(fAttDef->getAttName()->getURI());
00067 }
00068 
00069 XSNamespaceItem *XSAttributeDeclaration::getNamespaceItem() 
00070 {
00071     return fXSModel->getNamespaceItem(getNamespace());
00072 }
00073 
00074 // ---------------------------------------------------------------------------
00075 //  XSAttributeDeclaration: access methods
00076 // ---------------------------------------------------------------------------
00077 
00078 XSConstants::VALUE_CONSTRAINT XSAttributeDeclaration::getConstraintType() const
00079 {
00080     if (fScope != XSConstants::SCOPE_GLOBAL)
00081         return XSConstants::VALUE_CONSTRAINT_NONE;
00082 
00083     if (fAttDef->getDefaultType() == XMLAttDef::Default)
00084         return XSConstants::VALUE_CONSTRAINT_DEFAULT;
00085 
00086     if ((fAttDef->getDefaultType() == XMLAttDef::Fixed) ||
00087         (fAttDef->getDefaultType() == XMLAttDef::Required_And_Fixed))
00088         return XSConstants::VALUE_CONSTRAINT_FIXED;
00089 
00090     return XSConstants::VALUE_CONSTRAINT_NONE;
00091 }
00092 
00093 const XMLCh *XSAttributeDeclaration::getConstraintValue()
00094 {
00095     if (fScope == XSConstants::SCOPE_GLOBAL)
00096         return fAttDef->getValue();
00097 
00098     return 0;
00099 }
00100 
00101 bool XSAttributeDeclaration::getRequired() const
00102 {
00103     if (fAttDef->getDefaultType() == XMLAttDef::Required ||
00104         fAttDef->getDefaultType() == XMLAttDef::Required_And_Fixed)
00105         return true;
00106 
00107     return false;
00108 }
00109 
00110 XERCES_CPP_NAMESPACE_END
00111 
00112