ModuleURIResolver not used if set from Initializer

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

ModuleURIResolver not used if set from Initializer

Florent Georges-3
Hi,

First of all, sorry for my previous message, which newline characters
seem to have been removed from.  It seems my good old Yahoo! email box
cannot even be trusted anymore to post on mailing lists.  Here is the
same email again, hopefully with newlines.  Sorry about that.

I have a problem with an Initializer setting a ModuleURIResolver on
the Configuration object.  It seems the resolver is never called.  To
reproduce, here is TestInitializer.java:

    import net.sf.saxon.Configuration;
    import net.sf.saxon.lib.Initializer;
    import javax.xml.transform.stream.StreamSource;
    import net.sf.saxon.lib.ModuleURIResolver;

    public class TestInitializer
            implements Initializer
    {
        @Override
        public void initialize(Configuration config)
        {
            System.err.println("Initialize...");
            config.setModuleURIResolver(new Resolver());
        }

        private static final class Resolver
                implements ModuleURIResolver
        {
            @Override
            public StreamSource[] resolve(String ns, String base, String[] locs)
            {
                System.err.println("Resolve: " + ns + ", " + base);
                return null;
            }
        }
    }

If you compile it with (from within the same dir where the Java file
is, adapt the path to the Saxon JAR on your machine):

    javac -cp .:/path/to/saxon9he.jar TestInitializer.java

Given the following query file in the same dir (named query.xq):

    import module namespace h = "http://example.org/ns/hello";
    h:new-hello('world')

Execute Saxon with (adapt the path to the Saxon JAR):

    java -cp .:/path/to/saxon9he.jar net.sf.saxon.Query \
        -init:TestInitializer query.xq

The output is:

    Initialize...
    Error on line 2 column 1 of query.xq:
      XQST0059 XQuery static error near #...tp://example.org/ns/hello"; <#:
        Cannot locate module for namespace http://example.org/ns/hello
    Static error(s) in query

That is, the initializer is called, setting the ModuleURIResolver on
the configuration object it receives, but the import statement fails
without the resolver being called.

I use Saxon 9.6.0.7 (I can't use 9.7 already, waiting for some other
components to be adapted to Saxon 9.7 first).  But I tested this
example with 9.7.0.1 and it gives the same result.

Did I miss anything?  Is there anything specific to do in order to set
a module URI resolver from within an initializer?

Regards,

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

------------------------------------------------------------------------------
Go from Idea to Many App Stores Faster with Intel(R) XDK
Give your users amazing mobile app experiences with Intel(R) XDK.
Use one codebase in this all-in-one HTML5 development environment.
Design, debug & build mobile apps & 2D/3D high-impact games for multiple OSs.
http://pubads.g.doubleclick.net/gampad/clk?id=254741911&iu=/4140
_______________________________________________
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
|

Re: ModuleURIResolver not used if set from Initializer

Florent Georges-3
To add a bit more to this, the following main program succeeds in
calling the resolver when compiling query.xq (it still fails compiling
because the resolver returns null, but at least it it called, which is
not the case when set through the Initializer):

    import java.io.File;
    import java.io.IOException;
    import javax.xml.transform.stream.StreamSource;
    import net.sf.saxon.Configuration;
    import net.sf.saxon.lib.ModuleURIResolver;
    import net.sf.saxon.s9api.SaxonApiException;
    import net.sf.saxon.s9api.Processor;
    import net.sf.saxon.s9api.Serializer;
    import net.sf.saxon.s9api.XQueryCompiler;
    import net.sf.saxon.s9api.XQueryEvaluator;
    import net.sf.saxon.s9api.XQueryExecutable;

    public class TestQuery
    {
        public static void main(String[] args)
            throws SaxonApiException, IOException
        {
            Configuration config = new Configuration();
            config.setModuleURIResolver(new Resolver());
            Processor proc = new Processor(config);
            XQueryCompiler compiler = proc.newXQueryCompiler();
            XQueryExecutable exec = compiler.compile(new File("query.xq"));
            XQueryEvaluator eval = exec.load();
            Serializer out = new Serializer(System.out);
            eval.run(out);
        }

        private static final class Resolver
                implements ModuleURIResolver
        {
            @Override
            public StreamSource[] resolve(String ns, String base,
String[] locations)
            {
                System.err.println("Resolve: " + ns + ", " + base);
                return null;
            }
        }
    }

Compile it and run it with (adapt path to Saxon):

    javac -cp .:/path/to/saxon9he.jar TestQuery.java
    java -cp .:/path/to/saxon9he.jar TestQuery

So it seems there is really something different only when the module
URI resolver is set from within an initializer...

Regards,

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


On 7 December 2015 at 14:15, Florent Georges wrote:

> Hi,
>
> First of all, sorry for my previous message, which newline characters
> seem to have been removed from.  It seems my good old Yahoo! email box
> cannot even be trusted anymore to post on mailing lists.  Here is the
> same email again, hopefully with newlines.  Sorry about that.
>
> I have a problem with an Initializer setting a ModuleURIResolver on
> the Configuration object.  It seems the resolver is never called.  To
> reproduce, here is TestInitializer.java:
>
>     import net.sf.saxon.Configuration;
>     import net.sf.saxon.lib.Initializer;
>     import javax.xml.transform.stream.StreamSource;
>     import net.sf.saxon.lib.ModuleURIResolver;
>
>     public class TestInitializer
>             implements Initializer
>     {
>         @Override
>         public void initialize(Configuration config)
>         {
>             System.err.println("Initialize...");
>             config.setModuleURIResolver(new Resolver());
>         }
>
>         private static final class Resolver
>                 implements ModuleURIResolver
>         {
>             @Override
>             public StreamSource[] resolve(String ns, String base, String[] locs)
>             {
>                 System.err.println("Resolve: " + ns + ", " + base);
>                 return null;
>             }
>         }
>     }
>
> If you compile it with (from within the same dir where the Java file
> is, adapt the path to the Saxon JAR on your machine):
>
>     javac -cp .:/path/to/saxon9he.jar TestInitializer.java
>
> Given the following query file in the same dir (named query.xq):
>
>     import module namespace h = "http://example.org/ns/hello";
>     h:new-hello('world')
>
> Execute Saxon with (adapt the path to the Saxon JAR):
>
>     java -cp .:/path/to/saxon9he.jar net.sf.saxon.Query \
>         -init:TestInitializer query.xq
>
> The output is:
>
>     Initialize...
>     Error on line 2 column 1 of query.xq:
>       XQST0059 XQuery static error near #...tp://example.org/ns/hello"; <#:
>         Cannot locate module for namespace http://example.org/ns/hello
>     Static error(s) in query
>
> That is, the initializer is called, setting the ModuleURIResolver on
> the configuration object it receives, but the import statement fails
> without the resolver being called.
>
> I use Saxon 9.6.0.7 (I can't use 9.7 already, waiting for some other
> components to be adapted to Saxon 9.7 first).  But I tested this
> example with 9.7.0.1 and it gives the same result.
>
> Did I miss anything?  Is there anything specific to do in order to set
> a module URI resolver from within an initializer?
>
> Regards,
>
> --
> Florent Georges
> http://fgeorges.org/
> http://h2oconsulting.be/

------------------------------------------------------------------------------
Go from Idea to Many App Stores Faster with Intel(R) XDK
Give your users amazing mobile app experiences with Intel(R) XDK.
Use one codebase in this all-in-one HTML5 development environment.
Design, debug & build mobile apps & 2D/3D high-impact games for multiple OSs.
http://pubads.g.doubleclick.net/gampad/clk?id=254741911&iu=/4140
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help