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-he Show documentation
Show all versions of saxon-he Show documentation
An OSGi bundle for Saxon-HE
package net.sf.saxon.xqj;
import net.sf.saxon.Configuration;
import net.sf.saxon.lib.NamespaceConstant;
import net.sf.saxon.lib.Validation;
import net.sf.saxon.query.StaticQueryContext;
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;
/*@NotNull*/ 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;
/*@Nullable*/ SaxonXQItemType contextItemStaticType = null;
String defaultCollationName = NamespaceConstant.CODEPOINT_COLLATION_URI;
String defaultElementNamespace = "";
String defaultFunctionNamespace = NamespaceConstant.FN;
/**
* Create a SaxonXQStaticContext object, the Saxon implementation of XQStaticContext in XQJ
* @param config the Saxon configuration
*/
public SaxonXQStaticContext(Configuration config) {
this.config = config;
}
/**
* Create a SaxonXQStaticContext object as a copy of another SaxonXQStaticContext object
* @param sc the static context to be copied
*/
public SaxonXQStaticContext(/*@NotNull*/ SaxonXQStaticContext sc) {
this.config = sc.config;
this.bindingMode = sc.bindingMode;
this.holdability = sc.holdability;
this.scrollability = sc.scrollability;
this.namespaces = new HashMap(sc.namespaces);
this.baseURI = sc.baseURI;
this.preserveBoundarySpace = sc.preserveBoundarySpace;
this.constructionModeIsPreserve = sc.constructionModeIsPreserve;
this.inheritNamespaces = sc.inheritNamespaces;
this.preserveNamespaces = sc.preserveNamespaces;
this.emptyLeast = sc.emptyLeast;
this.isOrdered = sc.isOrdered;
this.contextItemStaticType = sc.contextItemStaticType;
this.defaultCollationName = sc.defaultCollationName;
this.defaultElementNamespace = sc.defaultElementNamespace;
this.defaultFunctionNamespace = sc.defaultFunctionNamespace;
}
/**
* Get a new Saxon StaticQueryContext object holding the information held in this
* XQStaticContext
* @return a newly constructed StaticQueryContext object
*/
/*@NotNull*/ protected StaticQueryContext getSaxonStaticQueryContext() {
StaticQueryContext sqc = config.newStaticQueryContext();
sqc.setSchemaAware(config.isLicensedFeature(Configuration.LicenseFeature.SCHEMA_VALIDATION));
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 (Map.Entry e : namespaces.entrySet()) {
sqc.declareNamespace(e.getKey(), e.getValue());
}
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;
}
/*@Nullable*/ 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;
}
/*@NotNull*/ public String[] getNamespacePrefixes() {
String[] result = new String[namespaces.size()];
Iterator iter = namespaces.keySet().iterator();
for (int i=0; i