Permalink
Browse files

Fixed issue #152 by replacing thread local variable with (threadsafe)…

… singleton registry.
  • Loading branch information...
ndw committed May 7, 2014
1 parent 5133df9 commit e6e1c50a4ea0f2e5023b3e78b062cd2b9df2605e
@@ -47,7 +47,7 @@ protected BaseURI() {
}
public BaseURI(XProcRuntime runtime) {
tl_runtime.set(runtime);
registry.registerRuntime(this, runtime);
}
public StructuredQName getFunctionQName() {
@@ -75,14 +75,20 @@ public boolean dependsOnFocus() {
}
public ExtensionFunctionCall makeCallExpression() {
return new BaseURICall();
return new BaseURICall(this);
}
private class BaseURICall extends ExtensionFunctionCall {
private XProcExtensionFunctionDefinition xdef = null;
public BaseURICall(XProcExtensionFunctionDefinition def) {
xdef = def;
}
public Sequence call(XPathContext xPathContext, Sequence[] sequences) throws XPathException {
String baseURI = null;
XProcRuntime runtime = tl_runtime.get();
XProcRuntime runtime = registry.getRuntime(xdef);
XStep step = runtime.getXProcData().getStep();
// FIXME: this can't be the best way to do this...
// step == null in use-when
@@ -47,7 +47,7 @@ protected Cwd() {
}
public Cwd(XProcRuntime runtime) {
tl_runtime.set(runtime);
registry.registerRuntime(this, runtime);
}
public StructuredQName getFunctionQName() {
@@ -71,12 +71,18 @@ public SequenceType getResultType(SequenceType[] suppliedArgumentTypes) {
}
public ExtensionFunctionCall makeCallExpression() {
return new CwdCall();
return new CwdCall(this);
}
private class CwdCall extends ExtensionFunctionCall {
private XProcExtensionFunctionDefinition xdef = null;
public CwdCall(XProcExtensionFunctionDefinition def) {
xdef = def;
}
public Sequence call(XPathContext xPathContext, Sequence[] sequences) throws XPathException {
XProcRuntime runtime = tl_runtime.get();
XProcRuntime runtime = registry.getRuntime(xdef);
XStep step = runtime.getXProcData().getStep();
// FIXME: this can't be the best way to do this...
// step == null in use-when
@@ -47,7 +47,7 @@ protected IterationPosition() {
}
public IterationPosition(XProcRuntime runtime) {
tl_runtime.set(runtime);
registry.registerRuntime(this, runtime);
}
public StructuredQName getFunctionQName() {
@@ -71,12 +71,18 @@ public SequenceType getResultType(SequenceType[] suppliedArgumentTypes) {
}
public ExtensionFunctionCall makeCallExpression() {
return new IterationPositionCall();
return new IterationPositionCall(this);
}
private class IterationPositionCall extends ExtensionFunctionCall {
private XProcExtensionFunctionDefinition xdef = null;
public IterationPositionCall(XProcExtensionFunctionDefinition def) {
xdef = def;
}
public Sequence call(XPathContext xPathContext, Sequence[] sequences) throws XPathException {
XProcRuntime runtime = tl_runtime.get();
XProcRuntime runtime = registry.getRuntime(xdef);
XProcData data = runtime.getXProcData();
XStep step = data.getStep();
// FIXME: this can't be the best way to do this...
@@ -5,14 +5,11 @@
import com.xmlcalabash.runtime.XStep;
import net.sf.saxon.expr.XPathContext;
import net.sf.saxon.lib.ExtensionFunctionCall;
import net.sf.saxon.lib.ExtensionFunctionDefinition;
import net.sf.saxon.om.Sequence;
import net.sf.saxon.trans.XPathException;
import net.sf.saxon.tree.iter.SingletonIterator;
import net.sf.saxon.value.SequenceType;
import net.sf.saxon.value.Int64Value;
import net.sf.saxon.om.StructuredQName;
import net.sf.saxon.om.SequenceIterator;
import com.xmlcalabash.core.XProcRuntime;
import com.xmlcalabash.core.XProcConstants;
@@ -46,7 +43,7 @@ protected IterationSize() {
}
public IterationSize(XProcRuntime runtime) {
tl_runtime.set(runtime);
registry.registerRuntime(this, runtime);
}
public StructuredQName getFunctionQName() {
@@ -70,12 +67,18 @@ public SequenceType getResultType(SequenceType[] suppliedArgumentTypes) {
}
public ExtensionFunctionCall makeCallExpression() {
return new IterationPositionCall();
return new IterationSizeCall(this);
}
private class IterationPositionCall extends ExtensionFunctionCall {
private class IterationSizeCall extends ExtensionFunctionCall {
private XProcExtensionFunctionDefinition xdef = null;
public IterationSizeCall(XProcExtensionFunctionDefinition def) {
xdef = def;
}
public Sequence call(XPathContext xPathContext, Sequence[] sequences) throws XPathException {
XProcRuntime runtime = tl_runtime.get();
XProcRuntime runtime = registry.getRuntime(xdef);
XStep step = runtime.getXProcData().getStep();
// FIXME: this can't be the best way to do this...
// step == null in use-when
@@ -51,7 +51,7 @@ protected ResolveURI() {
}
public ResolveURI(XProcRuntime runtime) {
tl_runtime.set(runtime);
registry.registerRuntime(this, runtime);
}
public StructuredQName getFunctionQName() {
@@ -79,14 +79,20 @@ public boolean dependsOnFocus() {
}
public ExtensionFunctionCall makeCallExpression() {
return new ResolveURICall();
return new ResolveURICall(this);
}
private class ResolveURICall extends ExtensionFunctionCall {
private XProcExtensionFunctionDefinition xdef = null;
public ResolveURICall(XProcExtensionFunctionDefinition def) {
xdef = def;
}
public Sequence call(XPathContext xPathContext, Sequence[] sequences) throws XPathException {
String relativeURI = sequences[0].head().getStringValue();
XProcRuntime runtime = tl_runtime.get();
XProcRuntime runtime = registry.getRuntime(xdef);
XStep step = runtime.getXProcData().getStep();
// FIXME: this can't be the best way to do this...
// step == null in use-when
@@ -51,7 +51,7 @@ protected StepAvailable() {
}
public StepAvailable(XProcRuntime runtime) {
tl_runtime.set(runtime);
registry.registerRuntime(this, runtime);
}
public StructuredQName getFunctionQName() {
@@ -75,11 +75,16 @@ public SequenceType getResultType(SequenceType[] suppliedArgumentTypes) {
}
public ExtensionFunctionCall makeCallExpression() {
return new StepAvailableCall();
return new StepAvailableCall(this);
}
private class StepAvailableCall extends ExtensionFunctionCall {
private StaticContext staticContext = null;
private XProcExtensionFunctionDefinition xdef = null;
public StepAvailableCall(XProcExtensionFunctionDefinition def) {
xdef = def;
}
public void supplyStaticContext(StaticContext context, int locationId, Expression[] arguments) throws XPathException {
staticContext = context;
@@ -88,7 +93,7 @@ public void supplyStaticContext(StaticContext context, int locationId, Expressio
public Sequence call(XPathContext xPathContext, Sequence[] sequences) throws XPathException {
StructuredQName stepName = null;
XProcRuntime runtime = tl_runtime.get();
XProcRuntime runtime = registry.getRuntime(xdef);
XStep step = runtime.getXProcData().getStep();
// FIXME: this can't be the best way to do this...
// step == null in use-when
@@ -30,7 +30,7 @@ protected SystemProperty() {
}
public SystemProperty(XProcRuntime runtime) {
tl_runtime.set(runtime);
registry.registerRuntime(this, runtime);
}
public StructuredQName getFunctionQName() {
@@ -54,11 +54,16 @@ public SequenceType getResultType(SequenceType[] suppliedArgumentTypes) {
}
public ExtensionFunctionCall makeCallExpression() {
return new SystemPropertyCall();
return new SystemPropertyCall(this);
}
private class SystemPropertyCall extends ExtensionFunctionCall {
private StaticContext staticContext = null;
private StaticContext staticContext = null;
private XProcExtensionFunctionDefinition xdef = null;
public SystemPropertyCall(XProcExtensionFunctionDefinition def) {
xdef = def;
}
public void supplyStaticContext(StaticContext context, int locationId, Expression[] arguments) throws XPathException {
staticContext = context;
@@ -67,7 +72,7 @@ public void supplyStaticContext(StaticContext context, int locationId, Expressio
public Sequence call(XPathContext xPathContext, Sequence[] sequences) throws XPathException {
StructuredQName propertyName = null;
XProcRuntime runtime = tl_runtime.get();
XProcRuntime runtime = registry.getRuntime(xdef);
XStep step = runtime.getXProcData().getStep();
// FIXME: this can't be the best way to do this...
// FIXME: And what, exactly, is this even supposed to be doing!?
@@ -52,7 +52,7 @@ protected ValueAvailable() {
}
public ValueAvailable(XProcRuntime runtime) {
tl_runtime.set(runtime);
registry.registerRuntime(this, runtime);
}
public StructuredQName getFunctionQName() {
@@ -76,11 +76,17 @@ public SequenceType getResultType(SequenceType[] suppliedArgumentTypes) {
}
public ExtensionFunctionCall makeCallExpression() {
return new ValueAvailableCall();
return new ValueAvailableCall(this);
}
private class ValueAvailableCall extends ExtensionFunctionCall {
private StaticContext staticContext = null;
private XProcExtensionFunctionDefinition xdef = null;
public ValueAvailableCall(XProcExtensionFunctionDefinition def) {
xdef = def;
}
public void supplyStaticContext(StaticContext context, int locationId, Expression[] arguments) throws XPathException {
staticContext = context;
@@ -89,7 +95,7 @@ public void supplyStaticContext(StaticContext context, int locationId, Expressio
public Sequence call(XPathContext xPathContext, Sequence[] sequences) throws XPathException {
StructuredQName sVarName = null;
XProcRuntime runtime = tl_runtime.get();
XProcRuntime runtime = registry.getRuntime(xdef);
XStep step = runtime.getXProcData().getStep();
// FIXME: this can't be the best way to do this...
// step == null in use-when
@@ -5,12 +5,9 @@
import com.xmlcalabash.runtime.XStep;
import net.sf.saxon.expr.XPathContext;
import net.sf.saxon.lib.ExtensionFunctionCall;
import net.sf.saxon.lib.ExtensionFunctionDefinition;
import net.sf.saxon.om.Sequence;
import net.sf.saxon.om.SequenceIterator;
import net.sf.saxon.om.StructuredQName;
import net.sf.saxon.trans.XPathException;
import net.sf.saxon.tree.iter.SingletonIterator;
import net.sf.saxon.value.SequenceType;
import net.sf.saxon.value.BooleanValue;
import net.sf.saxon.value.DoubleValue;
@@ -47,7 +44,7 @@ protected VersionAvailable() {
}
public VersionAvailable(XProcRuntime runtime) {
tl_runtime.set(runtime);
registry.registerRuntime(this, runtime);
}
public StructuredQName getFunctionQName() {
@@ -71,12 +68,18 @@ public SequenceType getResultType(SequenceType[] suppliedArgumentTypes) {
}
public ExtensionFunctionCall makeCallExpression() {
return new SystemPropertyCall();
return new VersionAvailableCall(this);
}
private class SystemPropertyCall extends ExtensionFunctionCall {
private class VersionAvailableCall extends ExtensionFunctionCall {
private XProcExtensionFunctionDefinition xdef = null;
public VersionAvailableCall(XProcExtensionFunctionDefinition def) {
xdef = def;
}
public Sequence call(XPathContext xPathContext, Sequence[] sequences) throws XPathException {
XProcRuntime runtime = tl_runtime.get();
XProcRuntime runtime = registry.getRuntime(xdef);
XStep step = runtime.getXProcData().getStep();
// FIXME: this can't be the best way to do this...
// step == null in use-when
@@ -5,12 +5,9 @@
import com.xmlcalabash.runtime.XStep;
import net.sf.saxon.expr.XPathContext;
import net.sf.saxon.lib.ExtensionFunctionCall;
import net.sf.saxon.lib.ExtensionFunctionDefinition;
import net.sf.saxon.om.Sequence;
import net.sf.saxon.om.SequenceIterator;
import net.sf.saxon.om.StructuredQName;
import net.sf.saxon.trans.XPathException;
import net.sf.saxon.tree.iter.SingletonIterator;
import net.sf.saxon.value.SequenceType;
import net.sf.saxon.value.BooleanValue;
import net.sf.saxon.value.DoubleValue;
@@ -47,7 +44,7 @@ protected XPathVersionAvailable() {
}
public XPathVersionAvailable(XProcRuntime runtime) {
tl_runtime.set(runtime);
registry.registerRuntime(this, runtime);
}
public StructuredQName getFunctionQName() {
@@ -71,12 +68,18 @@ public SequenceType getResultType(SequenceType[] suppliedArgumentTypes) {
}
public ExtensionFunctionCall makeCallExpression() {
return new SystemPropertyCall();
return new XPathVersionAvailableCall(this);
}
private class SystemPropertyCall extends ExtensionFunctionCall {
private class XPathVersionAvailableCall extends ExtensionFunctionCall {
private XProcExtensionFunctionDefinition xdef = null;
public XPathVersionAvailableCall(XProcExtensionFunctionDefinition def) {
xdef = def;
}
public Sequence call(XPathContext xPathContext, Sequence[] sequences) throws XPathException {
XProcRuntime runtime = tl_runtime.get();
XProcRuntime runtime = registry.getRuntime(xdef);
XStep step = runtime.getXProcData().getStep();
// FIXME: this can't be the best way to do this...
// step == null in use-when
@@ -1,6 +1,7 @@
package com.xmlcalabash.functions;
import com.xmlcalabash.core.XProcRuntime;
import com.xmlcalabash.util.RuntimeRegistry;
import net.sf.saxon.lib.ExtensionFunctionCall;
import net.sf.saxon.lib.ExtensionFunctionDefinition;
import net.sf.saxon.om.StructuredQName;
@@ -14,13 +15,9 @@
* To change this template use File | Settings | File Templates.
*/
public abstract class XProcExtensionFunctionDefinition extends ExtensionFunctionDefinition {
protected ThreadLocal<XProcRuntime> tl_runtime = new ThreadLocal<XProcRuntime>() {
protected synchronized XProcRuntime initialValue() {
return null;
}
};
protected RuntimeRegistry registry = RuntimeRegistry.getInstance();
public void close() {
tl_runtime.remove();
registry.unregisterRuntime(this);
}
}
Oops, something went wrong.

0 comments on commit e6e1c50

Please sign in to comment.