#include "../../config/pathan_config.h" /* * Copyright (c) 2001, DecisionSoft Limited All rights reserved. * Please see LICENSE.TXT for more information. */ #include "ATQNameOrDerivedImpl.hpp" #include #include #include #include #include #include #include #include "../../exceptions/InvalidLexicalSpaceException.hpp" #include #include "../../exceptions/XPath2TypeCastException.hpp" #include #include #include #include #include // defines X() and XMLCh* #include #include #include ATQNameOrDerivedImpl:: ATQNameOrDerivedImpl(const XMLCh* typeURI, const XMLCh* typeName, const XMLCh* value, XPath2MemoryManager* memMgr, const DynamicContext* context): ATQNameOrDerived(memMgr), _typeName(typeName), _typeURI(typeURI) { const XMLCh* prefix = XPath2NSUtils::getPrefix(value, context->getMemoryManager()); const XMLCh* uri; if(XERCES_CPP_NAMESPACE_QUALIFIER XMLString::equals(prefix, XERCES_CPP_NAMESPACE_QUALIFIER XMLUni::fgZeroLenString)) { // If $qname has no prefix uri = context->getDefaultExprNS(); } // If $qname has a prefix else { uri = context->getUriBoundToPrefix(prefix); if (uri == 0) { DSLthrow(IllegalArgumentException, X("ATQNameOrDerivedImpl::ATQNameOrDerivedImpl"),X("No namespace for prefix")); } } // _uri will be null if there is no default NS _uri = getMemoryManager()->getPooledString(uri); _name = getMemoryManager()->getPooledString(XPath2NSUtils::getLocalName(value)); } ATQNameOrDerivedImpl:: ATQNameOrDerivedImpl(const XMLCh* typeURI, const XMLCh* typeName, const XMLCh* uri, const XMLCh* name, XPath2MemoryManager* memMgr, const DynamicContext* context): ATQNameOrDerived(memMgr), _typeName(typeName), _typeURI(typeURI) { // if uri is NULL, so will _uri _uri = getMemoryManager()->getPooledString(uri); _name = getMemoryManager()->getPooledString(name); } /* Get the name of the primitive type (basic type) of this type * (ie "decimal" for xs:decimal) */ const XMLCh* ATQNameOrDerivedImpl::getPrimitiveTypeName() const { return this->getPrimitiveName(); } /* Get the name of this type (ie "integer" for xs:integer) */ const XMLCh* ATQNameOrDerivedImpl::getTypeName() const { return _typeName; } /* Get the namespace URI for this type */ const XMLCh* ATQNameOrDerivedImpl::getTypeURI() const { return _typeURI; } /* returns the URI */ const XMLCh* ATQNameOrDerivedImpl::getURI(void) const { return _uri; } /* returns the name */ const XMLCh* ATQNameOrDerivedImpl::getName(void) const { return _name; } AnyAtomicType::AtomicObjectType ATQNameOrDerivedImpl::getTypeIndex() { return AnyAtomicType::QNAME; } /* If possible, cast this type to the target type */ const AnyAtomicType* ATQNameOrDerivedImpl::castAsInternal(const XMLCh* targetURI, const XMLCh* targetType, const DynamicContext* context) const { const DatatypeFactory* target = context->getDatatypeFactory(targetURI, targetType); AnyAtomicType::AtomicObjectType targetIndex = target->getPrimitiveTypeIndex(); switch (targetIndex) { case ANY_SIMPLE_TYPE: case UNTYPED_ATOMIC: //anySimpleType and untypedAtomic follow the same casting rules as string. case STRING: { return DatatypeFactory::STR2AT::createDerivedFromAtomicType(context->getMemoryManager(), targetURI, targetType, this->asLexicalString(context), context); } case QNAME: { return DatatypeFactory::STR2AT::createQNameOrDerived(context->getMemoryManager(), targetURI, targetType, _uri, _name, context); } default: return AnyAtomicType::castAsInternal(targetURI, targetType, context); } } /* returns the XMLCh* (canonical) representation of this type */ const XMLCh* ATQNameOrDerivedImpl::asString(const DynamicContext* context) const { XERCES_CPP_NAMESPACE_QUALIFIER XMLBuffer buffer(1023, context->getMemoryManager()); buffer.set(_uri); buffer.append(XERCES_CPP_NAMESPACE_QUALIFIER chColon); buffer.append(_name); return context->getMemoryManager()->getPooledString(buffer.getRawBuffer()); } /* returns the XMLCh* (lexical => prefix:localname) representation of this type */ const XMLCh* ATQNameOrDerivedImpl::asLexicalString(const DynamicContext* context) const { XERCES_CPP_NAMESPACE_QUALIFIER XMLBuffer buffer(1023, context->getMemoryManager()); const XMLCh* prefix; if (this->_uri == 0) { if(context->getDefaultExprNS() != 0) { DSLthrow(NamespaceLookupException,X("ATQNameOrDerivedImpl::asLexicalString"), X("default namespace is defined")); } } else { prefix = context->getPrefixBoundToUri(this->_uri); if (prefix == 0) { DSLthrow(NamespaceLookupException,X("ATQNameOrDerivedImpl::asLexicalString"), X("no prefix defined for namespace")); } buffer.set(prefix); buffer.append(XERCES_CPP_NAMESPACE_QUALIFIER chColon); buffer.append(_name); } return context->getMemoryManager()->getPooledString(buffer.getRawBuffer()); } /* returns true if the two objects' URI are equal (string comparison) * false otherwise */ bool ATQNameOrDerivedImpl::equals(const AnyAtomicType* target, const DynamicContext* context) const { if(this->getPrimitiveTypeIndex() != target->getPrimitiveTypeIndex()) { DSLthrow(IllegalArgumentException,X("ATQNameOrDerivedImpl::equals"), X("Equality operator for given types not supported")); } return XPath2Utils::equals(((const ATQNameOrDerivedImpl*)target)->_name, _name) && XPath2Utils::equals(((const ATQNameOrDerivedImpl*)target)->_uri, _uri) ; } const XMLCh* ATQNameOrDerivedImpl::getPrimitiveName() { return XERCES_CPP_NAMESPACE_QUALIFIER SchemaSymbols::fgDT_QNAME; } AnyAtomicType::AtomicObjectType ATQNameOrDerivedImpl::getPrimitiveTypeIndex() const { return this->getTypeIndex(); } /** Releases the memory used by this Item */ void ATQNameOrDerivedImpl::release() const { //TODO needs to check for ownership before releasing! getMemoryManager()->deallocate((void*)this); }