16 package org.zorbaxquery.api.xqj;
18 import java.util.ArrayList;
19 import java.util.Collection;
20 import java.util.HashMap;
22 import javax.xml.xquery.XQConstants;
23 import javax.xml.xquery.XQException;
24 import javax.xml.xquery.XQItemType;
25 import org.zorbaxquery.api.*;
26 import org.zorbaxquery.api.ZorbaConstants.BoundarySpaceMode;
27 import org.zorbaxquery.api.ZorbaConstants.ConstructionMode;
28 import org.zorbaxquery.api.ZorbaConstants.InheritMode;
29 import org.zorbaxquery.api.ZorbaConstants.OrderEmptyMode;
30 import org.zorbaxquery.api.ZorbaConstants.OrderingMode;
31 import org.zorbaxquery.api.ZorbaConstants.PreserveMode;
83 private StaticContext staticContext;
84 private int scrollability = XQConstants.SCROLLTYPE_FORWARD_ONLY;
85 private int holdability = XQConstants.HOLDTYPE_CLOSE_CURSORS_AT_COMMIT;
86 private int queryLang = XQConstants.LANGTYPE_XQUERY;
87 private int binding = XQConstants.BINDING_MODE_IMMEDIATE;
88 Map<String, String> namespaces =
new HashMap<String, String>();
89 private StringVector uriPaths;
90 private StringVector libPaths;
91 private StringVector modulePaths;
97 String baseURI = null;
98 XQItemType contextItemStaticType = null;
100 return staticContext;
105 staticContext = zorba.createStaticContext();
106 if (uriPaths!=null) {
107 staticContext.setURIPath(uriPaths);
112 staticContext = query.getStaticContext();
113 if (uriPaths!=null) {
114 staticContext.setURIPath(uriPaths);
120 if (staticContext!=null) {
121 staticContext.setURIPath(uriPaths);
126 if (staticContext!=null) {
127 staticContext.setLIBPath(libPaths);
131 modulePaths = aMODPath;
132 if (staticContext!=null) {
133 staticContext.setModulePath(modulePaths);
145 StringPairVector bindings = staticContext.getNamespaceBindings();
146 Collection<String> stringBindings =
new ArrayList<String>();
147 int size= (int) bindings.size();
148 for (
int i=0; i<size; i++) {
149 StringPair pair = bindings.get(i);
150 stringBindings.add(pair.getFirst());
152 return stringBindings.toArray(
new String[0]);
164 isNullXQException(prefix);
165 String result = null;
167 result = staticContext.getNamespaceURIByPrefix(prefix);
168 }
catch (Exception e) {
169 throw new XQException(
"Error getting Namespace URI" + e.getLocalizedMessage());
183 isNullXQException(prefix);
184 isNullXQException(URI);
186 if ((URI.isEmpty()) && (namespaces.containsKey(prefix))) {
187 namespaces.remove(prefix);
188 StaticContext sc = null;
190 sc = query.getStaticContext();
192 sc = zorba.createStaticContext();
194 StringPairVector scNamespaces = sc.getNamespaceBindings();
195 int scNamespacesSize = (int) scNamespaces.size();
197 for (String key: namespaces.keySet()) {
198 Boolean found =
false;
199 for (
int i = 0; i<scNamespacesSize; i++) {
200 StringPair pair = scNamespaces.get(i);
201 if (key.equalsIgnoreCase(pair.getFirst())) {
206 sc.addNamespace(key, namespaces.get(key));
212 staticContext.addNamespace(prefix, URI);
213 namespaces.put(prefix, URI);
215 }
catch (Exception e) {
216 throw new XQException(
"Error declaring namespace on static context:" + e.getLocalizedMessage());
226 return staticContext.getDefaultElementAndTypeNamespace();
236 isNullXQException(URI);
237 staticContext.setDefaultElementAndTypeNamespace(URI);
246 return staticContext.getDefaultFunctionNamespace();
256 isNullXQException(URI);
257 staticContext.setDefaultFunctionNamespace(URI);
268 return contextItemStaticType;
278 contextItemStaticType = xqit;
279 if (xqit instanceof XQItemType) {
281 staticContext.setContextItemStaticType(wrapper.getTypeIdentifier());
291 return staticContext.getDefaultCollation();
301 isNullXQException(URI);
302 staticContext.setDefaultCollation(URI);
311 int result = XQConstants.CONSTRUCTION_MODE_PRESERVE;
312 int mode = staticContext.getConstructionMode();
313 if (mode == ConstructionMode.STRIP_CONSTRUCTION) {
314 result = XQConstants.CONSTRUCTION_MODE_STRIP;
326 if (!((i==XQConstants.CONSTRUCTION_MODE_PRESERVE) || (i==XQConstants.CONSTRUCTION_MODE_STRIP))) {
327 throw new XQException(
"Invalid construction mode.");
329 int mode = ConstructionMode.STRIP_CONSTRUCTION;
330 if (i==XQConstants.CONSTRUCTION_MODE_PRESERVE) {
331 mode = ConstructionMode.PRESERVE_CONSTRUCTION;
333 staticContext.setConstructionMode(mode);
342 int result = XQConstants.ORDERING_MODE_ORDERED;
343 int mode = staticContext.getOrderingMode();
344 if (mode == OrderingMode.UNORDERED) {
345 result = XQConstants.ORDERING_MODE_UNORDERED;
357 if (!((i==XQConstants.ORDERING_MODE_ORDERED) || (i==XQConstants.ORDERING_MODE_UNORDERED))) {
358 throw new XQException(
"Invalid ordering mode.");
360 int mode = OrderingMode.ORDERED;
361 if (i==XQConstants.ORDERING_MODE_UNORDERED) {
362 mode = OrderingMode.UNORDERED;
364 staticContext.setOrderingMode(mode);
373 int result = XQConstants.DEFAULT_ORDER_FOR_EMPTY_SEQUENCES_GREATEST;
374 int order = staticContext.getDefaultOrderForEmptySequences();
375 if (order == OrderEmptyMode.EMPTY_LEAST) {
376 result = XQConstants.DEFAULT_ORDER_FOR_EMPTY_SEQUENCES_LEAST;
388 if (!((i == XQConstants.DEFAULT_ORDER_FOR_EMPTY_SEQUENCES_GREATEST) || (i==XQConstants.DEFAULT_ORDER_FOR_EMPTY_SEQUENCES_LEAST))) {
389 throw new XQException(
"Invalid order specified.");
391 int result = OrderEmptyMode.EMPTY_GREATEST;
392 if (i == XQConstants.DEFAULT_ORDER_FOR_EMPTY_SEQUENCES_LEAST) {
393 result = OrderEmptyMode.EMPTY_LEAST;
395 staticContext.setDefaultOrderForEmptySequences(result);
404 int result = XQConstants.BOUNDARY_SPACE_PRESERVE;
405 int boundary = staticContext.getBoundarySpacePolicy();
406 if (boundary == BoundarySpaceMode.STRIP_SPACE) {
407 result = XQConstants.BOUNDARY_SPACE_STRIP;
419 if (!((i == XQConstants.BOUNDARY_SPACE_PRESERVE) || (i==XQConstants.BOUNDARY_SPACE_STRIP))) {
420 throw new XQException(
"Invalid boundary specified.");
422 int result = BoundarySpaceMode.PRESERVE_SPACE;
423 if (i == XQConstants.BOUNDARY_SPACE_STRIP) {
424 result = BoundarySpaceMode.STRIP_SPACE;
426 staticContext.setBoundarySpacePolicy(result);
435 int result = XQConstants.COPY_NAMESPACES_MODE_NO_PRESERVE;
436 int preserve = staticContext.getCopyNamespacesModePreserve();
437 if (preserve == PreserveMode.PRESERVE) {
438 result = XQConstants.COPY_NAMESPACES_MODE_PRESERVE;
450 if (!((i==XQConstants.COPY_NAMESPACES_MODE_PRESERVE) || (i==XQConstants.COPY_NAMESPACES_MODE_NO_PRESERVE))) {
451 throw new XQException(
"The specified mode is invalid.");
453 int inherit = staticContext.getCopyNamespacesModeInherit();
454 int preserve = PreserveMode.NO_PRESERVE;
455 if (i==XQConstants.COPY_NAMESPACES_MODE_PRESERVE) {
456 preserve = PreserveMode.PRESERVE;
458 staticContext.setCopyNamespacesMode(preserve, inherit);
467 int result = XQConstants.COPY_NAMESPACES_MODE_NO_INHERIT;
468 int inherit = staticContext.getCopyNamespacesModeInherit();
469 if (inherit == InheritMode.INHERIT) {
470 result = XQConstants.COPY_NAMESPACES_MODE_INHERIT;
482 if (!((i==XQConstants.COPY_NAMESPACES_MODE_INHERIT) || (i==XQConstants.COPY_NAMESPACES_MODE_NO_INHERIT))) {
483 throw new XQException(
"The specified mode is invalid.");
485 int preserve = staticContext.getCopyNamespacesModePreserve();
486 int inherit = InheritMode.NO_INHERIT;
487 if (i==XQConstants.COPY_NAMESPACES_MODE_INHERIT) {
488 inherit = InheritMode.INHERIT;
490 staticContext.setCopyNamespacesMode(preserve, inherit);
500 return staticContext.getBaseURI();
513 isNullXQException(URI);
514 staticContext.setBaseURI(URI);
536 if (!((i==XQConstants.BINDING_MODE_DEFERRED) || (i==XQConstants.BINDING_MODE_IMMEDIATE))) {
537 throw new XQException(
"The specified mode is invalid.");
558 if (!((i==XQConstants.HOLDTYPE_HOLD_CURSORS_OVER_COMMIT) || (i==XQConstants.HOLDTYPE_CLOSE_CURSORS_AT_COMMIT))) {
559 throw new XQException (
"Invalid holdability parameter.");
582 if (!((i==XQConstants.LANGTYPE_XQUERY) || (i==XQConstants.LANGTYPE_XQUERYX))) {
583 throw new XQException (
"Invalid holdability parameter.");
595 return scrollability;
606 if (!((i==XQConstants.SCROLLTYPE_FORWARD_ONLY) || (i==XQConstants.SCROLLTYPE_SCROLLABLE))) {
607 throw new XQException (
"Invalid scroll type.");
630 throw new XQException(
"Value can't be negative.");
643 if (lStaticCollectionManager==null) {
646 return lStaticCollectionManager;
649 private void isNullXQException(Object value)
throws XQException {
651 throw new XQException(
"Parameter shouldn't be null");
String getDefaultFunctionNamespace()
Gets the URI of the default function namespace, the empty string if not set.
An ZorbaXQStaticContext represents default values for various XQuery Static Context Components...
void declareNamespace(String prefix, String URI)
Declares a namespace prefix and associates it with a namespace URI.
void setLIBPaths(StringVector aLIBPath)
void setDefaultCollation(String URI)
Sets the URI of the default collation.
void setCopyNamespacesModePreserve(int i)
Sets the preserve part of the copy-namespaces mode in the static context.
void setDefaultElementTypeNamespace(String URI)
Sets the URI of the default element/type namespace, the empty string to make it unspecified.
int getScrollability()
Gets the value of the scrollability property.
ZorbaXQStaticCollectionManager getStaticCollectionManager()
Returns a StaticCollectionManager.
int getCopyNamespacesModeInherit()
Gets the inherit part of the copy-namespaces mode defined in the static context.
String getDefaultElementTypeNamespace()
Gets the URI of the default element/type namespace, the empty string if not set.
int getConstructionMode()
Gets the construction mode defined in the static context.
void setQueryTimeout(int i)
Sets the number of seconds an implementation will wait for a query to execute.
String getBaseURI()
Gets the Base URI, if set in the static context, else the empty string.
void setQueryLanguageTypeAndVersion(int i)
Sets the input query language type and version.
void setOrderingMode(int i)
Sets the ordering mode in the static context.
void setDefaultOrderForEmptySequences(int i)
Sets the default order for empty sequences in the static context.
int getQueryTimeout()
Retrieves the number of seconds an implementation will wait for a query to execute.
void setURIPaths(StringVector aURIPath)
void setContextItemStaticType(XQItemType xqit)
Sets the static type of the context item, specify null to make it unspecified.
The ZorbaXQItemType class represents an item type as defined in XQuery 1.0: An XML Query language...
void setMODPaths(StringVector aMODPath)
int getCopyNamespacesModePreserve()
Gets the preserve part of the copy-namespaces mode defined in the static context. ...
void setBoundarySpacePolicy(int i)
Sets the boundary-space policy in the static context.
int getOrderingMode()
Gets the ordering mode defined in the static context.
String getDefaultCollation()
Gets the URI of the default collation.
void setBaseURI(String URI)
Sets the Base URI in the static context, specify the empty string to make it undefined.
String getNamespaceURI(String prefix)
Retrieves the namespace URI associated with a prefix.
Using the ZorbaXQStaticCollectionManager one can retrieve information about statically declared colle...
void setDefaultFunctionNamespace(String URI)
Sets the URI of the default function namespace, the empty string to make it unspecified.
ZorbaXQStaticContext(Zorba aZorba)
ZorbaXQStaticContext(XQuery aQuery)
int getHoldability()
Gets the value of the holdability property.
XQItemType getContextItemStaticType()
Gets the static type of the context item.
void setScrollability(int i)
Sets the scrollability of the result sequence.
int getBindingMode()
Gets the value of the binding mode property.
void setCopyNamespacesModeInherit(int i)
Sets the inherit part of the copy-namespaces mode in the static context.
int getBoundarySpacePolicy()
Gets the boundary-space policy defined in the static context.
String[] getNamespacePrefixes()
Returns the prefixes of all the statically known namespaces.
void setHoldability(int i)
Sets the holdability property.
void setBindingMode(int i)
Sets the binding mode property.
int getQueryLanguageTypeAndVersion()
Gets the value of the language type and version property.
void setConstructionMode(int i)
Sets the construction mode in the static context.
int getDefaultOrderForEmptySequences()
Gets the default order for empty sequences defined in the static context.
StaticContext getZorbaStaticContext()