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.7 2006/11/01 16:37:14 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   typedef RefCountPointer<const AnyAtomicType> Ptr;
00029 
00030   /* isAtomicValue from Item */
00031   virtual bool isAtomicValue() const;
00032 
00033   /* isNode from Item */
00034   virtual bool isNode() const;
00035 
00036   /* is this type numeric?  Return false by default */
00037   virtual bool isNumericValue() const;
00038 
00039   /* is this type date or time based?  Return false by default */
00040   virtual bool isDateOrTimeTypeValue() const;
00041 
00042   /* Get the namespace uri of the primitive type (basic type) of this type */
00043   virtual const XMLCh* getPrimitiveTypeURI() const;
00044 
00045   /* Get the name of the primitive type (basic type) of this type (ie "decimal" for xs:decimal) */
00046   virtual const XMLCh* getPrimitiveTypeName() const = 0;
00047 
00048   /* Get the namespace URI for this type */
00049   virtual const XMLCh* getTypeURI() const = 0;
00050 
00051   /* Get the name of this type  (ie "integer" for xs:integer) */
00052   virtual const XMLCh* getTypeName() const = 0;
00053 
00054   /* If possible, cast this type to the target type  -- not virtual, this is the single entry point for casting */
00055   AnyAtomicType::Ptr castAs(const XMLCh* targetURI, const XMLCh* targetType, const DynamicContext* context) const;
00056 
00057   /* Test if this type can be cast to the target type */
00058   virtual bool castable(const XMLCh* targetURI, const XMLCh* targetType, const DynamicContext* context) const;
00059 
00060   /* returns the XMLCh* (canonical) representation of this type */
00061   virtual const XMLCh* asString(const DynamicContext* context) const = 0;
00062 
00063   /* returns true if the two objects are equal (whatever that means 
00064    * in the context of the datatype), false otherwise */
00065   virtual bool equals(const AnyAtomicType::Ptr &target, const DynamicContext* context) const = 0;
00066 
00067   /* Returns true if this typeName and uri match the given typeName and uri */
00068   virtual bool isOfType(const XMLCh* targetURI, const XMLCh* targetType, const DynamicContext* context) const;
00069 
00070   /* Returns true if this typeName and uri match the given typeName and uri,
00071    * or if any of this type's parents match the given typeName and uri */
00072   virtual bool isInstanceOfType(const XMLCh* targetURI, const XMLCh* targetType, const StaticContext* context) const;
00073   
00074   enum AtomicObjectType {
00075     ANY_SIMPLE_TYPE    = 0,
00076     ANY_URI            = 1,
00077     BASE_64_BINARY     = 2,
00078     BOOLEAN            = 3,
00079     DATE               = 4,
00080     DATE_TIME          = 5,
00081     DAY_TIME_DURATION  = 6,
00082     DECIMAL            = 7,
00083     DOUBLE             = 8,
00084     DURATION           = 9,
00085     FLOAT              = 10,
00086     G_DAY              = 11,
00087     G_MONTH            = 12,
00088     G_MONTH_DAY        = 13,
00089     G_YEAR             = 14,
00090     G_YEAR_MONTH       = 15,
00091     HEX_BINARY         = 16,
00092     NOTATION           = 17,
00093     QNAME              = 18,
00094     STRING             = 19,
00095     TIME               = 20,
00096     UNTYPED_ATOMIC     = 21,
00097     YEAR_MONTH_DURATION= 22,
00098     NumAtomicObjectTypes= 23
00099   };
00100 
00101   /* same ordering as in cast table in F&O, for debug
00102    * enum AtomicObjectType {
00103     UNTYPED_ATOMIC     = 0,
00104     ANY_SIMPLE_TYPE    = 1,
00105     STRING             = 2,
00106     FLOAT              = 3,
00107     DOUBLE             = 4,
00108     DECIMAL            = 5,
00109     DURATION           = 6,
00110     YEAR_MONTH_DURATION= 7,
00111     DAY_TIME_DURATION  = 8,
00112     DATE_TIME          = 9,
00113     TIME               = 10,
00114     DATE               = 11,
00115     G_YEAR_MONTH       = 12,
00116     G_YEAR             = 13,
00117     G_MONTH_DAY        = 14,
00118     G_DAY              = 15,
00119     G_MONTH            = 16,
00120     BOOLEAN            = 17,
00121     BASE_64_BINARY     = 18,
00122     HEX_BINARY         = 19,
00123     ANY_URI            = 20,
00124     QNAME              = 21,
00125     NOTATION           = 22,
00126     NumAtomicObjectTypes= 23
00127   };*/
00128 
00141   bool castIsSupported(AtomicObjectType targetIndex, const DynamicContext* context) const;
00142 
00143   virtual AtomicObjectType getPrimitiveTypeIndex() const = 0;
00144  
00145   static const XMLCh fgDT_ANYATOMICTYPE[];
00146   static const XMLCh fgDT_ANYATOMICTYPE_XERCESHASH[];
00147 
00148 protected:
00149   /* internal castAs method.  This one is virtual and does the real work */
00150   virtual AnyAtomicType::Ptr castAsInternal(AtomicObjectType targetIndex, const XMLCh* targetURI,
00151                                             const XMLCh* targetType, const DynamicContext* context) const;
00152 
00153 private:
00154 
00155   //friend class CastTable;
00156   //template <class TYPE> friend class DatatypeFactoryTemplate;
00157 
00158   // class that implements the Casting Table
00159   class CastTable {
00160     public: 
00161         CastTable();
00162         bool getCell(AtomicObjectType source, 
00163                      AtomicObjectType target) const;
00164     private:
00165         bool staticCastTable[NumAtomicObjectTypes][NumAtomicObjectTypes];
00166   };
00167 
00168 
00169   // reproduction of the XPath2 casting table: http://www.w3.org/TR/xquery-operators/#casting
00170   static const CastTable staticCastTable;  
00171 };
00172 
00173 #endif //  _ANYATOMICTYPE_HPP

Generated on Fri Jan 19 15:30:52 2007 for XQilla Simple API by  doxygen 1.4.6