Merge lp:~zorba-coders/zorba/bug905035 into lp:zorba

Proposed by Matthias Brantner on 2012-01-11
Status: Superseded
Proposed branch: lp:~zorba-coders/zorba/bug905035
Merge into: lp:zorba
Diff against target: 186 lines (+123/-0)
6 files modified
ChangeLog (+2/-0)
include/zorba/static_context.h (+11/-0)
src/api/staticcontextimpl.cpp (+31/-0)
src/api/staticcontextimpl.h (+3/-0)
test/unit/CMakeLists.txt (+1/-0)
test/unit/static_context.cpp (+75/-0)
To merge this branch: bzr merge lp:~zorba-coders/zorba/bug905035
Reviewer Review Type Date Requested Status
Hybridum (community) 2012-01-11 Approve on 2012-01-14
Rodolfo Ochoa Approve on 2012-01-12
Markos Zaharioudakis 2012-01-11 Pending
Review via email: mp+88271@code.launchpad.net

This proposal has been superseded by a proposal from 2012-01-17.

Commit Message

implemented StaticContext::getDeclaredPrefixes to resolve bug #905035

Description of the Change

implemented StaticContext::getDeclaredPrefixes to resolve bug #905035

To post a comment you must log in.
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue job bug905035-2012-01-11T20-48-04.305Z is finished. The final status was:

All tests succeeded!

Zorba Build Bot (zorba-buildbot) wrote :

Voting does not meet specified criteria. Required: Approve > 1, Disapprove < 1. Got: 2 Pending.

Chris Hillery (ceejatec) wrote :

Would it be better to have StaticContext::getNamespaceBindings(), rather than getDeclaredPrefixes()? That would allow users to get both the prefixes and the URIs they are bound to in one step. It would also be parallel with the new Item::getNamespaceBindings() method (and could use the same NsBindings typedef), and parallel with the existing static_context::get_namespace_bindings() method that is used internally.

Rodolfo Ochoa (rodolfo-ochoa) wrote :

How hard is to get a zorba iterator instead?

Chris Hillery (ceejatec) wrote :

IMHO a Zorba iterator wouldn't be the appropriate way to return this information, since it would require wrapping each prefix into an Item (which the end-user would probably just call getStringValue() on anyway).

Rodolfo Ochoa (rodolfo-ochoa) wrote :

For API purposes avoid STL usage like std::vector<string>, instead try to use Zorba Classes, like Iterator, I'm having difficulties trying to use STL on other languages.

Rodolfo Ochoa (rodolfo-ochoa) wrote :

It's fine, just FYI, this wouldn't work on Ruby, any usage of vectors from STL are excluded from Ruby.

review: Approve
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue job bug905035-2012-01-12T22-04-03.62Z is finished. The final status was:

All tests succeeded!

Zorba Build Bot (zorba-buildbot) wrote :

Voting does not meet specified criteria. Required: Approve > 1, Disapprove < 1. Got: 1 Approve, 2 Pending.

Hybridum (hybridum) :
review: Approve
Markos Zaharioudakis (markos-za) wrote :

I think I agree with Chris' comment about having a getNamespaceBindings() method instead. Any reason why it was not done that way?

lp:~zorba-coders/zorba/bug905035 updated on 2012-01-18
10617. By Matthias Brantner on 2012-01-17

merge with trunk

10618. By Matthias Brantner on 2012-01-17

renamed getDeclaredPrefixes to getNamespaceBindings to be consistent with the functions
in the Item class

10619. By Matthias Brantner on 2012-01-18

more efficient implementation of the getNamespaceBindings functions

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ChangeLog'
2--- ChangeLog 2012-01-11 17:30:25 +0000
3+++ ChangeLog 2012-01-17 19:11:30 +0000
4@@ -21,6 +21,8 @@
5 support.
6 * zerr is not predeclared anymore to be http://www.zorba-xquery.com/errors
7 * Added API method Item::getNamespaceBindings().
8+ * Added API method StaticContext::getNamespaceBindings() (see bug #905035)
9+ * Deprecated StaticContext:getNamespaceURIByPrefix()
10
11 version 2.1
12
13
14=== modified file 'include/zorba/static_context.h'
15--- include/zorba/static_context.h 2011-12-21 14:40:33 +0000
16+++ include/zorba/static_context.h 2012-01-17 19:11:30 +0000
17@@ -99,10 +99,21 @@
18 * could be found for the given prefix and an DiagnosticHandler has been
19 * registered.
20 * @throw ZorbaException if an error occured (e.g. no URI could be found for the given prefix).
21+ *
22+ * @deprecated This function is deprecated. Use getNamespaceBindings instead.
23 */
24 virtual String
25 getNamespaceURIByPrefix( const String& aPrefix ) const = 0;
26
27+ /**
28+ * \brief Get the list of all namespace bindings (prefix, uri)
29+ * declared in this and its parent static contexts.
30+ *
31+ * @param aBindings the bindings are added to this list
32+ */
33+ virtual void
34+ getNamespaceBindings( NsBindings& aBindings ) const = 0;
35+
36 /** \brief Set the default element and type namespace
37 * (see http://www.w3.org/TR/xquery/#static_context)
38 *
39
40=== modified file 'src/api/staticcontextimpl.cpp'
41--- src/api/staticcontextimpl.cpp 2012-01-11 17:30:25 +0000
42+++ src/api/staticcontextimpl.cpp 2012-01-17 19:11:30 +0000
43@@ -215,6 +215,37 @@
44 return "";
45 }
46
47+/*******************************************************************************
48+
49+********************************************************************************/
50+void
51+StaticContextImpl::getNamespaceBindings( NsBindings& aBindings ) const
52+{
53+ try
54+ {
55+ store::NsBindings lBindings;
56+ theCtx->get_namespace_bindings(lBindings);
57+
58+ for (store::NsBindings::const_iterator lIter = lBindings.begin();
59+ lIter != lBindings.end(); ++lIter)
60+ {
61+ aBindings.push_back(
62+ std::pair<zorba::String, zorba::String>(
63+ lIter->first.str(),
64+ lIter->second.str()
65+ )
66+ );
67+ }
68+ }
69+ catch (ZorbaException const& e)
70+ {
71+ ZorbaImpl::notifyError(theDiagnosticHandler, e);
72+ }
73+ catch (std::exception const& e)
74+ {
75+ ZorbaImpl::notifyError(theDiagnosticHandler, e.what());
76+ }
77+}
78
79 /*******************************************************************************
80
81
82=== modified file 'src/api/staticcontextimpl.h'
83--- src/api/staticcontextimpl.h 2011-12-21 14:40:33 +0000
84+++ src/api/staticcontextimpl.h 2012-01-17 19:11:30 +0000
85@@ -78,6 +78,9 @@
86
87 String getNamespaceURIByPrefix( const String& prefix ) const;
88
89+ void
90+ getNamespaceBindings( NsBindings& aBindings ) const;
91+
92 bool setDefaultElementAndTypeNamespace( const String& URI );
93
94 String getDefaultElementAndTypeNamespace( ) const;
95
96=== modified file 'test/unit/CMakeLists.txt'
97--- test/unit/CMakeLists.txt 2012-01-11 17:30:25 +0000
98+++ test/unit/CMakeLists.txt 2012-01-17 19:11:30 +0000
99@@ -94,6 +94,7 @@
100 xquery_functions.cpp
101 xmldatamanager.cpp
102 staticcollectionmanager.cpp
103+ static_context.cpp
104 )
105
106 IF (NOT ZORBA_NO_FULL_TEXT)
107
108=== added file 'test/unit/static_context.cpp'
109--- test/unit/static_context.cpp 1970-01-01 00:00:00 +0000
110+++ test/unit/static_context.cpp 2012-01-17 19:11:30 +0000
111@@ -0,0 +1,75 @@
112+/*
113+ * Copyright 2006-2012 The FLWOR Foundation.
114+ *
115+ * Licensed under the Apache License, Version 2.0 (the "License");
116+ * you may not use this file except in compliance with the License.
117+ * You may obtain a copy of the License at
118+ *
119+ * http://www.apache.org/licenses/LICENSE-2.0
120+ *
121+ * Unless required by applicable law or agreed to in writing, software
122+ * distributed under the License is distributed on an "AS IS" BASIS,
123+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
124+ * See the License for the specific language governing permissions and
125+ * limitations under the License.
126+ */
127+
128+#include <cassert>
129+#include <iostream>
130+#include <list>
131+#include <map>
132+
133+#include <sstream>
134+#include <zorba/store_manager.h>
135+#include <zorba/zorba.h>
136+#include <zorba/zorba_exception.h>
137+
138+using namespace std;
139+using namespace zorba;
140+using namespace zorba::locale;
141+
142+bool
143+sctx_test_1(Zorba* const zorba)
144+{
145+ StaticContext_t lSctx = zorba->createStaticContext();
146+
147+ Zorba_CompilerHints_t lHints;
148+
149+ std::stringstream lProlog;
150+ lProlog << "declare namespace foo = 'http://www.example.com';";
151+
152+ lSctx->loadProlog(lProlog.str(), lHints);
153+
154+ NsBindings lBindings;
155+ lSctx->getNamespaceBindings(lBindings);
156+
157+ bool lFooFound = false;
158+
159+ for (NsBindings::const_iterator lIter = lBindings.begin();
160+ lIter != lBindings.end(); ++lIter)
161+ {
162+ std::cout << "prefix: " << lIter->first << " bound to "
163+ << lIter->second << std::endl;
164+
165+ if (lIter->first.compare("foo") == 0)
166+ {
167+ lFooFound = true;
168+ }
169+ }
170+
171+ return lFooFound && lBindings.size() == 6;
172+}
173+
174+int static_context( int argc, char *argv[] ) {
175+ void *const zstore = StoreManager::getStore();
176+ Zorba *const zorba = Zorba::getInstance( zstore );
177+
178+ if (!sctx_test_1(zorba))
179+ return 1;
180+
181+ zorba->shutdown();
182+ StoreManager::shutdownStore( zstore );
183+ return 0;
184+}
185+/* vim:set et sw=2 ts=2: */
186+

Subscribers

People subscribed via source and target branches