SourceForge.net Logo

AnyAtomicType.hpp

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2001-2006
00003  *     DecisionSoft Limited. All rights reserved.
00004  * Copyright (c) 2004-2006
00005  *     Progress Software Corporation. All rights reserved.
00006  * Copyright (c) 2004-2006
00007  *     Oracle. All rights reserved.
00008  *
00009  * See the file LICENSE for redistribution information.
00010  *
00011  * $Id: AnyAtomicType.hpp,v 1.9 2007/08/23 11:52:08 jpcs Exp $
00012  */
00013 
00014 #ifndef _ANYATOMICTYPE_HPP
00015 #define _ANYATOMICTYPE_HPP
00016 
00017 #include <xqilla/framework/XQillaExport.hpp>
00018 #include <xqilla/items/Item.hpp>
00019 #include <xercesc/util/XercesDefs.hpp>
00020 
00021 class DynamicContext;
00022 class StaticContext;
00023 
00024 class XQILLA_API AnyAtomicType: public Item
00025 {
00026 
00027 public:
00028   enum AtomicObjectType {
00029     ANY_SIMPLE_TYPE    = 0,
00030     ANY_URI            = 1,
00031     BASE_64_BINARY     = 2,
00032     BOOLEAN            = 3,
00033     DATE               = 4,
00034     DATE_TIME          = 5,
00035     DAY_TIME_DURATION  = 6,
00036     DECIMAL            = 7,
00037     DOUBLE             = 8,
00038     DURATION           = 9,
00039     FLOAT              = 10,
00040     G_DAY              = 11,
00041     G_MONTH            = 12,
00042     G_MONTH_DAY        = 13,
00043     G_YEAR             = 14,
00044     G_YEAR_MONTH       = 15,
00045     HEX_BINARY         = 16,
00046     NOTATION           = 17,
00047     QNAME              = 18,
00048     STRING             = 19,
00049     TIME               = 20,
00050     UNTYPED_ATOMIC     = 21,
00051     YEAR_MONTH_DURATION= 22,
00052     NumAtomicObjectTypes= 23
00053   };
00054 
00055   /* same ordering as in cast table in F&O, for debug
00056    * enum AtomicObjectType {
00057     UNTYPED_ATOMIC     = 0,
00058     ANY_SIMPLE_TYPE    = 1,
00059     STRING             = 2,
00060     FLOAT              = 3,
00061     DOUBLE             = 4,
00062     DECIMAL            = 5,
00063     DURATION           = 6,
00064     YEAR_MONTH_DURATION= 7,
00065     DAY_TIME_DURATION  = 8,
00066     DATE_TIME          = 9,
00067     TIME               = 10,
00068     DATE               = 11,
00069     G_YEAR_MONTH       = 12,
00070     G_YEAR             = 13,
00071     G_MONTH_DAY        = 14,
00072     G_DAY              = 15,
00073     G_MONTH            = 16,
00074     BOOLEAN            = 17,
00075     BASE_64_BINARY     = 18,
00076     HEX_BINARY         = 19,
00077     ANY_URI            = 20,
00078     QNAME              = 21,
00079     NOTATION           = 22,
00080     NumAtomicObjectTypes= 23
00081   };*/
00082 
00083   typedef RefCountPointer<const AnyAtomicType> Ptr;
00084 
00085   /* isAtomicValue from Item */
00086   virtual bool isAtomicValue() const;
00087 
00088   /* isNode from Item */
00089   virtual bool isNode() const;
00090 
00091   /* is this type numeric?  Return false by default */
00092   virtual bool isNumericValue() const;
00093 
00094   /* is this type date or time based?  Return false by default */
00095   virtual bool isDateOrTimeTypeValue() const;
00096 
00097   /* Get the namespace uri of the primitive type (basic type) of this type */
00098   virtual const XMLCh* getPrimitiveTypeURI() const;
00099 
00100   /* Get the name of the primitive type (basic type) of this type (ie "decimal" for xs:decimal) */
00101   virtual const XMLCh* getPrimitiveTypeName() const = 0;
00102 
00103   /* Get the namespace URI for this type */
00104   virtual const XMLCh* getTypeURI() const = 0;
00105 
00106   /* Get the name of this type  (ie "integer" for xs:integer) */
00107   virtual const XMLCh* getTypeName() const = 0;
00108 
00109   /* If possible, cast this type to the target type  -- no casting table lookup made */
00110   AnyAtomicType::Ptr castAs(AtomicObjectType targetIndex, const DynamicContext* context) const;
00111 
00112   /* If possible, cast this type to the target type  -- no casting table lookup made */
00113   AnyAtomicType::Ptr castAsNoCheck(AtomicObjectType targetIndex, const XMLCh* targetURI, const XMLCh* targetType,
00114                                    const DynamicContext* context) const;
00115 
00116   /* If possible, cast this type to the target type  -- not virtual, this is the single entry point for casting */
00117   AnyAtomicType::Ptr castAs(AtomicObjectType targetIndex, const XMLCh* targetURI, const XMLCh* targetType,
00118                             const DynamicContext* context) const;
00119 
00120   /* Test if this type can be cast to the target type */
00121   virtual bool castable(AtomicObjectType targetIndex, const XMLCh* targetURI, const XMLCh* targetType,
00122                         const DynamicContext* context) const;
00123 
00124   /* returns the XMLCh* (canonical) representation of this type */
00125   virtual const XMLCh* asString(const DynamicContext* context) const = 0;
00126 
00127   /* returns true if the two objects are equal (whatever that means 
00128    * in the context of the datatype), false otherwise */
00129   virtual bool equals(const AnyAtomicType::Ptr &target, const DynamicContext* context) const = 0;
00130 
00131   /* Returns true if this typeName and uri match the given typeName and uri */
00132   virtual bool isOfType(const XMLCh* targetURI, const XMLCh* targetType, const DynamicContext* context) const;
00133 
00134   /* Returns true if this typeName and uri match the given typeName and uri,
00135    * or if any of this type's parents match the given typeName and uri */
00136   virtual bool isInstanceOfType(const XMLCh* targetURI, const XMLCh* targetType, const StaticContext* context) const;
00137   
00150   bool castIsSupported(AtomicObjectType targetIndex, const DynamicContext* context) const;
00151 
00152   virtual AtomicObjectType getPrimitiveTypeIndex() const = 0;
00153  
00154   static const XMLCh fgDT_ANYATOMICTYPE[];
00155 
00156 protected:
00157   /* internal castAs method.  This one is virtual and does the real work */
00158   virtual AnyAtomicType::Ptr castAsInternal(AtomicObjectType targetIndex, const XMLCh* targetURI,
00159                                             const XMLCh* targetType, const DynamicContext* context) const;
00160 
00161 private:
00162 
00163   //friend class CastTable;
00164   //template <class TYPE> friend class DatatypeFactoryTemplate;
00165 
00166   // class that implements the Casting Table
00167   class CastTable {
00168     public: 
00169         CastTable();
00170         bool getCell(AtomicObjectType source, 
00171                      AtomicObjectType target) const;
00172     private:
00173         bool staticCastTable[NumAtomicObjectTypes][NumAtomicObjectTypes];
00174   };
00175 
00176 
00177   // reproduction of the XPath2 casting table: http://www.w3.org/TR/xquery-operators/#casting
00178   static const CastTable staticCastTable;  
00179 };
00180 
00181 #endif //  _ANYATOMICTYPE_HPP

Generated on Fri Aug 31 14:37:35 2007 for XQilla Simple API by  doxygen 1.5.1