Exemplo n.º 1
0
Result XQNameExpression::createResult(DynamicContext* context, int flags) const
{
    AnyAtomicType::Ptr itemName = getExpression()->createResult(context)->next(context);

    switch(itemName->getPrimitiveTypeIndex()) {
    case AnyAtomicType::QNAME:
        return (Item::Ptr)itemName;
    case AnyAtomicType::STRING:
    case AnyAtomicType::UNTYPED_ATOMIC:
        try {
            return (Item::Ptr)context->getItemFactory()->createDerivedFromAtomicType(AnyAtomicType::QNAME, itemName->asString(context), context);
        }
        catch(XQException &) {
            XQThrow(ASTException,X("XQNameExpression::NameExpressionResult::createResult"),
                    X("The name expression cannot be converted to a xs:QName [err:XQDY0074]"));
        }
    default:
        break;
    }

    XMLBuffer buf;
    buf.set(X("The name expression must be a single xs:QName, xs:string or xs:untypedAtomic"));
    buf.append(X(" - found item of type "));
    itemName->typeToBuffer(context, buf);
    buf.append(X(" [err:XPTY0004]"));
    XQThrow(XPath2TypeMatchException, X("XQNameExpression::NameExpressionResult::createResult"), buf.getRawBuffer());
}
Exemplo n.º 2
0
void XercesUpdateFactory::addToPutSet(const Node::Ptr &node, const LocationInfo *location, DynamicContext *context)
{
  Node::Ptr root = node->root(context);

  Sequence docURISeq = root->dmDocumentURI(context);
  const XMLCh *docuri = 0;
  if(!docURISeq.isEmpty()) {
    docuri = docURISeq.first()->asString(context);
  }

  PutItem item(docuri, root, location, context);

  std::pair<PutSet::iterator, bool> res = putSet_.insert(item);
  if(!res.second && !res.first->node->equals(item.node)) {
    if(context->getMessageListener() != 0) {
      context->getMessageListener()->warning(X("In the context of this expression"), res.first->location);
    }

    XMLBuffer buf;
    buf.append(X("Document writing conflict for URI \""));
    buf.append(item.uri);
    buf.append(X("\""));

    XQThrow3(ASTException, X("XercesUpdateFactory::addToPutSet"), buf.getRawBuffer(), location);
  }
}
Exemplo n.º 3
0
ASTNode* XQFunctionCall::staticResolution(StaticContext *context) 
{
  if(uri_ == 0) {
    if(prefix_ == 0 || *prefix_ == 0) {
      uri_ = context->getDefaultFuncNS();
    }
    else {
      uri_ = context->getUriBoundToPrefix(prefix_, this);
    }
  }

  ASTNode *result = context->lookUpFunction(uri_, name_, *args_, this);
  if(result == 0) {
    XMLBuffer buf;
    buf.set(X("A function called {"));
    buf.append(uri_);
    buf.append(X("}"));
    buf.append(name_);
    buf.append(X(" with "));
    XPath2Utils::numToBuf(args_ ? (unsigned int)args_->size() : 0, buf);
    buf.append(X(" arguments is not defined [err:XPST0017]"));

    XQThrow(StaticErrorException, X("XQFunctionCall::staticResolution"), buf.getRawBuffer());
  }

  // Our arguments don't belong to us anymore
  for(VectorOfASTNodes::iterator i = args_->begin(); i != args_->end(); ++i) {
    *i = 0;
  }
  // Release this object
  this->release();

  return result->staticResolution(context);
}
Exemplo n.º 4
0
void XercesUpdateFactory::completeUpdate(DynamicContext *context)
{
  completeDeletions(context);
  completeRevalidation(context);

  // Call the URIResolvers to handle the PutSet
  for(PutSet::iterator i = putSet_.begin(); i != putSet_.end(); ++i) {
    try {
      if(!context->putDocument(i->node, i->uri)) {
        XMLBuffer buf;
        buf.append(X("Writing of updated document failed for URI \""));
        buf.append(i->uri);
        buf.append(X("\""));

        XQThrow3(ASTException, X("XercesUpdateFactory::completeUpdate"), buf.getRawBuffer(), i->location);
      }
    }
    catch(XQException& e) {
      if(e.getXQueryLine() == 0) {
        e.setXQueryPosition(i->location);
      }
      throw e;
    }
  }
}
Exemplo n.º 5
0
void XercesSequenceBuilder::textEvent(const XMLCh *chars, unsigned int length)
{
  if(document_ == 0) {
    document_ = new (context_->getMemoryManager()) XPathDocumentImpl(XQillaImplementation::getDOMImplementationImpl(), context_->getMemoryManager());
  }

  if(currentNode_->getNodeType() == DOMNode::TEXT_NODE) {
    // Combine adjacent text nodes
    XMLBuffer buf;
    buf.append(chars, length);
    ((DOMText *)currentNode_)->appendData(buf.getRawBuffer());
  }
  else if(currentParent_ == 0 || length != 0) {
		// Text nodes with a zero length value can only exist
		// when they have no parent
    XMLBuffer buf;
    buf.append(chars, length);
    DOMText *node = document_->createTextNode(buf.getRawBuffer());

    if(currentParent_ != 0)
      currentParent_->appendChild(node);
    currentNode_ = node;
  }

  if(currentParent_ == 0) {
    seq_.addItem(new XercesNodeImpl(currentNode_, (XercesURIResolver*)context_->getDefaultURIResolver()));
    document_ = 0;
    currentNode_ = 0;
  }
}
Exemplo n.º 6
0
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;
}
Exemplo n.º 7
0
void FunctionLookup::insertFunction(FuncFactory *func)
{
  // Use similar algorithm to lookup in order to detect overlaps
  // in argument numbers
  RefHash2KeysTableOfEnumerator<FuncFactory> iterator(const_cast<RefHash2KeysTableOf< FuncFactory >* >(&_funcTable));
  //
  // Walk the matches for the primary key (name) looking for overlaps:
  //   ensure func->max < min OR func->min > max
  //
  iterator.setPrimaryKey(func->getURINameHash());
  while(iterator.hasMoreElements())
    {
      FuncFactory *entry= &(iterator.nextElement());
      if ((func->getMaxArgs() < entry->getMinArgs()) ||
          (func->getMinArgs() > entry->getMaxArgs()))
        continue;
      // overlap -- throw exception
      XMLBuffer buf;
      buf.set(X("Multiple functions have the same expanded QName and number of arguments {"));
      buf.append(func->getURI());
      buf.append(X("}"));
      buf.append(func->getName());
      buf.append(X("#"));
      if(func->getMinArgs() >= entry->getMinArgs() &&
         func->getMinArgs() <= entry->getMaxArgs())
        XPath2Utils::numToBuf((unsigned int)func->getMinArgs(), buf);
      else
        XPath2Utils::numToBuf((unsigned int)entry->getMinArgs(), buf);
      buf.append(X(" [err:XQST0034]."));
      XQThrow2(StaticErrorException,X("FunctionLookup::insertFunction"), buf.getRawBuffer());
    }
  // Ok to add function
  size_t secondaryKey = SECONDARY_KEY(func);
  _funcTable.put((void*)func->getURINameHash(), (int)secondaryKey, func);
}
Exemplo n.º 8
0
TupleNode *ForTuple::staticResolution(StaticContext *context)
{
  parent_ = parent_->staticResolution(context);

  varURI_ = context->getUriBoundToPrefix(XPath2NSUtils::getPrefix(varQName_, context->getMemoryManager()), this);
  varName_ = XPath2NSUtils::getLocalName(varQName_);

  if(posQName_ && *posQName_) {
    posURI_ = context->getUriBoundToPrefix(XPath2NSUtils::getPrefix(posQName_, context->getMemoryManager()), this);
    posName_ = XPath2NSUtils::getLocalName(posQName_);

    if(XPath2Utils::equals(posName_, varName_) && XPath2Utils::equals(posURI_, varURI_)) {
      XMLBuffer errMsg;
      errMsg.set(X("The positional variable with name {"));
      errMsg.append(posURI_);
      errMsg.append(X("}"));
      errMsg.append(posName_);
      errMsg.append(X(" conflicts with the iteration variable [err:XQST0089]"));
      XQThrow(StaticErrorException,X("ForTuple::staticResolution"), errMsg.getRawBuffer());
    }
  }

  expr_ = expr_->staticResolution(context);

  return this;
}
Exemplo n.º 9
0
PendingUpdateList UInsertAsLast::createUpdateList(DynamicContext *context) const
{
  Node::Ptr node = (Node*)target_->createResult(context)->next(context).get();

  if(node->dmNodeKind() != Node::element_string &&
     node->dmNodeKind() != Node::document_string)
    XQThrow(XPath2TypeMatchException,X("UInsertAsLast::createUpdateList"),
            X("It is a type error for the target expression of an insert as last expression not to be a single element "
              "or document [err:XUTY0005]"));

  Sequence alist(context->getMemoryManager());
  Sequence clist(context->getMemoryManager());

  Result value = source_->createResult(context);
  Item::Ptr item;
  while((item = value->next(context)).notNull()) {
    if(((Node*)item.get())->dmNodeKind() == Node::attribute_string) {
      if(!clist.isEmpty())
        XQThrow(ASTException,X("UInsertAsLast::createUpdateList"),
                X("Attribute nodes must occur before other nodes in the source expression for an insert as last expression [err:XUTY0004]"));

      //    b. No attribute node in $alist may have a QName whose implied namespace binding conflicts with a namespace
      //       binding in the "namespaces" property of $target [err:XUDY0023].  
      ATQNameOrDerived::Ptr qname = ((Node*)item.get())->dmNodeName(context);
      if(qname->getURI() != 0 && *(qname->getURI()) != 0) {
        ATAnyURIOrDerived::Ptr uri = FunctionNamespaceURIForPrefix::uriForPrefix(qname->getPrefix(), node, context, this);
        if(uri.notNull() && !XPath2Utils::equals(uri->asString(context), qname->getURI())) {
          XMLBuffer buf;
          buf.append(X("Implied namespace binding for the insert as last expression (\""));
          buf.append(qname->getPrefix());
          buf.append(X("\" -> \""));
          buf.append(qname->getURI());
          buf.append(X("\") conflicts with those already existing on the parent element of the target attribute [err:XUDY0023]"));
          XQThrow3(DynamicErrorException, X("UInsertInto::createUpdateList"), buf.getRawBuffer(), this);
        }
      }

      alist.addItem(item);
    }
    else
      clist.addItem(item);
  }

  PendingUpdateList result;

  if(!alist.isEmpty()) {
    // 3. If $alist is not empty and into is specified, the following checks are performed:
    //    a. $target must be an element node [err:XUTY0022].
    if(node->dmNodeKind() == Node::document_string)
      XQThrow(XPath2TypeMatchException,X("UInsertInto::createUpdateList"),
              X("It is a type error if an insert expression specifies the insertion of an attribute node into a document node [err:XUTY0022]"));
    result.addUpdate(PendingUpdate(PendingUpdate::INSERT_ATTRIBUTES, node, alist, this));
  }
  if(!clist.isEmpty()) {
    result.addUpdate(PendingUpdate(PendingUpdate::INSERT_INTO_AS_LAST, node, clist, this));
  }

  return result;
}
Exemplo n.º 10
0
void AnyAtomicType::typeToBuffer(DynamicContext *context, XMLBuffer &buffer) const
{
  if(getTypeURI()) {
    buffer.append('{');
    buffer.append(getTypeURI());
    buffer.append('}');
  }
  buffer.append(getTypeName());
}
Exemplo n.º 11
0
PendingUpdateList URename::createUpdateList(DynamicContext *context) const
{
  Node::Ptr node = (Node*)target_->createResult(context)->next(context).get();

  if(node->dmNodeKind() != Node::element_string &&
     node->dmNodeKind() != Node::attribute_string &&
     node->dmNodeKind() != Node::processing_instruction_string)
    XQThrow(XPath2TypeMatchException,X("URename::createUpdateList"),
            X("It is a type error for the target expression of a rename expression not to be a single element, "
              "attribute or processing instruction [err:XUTY0012]"));

  ATQNameOrDerived::Ptr qname = (ATQNameOrDerived*)name_->createResult(context)->next(context).get();

  // 3. The following checks are performed for error conditions:
  //    a. If $target is an element node, the "namespaces" property of $target must not include any namespace binding that conflicts
  //       with the implied namespace binding of $QName [err:XUDY0023].
  if(node->dmNodeKind() == Node::element_string) {
    ATAnyURIOrDerived::Ptr uri = FunctionNamespaceURIForPrefix::uriForPrefix(qname->getPrefix(), node, context, this);
    if(uri.notNull() && !XPath2Utils::equals(uri->asString(context), qname->getURI())) {
      XMLBuffer buf;
      buf.append(X("Implied namespace binding for the rename expression (\""));
      buf.append(qname->getPrefix());
      buf.append(X("\" -> \""));
      buf.append(qname->getURI());
      buf.append(X("\") conflicts with those already existing on the target element [err:XUDY0023]"));
      XQThrow3(DynamicErrorException, X("URename::createUpdateList"), buf.getRawBuffer(), this);
    }
  }
  //    b. If $target is an attribute node that has a parent, the "namespaces" property of parent($target) must not include any
  //       namespace binding that conflicts with the implied namespace binding of $QName [err:XUDY0023].
  else if(node->dmNodeKind() == Node::attribute_string) {
    Node::Ptr parentNode = node->dmParent(context);
    if(parentNode.notNull() && qname->getURI() != 0 && *(qname->getURI()) != 0) {
      ATAnyURIOrDerived::Ptr uri = FunctionNamespaceURIForPrefix::uriForPrefix(qname->getPrefix(), parentNode, context, this);
      if(uri.notNull() && !XPath2Utils::equals(uri->asString(context), qname->getURI())) {
        XMLBuffer buf;
        buf.append(X("Implied namespace binding for the rename expression (\""));
        buf.append(qname->getPrefix());
        buf.append(X("\" -> \""));
        buf.append(qname->getURI());
        buf.append(X("\") conflicts with those already existing on the parent element of the target attribute [err:XUDY0023]"));
        XQThrow3(DynamicErrorException, X("URename::createUpdateList"), buf.getRawBuffer(), this);
      }
    }
  }
  //    c. If $target is processing instruction node, $QName must not include a non-empty namespace prefix. [err:XUDY0025].
  else if(node->dmNodeKind() == Node::processing_instruction_string && !XPath2Utils::equals(qname->getPrefix(), XMLUni::fgZeroLenString))
    XQThrow(XPath2TypeMatchException,X("URename::createUpdateList"),
            X("The target of a rename expression is a processing instruction node, and the new name "
              "expression returned a QName with a non-empty namespace prefix [err:XUDY0025]"));

  return PendingUpdate(PendingUpdate::RENAME, node, qname, this);
}
Exemplo n.º 12
0
EventGenerator::Ptr XQQNameLiteral::generateEvents(EventHandler *events, DynamicContext *context,
                                                   bool preserveNS, bool preserveType) const
{
  XMLBuffer buf;
  if(prefix_ && *prefix_) {
    buf.append(prefix_);
    buf.append(':');
  }
  buf.append(localname_);
  events->atomicItemEvent(AnyAtomicType::QNAME, buf.getRawBuffer(), typeURI_, typeName_);
  return 0;
}
Exemplo n.º 13
0
void XQUserFunction::staticTypingOnce(StaticContext *context, StaticTyper *styper)
{
  // Avoid inifinite recursion for recursive functions
  // TBD Need to declare everything as being used - jpcs
  if(staticTyped_ != BEFORE) {
    if(staticTyped_ == DURING)
      recursive_ = true;

    XQGlobalVariable *global = 0;
    StaticTyper::PrologItem *breadcrumb = styper->getTrail();
    for(; breadcrumb; breadcrumb = breadcrumb->prev) {
      if(breadcrumb->global) global = breadcrumb->global;
      if(breadcrumb->function == this) break;
    }

    if(global && breadcrumb) {
      XMLBuffer buf;
      buf.append(X("The initializing expression for variable {"));
      buf.append(global->getVariableURI());
      buf.append(X("}"));
      buf.append(global->getVariableLocalName());
      buf.append(X(" depends on itself [err:XQST0054]"));
      XQThrow3(StaticErrorException, X("XQUserFunction::staticTypingOnce"), buf.getRawBuffer(), global);
    }

    return;
  }
  staticTyped_ = DURING;

  StaticTyper::PrologItem breadcrumb(this, styper->getTrail());
  AutoReset<StaticTyper::PrologItem*> autorReset2(styper->getTrail());
  styper->getTrail() = &breadcrumb;;

  GlobalVariables globalsUsed(XQillaAllocator<XQGlobalVariable*>(context->getMemoryManager()));
  {
    AutoReset<GlobalVariables*> autoReset(styper->getGlobalsUsed());
    styper->getGlobalsUsed() = &globalsUsed;
    staticTyping(context, styper);
  }

  if(!globalsUsed.empty()) {
    // Static type the global variables we depend on
    GlobalVariables::iterator it = globalsUsed.begin();
    for(; it != globalsUsed.end(); ++it) {
      (*it)->staticTypingOnce(context, styper);
    }

    // Re-static type this function definition
    staticTyping(context, styper);
  }

  staticTyped_ = AFTER;
}
Exemplo n.º 14
0
FunctionRef::Ptr FunctionRefImpl::partialApply(const Result &arg, unsigned int argNum, DynamicContext *context, const LocationInfo *location) const
{
  if(getNumArgs() < argNum) {
    XMLBuffer buf;
    buf.set(X("The function item argument to fn:partial-apply() must have an arity of at least "));
    XPath2Utils::numToBuf(argNum, buf);
    buf.append(X(" - found item of type "));
    typeToBuffer(context, buf);
    buf.append(X(" [err:TBD]"));
    XQThrow3(XPath2TypeMatchException, X("FunctionRefImpl::partialApply"), buf.getRawBuffer(), location);
  }

  return new FunctionRefImpl(this, arg, argNum - 1, context);
}
Exemplo n.º 15
0
 virtual InputSource *resolveEntity(XMLResourceIdentifier* resourceIdentifier)
 {
   if(resourceIdentifier->getResourceIdentifierType() == XMLResourceIdentifier::UnKnown &&
      XPath2Utils::equals(resourceIdentifier->getNameSpace(), m_PreviousModuleNamespace)) {
     XMLBuffer buf;
     buf.set(X("The graph of module imports contains a cycle for namespace '"));
     buf.append(resourceIdentifier->getNameSpace());
     buf.append(X("' [err:XQST0073]"));
     XQThrow3(StaticErrorException, X("LoopDetector::resolveEntity"), buf.getRawBuffer(), m_location);
   }
   if(m_pParentResolver)
     return m_pParentResolver->resolveEntity(resourceIdentifier);
   return NULL;
 }
Exemplo n.º 16
0
static void duplicateVariableError(const XQGlobalVariable *existing, const XQGlobalVariable *bad,
                                   MessageListener *mlistener)
{
  if(mlistener) {
    mlistener->warning(X("In the context of this variable declaration"), existing);
  }
  XMLBuffer buf;
  buf.set(X("A variable with name {"));
  buf.append(bad->getVariableURI());
  buf.append(X("}"));
  buf.append(bad->getVariableLocalName());
  buf.append(X(" conflicts with an existing global variable [err:XQST0049]."));
  XQThrow3(StaticErrorException, X("XQQuery::staticResolution"), buf.getRawBuffer(), bad);
}
Exemplo n.º 17
0
bool XQDOMConstructor::getStringValue(const ASTNode *child, XMLBuffer &value, DynamicContext *context)
{
    bool bSomethingFound=false;
    Result childList = child->createResult(context);
    Item::Ptr item;
    bool addSpace = false;
    while((item = childList->next(context)) != NULLRCP) {
        if(addSpace) value.append(' ');
        else addSpace = true;
        value.append(item->asString(context));
        bSomethingFound=true;
    }
    return bSomethingFound;
}
Exemplo n.º 18
0
inline void outputPrefixOrURI(const XMLCh *prefix, const XMLCh *uri, XMLBuffer &buffer)
{
  if(prefix != 0) {
    buffer.append(prefix);
    buffer.append(':');
  }
  else if(XPath2Utils::equals(uri, SchemaSymbols::fgURI_SCHEMAFORSCHEMA)) {
    buffer.append(X("xs:"));
  }
  else if(uri != 0) {
    buffer.append('{');
    buffer.append(uri);
    buffer.append('}');
  }
}
Exemplo n.º 19
0
Result FunctionRefImpl::execute(const VectorOfResults &args, DynamicContext *context, const LocationInfo *location) const
{
  if(args.size() != getNumArgs()) {
    XMLBuffer buf;
    buf.set(X("The function item invoked does not accept "));
    XPath2Utils::numToBuf((unsigned int)args.size(), buf);
    buf.append(X(" arguments - found item of type "));
    typeToBuffer(context, buf);
    buf.append(X(" [err:XPTY0004]"));
    XQThrow3(XPath2TypeMatchException, X("FunctionRefImpl::execute"), buf.getRawBuffer(), location);
  }

  FunctionRefScope scope(this, args, context);
  AutoVariableStoreReset vsReset(context, &scope);
  return instance_->createResult(context);
}
Exemplo n.º 20
0
ASTNode* FunctionLookup::lookUpFunction(const XMLCh* URI, const XMLCh* fname,
                                        const VectorOfASTNodes &args, XPath2MemoryManager* memMgr) const
{
  if (this != g_globalFunctionTable) {
    ASTNode *ret = g_globalFunctionTable->lookUpFunction(
                                                         URI, fname, args, memMgr);
    if (ret)
      return ret;
  }

  RefHash2KeysTableOfEnumerator<FuncFactory> iterator(const_cast<RefHash2KeysTableOf< FuncFactory >* >(&_funcTable));
  //
  // Walk the matches for the primary key (name) looking for matches
  // based on allowable parameters
  //
  XMLBuffer key;
  key.set(fname);
  key.append(':');
  key.append(URI);
  iterator.setPrimaryKey(key.getRawBuffer());
  size_t nargs = args.size();
  while(iterator.hasMoreElements()) {
    FuncFactory *entry= &(iterator.nextElement());
    if (entry->getMinArgs() <= nargs &&
        entry->getMaxArgs() >= nargs)
      return entry->createInstance(args, memMgr);
  }
  return NULL;
}
Exemplo n.º 21
0
void SequenceType::toBuffer(XMLBuffer &buffer) const
{
  if(m_pItemType == 0) {
    buffer.append(X("empty-sequence()"));
  }
  else {
    m_pItemType->toBuffer(buffer, m_nOccurrence != EXACTLY_ONE);

    switch(m_nOccurrence) {
    case EXACTLY_ONE: break;
    case STAR: buffer.append('*'); break;
    case PLUS: buffer.append('+'); break;
    case QUESTION_MARK: buffer.append('?'); break;
    }
  }
}
Exemplo n.º 22
0
void DateUtils::formatNumber(int value, int minDigits, XMLBuffer& buffer)
{
  bool bIsNegative=false;
  if(value<0)
  {
    bIsNegative=true;
    value=-value;
  }
  XMLCh tmpBuff[19];
  XMLString::binToText(value,tmpBuff,18,10);
  if(bIsNegative)
    buffer.append(chDash);
  for(int len = XPath2Utils::intStrlen(tmpBuff);len<minDigits;len++)
    buffer.append(chDigit_0);
  buffer.append(tmpBuff);
}
Exemplo n.º 23
0
// ---------------------------------------------------------------------------
//  ContentSpecNode: Miscellaneous
// ---------------------------------------------------------------------------
void ContentSpecNode::formatSpec(XMLBuffer&      bufToFill) const
{
    // Clean out the buffer first
    bufToFill.reset();

    if (fType == ContentSpecNode::Leaf)
        bufToFill.append(chOpenParen);
    formatNode
    (
        this
        , UnknownType
        , bufToFill
    );
    if (fType == ContentSpecNode::Leaf)
        bufToFill.append(chCloseParen);
}
Exemplo n.º 24
0
ASTNode *XQAtomize::staticTypingImpl(StaticContext *context)
{
  _src.clear();

  _src.getStaticType() = expr_->getStaticAnalysis().getStaticType();
  _src.add(expr_->getStaticAnalysis());

  if(expr_->getStaticAnalysis().isUpdating()) {
    XQThrow(StaticErrorException,X("XQAtomize::staticTyping"),
            X("It is a static error for an atomized expression "
              "to be an updating expression [err:XUST0001]"));
  }

  if(_src.getStaticType().isType(StaticType::FUNCTION_TYPE) &&
     _src.getStaticType().getMin() > 0) {
    XMLBuffer buf;
    buf.set(X("Sequence does not match type (xs:anyAtomicType | node())*"));
    buf.append(X(" - the expression has a static type of "));
    _src.getStaticType().typeToBuf(buf);
    buf.append(X(" [err:XPTY0004]"));
    XQThrow(XPath2TypeMatchException, X("XQAtomize::staticTyping"), buf.getRawBuffer());
  }

  if(!_src.getStaticType().containsType(StaticType::NODE_TYPE|StaticType::FUNCTION_TYPE)) {
    // If the expression has no nodes, this function does nothing
    return substitute(expr_);
  }

  if(doPSVI_) {
    _src.getStaticType().substitute(StaticType::ELEMENT_TYPE | StaticType::ATTRIBUTE_TYPE,
                                    StaticType(StaticType::ANY_ATOMIC_TYPE, 0, StaticType::UNLIMITED));
  } else {
    _src.getStaticType().substitute(StaticType::ELEMENT_TYPE | StaticType::ATTRIBUTE_TYPE,
                                    StaticType::UNTYPED_ATOMIC_TYPE);
  }

  _src.getStaticType().substitute(StaticType::DOCUMENT_TYPE | StaticType::TEXT_TYPE,
                                  StaticType::UNTYPED_ATOMIC_TYPE);
  _src.getStaticType().substitute(StaticType::NAMESPACE_TYPE | StaticType::COMMENT_TYPE |
                                  StaticType::PI_TYPE, StaticType::STRING_TYPE);

  // Remove function types
  _src.getStaticType() &= StaticType(StaticType::NODE_TYPE | StaticType::ANY_ATOMIC_TYPE, 0, StaticType::UNLIMITED);

  return this;
}
Exemplo n.º 25
0
void XercesUpdateFactory::applyPut(const PendingUpdate &update, DynamicContext *context)
{
  PutItem item(update.getValue().first()->asString(context), update.getTarget(), &update, context);

  std::pair<PutSet::iterator, bool> res = putSet_.insert(item);
  if(!res.second) {
    if(context->getMessageListener() != 0) {
      context->getMessageListener()->warning(X("In the context of this expression"), res.first->location);
    }

    XMLBuffer buf;
    buf.append(X("fn:put() called with the URI \""));
    buf.append(item.uri);
    buf.append(X("\" twice. [err:XUDY0031]"));

    XQThrow3(ASTException, X("XercesUpdateFactory::applyPut"), buf.getRawBuffer(), &update);
  }
}
Exemplo n.º 26
0
void DateUtils::formatNumber(const MAPM &value, int minDigits, XMLBuffer &buffer)
{
  char obuf[1024];
  value.toIntegerString(obuf);

  char *str = obuf;
  if(value.sign() < 0) {
    ++str;
    buffer.append(chDash);
  }

  size_t length = strlen(str);
  for(int i = (int)length; i < minDigits; ++i) {
    buffer.append(chDigit_0);
  }

  buffer.append(X(str));
}
Exemplo n.º 27
0
const ExternalFunction *FunctionLookup::lookUpExternalFunction(
  const XMLCh* URI, const XMLCh* fname, size_t numArgs) const
{
  size_t secondaryKey = numArgs;
  XMLBuffer key;
  key.set(fname);
  key.append(':');
  key.append(URI);
  return _exFuncTable.get(key.getRawBuffer(), (int)secondaryKey);
}
Exemplo n.º 28
0
Sequence FunctionConcat::createSequence(DynamicContext* context, int flags) const
{
  XMLBuffer result;
  for(unsigned int i = 1; i <= getNumArgs(); ++i) {
    Item::Ptr item = getParamNumber(i,context)->next(context);
    if(!item.isNull()) {
      result.append(item->asString(context));
    }
  }
  return Sequence(context->getItemFactory()->createString(result.getRawBuffer(), context), context->getMemoryManager());
}
Exemplo n.º 29
0
Item::Ptr SequenceType::TypeMatchesResult::next(DynamicContext *context)
{
  Item::Ptr item = _parent->next(context);
  if(item.isNull()) {
    _parent = 0;
  }
  else if(!_seqType->getItemType()->matches(item, context)) {
    XMLBuffer buf;
    buf.set(X("Sequence does not match type "));
    _seqType->toBuffer(buf);
    buf.append(X(" - found item of type "));
    item->typeToBuffer(context, buf);
    buf.append(X(" ["));
    buf.append(_errorCode);
    buf.append(X("]"));
    XQThrow(XPath2TypeMatchException, X("SequenceType::MatchesResult::next"), buf.getRawBuffer());
  }

  return item;
}
Exemplo n.º 30
0
void DOMAttrImpl::getTextValue(DOMNode* node, XMLBuffer& buf) const
{
    if (node->getNodeType() == DOMNode::TEXT_NODE)
        buf.append(node->getNodeValue());
    else if (node->getNodeType() == DOMNode::ENTITY_REFERENCE_NODE)
    {
        for (node = node->getFirstChild(); node != 0; node = castToChildImpl(node)->nextSibling)
        {
            getTextValue(node, buf);
        }
    }

    return;
}