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

Proposed by Matthias Brantner
Status: Superseded
Proposed branch: lp:~zorba-coders/zorba/bug905035
Merge into: lp:zorba
Diff against target: 211 lines (+131/-1)
7 files modified
ChangeLog (+2/-0)
include/zorba/static_context.h (+11/-0)
src/api/item.cpp (+7/-1)
src/api/staticcontextimpl.cpp (+32/-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
Markos Zaharioudakis Approve
Rodolfo Ochoa Approve
Hybridum Pending
Review via email: mp+88922@code.launchpad.net

This proposal supersedes a proposal from 2012-01-11.

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

Commit message

Implemented StaticContext::getNamespaceBindings to resolve bug #905035.

Description of the change

Implemented StaticContext::getNamespaceBindings to resolve bug #905035. In the same commit, the function getNamespaceURIByPrefix was deprecated because it's superseded by the new function.

To post a comment you must log in.
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote : Posted in a previous version of this proposal
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote : Posted in a previous version of this proposal

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

All tests succeeded!

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote : Posted in a previous version of this proposal

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

Revision history for this message
Chris Hillery (ceejatec) wrote : Posted in a previous version of this proposal

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.

Revision history for this message
Rodolfo Ochoa (rodolfo-ochoa) wrote : Posted in a previous version of this proposal

How hard is to get a zorba iterator instead?

Revision history for this message
Chris Hillery (ceejatec) wrote : Posted in a previous version of this proposal

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).

Revision history for this message
Rodolfo Ochoa (rodolfo-ochoa) wrote : Posted in a previous version of this proposal

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.

Revision history for this message
Rodolfo Ochoa (rodolfo-ochoa) wrote : Posted in a previous version of this proposal

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

review: Approve
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote : Posted in a previous version of this proposal
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote : Posted in a previous version of this proposal

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

All tests succeeded!

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote : Posted in a previous version of this proposal

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

Revision history for this message
Hybridum (hybridum) : Posted in a previous version of this proposal
review: Approve
Revision history for this message
Markos Zaharioudakis (markos-za) wrote : Posted in a previous version of this proposal

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

Revision history for this message
Matthias Brantner (matthias-brantner) wrote :

I have adapted the fix as suggested. However, I'm not sure how to address Rodolfo's issues regarding other language bindings. This seems to be a bigger problem which is present in many places in our api.

Revision history for this message
Rodolfo Ochoa (rodolfo-ochoa) wrote :

I think I can use it like it is now...
BTW: NSBindings class is no on zorba website's documentation

review: Approve
Revision history for this message
Markos Zaharioudakis (markos-za) wrote :

Matthias, the getNamespaceBindings method is rather inefficient as it will copy the actual strings twice. And it should also pre-allocated the space for the returned vector. I don't think this is going to be a major bottleneck, so I have approved the proposal. But in the spirit of "best practices", it is better if it is fixed.

Revision history for this message
Markos Zaharioudakis (markos-za) :
review: Approve
lp:~zorba-coders/zorba/bug905035 updated
10619. By Matthias Brantner

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
=== modified file 'ChangeLog'
--- ChangeLog 2012-01-18 12:18:59 +0000
+++ ChangeLog 2012-01-18 18:13:25 +0000
@@ -22,6 +22,8 @@
22 support.22 support.
23 * zerr is not predeclared anymore to be http://www.zorba-xquery.com/errors23 * zerr is not predeclared anymore to be http://www.zorba-xquery.com/errors
24 * Added API method Item::getNamespaceBindings().24 * Added API method Item::getNamespaceBindings().
25 * Added API method StaticContext::getNamespaceBindings() (see bug #905035)
26 * Deprecated StaticContext:getNamespaceURIByPrefix()
2527
26version 2.128version 2.1
2729
2830
=== modified file 'include/zorba/static_context.h'
--- include/zorba/static_context.h 2011-12-21 14:40:33 +0000
+++ include/zorba/static_context.h 2012-01-18 18:13:25 +0000
@@ -99,10 +99,21 @@
99 * could be found for the given prefix and an DiagnosticHandler has been99 * could be found for the given prefix and an DiagnosticHandler has been
100 * registered.100 * registered.
101 * @throw ZorbaException if an error occured (e.g. no URI could be found for the given prefix).101 * @throw ZorbaException if an error occured (e.g. no URI could be found for the given prefix).
102 *
103 * @deprecated This function is deprecated. Use getNamespaceBindings instead.
102 */104 */
103 virtual String105 virtual String
104 getNamespaceURIByPrefix( const String& aPrefix ) const = 0;106 getNamespaceURIByPrefix( const String& aPrefix ) const = 0;
105107
108 /**
109 * \brief Get the list of all namespace bindings (prefix, uri)
110 * declared in this and its parent static contexts.
111 *
112 * @param aBindings the bindings are added to this list
113 */
114 virtual void
115 getNamespaceBindings( NsBindings& aBindings ) const = 0;
116
106 /** \brief Set the default element and type namespace117 /** \brief Set the default element and type namespace
107 * (see http://www.w3.org/TR/xquery/#static_context)118 * (see http://www.w3.org/TR/xquery/#static_context)
108 *119 *
109120
=== modified file 'src/api/item.cpp'
--- src/api/item.cpp 2012-01-11 17:30:25 +0000
+++ src/api/item.cpp 2012-01-18 18:13:25 +0000
@@ -389,12 +389,18 @@
389389
390 store::NsBindings lStoreBindings;390 store::NsBindings lStoreBindings;
391 m_item->getNamespaceBindings(lStoreBindings, aNsScoping);391 m_item->getNamespaceBindings(lStoreBindings, aNsScoping);
392 aBindings.reserve(aBindings.size() + lStoreBindings.size());
393
392 store::NsBindings::iterator ite = lStoreBindings.begin();394 store::NsBindings::iterator ite = lStoreBindings.begin();
393 store::NsBindings::iterator end = lStoreBindings.end();395 store::NsBindings::iterator end = lStoreBindings.end();
394 for (; ite != end; ++ite) {396 for (; ite != end; ++ite) {
395 zstring& prefix = ite->first;397 zstring& prefix = ite->first;
396 zstring& nsuri = ite->second;398 zstring& nsuri = ite->second;
397 aBindings.push_back(std::pair<String, String>(prefix.str(), nsuri.str()));399 aBindings.push_back(
400 std::pair<String, String>(
401 Unmarshaller::newString(prefix),
402 Unmarshaller::newString(nsuri))
403 );
398 }404 }
399405
400 ITEM_CATCH406 ITEM_CATCH
401407
=== modified file 'src/api/staticcontextimpl.cpp'
--- src/api/staticcontextimpl.cpp 2012-01-11 17:30:25 +0000
+++ src/api/staticcontextimpl.cpp 2012-01-18 18:13:25 +0000
@@ -215,6 +215,38 @@
215 return "";215 return "";
216}216}
217217
218/*******************************************************************************
219
220********************************************************************************/
221void
222StaticContextImpl::getNamespaceBindings( NsBindings& aBindings ) const
223{
224 try
225 {
226 store::NsBindings lBindings;
227 theCtx->get_namespace_bindings(lBindings);
228 aBindings.reserve(aBindings.size() + lBindings.size());
229
230 for (store::NsBindings::const_iterator lIter = lBindings.begin();
231 lIter != lBindings.end(); ++lIter)
232 {
233 aBindings.push_back(
234 std::pair<zorba::String, zorba::String>(
235 Unmarshaller::newString(lIter->first),
236 Unmarshaller::newString(lIter->second)
237 )
238 );
239 }
240 }
241 catch (ZorbaException const& e)
242 {
243 ZorbaImpl::notifyError(theDiagnosticHandler, e);
244 }
245 catch (std::exception const& e)
246 {
247 ZorbaImpl::notifyError(theDiagnosticHandler, e.what());
248 }
249}
218250
219/*******************************************************************************251/*******************************************************************************
220252
221253
=== modified file 'src/api/staticcontextimpl.h'
--- src/api/staticcontextimpl.h 2011-12-21 14:40:33 +0000
+++ src/api/staticcontextimpl.h 2012-01-18 18:13:25 +0000
@@ -78,6 +78,9 @@
7878
79 String getNamespaceURIByPrefix( const String& prefix ) const;79 String getNamespaceURIByPrefix( const String& prefix ) const;
8080
81 void
82 getNamespaceBindings( NsBindings& aBindings ) const;
83
81 bool setDefaultElementAndTypeNamespace( const String& URI );84 bool setDefaultElementAndTypeNamespace( const String& URI );
8285
83 String getDefaultElementAndTypeNamespace( ) const;86 String getDefaultElementAndTypeNamespace( ) const;
8487
=== modified file 'test/unit/CMakeLists.txt'
--- test/unit/CMakeLists.txt 2012-01-11 17:30:25 +0000
+++ test/unit/CMakeLists.txt 2012-01-18 18:13:25 +0000
@@ -94,6 +94,7 @@
94 xquery_functions.cpp94 xquery_functions.cpp
95 xmldatamanager.cpp95 xmldatamanager.cpp
96 staticcollectionmanager.cpp96 staticcollectionmanager.cpp
97 static_context.cpp
97)98)
9899
99IF (NOT ZORBA_NO_FULL_TEXT)100IF (NOT ZORBA_NO_FULL_TEXT)
100101
=== added file 'test/unit/static_context.cpp'
--- test/unit/static_context.cpp 1970-01-01 00:00:00 +0000
+++ test/unit/static_context.cpp 2012-01-18 18:13:25 +0000
@@ -0,0 +1,75 @@
1/*
2 * Copyright 2006-2012 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
17#include <cassert>
18#include <iostream>
19#include <list>
20#include <map>
21
22#include <sstream>
23#include <zorba/store_manager.h>
24#include <zorba/zorba.h>
25#include <zorba/zorba_exception.h>
26
27using namespace std;
28using namespace zorba;
29using namespace zorba::locale;
30
31bool
32sctx_test_1(Zorba* const zorba)
33{
34 StaticContext_t lSctx = zorba->createStaticContext();
35
36 Zorba_CompilerHints_t lHints;
37
38 std::stringstream lProlog;
39 lProlog << "declare namespace foo = 'http://www.example.com';";
40
41 lSctx->loadProlog(lProlog.str(), lHints);
42
43 NsBindings lBindings;
44 lSctx->getNamespaceBindings(lBindings);
45
46 bool lFooFound = false;
47
48 for (NsBindings::const_iterator lIter = lBindings.begin();
49 lIter != lBindings.end(); ++lIter)
50 {
51 std::cout << "prefix: " << lIter->first << " bound to "
52 << lIter->second << std::endl;
53
54 if (lIter->first.compare("foo") == 0)
55 {
56 lFooFound = true;
57 }
58 }
59
60 return lFooFound && lBindings.size() == 6;
61}
62
63int static_context( int argc, char *argv[] ) {
64 void *const zstore = StoreManager::getStore();
65 Zorba *const zorba = Zorba::getInstance( zstore );
66
67 if (!sctx_test_1(zorba))
68 return 1;
69
70 zorba->shutdown();
71 StoreManager::shutdownStore( zstore );
72 return 0;
73}
74/* vim:set et sw=2 ts=2: */
75

Subscribers

People subscribed via source and target branches