#include "../config/pathan_config.h" /* * Copyright (c) 2001, DecisionSoft Limited All rights reserved. * Please see LICENSE.TXT for more information. */ #include #include #include #include #include "../exceptions/MiscException.hpp" #include #include #include #include ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// DataItemCastAs::DataItemCastAs(DataItem* expr, SequenceType* exprType, XPath2MemoryManager* memMgr) : DataItemImpl(memMgr), _expr(expr), _exprType(exprType) { setType(DataItem::CAST_AS); } Sequence DataItemCastAs::collapseTreeInternal(DynamicContext* context, int flags) const { Sequence toBeCasted(_expr->collapseTree(context)); if(toBeCasted.isEmpty()) return toBeCasted; const Item* value = toBeCasted.atomize(context).first(); //if(!value.builtInType()) // DSLthrow(MiscException,X("DataItemCastAs::collapseTreeInternal"),X("Cannot cast from a non built-in data type")); if( _exprType->getItemTestType()!=SequenceType::ItemType::TEST_ATOMIC_TYPE || _exprType->getOccurrenceIndicator()!=SequenceType::EXACTLY_ONE) { DSLthrow(MiscException,X("DataItemCastAs::collapseTreeInternal"),X("Cannot cast to a non atomic data type")); } return Sequence(((const AnyAtomicType*)value)->castAs(_exprType->getTypeURI(context), _exprType->getConstrainingType()->getName(),context), context->getMemoryManager()); } DataItem* DataItemCastAs::staticResolution(StaticContext *context, StaticResolutionContext *src) { return resolveDataItem(_expr, context, src, true); } const DataItem *DataItemCastAs::getExpression() const { return _expr; } const SequenceType *DataItemCastAs::getSequenceType() const { return _exprType; } void DataItemCastAs::setExpression(DataItem *item) { _expr = item; }