Quantcast

Configure Processor to call fn:collection()

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Configure Processor to call fn:collection()

Florent Georges-3
Hi,

The main class below, when invoked, throws the error "FODC0002: No default
collection has been defined", our own collection finder not even being called
before the error.  The query evaluated, as embedded in the class code, is simply
"collection()".

Using the deprecated setCollectionURIResolver() function gives the same error
(as well as not trying to change either of the finder/resolver at all).

The only dependency to compile and run this class is to have Saxon 9.7 in the
classpath.  Tested with HE 9.7.0.10.

The Java class code:

package saxon;

import net.sf.saxon.Configuration;
import net.sf.saxon.expr.XPathContext;
import net.sf.saxon.lib.CollectionFinder;
import net.sf.saxon.lib.ResourceCollection;
import net.sf.saxon.s9api.Processor;
import net.sf.saxon.s9api.SaxonApiException;
import net.sf.saxon.s9api.XQueryCompiler;
import net.sf.saxon.s9api.XQueryEvaluator;
import net.sf.saxon.s9api.XQueryExecutable;

public class CollectionResolution
{
    public static void main(String[] args)
            throws SaxonApiException
    {
        // the processor
        Processor proc = new Processor(false);

        // set out own collection finder
        Configuration config = proc.getUnderlyingConfiguration();
        config.setCollectionFinder(new CollectionFinder() {
            @Override
            public ResourceCollection findCollection(XPathContext
ctxt, String href) {
                System.err.println("find: " + href);
                return null;
            }
        });

        // compile and evaluate the query
        String query = "collection()";
        XQueryCompiler compiler = proc.newXQueryCompiler();
        XQueryExecutable exe = compiler.compile(query);
        XQueryEvaluator eval = exe.load();
        eval.evaluate();
    }
}

The full stack trace:

Error on line 1 column 1
  FODC0002: No default collection has been defined
Exception in thread "main" net.sf.saxon.s9api.SaxonApiException: No
default collection has been defined
at net.sf.saxon.s9api.XQueryEvaluator.evaluate(XQueryEvaluator.java:437)
at saxon.CollectionResolution.main(CollectionResolution.java:41)
Caused by: net.sf.saxon.trans.XPathException: No default collection
has been defined
at net.sf.saxon.functions.CollectionFn.call(CollectionFn.java:170)
at net.sf.saxon.expr.FunctionCall.iterate(FunctionCall.java:546)
at net.sf.saxon.query.XQueryExpression.iterator(XQueryExpression.java:317)
at net.sf.saxon.s9api.XQueryEvaluator.evaluate(XQueryEvaluator.java:433)
... 1 more

Regards,

--
Florent Georges
http://fgeorges.org/
http://h2oconsulting.be/

------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today. http://sdm.link/xeonphi
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help 
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Configure Processor to call fn:collection()

Michael Kay
To define a default collection, use Configuration.setDefaultCollection(), or set the configuration property FeatureKeys.DEFAULT_COLLECTION. The value is simply a name N, which has the effect that collection() is interpreted as collection(N) - the name N will be passed to the CollectionFinder or CollectionURIResolver to get an actual collection.

(In other words, it's really a default collection name, not a default collection).

The default COLLATION name works in a very similar way.

Michael Kay
Saxonica

> On 6 Nov 2016, at 11:59, Florent Georges <[hidden email]> wrote:
>
> Hi,
>
> The main class below, when invoked, throws the error "FODC0002: No default
> collection has been defined", our own collection finder not even being called
> before the error.  The query evaluated, as embedded in the class code, is simply
> "collection()".
>
> Using the deprecated setCollectionURIResolver() function gives the same error
> (as well as not trying to change either of the finder/resolver at all).
>
> The only dependency to compile and run this class is to have Saxon 9.7 in the
> classpath.  Tested with HE 9.7.0.10.
>
> The Java class code:
>
> package saxon;
>
> import net.sf.saxon.Configuration;
> import net.sf.saxon.expr.XPathContext;
> import net.sf.saxon.lib.CollectionFinder;
> import net.sf.saxon.lib.ResourceCollection;
> import net.sf.saxon.s9api.Processor;
> import net.sf.saxon.s9api.SaxonApiException;
> import net.sf.saxon.s9api.XQueryCompiler;
> import net.sf.saxon.s9api.XQueryEvaluator;
> import net.sf.saxon.s9api.XQueryExecutable;
>
> public class CollectionResolution
> {
>   public static void main(String[] args)
>           throws SaxonApiException
>   {
>       // the processor
>       Processor proc = new Processor(false);
>
>       // set out own collection finder
>       Configuration config = proc.getUnderlyingConfiguration();
>       config.setCollectionFinder(new CollectionFinder() {
>           @Override
>           public ResourceCollection findCollection(XPathContext
> ctxt, String href) {
>               System.err.println("find: " + href);
>               return null;
>           }
>       });
>
>       // compile and evaluate the query
>       String query = "collection()";
>       XQueryCompiler compiler = proc.newXQueryCompiler();
>       XQueryExecutable exe = compiler.compile(query);
>       XQueryEvaluator eval = exe.load();
>       eval.evaluate();
>   }
> }
>
> The full stack trace:
>
> Error on line 1 column 1
> FODC0002: No default collection has been defined
> Exception in thread "main" net.sf.saxon.s9api.SaxonApiException: No
> default collection has been defined
> at net.sf.saxon.s9api.XQueryEvaluator.evaluate(XQueryEvaluator.java:437)
> at saxon.CollectionResolution.main(CollectionResolution.java:41)
> Caused by: net.sf.saxon.trans.XPathException: No default collection
> has been defined
> at net.sf.saxon.functions.CollectionFn.call(CollectionFn.java:170)
> at net.sf.saxon.expr.FunctionCall.iterate(FunctionCall.java:546)
> at net.sf.saxon.query.XQueryExpression.iterator(XQueryExpression.java:317)
> at net.sf.saxon.s9api.XQueryEvaluator.evaluate(XQueryEvaluator.java:433)
> ... 1 more
>
> Regards,
>
> --
> Florent Georges
> http://fgeorges.org/
> http://h2oconsulting.be/
>
> ------------------------------------------------------------------------------
> Developer Access Program for Intel Xeon Phi Processors
> Access to Intel Xeon Phi processor-based developer platforms.
> With one year of Intel Parallel Studio XE.
> Training and support from Colfax.
> Order your platform today. http://sdm.link/xeonphi
> _______________________________________________
> saxon-help mailing list archived at http://saxon.markmail.org/
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/saxon-help 


------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today. http://sdm.link/xeonphi
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help 
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Configure Processor to call fn:collection()

Florent Georges-3
Thank you, Mike.

I see.  So where the CollectionURIResolver was called with null before
9.7, it is called now with whatever has been configured as the default
collection.  Which makes sense, except it is not backward compatible
with code developed for 9.7, even though setCollectionURIResolver()
has been kept for backward compatibility.

So where we had CollectionURIResolver.resolve() containing a test like
"href == null", we now have to replace that with "href.equals(...)",
and get a way to know the URI set on the Configuration object earlier.
If I understood correctly.

For the archives, this is a working example of my earlier example (the
only change is the call to setDefaultCollection):

public static void main(String[] args)
        throws SaxonApiException
{
    Processor proc = new Processor(false);
    Configuration config = proc.getUnderlyingConfiguration();
    config.setCollectionFinder(new CFinder());
    config.setDefaultCollection("http://example.org/default/collection");
    proc
        .newXQueryCompiler()
        .compile("collection()")
        .load()
        .evaluate();
}

private static class CFinder
        implements CollectionFinder
{
    @Override
    public ResourceCollection findCollection(XPathContext ctxt, String href) {
        System.err.println("find: " + href);
        return null;
    }
}

This was very helpful, thank you!

--
Florent Georges
http://fgeorges.org/
http://h2oconsulting.be/


On 6 November 2016 at 16:12, Michael Kay wrote:

> To define a default collection, use Configuration.setDefaultCollection(), or set the configuration property FeatureKeys.DEFAULT_COLLECTION. The value is simply a name N, which has the effect that collection() is interpreted as collection(N) - the name N will be passed to the CollectionFinder or CollectionURIResolver to get an actual collection.
>
> (In other words, it's really a default collection name, not a default collection).
>
> The default COLLATION name works in a very similar way.
>
> Michael Kay
> Saxonica
>
>> On 6 Nov 2016, at 11:59, Florent Georges <[hidden email]> wrote:
>>
>> Hi,
>>
>> The main class below, when invoked, throws the error "FODC0002: No default
>> collection has been defined", our own collection finder not even being called
>> before the error.  The query evaluated, as embedded in the class code, is simply
>> "collection()".
>>
>> Using the deprecated setCollectionURIResolver() function gives the same error
>> (as well as not trying to change either of the finder/resolver at all).
>>
>> The only dependency to compile and run this class is to have Saxon 9.7 in the
>> classpath.  Tested with HE 9.7.0.10.
>>
>> The Java class code:
>>
>> package saxon;
>>
>> import net.sf.saxon.Configuration;
>> import net.sf.saxon.expr.XPathContext;
>> import net.sf.saxon.lib.CollectionFinder;
>> import net.sf.saxon.lib.ResourceCollection;
>> import net.sf.saxon.s9api.Processor;
>> import net.sf.saxon.s9api.SaxonApiException;
>> import net.sf.saxon.s9api.XQueryCompiler;
>> import net.sf.saxon.s9api.XQueryEvaluator;
>> import net.sf.saxon.s9api.XQueryExecutable;
>>
>> public class CollectionResolution
>> {
>>   public static void main(String[] args)
>>           throws SaxonApiException
>>   {
>>       // the processor
>>       Processor proc = new Processor(false);
>>
>>       // set out own collection finder
>>       Configuration config = proc.getUnderlyingConfiguration();
>>       config.setCollectionFinder(new CollectionFinder() {
>>           @Override
>>           public ResourceCollection findCollection(XPathContext
>> ctxt, String href) {
>>               System.err.println("find: " + href);
>>               return null;
>>           }
>>       });
>>
>>       // compile and evaluate the query
>>       String query = "collection()";
>>       XQueryCompiler compiler = proc.newXQueryCompiler();
>>       XQueryExecutable exe = compiler.compile(query);
>>       XQueryEvaluator eval = exe.load();
>>       eval.evaluate();
>>   }
>> }
>>
>> The full stack trace:
>>
>> Error on line 1 column 1
>> FODC0002: No default collection has been defined
>> Exception in thread "main" net.sf.saxon.s9api.SaxonApiException: No
>> default collection has been defined
>> at net.sf.saxon.s9api.XQueryEvaluator.evaluate(XQueryEvaluator.java:437)
>> at saxon.CollectionResolution.main(CollectionResolution.java:41)
>> Caused by: net.sf.saxon.trans.XPathException: No default collection
>> has been defined
>> at net.sf.saxon.functions.CollectionFn.call(CollectionFn.java:170)
>> at net.sf.saxon.expr.FunctionCall.iterate(FunctionCall.java:546)
>> at net.sf.saxon.query.XQueryExpression.iterator(XQueryExpression.java:317)
>> at net.sf.saxon.s9api.XQueryEvaluator.evaluate(XQueryEvaluator.java:433)
>> ... 1 more
>>
>> Regards,
>>
>> --
>> Florent Georges
>> http://fgeorges.org/
>> http://h2oconsulting.be/
>>
>> ------------------------------------------------------------------------------
>> Developer Access Program for Intel Xeon Phi Processors
>> Access to Intel Xeon Phi processor-based developer platforms.
>> With one year of Intel Parallel Studio XE.
>> Training and support from Colfax.
>> Order your platform today. http://sdm.link/xeonphi
>> _______________________________________________
>> saxon-help mailing list archived at http://saxon.markmail.org/
>> [hidden email]
>> https://lists.sourceforge.net/lists/listinfo/saxon-help
>
>
> ------------------------------------------------------------------------------
> Developer Access Program for Intel Xeon Phi Processors
> Access to Intel Xeon Phi processor-based developer platforms.
> With one year of Intel Parallel Studio XE.
> Training and support from Colfax.
> Order your platform today. http://sdm.link/xeonphi
> _______________________________________________
> saxon-help mailing list archived at http://saxon.markmail.org/
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/saxon-help

------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today. http://sdm.link/xeonphi
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help 
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Configure Processor to call fn:collection()

Michael Kay
>
> I see.  So where the CollectionURIResolver was called with null before
> 9.7, it is called now with whatever has been configured as the default
> collection.  Which makes sense, except it is not backward compatible
> with code developed for 9.7, even though setCollectionURIResolver()
> has been kept for backward compatibility.

Yes, sorry, that does seem to be a backwards incompatibility that crept in.
>

Michael Kay
Saxonica


------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today. http://sdm.link/xeonphi
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help 
Loading...