SourceForge.net Logo
AnyAtomicType.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2001-2008
3  * DecisionSoft Limited. All rights reserved.
4  * Copyright (c) 2004-2008
5  * Oracle. All rights reserved.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  * $Id$
20  */
21 
22 #ifndef _ANYATOMICTYPE_HPP
23 #define _ANYATOMICTYPE_HPP
24 
25 #include <xqilla/framework/XQillaExport.hpp>
26 #include <xqilla/items/Item.hpp>
27 #include <xercesc/util/XercesDefs.hpp>
28 
29 class DynamicContext;
30 class StaticContext;
31 
32 class XQILLA_API AnyAtomicType: public Item
33 {
34 
35 public:
37  ANY_SIMPLE_TYPE = 0,
38  ANY_URI = 1,
39  BASE_64_BINARY = 2,
40  BOOLEAN = 3,
41  DATE = 4,
42  DATE_TIME = 5,
43  DAY_TIME_DURATION = 6,
44  DECIMAL = 7,
45  DOUBLE = 8,
46  DURATION = 9,
47  FLOAT = 10,
48  G_DAY = 11,
49  G_MONTH = 12,
50  G_MONTH_DAY = 13,
51  G_YEAR = 14,
52  G_YEAR_MONTH = 15,
53  HEX_BINARY = 16,
54  NOTATION = 17,
55  QNAME = 18,
56  STRING = 19,
57  TIME = 20,
58  UNTYPED_ATOMIC = 21,
59  YEAR_MONTH_DURATION= 22,
60  NumAtomicObjectTypes= 23
61  };
62 
64 
65  /* isAtomicValue from Item */
66  virtual bool isAtomicValue() const;
67 
68  /* isNode from Item */
69  virtual bool isNode() const;
70 
71  virtual bool isFunction() const;
72 
73  /* is this type numeric? Return false by default */
74  virtual bool isNumericValue() const;
75 
76  /* is this type date or time based? Return false by default */
77  virtual bool isDateOrTimeTypeValue() const;
78 
79  /* Get the namespace uri of the primitive type (basic type) of this type */
80  virtual const XMLCh* getPrimitiveTypeURI() const;
81 
82  /* Get the name of the primitive type (basic type) of this type (ie "decimal" for xs:decimal) */
83  virtual const XMLCh* getPrimitiveTypeName() const = 0;
84 
85  /* Get the namespace URI for this type */
86  virtual const XMLCh* getTypeURI() const = 0;
87 
88  /* Get the name of this type (ie "integer" for xs:integer) */
89  virtual const XMLCh* getTypeName() const = 0;
90 
91  virtual void generateEvents(EventHandler *events, const DynamicContext *context,
92  bool preserveNS = true, bool preserveType = true) const;
93 
94  /* If possible, cast this type to the target type -- no casting table lookup made */
95  AnyAtomicType::Ptr castAs(AtomicObjectType targetIndex, const DynamicContext* context) const;
96 
97  /* If possible, cast this type to the target type -- no casting table lookup made */
98  AnyAtomicType::Ptr castAsNoCheck(AtomicObjectType targetIndex, const XMLCh* targetURI, const XMLCh* targetType,
99  const DynamicContext* context) const;
100 
101  /* If possible, cast this type to the target type -- not virtual, this is the single entry point for casting */
102  AnyAtomicType::Ptr castAs(AtomicObjectType targetIndex, const XMLCh* targetURI, const XMLCh* targetType,
103  const DynamicContext* context) const;
104 
105  /* Test if this type can be cast to the target type */
106  virtual bool castable(AtomicObjectType targetIndex, const XMLCh* targetURI, const XMLCh* targetType,
107  const DynamicContext* context) const;
108 
109  /* returns the XMLCh* (canonical) representation of this type */
110  virtual const XMLCh* asString(const DynamicContext* context) const = 0;
111 
112  /* returns true if the two objects are equal (whatever that means
113  * in the context of the datatype), false otherwise */
114  virtual bool equals(const AnyAtomicType::Ptr &target, const DynamicContext* context) const = 0;
115 
116  /* Returns true if this typeName and uri match the given typeName and uri */
117  virtual bool isOfType(const XMLCh* targetURI, const XMLCh* targetType, const DynamicContext* context) const;
118 
119  /* Returns true if this typeName and uri match the given typeName and uri,
120  * or if any of this type's parents match the given typeName and uri */
121  virtual bool isInstanceOfType(const XMLCh* targetURI, const XMLCh* targetType, const StaticContext* context) const;
122 
123  virtual void typeToBuffer(DynamicContext *context, XERCES_CPP_NAMESPACE_QUALIFIER XMLBuffer &buffer) const;
124 
137  bool castIsSupported(AtomicObjectType targetIndex, const DynamicContext* context) const;
138 
139  virtual AtomicObjectType getPrimitiveTypeIndex() const = 0;
140 
141  static const XMLCh fgDT_ANYATOMICTYPE[];
142 
143 protected:
144  /* internal castAs method. This one is virtual and does the real work */
145  virtual AnyAtomicType::Ptr castAsInternal(AtomicObjectType targetIndex, const XMLCh* targetURI,
146  const XMLCh* targetType, const DynamicContext* context) const;
147 
148 private:
149 
150  //friend class CastTable;
151  //template <class TYPE> friend class DatatypeFactoryTemplate;
152 
153  // class that implements the Casting Table
154  class CastTable {
155  public:
156  CastTable();
157  bool getCell(AtomicObjectType source,
158  AtomicObjectType target) const;
159  private:
160  bool staticCastTable[NumAtomicObjectTypes][NumAtomicObjectTypes];
161  };
162 
163 
164  // reproduction of the XPath2 casting table: http://www.w3.org/TR/xquery-operators/#casting
165  static const CastTable staticCastTable;
166 };
167 
168 #endif
virtual const XMLCh * getTypeName() const =0
virtual bool isAtomicValue() const =0
virtual bool isNode() const =0
Definition: EventHandler.hpp:31
RefCountPointer< const AnyAtomicType > Ptr
Definition: AnyAtomicType.hpp:63
virtual bool isFunction() const =0
Super class of all the reference counted wrappers for Items.
Definition: ReferenceCounted.hpp:58
The parse time static context interface.
Definition: StaticContext.hpp:59
AtomicObjectType
Definition: AnyAtomicType.hpp:36
Definition: AnyAtomicType.hpp:32
Definition: Item.hpp:38
virtual void generateEvents(EventHandler *events, const DynamicContext *context, bool preserveNS=true, bool preserveType=true) const =0
Generate events for this Item to the given EventHandler.
virtual void typeToBuffer(DynamicContext *context, xercesc::XMLBuffer &buffer) const =0
Debug method to output the type of the item in SequenceType notation.
The execution time dynamic context interface.
Definition: DynamicContext.hpp:39
virtual const XMLCh * getTypeURI() const =0
virtual const XMLCh * asString(const DynamicContext *context) const =0