#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 #include "../exceptions/MiscException.hpp" #include #include #include #include #include #include ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// DataItemCastableAs::DataItemCastableAs(DataItem* expr, SequenceType* exprType, XPath2MemoryManager* memMgr) : DataItemImpl(memMgr), _expr(expr), _exprType(exprType) { setType(DataItem::CASTABLE_AS); } Sequence DataItemCastableAs::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("FunctionCastableAs::collapseTreeInternal"),X("Cannot cast from a non built-in data type")); if(_exprType->getItemTestType()!=SequenceType::ItemType::TEST_ATOMIC_TYPE) DSLthrow(MiscException,X("DataItemCastableAs::collapseTreeInternal"),X("Cannot cast to a non atomic type")); bool castable = ((const AnyAtomicType*)value)->castable(_exprType->getTypeURI(context), _exprType->getConstrainingType()->getName(),context); return Sequence(DatatypeFactory::POD2AT::createBoolean(context->getMemoryManager(), castable, context), context->getMemoryManager()); } DataItem* DataItemCastableAs::staticResolution(StaticContext *context, StaticResolutionContext *src) { return resolveDataItem(_expr, context, src, true); } const DataItem *DataItemCastableAs::getExpression() const { return _expr; } const SequenceType *DataItemCastableAs::getSequenceType() const { return _exprType; } void DataItemCastableAs::setExpression(DataItem *item) { _expr = item; }