Class cast exception?

View: New views
20 Messages — Rating Filter:   Alert me  
< Prev | 1 - 2 | Next >

Class cast exception?

by Norman Walsh :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

My code for walking over a tree finding matching nodes works for
elements, but causes a class cast exception when the match pattern
includes an attribute test. The heart of the problem seems to be
an attempt to treat an attribute as an AtomicValue.

 java.lang.ClassCastException: net.sf.saxon.tinytree.TinyAttributeImpl
 at net.sf.saxon.expr.GeneralComparison.effectiveBooleanValue(GeneralComparison.java:525)
 at net.sf.saxon.pattern.LocationPathPattern.internalMatches(LocationPathPattern.java:501)
 at net.sf.saxon.pattern.LocationPathPattern.matches(LocationPathPattern.java:413)
 at org.xproc.util.ProcessMatch.traverse(ProcessMatch.java:142)
 at org.xproc.util.ProcessMatch.traverse(ProcessMatch.java:186)
 at org.xproc.util.ProcessMatch.traverse(ProcessMatch.java:156)
 at org.xproc.util.ProcessMatch.match(ProcessMatch.java:131)
 at org.xproc.util.ProcessMatchTest.testMatch1(ProcessMatchTest.java:54)

Probably something stupid on my part, but I'm not seeing it.

                                        Be seeing you,
                                          norm

--
Norman Walsh <ndw@...> | Is sloppiness in speech caused by
http://nwalsh.com/            | ignorance or apathy? I don't know and I
                              | don't care.--William Safire


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
saxon-help@...
https://lists.sourceforge.net/lists/listinfo/saxon-help 

attachment0 (191 bytes) Download Attachment

Re: Class cast exception?

by Michael Kay :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

This suggests that code for atomizing an attribute node has not been added
to the expression tree, which in turn suggests that a predicate in the
pattern has not been type-checked. To do this you need to call the
Pattern.analyze() method at compile time.

I can't offer any guarantee that the Saxon code for patterns will work
outside an XSLT environment - it hasn't been tested. For example, it's not
impossible that there's code that assumes that the static context is an
ExpressionContext object. I'm happy to make reasonable efforts to get it to
work for you, but it might not be right first time.

As well as type-checking the pattern you may need to allocate slots for
variables used within the pattern. These can arise not just for user-defined
variables (e.g. match="fdiv[some $x in * satisfies ....]) but also for
variables introduced by the Saxon optimizer. You then also need to ensure
when evaluating the pattern that the current stack-frame in the XPathContext
object has sufficient space for these variables. I'm afraid this is all
rather low-level, based on the erroneous assumption that patterns would not
be used directly by user applications.

Michael Kay
http://www.saxonica.com/

> -----Original Message-----
> From: saxon-help-bounces@...
> [mailto:saxon-help-bounces@...] On Behalf
> Of Norman Walsh
> Sent: 19 May 2008 09:29
> To: saxon-help@...
> Subject: [saxon] Class cast exception?
>
> My code for walking over a tree finding matching nodes works
> for elements, but causes a class cast exception when the
> match pattern includes an attribute test. The heart of the
> problem seems to be an attempt to treat an attribute as an
> AtomicValue.
>
>  java.lang.ClassCastException: net.sf.saxon.tinytree.TinyAttributeImpl
>  at
> net.sf.saxon.expr.GeneralComparison.effectiveBooleanValue(Gene
> ralComparison.java:525)
>  at
> net.sf.saxon.pattern.LocationPathPattern.internalMatches(Locat
> ionPathPattern.java:501)
>  at
> net.sf.saxon.pattern.LocationPathPattern.matches(LocationPathP
> attern.java:413)
>  at org.xproc.util.ProcessMatch.traverse(ProcessMatch.java:142)
>  at org.xproc.util.ProcessMatch.traverse(ProcessMatch.java:186)
>  at org.xproc.util.ProcessMatch.traverse(ProcessMatch.java:156)
>  at org.xproc.util.ProcessMatch.match(ProcessMatch.java:131)
>  at
> org.xproc.util.ProcessMatchTest.testMatch1(ProcessMatchTest.java:54)
>
> Probably something stupid on my part, but I'm not seeing it.
>
>                                         Be seeing you,
>                                           norm
>
> --
> Norman Walsh <ndw@...> | Is sloppiness in speech caused by
> http://nwalsh.com/            | ignorance or apathy? I don't
> know and I
>                               | don't care.--William Safire
>


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
saxon-help@...
https://lists.sourceforge.net/lists/listinfo/saxon-help 

Re: Class cast exception?

by Norman Walsh :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

/ "Michael Kay" <mike@...> was heard to say:
| This suggests that code for atomizing an attribute node has not been added
| to the expression tree, which in turn suggests that a predicate in the
| pattern has not been type-checked. To do this you need to call the
| Pattern.analyze() method at compile time.
|
| I can't offer any guarantee that the Saxon code for patterns will work
| outside an XSLT environment - it hasn't been tested. For example, it's not
| impossible that there's code that assumes that the static context is an
| ExpressionContext object. I'm happy to make reasonable efforts to get it to
| work for you, but it might not be right first time.

I appreciate your willingness to help. I understand that I'm off the
beaten track.

| As well as type-checking the pattern you may need to allocate slots for
| variables used within the pattern. These can arise not just for user-defined
| variables (e.g. match="fdiv[some $x in * satisfies ....]) but also for
| variables introduced by the Saxon optimizer. You then also need to ensure
| when evaluating the pattern that the current stack-frame in the XPathContext
| object has sufficient space for these variables. I'm afraid this is all
| rather low-level, based on the erroneous assumption that patterns would not
| be used directly by user applications.

Uhm. Ok. I think I understand some of that :-)

I added the call to pattern.analyze() and now the code does work for
my very small number of simple tests. Here it is:

  IndependentContext staticContext = new IndependentContext(config);

  // FIXME: actually find the real namespace bindings!
  staticContext.declareNamespace("p", XProcConstants.NS_XPROC);

  exec = new Executable(config);
  Pattern pattern = Pattern.make(matchPattern, staticContext, exec);
  ExpressionVisitor visitor = new ExpressionVisitor();
  pattern = pattern.analyze(visitor,null); // I don't know the type

  destination = new XdmDestination();
  receiver = destination.getReceiver(config);
  PipelineConfiguration pipe = controller.makePipelineConfiguration();
  receiver.setPipelineConfiguration(pipe);
  receiver.open();
  traverse(doc, pattern); // this code walks over the tree calling pattern.match
  receiver.close();

I'm open to suggestions for what I ought to change. I'll report new errors
as and when they arise. :-)

                                        Be seeing you,
                                          norm

--
Norman Walsh <ndw@...> | There is no cure for birth and death
http://nwalsh.com/            | save to enjoy the interval.--George
                              | Santayana


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
saxon-help@...
https://lists.sourceforge.net/lists/listinfo/saxon-help 

attachment0 (191 bytes) Download Attachment

Re: Class cast exception?

by Michael Kay :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

> I added the call to pattern.analyze() and now the code does
> work for my very small number of simple tests. Here it is:
>
>   IndependentContext staticContext = new IndependentContext(config);
>
>   // FIXME: actually find the real namespace bindings!
>   staticContext.declareNamespace("p", XProcConstants.NS_XPROC);
>
>   exec = new Executable(config);
>   Pattern pattern = Pattern.make(matchPattern, staticContext, exec);

Then in principle you should do

int slots = pattern.allocateSlots(staticContext, 0);

>   ExpressionVisitor visitor = new ExpressionVisitor();

I'd advise using the factory method:

ExpressionVisitor visitor = ExpressionVisitor.make(staticContext);
visitor.setExecutable(exec);

>   traverse(doc, pattern); // this code walks over the tree

and in traverse(), when evaluating the pattern, use an XPathContextMajor on
which you have done

context.setStackFrame(new SlotManager(slots), new
ValueRepresentation[slots]);

(the variableMap in the SlotManager will be uninitialized, but it's only
there for use by debuggers.)

However, there's a snag: allocateSlots() requires the StaticContext to be an
ExpressionContext (which is the XSLT implementation of a StaticContext); and
an ExpressionContext requires there to be a stylesheet tree in the
background.

If you don't allocate slots then any pattern containing a variable reference
is going to fail. You can probably survive with that as a beta-release
restriction, but it's not nice. As far as I can see this is the only
dependency of patterns on the XSLT engine, so it would be nice to abstract
it away. I think in fact that's not hard to do: it essentially involves
changing the method in LocationPathPattern to

    public int allocateSlots(StaticContext env, SlotManager slotManager, int
nextFree) {
        // See tests cnfr23, idky239, match54, group018
        // SlotManager slotManager =
env.getStyleElement().getContainingSlotManager();
        if (variableBinding != null) {
            nextFree = ExpressionTool.allocateSlots(variableBinding,
nextFree, slotManager);
        }
        for (int i = 0; i < numberOfFilters; i++) {
            nextFree = ExpressionTool.allocateSlots(filters[i], nextFree,
slotManager);
        }
        if (parentPattern instanceof LocationPathPattern) {
            nextFree = parentPattern.allocateSlots(env, nextFree);
        }
        if (ancestorPattern instanceof LocationPathPattern) {
            nextFree = ancestorPattern.allocateSlots(env, nextFree);
        }
        //
env.getStyleElement().getPrincipalStylesheet().allocatePatternSlots(nextFree
);
        return nextFree;
    }
(with obvious changes to the other implementations of the method)

and making the call to
getPrincipalStylesheet().allocatePatternSlots(nextFree) from the calling
(XSLT-specific) code.


Michael Kay
http://www.saxonica.com/ 


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
saxon-help@...
https://lists.sourceforge.net/lists/listinfo/saxon-help 

Re: Class cast exception?

by Michael Kay :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

> I think in fact that's not hard to do: it essentially
> involves changing the method in LocationPathPattern ...

OK, I've applied that change on the 9.1 branch and it seems trouble-free.

Michael Kay
http://www.saxonica.com/ 


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
saxon-help@...
https://lists.sourceforge.net/lists/listinfo/saxon-help 

SQL extension and MSSQL Server JDBC driver

by Houghton,Andrew :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I'm having a problem trying to get a basic XSL to work using the SQL extensions.  I keep getting:

SXSQ0003: JDBC Connection Failure: com.microsoft.sqlserver.jdbc.SQLServerDriver

I installed the Microsoft SQL server JDBC driver and placed the sqljdbc.jar file on my class path.  Then I hacked the example in the Saxon documentation to look like the following with the driver and database specified per the Microsoft SQL server JDBC driver help file.  SQL Express is running and I can use SQL Server Management Studio to run queries against the database.  Can anyone see anything that I might have overlooked?

Thanks, Andy.

<xsl:transform version="2.0"
  exclude-result-prefixes="java saxon xsd xsi xsl"
  extension-element-prefixes="saxon sql"

  xmlns:java="http://saxon.sf.net/java-type"
  xmlns:saxon="http://saxon.sf.net/"
  xmlns:sql="java://net.sf.saxon.sql.SQLElementFactory"

  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

>

  <xsl:output method="text" media-type="text/plain" encoding="utf-8" />
  <xsl:preserve-space elements="*" />

  <xsl:param name="jdbc.driver"   as="xsd:string" select="string('com.microsoft.sqlserver.jdbc.SQLServerDriver')" />

  <xsl:param name="jdbc.database" as="xsd:string" select="string('jdbc:sqlserver://localhost\SQLEXPRESS:1433;serverName=localhost;instanceName=SQLEXPRESS;portNumber=1433;databaseName=Test Ideas;integratedSecurity=false;sendStringParametersAsUnicode=true;workstationID=localhost')" />

  <xsl:param name="jdbc.user" as="xsd:string" select="string('')" />
  <xsl:param name="jdbc.pass" as="xsd:string" select="string('')" />
 
  <xsl:template match="/">
    <xsl:choose>

      <xsl:when test="element-available('sql:connect')">

        <xsl:variable name="sql.conn" as="java:java.sql.Connection">
          <sql:connect driver="{$jdbc.driver}" database="{$jdbc.database}" user="{$jdbc.user}" password="{$jdbc.pass}">
            <xsl:fallback>
              <xsl:message terminate="yes">SQL extenstions are not installed</xsl:message>
            </xsl:fallback>
          </sql:connect>
        </xsl:variable>

        <xsl:variable name="sql.employees" as="element()*">
          <sql:query connection="$sql.conn" table="dbo.Employees" column="*" />
        </xsl:variable>

        <xsl:sequence select="$sql.employees" />
       
        <sql:close connection="$sql.conn" />
       
      </xsl:when>

      <xsl:otherwise>
        <xsl:message terminate="yes">sql:connect element is not available</xsl:message>
      </xsl:otherwise>

    </xsl:choose>
  </xsl:template>
 
</xsl:transform>


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
saxon-help@...
https://lists.sourceforge.net/lists/listinfo/saxon-help 

Re: SQL extension and MSSQL Server JDBC driver

by Michael Kay :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Sorry, I can't help very much on this one. I'd suggest taking a look at the
code in net.sf.saxon.sql.SQLConnect.java, and trying to write a Java class
that follows the same logic; see if you get a similar failure and whether
you can solve it outside the Saxon environment.

Michael Kay
http://www.saxonica.com/ 

> -----Original Message-----
> From: saxon-help-bounces@...
> [mailto:saxon-help-bounces@...] On Behalf
> Of Houghton,Andrew
> Sent: 20 May 2008 20:01
> To: Mailing list for the SAXON XSLT and XQuery processor
> Subject: [saxon] SQL extension and MSSQL Server JDBC driver
>
> I'm having a problem trying to get a basic XSL to work using
> the SQL extensions.  I keep getting:
>
> SXSQ0003: JDBC Connection Failure:
> com.microsoft.sqlserver.jdbc.SQLServerDriver
>
> I installed the Microsoft SQL server JDBC driver and placed
> the sqljdbc.jar file on my class path.  Then I hacked the
> example in the Saxon documentation to look like the following
> with the driver and database specified per the Microsoft SQL
> server JDBC driver help file.  SQL Express is running and I
> can use SQL Server Management Studio to run queries against
> the database.  Can anyone see anything that I might have overlooked?
>
> Thanks, Andy.
>
> <xsl:transform version="2.0"
>   exclude-result-prefixes="java saxon xsd xsi xsl"
>   extension-element-prefixes="saxon sql"
>
>   xmlns:java="http://saxon.sf.net/java-type"
>   xmlns:saxon="http://saxon.sf.net/"
>   xmlns:sql="java://net.sf.saxon.sql.SQLElementFactory"
>
>   xmlns:xsd="http://www.w3.org/2001/XMLSchema"
>   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>
> >
>
>   <xsl:output method="text" media-type="text/plain"
> encoding="utf-8" />
>   <xsl:preserve-space elements="*" />
>
>   <xsl:param name="jdbc.driver"   as="xsd:string"
> select="string('com.microsoft.sqlserver.jdbc.SQLServerDriver')" />
>
>   <xsl:param name="jdbc.database" as="xsd:string"
> select="string('jdbc:sqlserver://localhost\SQLEXPRESS:1433;ser
> verName=localhost;instanceName=SQLEXPRESS;portNumber=1433;data
> baseName=Test
> Ideas;integratedSecurity=false;sendStringParametersAsUnicode=t
> rue;workstationID=localhost')" />
>
>   <xsl:param name="jdbc.user" as="xsd:string" select="string('')" />
>   <xsl:param name="jdbc.pass" as="xsd:string" select="string('')" />
>  
>   <xsl:template match="/">
>     <xsl:choose>
>
>       <xsl:when test="element-available('sql:connect')">
>
>         <xsl:variable name="sql.conn" as="java:java.sql.Connection">
>           <sql:connect driver="{$jdbc.driver}"
> database="{$jdbc.database}" user="{$jdbc.user}"
> password="{$jdbc.pass}">
>             <xsl:fallback>
>               <xsl:message terminate="yes">SQL extenstions
> are not installed</xsl:message>
>             </xsl:fallback>
>           </sql:connect>
>         </xsl:variable>
>
>         <xsl:variable name="sql.employees" as="element()*">
>           <sql:query connection="$sql.conn"
> table="dbo.Employees" column="*" />
>         </xsl:variable>
>
>         <xsl:sequence select="$sql.employees" />
>        
>         <sql:close connection="$sql.conn" />
>        
>       </xsl:when>
>
>       <xsl:otherwise>
>         <xsl:message terminate="yes">sql:connect element is
> not available</xsl:message>
>       </xsl:otherwise>
>
>     </xsl:choose>
>   </xsl:template>
>  
> </xsl:transform>
>
>
> --------------------------------------------------------------
> -----------
> This SF.net email is sponsored by: Microsoft Defy all
> challenges. Microsoft(R) Visual Studio 2008.
> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> _______________________________________________
> saxon-help mailing list archived at
> http://saxon.markmail.org/ saxon-help@...
> https://lists.sourceforge.net/lists/listinfo/saxon-help 


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
saxon-help@...
https://lists.sourceforge.net/lists/listinfo/saxon-help 

Re: SQL extension and MSSQL Server JDBC driver

by Houghton,Andrew :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

> From: saxon-help-bounces@... [mailto:saxon-help-
> bounces@...] On Behalf Of Michael Kay
> Sent: Tuesday, May 20, 2008 4:43 PM
> To: 'Mailing list for the SAXON XSLT and XQuery processor'
> Subject: Re: [saxon] SQL extension and MSSQL Server JDBC driver
>
> Sorry, I can't help very much on this one. I'd suggest taking a look at
> the
> code in net.sf.saxon.sql.SQLConnect.java, and trying to write a Java
> class
> that follows the same logic; see if you get a similar failure and
> whether
> you can solve it outside the Saxon environment.
>
> Michael Kay
> http://www.saxonica.com/

I copied a sample from the Microsoft documentation and hacked it just a little.  The java program runs and outputs the correct data.  However, I'm still getting the JDBC connection failure when running the XSL with Saxon.  So as far as I can tell, everything in my environment is working through Java and Microsoft tools, but not through Saxon.  Obviously, there is something missing from this puzzle, but I'm stumpped.  Any other suggestions?

Thanks, Andy.


Java program:

import java.sql.*;

public class connectURL {

    public static void main(String[] args) {

      // Create a variable for the connection string.
        String connectionUrl = "" +
                               "jdbc:sqlserver://houghton.oa.oclc.org:1443" +
                               ";user=saxon;password=*******" +
                               ";databaseName=prototype";

      // Declare the JDBC objects.
        Connection con = null;
        Statement stmt = null;
        ResultSet rs = null;

        try {
         // Establish the connection.
            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
            con = DriverManager.getConnection(connectionUrl);

         // Create and execute an SQL statement that returns some data.
            String SQL = "SELECT * FROM dbo.Employees";
            stmt = con.createStatement();
            rs = stmt.executeQuery(SQL);

         // Iterate through the data in the result set and display it.
            while (rs.next()) {
                System.out.println(rs.getString(1) + "\t" + rs.getString(2) + "\t" + rs.getString(3) + "\t" + rs.getString(4));
            }
        }

      // Handle any errors that may have occurred.
        catch (Exception e) {
            e.printStackTrace();
        }
        finally {
            if (rs != null) try { rs.close(); } catch(Exception e) {}
            if (stmt != null) try { stmt.close(); } catch(Exception e) {}
            if (con != null) try { con.close(); } catch(Exception e) {}
        }
    }
}

Here is the output from the Java program:
1       null    David   10000.0000
2       1       Eitan   7000.0000
3       1       Ina     7500.0000
4       2       Seraph  5000.0000
5       2       Jiru    5500.0000
6       2       Steve   4500.0000
7       3       Aaron   5000.0000
8       5       Lilach  3500.0000
9       7       Rita    3000.0000
10      5       Sean    3000.0000
11      7       Gabriel 3000.0000
12      9       Emilia  2000.0000
13      9       Michael 2000.0000
14      9       Didi    1500.0000


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
saxon-help@...
https://lists.sourceforge.net/lists/listinfo/saxon-help 

Re: SQL extension and MSSQL Server JDBC driver

by Michael Kay :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

>
>         try {
>          // Establish the connection.
>            
>             Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
>             con = DriverManager.getConnection(connectionUrl);
>

The Saxon code is using

               Class.forName(dbDriverString);
               connection = DriverManager.getConnection(dbString,
userString, pwdString);

See if you can get your Java program working using that connection method,
and then use the same parameter values.

Michael Kay
http://www.saxonica.com/


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
saxon-help@...
https://lists.sourceforge.net/lists/listinfo/saxon-help 

Re: Patterns (was: Class cast exception?)

by Michael Kay :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

For future reference, I have now front-ended the pattern engine with a s9api
interface:

            Processor p = new Processor(false);
            XPathCompiler c = p.newXPathCompiler();
            XPathExecutable e =
c.compilePattern("document-node(element(foo))");
            DocumentBuilder b = p.newDocumentBuilder();
            XdmNode foo = b.build(new StreamSource(new
StringReader("<foo/>")));
            XPathSelector s = e.load();
            s.setContextItem(foo);
            assertTrue(s.effectiveBooleanValue());

avoiding the need for all the low-level calls described previously. The
compiled pattern is treated as a pseudo-expression which returns true if the
context node matches the pattern, false otherwise.

Michael Kay
http://www.saxonica.com/

> -----Original Message-----
> From: saxon-help-bounces@...
> [mailto:saxon-help-bounces@...] On Behalf
> Of Norman Walsh
> Sent: 20 May 2008 18:10
> To: saxon-help@...
> Subject: Re: [saxon] Class cast exception?
>
> / "Michael Kay" <mike@...> was heard to say:
> | This suggests that code for atomizing an attribute node has
> not been
> | added to the expression tree, which in turn suggests that a
> predicate
> | in the pattern has not been type-checked. To do this you
> need to call
> | the
> | Pattern.analyze() method at compile time.
> |
> | I can't offer any guarantee that the Saxon code for
> patterns will work
> | outside an XSLT environment - it hasn't been tested. For
> example, it's
> | not impossible that there's code that assumes that the
> static context
> | is an ExpressionContext object. I'm happy to make
> reasonable efforts
> | to get it to work for you, but it might not be right first time.
>
> I appreciate your willingness to help. I understand that I'm
> off the beaten track.
>
> | As well as type-checking the pattern you may need to allocate slots
> | for variables used within the pattern. These can arise not just for
> | user-defined variables (e.g. match="fdiv[some $x in *
> satisfies ....])
> | but also for variables introduced by the Saxon optimizer. You then
> | also need to ensure when evaluating the pattern that the current
> | stack-frame in the XPathContext object has sufficient space
> for these
> | variables. I'm afraid this is all rather low-level, based on the
> | erroneous assumption that patterns would not be used
> directly by user applications.
>
> Uhm. Ok. I think I understand some of that :-)
>
> I added the call to pattern.analyze() and now the code does
> work for my very small number of simple tests. Here it is:
>
>   IndependentContext staticContext = new IndependentContext(config);
>
>   // FIXME: actually find the real namespace bindings!
>   staticContext.declareNamespace("p", XProcConstants.NS_XPROC);
>
>   exec = new Executable(config);
>   Pattern pattern = Pattern.make(matchPattern, staticContext, exec);
>   ExpressionVisitor visitor = new ExpressionVisitor();
>   pattern = pattern.analyze(visitor,null); // I don't know the type
>
>   destination = new XdmDestination();
>   receiver = destination.getReceiver(config);
>   PipelineConfiguration pipe = controller.makePipelineConfiguration();
>   receiver.setPipelineConfiguration(pipe);
>   receiver.open();
>   traverse(doc, pattern); // this code walks over the tree
> calling pattern.match
>   receiver.close();
>
> I'm open to suggestions for what I ought to change. I'll
> report new errors as and when they arise. :-)
>
>                                         Be seeing you,
>                                           norm
>
> --
> Norman Walsh <ndw@...> | There is no cure for birth and death
> http://nwalsh.com/            | save to enjoy the interval.--George
>                               | Santayana
>


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
saxon-help@...
https://lists.sourceforge.net/lists/listinfo/saxon-help 

Re: SQL extension and MSSQL Server JDBC driver

by Houghton,Andrew :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

> From: saxon-help-bounces@... [mailto:saxon-help-
> bounces@...] On Behalf Of Michael Kay
> Sent: Tuesday, May 20, 2008 7:11 PM
> To: 'Mailing list for the SAXON XSLT and XQuery processor'
> Subject: Re: [saxon] SQL extension and MSSQL Server JDBC driver
>
> >
> >         try {
> >          // Establish the connection.
> >
> >
> Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
> >             con = DriverManager.getConnection(connectionUrl);
> >
>
> The Saxon code is using
>
>                Class.forName(dbDriverString);
>                connection = DriverManager.getConnection(dbString,
> userString, pwdString);
>
> See if you can get your Java program working using that connection
> method,
> and then use the same parameter values.

OK, I changed my Java code to look like this:

        String connectionUrl = "" +
                               "jdbc:sqlserver://localhost:1443" +
                               ";databaseName=prototype";
           // ...
         // Establish the connection.
            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
            con = DriverManager.getConnection(connectionUrl, args[0], args[1]);

and it produces the list of employees in the dbo.Employees table in the database when the user name and password are passed on the command line.  I also went back and changed the XSL program so it looks like:

  <xsl:param name="jdbc.driver"   as="xsd:string" select="string('com.microsoft.sqlserver.jdbc.SQLServerDriver')" />

  <xsl:param name="jdbc.database" as="xsd:string" select="string('jdbc:sqlserver://localhost:1433;databaseName=prototype')" />

  <xsl:param name="jdbc.user" as="xsd:string" select="string('saxon')" />
  <xsl:param name="jdbc.pass" as="xsd:string" select="string('')" />

  <!-- ... -->

  <sql:connect driver="{$jdbc.driver}" database="{$jdbc.database}" user="{$jdbc.user}" password="{$jdbc.pass}">

But the XSL still didn't work (I did give the correct password for jdbc.pass on the command line and also tried embedding the password too).  Saxon is run from a Windows command script that produces these lines:

set CLASSPATH=D:\Vocabularies\Tools\Saxon\saxon9.jar;D:\Vocabularies\Tools\Saxon\saxon9-ant.jar;D:\Vocabularies\Tools\Saxon\saxon9-dom.jar;D:\Vocabularies\Tools\Saxon\saxon9-dom4j.jar;D:\Vocabularies\Tools\Saxon\saxon9-jdom.jar;D:\Vocabularies\Tools\Saxon\saxon9-s9api.jar;D:\Vocabularies\Tools\Saxon\saxon9-sql.jar;D:\Vocabularies\Tools\Saxon\saxon9-xom.jar;D:\Vocabularies\Tools\Saxon\saxon9-xpath.jar;D:\Vocabularies\Tools\Saxon\saxon9-xqj.jar;D:\Vocabularies\Tools\TagSoup\tagsoup.jar;.;D:\Vocabularies\Tools\mssql-jdbc\enu\sqljdbc.jar;C:\Program Files (x86)\Oracle\Berkeley DB XML 2.4.11\jar\dbxmlexamples.jar;C:\Program Files (x86)\Oracle\Berkeley DB XML 2.4.11\jar\dbxml.jar;C:\Program Files (x86)\Oracle\Berkeley DB XML 2.4.11\jar\db.jar;C:\Program Files (x86)\QuickTime\QTSystem\QTJava.zip

java -Xincgc -Xmx1024m -Xms1024m  net.sf.saxon.Transform "test-sql.xsl" "test-sql.xsl"
Error on line 49 of file:/D:/temp/test-sql.xsl:
  SXSQ0003: JDBC Connection Failure: The TCP/IP connection to the host  has failed.

The CLASSPATH does have sqljdbc.jar on it, so I'm assuming that saxon can find the JDBC driver and the connection failure is caused by something unexpected, that doesn't occur in the Java program I used to access the database, which worked.

The only difference is when I compile my Java program, the class path is set to:

set CLASSPATH=.;D:\Vocabularies\Tools\mssql-jdbc\enu\sqljdbc.jar;C:\Program Files (x86)\Oracle\Berkeley DB XML 2.4.11\jar\dbxmlexamples.jar;C:\Program Files (x86)\Oracle\Berkeley DB XML 2.4.11\jar\dbxml.jar;C:\Program Files (x86)\Oracle\Berkeley DB XML 2.4.11\jar\db.jar;C:\Program Files (x86)\QuickTime\QTSystem\QTJava.zip

which is minus all the saxon jar files and tagsoup.jar, but I wouldn't think that would matter.


Andy.


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
saxon-help@...
https://lists.sourceforge.net/lists/listinfo/saxon-help 

Re: SQL extension and MSSQL Server JDBC driver

by Michael Kay :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

>The TCP/IP connection to the host has failed.

That's something happening several layers down the stack from anything Saxon
has any direct control over. (And it's something I know nothing about -
sorry!) I think you now need a support forum specific to your JDBC driver.

Michael Kay
http://www.saxonica.com/


> -----Original Message-----
> From: saxon-help-bounces@...
> [mailto:saxon-help-bounces@...] On Behalf
> Of Houghton,Andrew
> Sent: 21 May 2008 15:07
> To: Mailing list for the SAXON XSLT and XQuery processor
> Subject: Re: [saxon] SQL extension and MSSQL Server JDBC driver
>
> > From: saxon-help-bounces@... [mailto:saxon-help-
> > bounces@...] On Behalf Of Michael Kay
> > Sent: Tuesday, May 20, 2008 7:11 PM
> > To: 'Mailing list for the SAXON XSLT and XQuery processor'
> > Subject: Re: [saxon] SQL extension and MSSQL Server JDBC driver
> >
> > >
> > >         try {
> > >          // Establish the connection.
> > >
> > >
> > Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
> > >             con = DriverManager.getConnection(connectionUrl);
> > >
> >
> > The Saxon code is using
> >
> >                Class.forName(dbDriverString);
> >                connection = DriverManager.getConnection(dbString,
> > userString, pwdString);
> >
> > See if you can get your Java program working using that connection
> > method, and then use the same parameter values.
>
> OK, I changed my Java code to look like this:
>
>         String connectionUrl = "" +
>                                "jdbc:sqlserver://localhost:1443" +
>                                ";databaseName=prototype";
>   // ...
>          // Establish the connection.
>            
> Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
>             con = DriverManager.getConnection(connectionUrl,
> args[0], args[1]);
>
> and it produces the list of employees in the dbo.Employees
> table in the database when the user name and password are
> passed on the command line.  I also went back and changed the
> XSL program so it looks like:
>
>   <xsl:param name="jdbc.driver"   as="xsd:string"
> select="string('com.microsoft.sqlserver.jdbc.SQLServerDriver')" />
>
>   <xsl:param name="jdbc.database" as="xsd:string"
> select="string('jdbc:sqlserver://localhost:1433;databaseName=p
> rototype')" />
>
>   <xsl:param name="jdbc.user" as="xsd:string"
> select="string('saxon')" />
>   <xsl:param name="jdbc.pass" as="xsd:string" select="string('')" />
>
>   <!-- ... -->
>
>   <sql:connect driver="{$jdbc.driver}"
> database="{$jdbc.database}" user="{$jdbc.user}"
> password="{$jdbc.pass}">
>
> But the XSL still didn't work (I did give the correct
> password for jdbc.pass on the command line and also tried
> embedding the password too).  Saxon is run from a Windows
> command script that produces these lines:
>
> set
> CLASSPATH=D:\Vocabularies\Tools\Saxon\saxon9.jar;D:\Vocabulari
> es\Tools\Saxon\saxon9-ant.jar;D:\Vocabularies\Tools\Saxon\saxo
> n9-dom.jar;D:\Vocabularies\Tools\Saxon\saxon9-dom4j.jar;D:\Voc
> abularies\Tools\Saxon\saxon9-jdom.jar;D:\Vocabularies\Tools\Sa
> xon\saxon9-s9api.jar;D:\Vocabularies\Tools\Saxon\saxon9-sql.ja
> r;D:\Vocabularies\Tools\Saxon\saxon9-xom.jar;D:\Vocabularies\T
> ools\Saxon\saxon9-xpath.jar;D:\Vocabularies\Tools\Saxon\saxon9
> -xqj.jar;D:\Vocabularies\Tools\TagSoup\tagsoup.jar;.;D:\Vocabu
> laries\Tools\mssql-jdbc\enu\sqljdbc.jar;C:\Program Files
> (x86)\Oracle\Berkeley DB XML
> 2.4.11\jar\dbxmlexamples.jar;C:\Program Files
> (x86)\Oracle\Berkeley DB XML 2.4.11\jar\dbxml.jar;C:\Program
> Files (x86)\Oracle\Berkeley DB XML
> 2.4.11\jar\db.jar;C:\Program Files (x86)\QuickTime\QTSystem\QTJava.zip
>
> java -Xincgc -Xmx1024m -Xms1024m  net.sf.saxon.Transform
> "test-sql.xsl" "test-sql.xsl"
> Error on line 49 of file:/D:/temp/test-sql.xsl:
>   SXSQ0003: JDBC Connection Failure: The TCP/IP connection to
> the host  has failed.
>
> The CLASSPATH does have sqljdbc.jar on it, so I'm assuming
> that saxon can find the JDBC driver and the connection
> failure is caused by something unexpected, that doesn't occur
> in the Java program I used to access the database, which worked.
>
> The only difference is when I compile my Java program, the
> class path is set to:
>
> set
> CLASSPATH=.;D:\Vocabularies\Tools\mssql-jdbc\enu\sqljdbc.jar;C
> :\Program Files (x86)\Oracle\Berkeley DB XML
> 2.4.11\jar\dbxmlexamples.jar;C:\Program Files
> (x86)\Oracle\Berkeley DB XML 2.4.11\jar\dbxml.jar;C:\Program
> Files (x86)\Oracle\Berkeley DB XML
> 2.4.11\jar\db.jar;C:\Program Files (x86)\QuickTime\QTSystem\QTJava.zip
>
> which is minus all the saxon jar files and tagsoup.jar, but I
> wouldn't think that would matter.
>
>
> Andy.
>
>
> --------------------------------------------------------------
> -----------
> This SF.net email is sponsored by: Microsoft Defy all
> challenges. Microsoft(R) Visual Studio 2008.
> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> _______________________________________________
> saxon-help mailing list archived at
> http://saxon.markmail.org/ saxon-help@...
> https://lists.sourceforge.net/lists/listinfo/saxon-help 


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
saxon-help@...
https://lists.sourceforge.net/lists/listinfo/saxon-help 

Re: Patterns