SourceForge.net Logo

AnyAtomicType.hpp

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

Generated on Wed Feb 8 12:53:55 2012 for XQilla Simple API by  doxygen 1.4.7