# XQilla Simple API Documentation

- Main Page
- Namespaces
- Classes
- Files
- Examples

- File List
- File Members

# AnyAtomicType.hpp

Go to the documentation of this file.

    00001 /*
    00002  * Copyright (c) 2001, 2008,
    00003  *     DecisionSoft Limited. All rights reserved.
    00004  * Copyright (c) 2004, 2015 Oracle and/or its affiliates. All rights reserved.
    00005  *
    00006  *
    00007  * Licensed under the Apache License, Version 2.0 (the "License");
    00008  * you may not use this file except in compliance with the License.
    00009  * You may obtain a copy of the License at
    00010  *
    00011  *     http://www.apache.org/licenses/LICENSE-2.0
    00012  *
    00013  * Unless required by applicable law or agreed to in writing, software
    00014  * distributed under the License is distributed on an "AS IS" BASIS,
    00015  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    00016  * See the License for the specific language governing permissions and
    00017  * limitations under the License.
    00018  */
    00019
    00020 #ifndef _ANYATOMICTYPE_HPP
    00021 #define _ANYATOMICTYPE_HPP
    00022
    00023 #include <xqilla/framework/XQillaExport.hpp>
    00024 #include <xqilla/items/Item.hpp>
    00025 #include <xercesc/util/XercesDefs.hpp>
    00026
    00027 class DynamicContext;
    00028 class StaticContext;
    00029
    00030 class XQILLA_API AnyAtomicType: public Item
    00031 {
    00032
    00033 public:
    00034   enum AtomicObjectType {
    00035     ANY_SIMPLE_TYPE    = 0,
    00036     ANY_URI            = 1,
    00037     BASE_64_BINARY     = 2,
    00038     BOOLEAN            = 3,
    00039     DATE               = 4,
    00040     DATE_TIME          = 5,
    00041     DAY_TIME_DURATION  = 6,
    00042     DECIMAL            = 7,
    00043     DOUBLE             = 8,
    00044     DURATION           = 9,
    00045     FLOAT              = 10,
    00046     G_DAY              = 11,
    00047     G_MONTH            = 12,
    00048     G_MONTH_DAY        = 13,
    00049     G_YEAR             = 14,
    00050     G_YEAR_MONTH       = 15,
    00051     HEX_BINARY         = 16,
    00052     NOTATION           = 17,
    00053     QNAME              = 18,
    00054     STRING             = 19,
    00055     TIME               = 20,
    00056     UNTYPED_ATOMIC     = 21,
    00057     YEAR_MONTH_DURATION= 22,
    00058     NumAtomicObjectTypes= 23
    00059   };
    00060
    00061   typedef RefCountPointer<const AnyAtomicType> Ptr;
    00062
    00063   /* isAtomicValue from Item */
    00064   virtual bool isAtomicValue() const;
    00065
    00066   /* isNode from Item */
    00067   virtual bool isNode() const;
    00068
    00069   virtual bool isFunction() const;
    00070
    00071   /* is this type numeric?  Return false by default */
    00072   virtual bool isNumericValue() const;
    00073
    00074   /* is this type date or time based?  Return false by default */
    00075   virtual bool isDateOrTimeTypeValue() const;
    00076
    00077   /* Get the namespace uri of the primitive type (basic type) of this type */
    00078   virtual const XMLCh* getPrimitiveTypeURI() const;
    00079
    00080   /* Get the name of the primitive type (basic type) of this type (ie "decimal" for xs:decimal) */
    00081   virtual const XMLCh* getPrimitiveTypeName() const = 0;
    00082
    00083   /* Get the namespace URI for this type */
    00084   virtual const XMLCh* getTypeURI() const = 0;
    00085
    00086   /* Get the name of this type  (ie "integer" for xs:integer) */
    00087   virtual const XMLCh* getTypeName() const = 0;
    00088
    00089   virtual void generateEvents(EventHandler *events, const DynamicContext *context,
    00090                               bool preserveNS = true, bool preserveType = true) const;
    00091
    00092   /* If possible, cast this type to the target type  -- no casting table lookup made */
    00093   AnyAtomicType::Ptr castAs(AtomicObjectType targetIndex, const DynamicContext* context) const;
    00094
    00095   /* If possible, cast this type to the target type  -- no casting table lookup made */
    00096   AnyAtomicType::Ptr castAsNoCheck(AtomicObjectType targetIndex, const XMLCh* targetURI, const XMLCh* targetType,
    00097                                    const DynamicContext* context) const;
    00098
    00099   /* If possible, cast this type to the target type  -- not virtual, this is the single entry point for casting */
    00100   AnyAtomicType::Ptr castAs(AtomicObjectType targetIndex, const XMLCh* targetURI, const XMLCh* targetType,
    00101                             const DynamicContext* context) const;
    00102
    00103   /* Test if this type can be cast to the target type */
    00104   virtual bool castable(AtomicObjectType targetIndex, const XMLCh* targetURI, const XMLCh* targetType,
    00105                         const DynamicContext* context) const;
    00106
    00107   /* returns the XMLCh* (canonical) representation of this type */
    00108   virtual const XMLCh* asString(const DynamicContext* context) const = 0;
    00109
    00110   /* returns true if the two objects are equal (whatever that means
    00111    * in the context of the datatype), false otherwise */
    00112   virtual bool equals(const AnyAtomicType::Ptr &target, const DynamicContext* context) const = 0;
    00113
    00114   /* Returns true if this typeName and uri match the given typeName and uri */
    00115   virtual bool isOfType(const XMLCh* targetURI, const XMLCh* targetType, const DynamicContext* context) const;
    00116
    00117   /* Returns true if this typeName and uri match the given typeName and uri,
    00118    * or if any of this type's parents match the given typeName and uri */
    00119   virtual bool isInstanceOfType(const XMLCh* targetURI, const XMLCh* targetType, const StaticContext* context) const;
    00120
    00121   virtual void typeToBuffer(DynamicContext *context, XERCES_CPP_NAMESPACE_QUALIFIER XMLBuffer &buffer) const;
    00122
    00135   bool castIsSupported(AtomicObjectType targetIndex, const DynamicContext* context) const;
    00136
    00137   virtual AtomicObjectType getPrimitiveTypeIndex() const = 0;
    00138
    00139   static const XMLCh fgDT_ANYATOMICTYPE[];
    00140
    00141 protected:
    00142   /* internal castAs method.  This one is virtual and does the real work */
    00143   virtual AnyAtomicType::Ptr castAsInternal(AtomicObjectType targetIndex, const XMLCh* targetURI,
    00144                                             const XMLCh* targetType, const DynamicContext* context) const;
    00145
    00146 private:
    00147
    00148   //friend class CastTable;
    00149   //template <class TYPE> friend class DatatypeFactoryTemplate;
    00150
    00151   // class that implements the Casting Table
    00152   class CastTable {
    00153     public:
    00154         CastTable();
    00155         bool getCell(AtomicObjectType source,
    00156                      AtomicObjectType target) const;
    00157     private:
    00158         bool staticCastTable[NumAtomicObjectTypes][NumAtomicObjectTypes];
    00159   };
    00160
    00161
    00162   // reproduction of the XPath2 casting table: http://www.w3.org/TR/xquery-operators/#casting
    00163   static const CastTable staticCastTable;
    00164 };
    00165
    00166 #endif