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_NAMESPACE_CONTEXT_H
18 #define ZORBA_NAMESPACE_CONTEXT_H
19 
20 #include <string>
21 #include <vector>
22 
23 #include "zorbatypes/schema_types.h"
24 #include "zorbatypes/rchandle.h"
25 
26 #include "zorbamisc/ns_consts.h"
27 #include "store/api/item.h"
28 
29 #include "zorbaserialization/class_serializer.h"
30 
31 namespace zorba {
32 
33 class static_context;
34 class namespace_context;
35 
36 typedef rchandle<namespace_context> NamespaceContext_t;
37 
38 
39 class namespace_context : public SimpleRCObject
40 {
41 private:
42   static_context              * m_sctx;
43   rchandle<namespace_context>   m_parent;
44   store::NsBindings             m_bindings;
45 
46 public:
47   SERIALIZABLE_CLASS(namespace_context)
48   SERIALIZABLE_CLASS_CONSTRUCTOR2(namespace_context, SimpleRCObject)
49   void serialize(::zorba::serialization::Archiver& ar);
50 
51 public:
namespace_context(const static_context * sctx)52   namespace_context(const static_context* sctx)
53     :
54     m_sctx(const_cast<static_context*>(sctx))
55   {
56   }
57 
58   namespace_context(const static_context* sctx, store::NsBindings& bindings);
59 
namespace_context(rchandle<namespace_context> parent)60   namespace_context(rchandle<namespace_context> parent)
61     :
62     m_sctx(parent->m_sctx),
63     m_parent(parent)
64   {
65   }
66 
get_parent()67   rchandle<namespace_context> get_parent() const { return m_parent; }
68 
get_context()69   const static_context* get_context() const { return m_sctx; }
70 
71   void bind_ns(const zstring& prefix, const zstring& ns);
72 
getLocalBindings()73   const store::NsBindings& getLocalBindings() const { return m_bindings; }
74 
75   void getAllBindings(store::NsBindings& bindings) const;
76 
77   bool findBinding(const zstring& aPrefix, zstring& aNamespace);
78 };
79 
80 }
81 
82 #endif /* ZORBA_NAMESPACE_CONTEXT_H */
83 /*
84  * Local variables:
85  * mode: c++
86  * End:
87  */
88 /* vim:set et sw=2 ts=2: */
89