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: 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) Approve
Rodolfo Ochoa Approve
Markos Zaharioudakis 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.
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
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!

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

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

Revision history for this message
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.

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

How hard is to get a zorba iterator instead?

Revision history for this message
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).

Revision history for this message
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.

Revision history for this message
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
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
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!

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

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

Revision history for this message
Hybridum (hybridum) :
review: Approve
Revision history for this message
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
10617. By Matthias Brantner

merge with trunk

10618. By Matthias Brantner

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

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-11 17:30:25 +0000
+++ ChangeLog 2012-01-17 19:11:30 +0000
@@ -21,6 +21,8 @@
21 support.21 support.
22 * zerr is not predeclared anymore to be http://www.zorba-xquery.com/errors22 * zerr is not predeclared anymore to be http://www.zorba-xquery.com/errors
23 * Added API method Item::getNamespaceBindings().23 * Added API method Item::getNamespaceBindings().
24 * Added API method StaticContext::getNamespaceBindings() (see bug #905035)
25 * Deprecated StaticContext:getNamespaceURIByPrefix()
2426
25version 2.127version 2.1
2628
2729
=== 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-17 19:11:30 +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/staticcontextimpl.cpp'
--- src/api/staticcontextimpl.cpp 2012-01-11 17:30:25 +0000
+++ src/api/staticcontextimpl.cpp 2012-01-17 19:11:30 +0000
@@ -215,6 +215,37 @@
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
229 for (store::NsBindings::const_iterator lIter = lBindings.begin();
230 lIter != lBindings.end(); ++lIter)
231 {
232 aBindings.push_back(
233 std::pair<zorba::String, zorba::String>(
234 lIter->first.str(),
235 lIter->second.str()
236 )
237 );
238 }
239 }
240 catch (ZorbaException const& e)
241 {
242 ZorbaImpl::notifyError(theDiagnosticHandler, e);
243 }
244 catch (std::exception const& e)
245 {
246 ZorbaImpl::notifyError(theDiagnosticHandler, e.what());
247 }
248}
218249
219/*******************************************************************************250/*******************************************************************************
220251
221252
=== modified file 'src/api/staticcontextimpl.h'
--- src/api/staticcontextimpl.h 2011-12-21 14:40:33 +0000
+++ src/api/staticcontextimpl.h 2012-01-17 19:11:30 +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-17 19:11:30 +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-17 19:11:30 +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