Beispiel #1
0
void Node::typeToBuffer(DynamicContext *context, XERCES_CPP_NAMESPACE_QUALIFIER XMLBuffer &buffer) const
{
    buffer.append(dmNodeKind());
    buffer.append('(');

    if(dmNodeKind() == element_string ||
       dmNodeKind() == attribute_string) {
      ATQNameOrDerived::Ptr qname = dmNodeName(context);
      if(qname->getURI()) {
        buffer.append('{');
        buffer.append(qname->getURI());
        buffer.append('}');
      }
      buffer.append(qname->getName());

      buffer.append(',');
      buffer.append(' ');
      if(getTypeURI()) {
        buffer.append('{');
        buffer.append(getTypeURI());
        buffer.append('}');
      }
      buffer.append(getTypeName());
    }

    buffer.append(')');
}
Beispiel #2
0
void AnyAtomicType::typeToBuffer(DynamicContext *context, XMLBuffer &buffer) const
{
  if(getTypeURI()) {
    buffer.append('{');
    buffer.append(getTypeURI());
    buffer.append('}');
  }
  buffer.append(getTypeName());
}
/** Returns a Numeric object which is the difference of this and
   * other */
Numeric::Ptr ATDecimalOrDerivedImpl::subtract(const Numeric::Ptr &other, const DynamicContext* context) const {
    if(this->isOfType(other->getTypeURI(), other->getTypeName(), context)) {
    // if both are of the same type exactly, we can perform subtraction
    ATDecimalOrDerivedImpl* otherImpl = (ATDecimalOrDerivedImpl*)(const Numeric*)other;
    // if integer, return xs:integer, otherwise xs:decimal    
    if(_isInteger) {
      return context->getItemFactory()->createInteger(_decimal - otherImpl->_decimal, context);
    }
    return context->getItemFactory()->createDecimal(_decimal - otherImpl->_decimal, context);

  } else if(this->getPrimitiveTypeIndex() != other->getPrimitiveTypeIndex()) {
    // if other is not a decimal, then we need to promote this to a float or double
    return ((const Numeric::Ptr )this->castAs(other->getPrimitiveTypeIndex(), context))->subtract(other, context);
  } else if (this->isInstanceOfType(other->getTypeURI(), other->getTypeName(), context)) {
    // here we know we have two decimals, and this is 'lower' in the hierarchy than other
    // so cast this to other's type
    return ((const Numeric::Ptr )this->castAs(AnyAtomicType::DECIMAL, other->getTypeURI(), other->getTypeName(),
                                              context))->subtract(other, context);
  } else if (other->isInstanceOfType(this->getTypeURI(), this->getTypeName(), context)) {
    // here we have two decimals, and this is 'higher' in the hierarchy than other
    // so cast other to this' type
    return this->subtract((const Numeric::Ptr )other->castAs(AnyAtomicType::DECIMAL, getTypeURI(), getTypeName(),
                                                             context), context);
  } else {
    // we have two separate branches.  if either is instance of integer, cast it to integer, otherwise, cast to decimal
    // revisit: this is not the prettiest way to do it.  You would want to go up the tree one by one instead of
    // jumping to integer and decimal
    ATDecimalOrDerived::Ptr first; 
    ATDecimalOrDerived::Ptr second; 
    if(this->_isInteger) {
      first = (const ATDecimalOrDerived::Ptr )this->castAs(AnyAtomicType::DECIMAL, SchemaSymbols::fgURI_SCHEMAFORSCHEMA,
                           SchemaSymbols::fgDT_INTEGER, context);
    } else {
      first = (const ATDecimalOrDerived::Ptr )this->castAs(AnyAtomicType::DECIMAL, context);
    }

    if(((ATDecimalOrDerivedImpl*)(const Numeric*)other)->_isInteger) {
      second = (const ATDecimalOrDerived::Ptr )other->castAs(AnyAtomicType::DECIMAL, SchemaSymbols::fgURI_SCHEMAFORSCHEMA,
                            SchemaSymbols::fgDT_INTEGER, context);
    } else {
      second = (const ATDecimalOrDerived::Ptr )other->castAs(AnyAtomicType::DECIMAL, context);
    }
    return first->subtract(second, context);
  }

}
Beispiel #4
0
AnyAtomicType::Ptr AnyAtomicType::castAs(AtomicObjectType targetIndex, const XMLCh* targetTypeURI,
                                         const XMLCh* targetTypeName, const DynamicContext* context) const
{
  if(!castIsSupported(targetIndex, context)) {
    if(targetTypeName == 0) {
      context->getItemFactory()->getPrimitiveTypeName(targetIndex, targetTypeURI, targetTypeName);
    }

    XMLBuffer buffer(1023, context->getMemoryManager());
    buffer.set(X("Casting from {"));
    buffer.append(getTypeURI());
    buffer.append(X("}"));
    buffer.append(getTypeName());
    buffer.append(X(" to {"));
    buffer.append(targetTypeURI);
    buffer.append(X("}"));
    buffer.append(targetTypeName);
    buffer.append(X(" is not supported [err:XPTY0004]"));

    XQThrow2(XPath2TypeCastException, X("AnyAtomicType::castAs"), buffer.getRawBuffer());
  }

  return castAsNoCheck(targetIndex, targetTypeURI, targetTypeName, context);
}
Beispiel #5
0
void AnyAtomicType::generateEvents(EventHandler *events, const DynamicContext *context,
                                   bool preserveNS, bool preserveType) const
{
  events->atomicItemEvent(getPrimitiveTypeIndex(), asString(context),
                          getTypeURI(), getTypeName());
}