Item::Ptr MetaDataFunction::MetaDataResult::getSingleResult(DynamicContext *context) const { // Get the node argument Item::Ptr node = 0; if(func_->getNumArgs() == 1) { // node argument is the context item node = context->getContextItem(); if(node == NULLRCP || !node->isNode()) { XQThrow(FunctionException,X("MetaDataFunction::MetaDataResult::getSingleResult"), X("The context item is not a node in function dbxml:metadata [err:FODC0001]")); } } else { // node argument is given node = func_->getParamNumber(2, context)->next(context); } // Resolve the string argument as a QName const XMLCh *uri, *name; func_->getQNameArg(1, uri, name, context); // Lookup the metadata const DbXmlNodeImpl *nodeImpl = (const DbXmlNodeImpl*)node->getInterface(DbXmlNodeImpl::gDbXml); DBXML_ASSERT(nodeImpl != 0); return nodeImpl->getMetaData(uri, name, context); }
Item::Ptr AtomizeResult::next(DynamicContext *context) { // for $item in (Expr) return // typeswitch ($item) // case $value as atomic value return $value // default $node return fn:data($node) Item::Ptr result = _sub->next(context); while(result.isNull()) { _sub = 0; result = _parent->next(context); if(result.isNull()) { _parent = 0; return 0; } if(result->isNode()) { _sub = ((Node*)result.get())->dmTypedValue(context); result = _sub->next(context); } else if(result->isFunction()) { XMLBuffer buf; buf.set(X("Sequence does not match type (xs:anyAtomicType | node())*")); buf.append(X(" - found item of type ")); result->typeToBuffer(context, buf); buf.append(X(" [err:XPTY0004]")); XQThrow(XPath2TypeMatchException, X("AtomizeResult::next"), buf.getRawBuffer()); } } return result; }
Sequence FunctionLocalname::createSequence(DynamicContext* context, int flags) const { XPath2MemoryManager* memMgr = context->getMemoryManager(); Node::Ptr ctxNode; if(getNumArgs() == 1) { Sequence arg=getParamNumber(1,context)->toSequence(context); if(arg.isEmpty()) return Sequence(context->getItemFactory()->createString(XERCES_CPP_NAMESPACE_QUALIFIER XMLUni::fgZeroLenString, context), memMgr); ctxNode=arg.first(); } else { const Item::Ptr item = context->getContextItem(); if(item==NULLRCP) XQThrow(FunctionException, X("FunctionLocalName::createSequence"),X("Undefined context item in fn:local-name [err:XPDY0002]")); if(!item->isNode()) XQThrow(FunctionException, X("FunctionLocalName::createSequence"),X("The context item is not a node [err:XPTY0004]")); ctxNode=item; } ATQNameOrDerived::Ptr name = ctxNode->dmNodeName(context); if(name.notNull()) return Sequence(context->getItemFactory()->createString(((const ATQNameOrDerived*)name.get())->getName(), context), memMgr); return Sequence(context->getItemFactory()->createString(XERCES_CPP_NAMESPACE_QUALIFIER XMLUni::fgZeroLenString, context), memMgr); }
EventGenerator::Ptr XQCopy::generateEventsImpl(const Item::Ptr &toBeCopied, EventHandler *events, DynamicContext *context, bool preserveNS, bool preserveType) const { if(!toBeCopied->isNode()) { toBeCopied->generateEvents(events, context, preserveNS, preserveType); return 0; } Node *node = (Node*)toBeCopied.get(); if(node->dmNodeKind() == Node::element_string) { NoInheritFilter niFilter(events, context->getMemoryManager()); if(!inheritNamespaces_) events = &niFilter; AnyAtomicType::Ptr itemName = node->dmNodeName(context); const ATQNameOrDerived *pQName = (const ATQNameOrDerived*)itemName.get(); const XMLCh *prefix = emptyToNull(pQName->getPrefix()); const XMLCh *uri = emptyToNull(pQName->getURI()); const XMLCh *localname = pQName->getName(); events->startElementEvent(prefix, uri, localname); ElemConstructFilter elemFilter(events, this, context->getMemoryManager()); if(copyNamespaces_) { Result nsnodes = node->dmNamespaceNodes(context, this); Item::Ptr ns; while((ns = nsnodes->next(context)).notNull()) { ns->generateEvents(&elemFilter, context, preserveNS, preserveType); } } for(VectorOfASTNodes::const_iterator itCont = children_.begin(); itCont != children_.end (); ++itCont) { (*itCont)->generateAndTailCall(&elemFilter, context, preserveNS, preserveType); } // TBD validation and type - jpcs const XMLCh *typeURI = SchemaSymbols::fgURI_SCHEMAFORSCHEMA; const XMLCh *typeName = DocumentCache::g_szUntyped; events->endElementEvent(prefix, uri, localname, typeURI, typeName); } else if(node->dmNodeKind() == Node::document_string) { events->startDocumentEvent(0, 0); DocConstructFilter filter(events, this); for(VectorOfASTNodes::const_iterator itCont = children_.begin(); itCont != children_.end (); ++itCont) { (*itCont)->generateAndTailCall(&filter, context, preserveNS, preserveType); } events->endDocumentEvent(); } else { node->generateEvents(events, context, preserveNS, preserveType); } return 0; }
bool SequenceType::ItemType::matchesNameType(const Item::Ptr &toBeTested, const DynamicContext* context) const { // Check name constraint if(m_pName) { if(toBeTested->isNode()) { ATQNameOrDerived::Ptr name = ((const Node*)(const Item*)toBeTested)->dmNodeName(context); if(name.isNull()) return false; // Match node name if(!(XPath2Utils::equals(m_pName->getName(), ((const ATQNameOrDerived*)name.get())->getName()))) return false; // Match node uri if(!(XPath2Utils::equals(m_NameURI, ((const ATQNameOrDerived*)name.get())->getURI()))) return false; } else return false; } //A named atomic type matches a value if the dynamic type of the //value is the same as the named atomic type or is derived from the //named atomic type by restriction. For example, the ItemType //xs:decimal matches the value 12.34 (a decimal literal); it also //matches a value whose dynamic type is shoesize, if shoesize is an //atomic type derived from xs:decimal. if(m_pType) { if(toBeTested->isAtomicValue()) { return ((AnyAtomicType*)toBeTested.get())->isInstanceOfType(m_TypeURI, m_pType->getName(), context); } else if (toBeTested->isNode()) { return ((Node*)toBeTested.get())->hasInstanceOfType(m_TypeURI, m_pType->getName(), context); } return false; } return true; }
virtual Item::Ptr nextOrTail(Result &tail, DynamicContext *context) { Item::Ptr toBeCopied = ast_->getExpression()->createResult(context)->next(context); if(!toBeCopied->isNode()) { tail = 0; return toBeCopied; } AutoDelete<SequenceBuilder> builder(context->createSequenceBuilder()); EventGenerator::generateAndTailCall(ast_->generateEventsImpl(toBeCopied, builder.get(), context, true, true), builder.get(), context); builder->endEvent(); tail = builder->getSequence(); return 0; }
bool SequenceType::ItemType::matches(const Item::Ptr &toBeTested, DynamicContext* context) const { if(toBeTested->isNode()) return matches((const Node::Ptr)toBeTested, context); switch(m_nTestType) { case TEST_ELEMENT: case TEST_ATTRIBUTE: case TEST_SCHEMA_ELEMENT: case TEST_SCHEMA_ATTRIBUTE: case TEST_NODE: case TEST_PI: case TEST_COMMENT: case TEST_TEXT: case TEST_DOCUMENT: case TEST_SCHEMA_DOCUMENT: { return false; } case TEST_ANYTHING: { return true; } case TEST_ATOMIC_TYPE: { if(!toBeTested->isAtomicValue()) return false; return matchesNameType(toBeTested, context); } case TEST_FUNCTION: { if(!toBeTested->isFunction()) return false; if(returnType_ == 0) return true; FunctionRef *func = (FunctionRef*)toBeTested.get(); if(func->getNumArgs() != argTypes_->size()) return false; return true; } } return true; }
Item::Ptr next(DynamicContext *context) { Item::Ptr result; while((result = stepResult_->next(context)).isNull()) { context->testInterrupt(); Item::Ptr item = parent_->next(context); if(item.isNull()) { return 0; } if(!item->isNode()) { XQThrow(TypeErrorException,X("StepResult::next"), X("An attempt was made to perform an axis step when the Context Item was not a node [err:XPTY0020]")); } stepResult_ = ((Node*)item.get())->getAxisResult(step_->getAxis(), step_->getNodeTest(), context, this); } return result; }