Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 276134

Summary: [xpath2] improvements to schema aware primitive type support for attribute/element nodes
Product: [WebTools] WTP Source Editing Reporter: Mukul Gandhi <gandhi.mukul>
Component: wst.xpathAssignee: David Carver <d_a_carver>
Status: RESOLVED FIXED QA Contact: David Carver <d_a_carver>
Severity: normal    
Priority: P3 CC: gandhi.mukul
Version: unspecified   
Target Milestone: 3.2 M1   
Hardware: All   
OS: All   
Whiteboard:
Attachments:
Description Flags
patch file for the bug
none
test case patch file for the bug
none
updated patch file for the bug
none
updated patch file for the bug
none
updated test case patch file for the bug
none
Merged patch
none
mylyn/context/zip
none
corrected patch file
none
the updated test cases and supporting files none

Description Mukul Gandhi CLA 2009-05-13 12:48:49 EDT
Build ID: I20090430-2300

Steps To Reproduce:
PsychoPath currently is not able to perform schema aware XPath evaluations correctly.

for e.g., if an XPath 2.0 expression is written like below:

person/@dob eq xs:date('2006-12-10')

and the XML document was validated with an XML Schema, and the attribute @dob above had schema type xs:date, then the above XPath evaluation should succeed. PsychoPath currently gives an exception, due to non handling of this situation.

For expressions like above to succeed, internally the XDM tree should have correct type annotations on attribute nodes (in this case xs:date).

This patch improves schema aware support for attribute nodes.

More information:
Comment 1 Mukul Gandhi CLA 2009-05-13 13:10:01 EDT
Created attachment 135625 [details]
patch file for the bug
Comment 2 Mukul Gandhi CLA 2009-05-13 13:10:59 EDT
Created attachment 135626 [details]
test case patch file for the bug
Comment 3 Mukul Gandhi CLA 2009-05-13 13:22:47 EDT
Created attachment 135634 [details]
updated patch file for the bug

sorry, I missed the xs:long type in my implemented. I have corrected it.

This patch adds support for following built in schema types, on XDM attribute nodes:

xs:date
xs:int
xs:long
xs:integer
xs:double
xs:float
xs:decimal
Comment 4 David Carver CLA 2009-05-13 13:30:25 EDT
Targeting for 3.2, we may need to split some of this up into smaller patches, once WTP Source Editing is branched at WTP 3.1RC1.  I'll have a better idea after I get some of the earlier patches in place when this one will go in.  Keep them coming, Mukul, you are giving me a good contribution trail.
Comment 5 Mukul Gandhi CLA 2009-05-13 13:47:29 EDT
(In reply to comment #4)
> Targeting for 3.2, we may need to split some of this up into smaller patches,
> once WTP Source Editing is branched at WTP 3.1RC1.  I'll have a better idea
> after I get some of the earlier patches in place when this one will go in. 
> Keep them coming, Mukul, you are giving me a good contribution trail.

Incidentally, quite a number of patches are coming from my side. It's just accidental, and I am able to solve certain problems :)

Please let me know, if I can support on any of your efforts to improve PsychoPath.

Regards,
Mukul  

Comment 6 Mukul Gandhi CLA 2009-05-13 23:38:51 EDT
Created attachment 135722 [details]
updated patch file for the bug

updated the patch to support primitive types on element nodes as well [2].

so now, something like,
<xs:element name="dob" type="xs:date" /> would also work.

Since this enhancement [1] is closely related to this issue and required minor changes to the code, I have incoprporated this improvement in this patch only.
Comment 7 Mukul Gandhi CLA 2009-05-13 23:40:29 EDT
Created attachment 135723 [details]
updated test case patch file for the bug
Comment 8 Mukul Gandhi CLA 2009-05-13 23:43:37 EDT
(In reply to comment #6)
> Created an attachment (id=135722) [details]
> updated patch file for the bug

>updated the patch to support primitive types on element nodes as well [2].

sorry, I meant [1] instead of [2]. The correct sentence is below.

"updated the patch to support primitive types on element nodes as well [1]".

sorry for the typo.

Comment 9 David Carver CLA 2009-05-23 11:30:24 EDT
Looking this over, I think the type should by xsi:type instead of just type.   I'm going to attach a cleaned up patch with the bug fix and all your other changes.  If you could look it over again and check the specification, I think your type implementation needs to xsi:type.

Comment 10 David Carver CLA 2009-05-23 11:36:25 EDT
Created attachment 136887 [details]
Merged patch

This patch merges all the changes for Schema Awarness...However the two unit tests are getting null pointers.   Mukul if you could look over the merged patch and resubmit an updated patch that passes the test, I'll get the changes in place.   I suspect it is something on my end I missed because I had to merge some stuff manually and address the other items I raised earlier.
Comment 11 David Carver CLA 2009-05-23 11:36:27 EDT
Created attachment 136888 [details]
mylyn/context/zip
Comment 12 Mukul Gandhi CLA 2009-05-23 12:42:10 EDT
Created attachment 136890 [details]
corrected patch file

by mistake I had kept the syntax xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" in my XML files. This is redundant. I have now removed this from XML files in this patch, and this fixes the problem you cited.

Sorry about this.

We can specify the schema to the XML document, in following two ways:

1) by providing the following hint in the XML
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="bug276134.xsd"

OR

2) by passing the schema through an API (using the JAXP Schema object)

The patch I submitted uses the technique 2) above. Though I have tested the technique 1) as well, and it works fine too. By mistake, I accidentaly left the fragment xmlns:xsi .. in my XMLs.

I have now cleaned everything, and am submitting the patch and the test patch again. These work fine at my end.
Please let me know, if I can support further.

Sorry, we couldn't do this with zero error the first time. I apologize for it.

Regards,
Mukul
Comment 13 Mukul Gandhi CLA 2009-05-23 12:43:55 EDT
Created attachment 136891 [details]
the updated test cases and supporting files
Comment 14 David Carver CLA 2009-05-23 13:22:28 EDT
The issue I'm running into now is that the following:

java.lang.ClassCastException: com.sun.org.apache.xerces.internal.jaxp.validation.xs.SchemaImpl
	at org.eclipse.wst.xml.xpath2.processor.test.AbstractPsychoPathTest.getGrammar(AbstractPsychoPathTest.java:115)
	at org.eclipse.wst.xml.xpath2.processor.test.TestBugs.testSchemaAwarenessForAttributes(TestBugs.java:388)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:585)
	at junit.framework.TestCase.runTest(TestCase.java:164)
	at junit.framework.TestCase.runBare(TestCase.java:130)
	at junit.framework.TestResult$1.protect(TestResult.java:106)
	at junit.framework.TestResult.runProtected(TestResult.java:124)
	at junit.framework.TestResult.run(TestResult.java:109)
	at junit.framework.TestCase.run(TestCase.java:120)
	at junit.framework.TestSuite.runTest(TestSuite.java:230)
	at junit.framework.TestSuite.run(TestSuite.java:225)
	at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
	at org.eclipse.pde.internal.junit.runtime.RemotePluginTestRunner.main(RemotePluginTestRunner.java:62)
	at org.eclipse.pde.internal.junit.runtime.CoreTestApplication.run(CoreTestApplication.java:23)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:585)
	at org.eclipse.equinox.internal.app.EclipseAppContainer.callMethodWithException(EclipseAppContainer.java:574)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:368)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:585)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:556)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:511)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1270)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1246)

My system is somehow picking up the Sun Xerces instead of using the Apache Xerces.   I think we need to set the system properties in the tests or in the XercesLoader class itself.   This is potentially a interop problem, that we will need to address.
Comment 15 David Carver CLA 2009-05-23 13:28:22 EDT
Oh, and please synch up the test case as well, it's still out of synch with the code that is in head.
Comment 16 Mukul Gandhi CLA 2009-05-23 13:37:03 EDT
Hi Dave,

(In reply to comment #14)
> The issue I'm running into now is that the following:
> 
> java.lang.ClassCastException:
> com.sun.org.apache.xerces.internal.jaxp.validation.xs.SchemaImpl
>         at

> My system is somehow picking up the Sun Xerces instead of using the Apache
> Xerces.   I think we need to set the system properties in the tests or in the
> XercesLoader class itself.   This is potentially a interop problem, that we
> will need to address.

I believe, you are running the tests from within Eclipse. If you don't setup
the eclipse Java project to use, an external Xerces JAR from Apache, eclipse
would select the Xerces bundled with JDK.

If you don't have Apache Xerces, kindly download the latest version from,
http://xerces.apache.org/xerces2-j/.

Then, please put the downloaded JARs xercesImpl.jar and xml-apis.jar in the
PsychoPath eclipse project build classpath. In the tab, "order and export"
please make sure the Apache JARs are above the "JRE system libraries" so they
are selected instead of the classes in Sun JRE.

This should work fine I believe. It works fine with me..

Regards,
Mukul
Comment 17 Mukul Gandhi CLA 2009-05-23 13:48:21 EDT
(In reply to comment #15)
> Oh, and please synch up the test case as well, it's still out of synch with the
> code that is in head.

It's not clear to me, what's missing here. Could you please clarify, so I can fix it..

Regards,
Mukul

Comment 18 David Carver CLA 2009-05-23 21:12:54 EDT
(In reply to comment #17)
> (In reply to comment #15)
> > Oh, and please synch up the test case as well, it's still out of synch with
> the
> > code that is in head.
> 
> It's not clear to me, what's missing here. Could you please clarify, so I can
> fix it..

I think we are running into a CRLF issue if you are on Windows.   If you are using Eclipse to check out the source code, make sure you have your CVS options set to NOT convert to native format (i.e. it should keep the CRLF endings as they are).

(In reply to comment #16)
> 
> I believe, you are running the tests from within Eclipse. If you don't setup
> the eclipse Java project to use, an external Xerces JAR from Apache, eclipse
> would select the Xerces bundled with JDK.
> 
> If you don't have Apache Xerces, kindly download the latest version from,
> http://xerces.apache.org/xerces2-j/.
> 
> Then, please put the downloaded JARs xercesImpl.jar and xml-apis.jar in the
> PsychoPath eclipse project build classpath. In the tab, "order and export"
> please make sure the Apache JARs are above the "JRE system libraries" so they
> are selected instead of the classes in Sun JRE.

I have the Eclipse Orbit version of Xerces 2.9.0 included as a dependency.   However since we are using JAXP to get the schema factory (and this is the reason I HATE jaxp), it's picking up the Sun JRE instead of the Plugin version in Xerces.    Anyways, I've solved it by putting in AbstractPsychoPathTest in the setUp method the following:

		System.setProperty("javax.xml.validation.SchemaFactory:http://www.w3.org/2001/XMLSchema","org.apache.xerces.jaxp.validation.XMLSchemaFactory");

It's a work around but it seems to do the trick.

All of the tests for this patch pass now.
 
Comment 19 David Carver CLA 2009-05-23 21:15:29 EDT
This patch is now checked into head.  Thanks Mukul.