net.sf.saxon.xqj.SaxonXQStaticContext Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of saxon Show documentation
Show all versions of saxon Show documentation
Saxon a complete and conformant implementation of the XSLT 2.0, XQuery 1.0, and XPath 2.0 Recommendations published on 23 January 2007 by W3C
The newest version!
package net.sf.saxon.xqj;
import net.sf.saxon.Configuration;
import net.sf.saxon.query.StaticQueryContext;
import net.sf.saxon.om.NamespaceConstant;
import net.sf.saxon.om.Validation;
import javax.xml.xquery.XQConstants;
import javax.xml.xquery.XQException;
import javax.xml.xquery.XQItemType;
import javax.xml.xquery.XQStaticContext;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
/**
* Saxon implementation of the XQJ XQStaticContext interface
*/
public class SaxonXQStaticContext implements XQStaticContext {
private Configuration config;
private int bindingMode = XQConstants.BINDING_MODE_IMMEDIATE;
private int holdability = XQConstants.HOLDTYPE_HOLD_CURSORS_OVER_COMMIT;
private int scrollability = XQConstants.SCROLLTYPE_FORWARD_ONLY;
private Map namespaces = new HashMap();
private String baseURI = "";
boolean preserveBoundarySpace = false;
boolean constructionModeIsPreserve = false;
boolean inheritNamespaces = true;
boolean preserveNamespaces = true;
boolean emptyLeast = true;
boolean isOrdered = true;
SaxonXQItemType contextItemStaticType = null;
String defaultCollationName = NamespaceConstant.CODEPOINT_COLLATION_URI;
String defaultElementNamespace = "";
String defaultFunctionNamespace = NamespaceConstant.FN;
//private StaticQueryContext sqc;
/**
* Create a SaxonXQStaticContext object, the Saxon implementation of XQStaticContext in XQJ
* @param config the Saxon configuration
*/
public SaxonXQStaticContext(Configuration config) {
this.config = config;
}
/**
* Get a new Saxon StaticQueryContext object holding the information held in this
* XQStaticContext
* @return a newly constructed StaticQueryContext object
*/
protected StaticQueryContext getSaxonStaticQueryContext() {
StaticQueryContext sqc = new StaticQueryContext(config);
sqc.setBaseURI(baseURI);
sqc.setConstructionMode(constructionModeIsPreserve ? Validation.PRESERVE : Validation.STRIP);
sqc.setDefaultElementNamespace(defaultElementNamespace);
sqc.setDefaultFunctionNamespace(defaultFunctionNamespace);
sqc.setEmptyLeast(emptyLeast);
sqc.setInheritNamespaces(inheritNamespaces);
sqc.setPreserveBoundarySpace(preserveBoundarySpace);
sqc.setPreserveNamespaces(preserveNamespaces);
if (contextItemStaticType != null) {
sqc.setRequiredContextItemType(contextItemStaticType.getSaxonItemType());
}
for (Iterator iter = namespaces.keySet().iterator(); iter.hasNext();) {
String prefix = (String)iter.next();
String uri = (String)namespaces.get(prefix);
sqc.declareNamespace(prefix, uri);
}
return sqc;
}
public void declareNamespace(String prefix, String uri) throws XQException {
checkNotNull(prefix);
checkNotNull(uri);
if (uri.length() == 0) {
namespaces.remove(prefix);
} else {
namespaces.put(prefix, uri);
}
}
public String getBaseURI() {
return baseURI;
}
public int getBindingMode() {
return bindingMode;
}
public int getBoundarySpacePolicy() {
return preserveBoundarySpace
? XQConstants.BOUNDARY_SPACE_PRESERVE
: XQConstants.BOUNDARY_SPACE_STRIP;
}
public int getConstructionMode() {
return constructionModeIsPreserve
? XQConstants.CONSTRUCTION_MODE_PRESERVE
: XQConstants.CONSTRUCTION_MODE_STRIP;
}
public XQItemType getContextItemStaticType() {
return contextItemStaticType;
}
public int getCopyNamespacesModeInherit() {
return inheritNamespaces ?
XQConstants.COPY_NAMESPACES_MODE_INHERIT :
XQConstants.COPY_NAMESPACES_MODE_NO_INHERIT;
}
public int getCopyNamespacesModePreserve() {
return preserveNamespaces ?
XQConstants.COPY_NAMESPACES_MODE_PRESERVE :
XQConstants.COPY_NAMESPACES_MODE_NO_PRESERVE;
}
public String getDefaultCollation() {
return defaultCollationName;
}
public String getDefaultElementTypeNamespace() {
return defaultElementNamespace;
}
public String getDefaultFunctionNamespace() {
return defaultFunctionNamespace;
}
public int getDefaultOrderForEmptySequences() {
return emptyLeast ?
XQConstants.DEFAULT_ORDER_FOR_EMPTY_SEQUENCES_LEAST :
XQConstants.DEFAULT_ORDER_FOR_EMPTY_SEQUENCES_GREATEST;
}
public String[] getNamespacePrefixes() {
String[] result = new String[namespaces.size()];
Iterator iter = namespaces.keySet().iterator();
for (int i=0; i