1 /*
2  * Copyright 2006-2008 The FLWOR Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #pragma once
17 #ifndef ZORBA_TYPEMANAGER_H
18 #define ZORBA_TYPEMANAGER_H
19 
20 #include <ostream>
21 #include <zorba/typeident.h>
22 #include <zorba/store_consts.h>
23 #include <zorba/diagnostic_list.h>
24 
25 #include "common/shared_types.h"
26 
27 #include "zorbatypes/rchandle.h"
28 
29 #include "types/typeconstants.h"
30 
31 #include "compiler/parser/query_loc.h"
32 
33 #include "zorbaserialization/class_serializer.h"
34 
35 #include <zorba/store_consts.h>
36 
37 
38 namespace zorba {
39 
40 class NodeTest;
41 class Schema;
42 
43 
44 /***************************************************************************//**
45   A type manager acts as a factory and manager of XQType instances.
46 
47   Multiple type managers may participate in an xquery program, each corresponding
48   to a different xml schema. These type managers are arranged in a tree hierarchy.
49   There is always a root type manager (see root_typemanager.h) that is created
50   during system initialization and manages the built-in types of XQDM. Other
51   type managers are allocated dynamically during the processing of schema import
52   statements inside an xquery program.
53 
54   Each XQType instance has a pointer back to the type manager that created that
55   XQType.
56 ********************************************************************************/
57 class TypeManager : public SimpleRCObject
58 {
59 
60 protected:
61   unsigned int m_level;
62 
63 public:
64   SERIALIZABLE_ABSTRACT_CLASS(TypeManager)
65   SERIALIZABLE_CLASS_CONSTRUCTOR2(TypeManager, SimpleRCObject)
66   void serialize(::zorba::serialization::Archiver& ar);
67 
68 public:
TypeManager(unsigned int level)69   TypeManager(unsigned int level) : m_level(level) { }
70 
~TypeManager()71   virtual ~TypeManager() { }
72 
73   virtual TypeManager* get_parent_type_manager() const = 0;
74 
level()75   virtual unsigned int level() const { return m_level; }
76 
77   virtual void initializeSchema() = 0;
78 
79   virtual void terminateSchema() = 0;
80 
81   virtual Schema* getSchema() const = 0;
82 
83   /* Factory Methods */
84 
85   virtual xqtref_t create_any_type() const = 0;
86 
87   virtual xqtref_t create_untyped_type() const = 0;
88 
89   virtual xqtref_t create_any_simple_type() const = 0;
90 
91   virtual xqtref_t create_empty_type() const = 0;
92 
93   virtual xqtref_t create_none_type() const = 0;
94 
95   virtual xqtref_t create_any_item_type(
96         TypeConstants::quantifier_t q) const = 0;
97 
98   virtual xqtref_t create_any_function_type(
99         TypeConstants::quantifier_t q) const = 0;
100 
101   virtual xqtref_t create_function_type(
102         const std::vector<xqtref_t>& aArgs,
103         const xqtref_t& aReturn,
104         TypeConstants::quantifier_t q) const = 0;
105 
106   virtual xqtref_t create_builtin_atomic_type(
107         store::SchemaTypeCode type_code,
108         TypeConstants::quantifier_t q) const = 0;
109 
110   virtual xqtref_t create_named_atomic_type(
111         store::Item* qname,
112         TypeConstants::quantifier_t q,
113         const QueryLoc& loc,
114         const Error& error = zerr::ZXQP0000_NO_ERROR) const = 0;
115 
116   virtual xqtref_t create_named_type(
117         store::Item* qname,
118         TypeConstants::quantifier_t q,
119         const QueryLoc& loc,
120         const Error& error = zerr::ZXQP0000_NO_ERROR) const = 0;
121 
122   virtual xqtref_t create_structured_item_type(TypeConstants::quantifier_t q) const = 0;
123 
124 #ifdef ZORBA_WITH_JSON
125  virtual xqtref_t create_json_type(
126         store::StoreConsts::JSONItemKind kind,
127         TypeConstants::quantifier_t q) const = 0;
128 #endif
129 
130   virtual xqtref_t create_node_type(
131         store::StoreConsts::NodeKind nodeKind,
132         const store::Item_t& nodeName,
133         const xqtref_t& contentType,
134         TypeConstants::quantifier_t q,
135         bool nillable,
136         bool schematype) const = 0;
137 
138   virtual xqtref_t create_type(
139         const XQType& type,
140         TypeConstants::quantifier_t quantifier) const = 0;
141 
142   virtual xqtref_t create_type_x_quant(
143         const XQType& type,
144         TypeConstants::quantifier_t quantifier) const = 0;
145 
146   virtual xqtref_t create_value_type(
147         const store::Item* item,
148         const QueryLoc& loc = QueryLoc::null) const = 0;
149 
150   virtual xqtref_t create_type(const TypeIdentifier& ident) const = 0;
151 
152 #ifndef ZORBA_NO_XMLSCHEMA
153 
154   virtual xqtref_t create_schema_element_type(
155         const store::Item_t& eName,
156         TypeConstants::quantifier_t quant,
157         const QueryLoc& loc) const = 0;
158 
159   virtual void get_schema_element_typename(
160         const store::Item* elemName,
161         store::Item_t& typeName,
162         const QueryLoc& loc) = 0;
163 
164   virtual xqtref_t create_schema_attribute_type(
165         const store::Item_t& aName,
166         TypeConstants::quantifier_t quant,
167         const QueryLoc& loc) const = 0;
168 
169   virtual void get_schema_attribute_typename(
170         const store::Item* attrName,
171         store::Item_t& typeName,
172         const QueryLoc& loc) = 0;
173 
174 #endif
175 };
176 
177 }
178 
179 #endif /* ZORBA_TYPEMANAGER_H */
180 /*
181  * Local variables:
182  * mode: c++
183  * End:
184  */
185 /* vim:set et sw=2 ts=2: */
186