public XQPreparedExpression copyPreparedExpression(XQPreparedExpression expression) throws XQException {
checkNotClosed();
if (!(expression instanceof SaxonXQPreparedExpression)) {
throw new IllegalArgumentException("Supplied expression must be compiled using Saxon");
}
XQueryExpression xqe = ((SaxonXQPreparedExpression)expression).getXQueryExpression();
if (xqe.getExecutable().getConfiguration() != config) {
throw new IllegalArgumentException("Supplied expression must derive from the same XQDataSource");
}
SaxonXQStaticContext sqc = ((SaxonXQPreparedExpression)expression).getSaxonXQStaticContext();
DynamicQueryContext dqc = new DynamicQueryContext(config);
return new SaxonXQPreparedExpression(this, xqe, sqc, dqc);