Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 355751 - General improvement of XML root binding API
Summary: General improvement of XML root binding API
Status: CLOSED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Sapphire (show other bugs)
Version: unspecified   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Konstantin Komissarchik CLA
QA Contact:
URL:
Whiteboard:
Keywords: plan
: 342487 (view as bug list)
Depends on:
Blocks:
 
Reported: 2011-08-24 13:54 EDT by Kamesh Sampath CLA
Modified: 2021-11-19 09:21 EST (History)
2 users (show)

See Also:


Attachments
Patch_v0.1 (93.61 KB, patch)
2011-10-28 04:52 EDT, Kamesh Sampath CLA
konstantin: iplog+
Details | Diff
Enhancement Documentation (4.35 KB, patch)
2011-11-10 06:47 EST, Kamesh Sampath CLA
konstantin: iplog+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Kamesh Sampath CLA 2011-08-24 13:54:08 EDT
Need to fix the borken links in the samples, sdk and other identified packages as @XmlRootBinding will be dropped as a result of discussions and implementation of Bug-355457
Comment 1 Kamesh Sampath CLA 2011-08-24 13:55:51 EDT
As part of Bug-355457 i will submit an annoatations/testcases etc., and please review and close the issue once thats done I will take up this bug and fix the broken links.

Please let me know if you think otherwise.
Comment 2 Konstantin Komissarchik CLA 2011-08-24 14:02:19 EDT
We cannot do it this way. A change that breaks the build cannot be committed. I added some comments to Bug 355457 regarding how we can split this work into multiple phases.

Lets repurpose this bug be the second phase of cleanup of root xml binding API
Comment 3 Konstantin Komissarchik CLA 2011-08-24 14:11:01 EDT
This is continuation of work started in Bug 355457. Copying relevant text:

==========

I am finally remembering all aspects of this API that I've been intending to
correct. Let me fill you in on that... @XmlRootBinding predates @XmlNamespace
that provides for more flexible way specify namespaces. I've been meaning to
clean this up. Might as well do all of this cleanup in one shot. If
@XmlNamespace owns association of a prefix with a namespace uri and @XmlSchema
owns association of namespace uri with schema location, then there is not much
left for @XmlRootBinding (just the element name). Given that, I think we can
just drop this annotation and use the existing generic @XmlBinding in its
place. 

Declarations would look something like this:

@XmlNamespace( prefix = "m", uri = "http://something.com" )
@XmlSchema( namespace = "http://something.com", location =
"http://something.com/schema.xsd" )
@XmlBinding( path = "m:root" )

or

@XmlDocType( ... )
@XmlBinding( path = "root" )

or just

@XmlBinding( path = "root" )

To complete this change, I'd like to move StandardRootElementController into
the internal package. It doesn't make for good API and will need to change
extensively anyway for these changes.

==========

This tracks the following changes:

1. Make StandardRootElementController internal. It will no longer be API.

2. Remove @RootXmlBinding annotation.

3. Add @XmlSchema( namespace, location ) annotation.

4. Entry in migration guide, enhancements doc and other documentation pages.

5. Tests, sample updates. Don't know if we need to add stuff here, but we will certainly need to update the existing stuff.
Comment 4 Kamesh Sampath CLA 2011-08-24 21:24:36 EDT
(In reply to comment #3)
> This is continuation of work started in Bug 355457. Copying relevant text:
> 
> ==========
> 
> I am finally remembering all aspects of this API that I've been intending to
> correct. Let me fill you in on that... @XmlRootBinding predates @XmlNamespace
> that provides for more flexible way specify namespaces. I've been meaning to
> clean this up. Might as well do all of this cleanup in one shot. If
> @XmlNamespace owns association of a prefix with a namespace uri and @XmlSchema
> owns association of namespace uri with schema location, then there is not much
> left for @XmlRootBinding (just the element name). Given that, I think we can
> just drop this annotation and use the existing generic @XmlBinding in its
> place.
> 
> Declarations would look something like this:
> 
> @XmlNamespace( prefix = "m", uri = "http://something.com" )
> @XmlSchema( namespace = "http://something.com", location =
> "http://something.com/schema.xsd" )
> @XmlBinding( path = "m:root" )
> 
> or
> 
> @XmlDocType( ... )
> @XmlBinding( path = "root" )
> 
> or just
> 
> @XmlBinding( path = "root" )
> 
> To complete this change, I'd like to move StandardRootElementController into
> the internal package. It doesn't make for good API and will need to change
> extensively anyway for these changes.
> 
> ==========
> 
> This tracks the following changes:
> 
> 1. Make StandardRootElementController internal. It will no longer be API.
> 
This is already done in Bug-355457, since i doesn't break the build i did that as part of previous ticket

I will work on it please change the status.
Comment 5 Kamesh Sampath CLA 2011-08-29 11:00:24 EDT
I will work on these changes once I see you marking the 355457 as closed. Let me know if you wish me to anyting particular with respect to the changes for this bug, its mainly going to be cleaning.
Comment 6 Kamesh Sampath CLA 2011-08-29 11:10:01 EDT
Adding one more comment:
For any Xmlbinding  - i.e. Root we should allow either @XmlDocumentType or @XmlSchema, is there is anyway we can valdiate this ? So that user does not added both of them to the class  - Sapphire should restrict declaratively rather than @ runtime.
Hope I make some sense here ?
Comment 7 Konstantin Komissarchik CLA 2011-08-29 12:47:31 EDT
> For any Xmlbinding  - i.e. Root we should allow either @XmlDocumentType or 
> @XmlSchema, 

That's right.

> is there is anyway we can valdiate this ? So that user does not added both of > them to the class  - Sapphire should restrict declaratively rather than 
> @ runtime. Hope I make some sense here ?

There are ways to validate this at build-time, but they are expensive to implement and cost/benefit is unlikely to balance here as the user will quickly discover their mistake at runtime.
Comment 8 Kamesh Sampath CLA 2011-08-29 13:36:50 EDT
so ideally when we discover the user has both these annotations we can throw an IllgealStateException and allow the user to correct it. is this what you mean ?
Comment 9 Kamesh Sampath CLA 2011-08-29 13:40:39 EDT
so how to you want to priortise between bugs 355751 and 354199 , i mean to say which one you want to close first. if you are fine with either ones i will work on them parllely.

Let me know your thoughts .
Comment 10 Konstantin Komissarchik CLA 2011-08-29 15:25:23 EDT
> so ideally when we discover the user has both these annotations we can throw an
> IllgealStateException and allow the user to correct it. is this what you mean ?

Throwing exceptions is reserved for situations where there isn't a reasonable fallback. In this case, I would expect that the code would either detect @XmlSchema or @XmlDocumentType first and go with that.

> so how to you want to priortise between bugs 355751 and 354199 , i mean to say
> which one you want to close first. if you are fine with either ones i will work
> on them parllely.

Either way is fine with me.
Comment 11 Kamesh Sampath CLA 2011-08-29 20:00:35 EDT
Ok then let me work on 354199 as that sounds intresting and might need more time compared to this.  Will take this up once I am done with 354199
Comment 12 Konstantin Komissarchik CLA 2011-09-05 14:53:29 EDT
Let me know if this item feels too daunting.
Comment 13 Kamesh Sampath CLA 2011-09-06 04:53:24 EDT
Let me try to work on other bugs and close them and come to this. I guess it should not be too daunting and all depends on how quickly i close the other ones :)
Comment 14 Kamesh Sampath CLA 2011-10-28 01:07:05 EDT
Started to work on this issue, from where we left off. 

Tasks
  1. define @XmlSchema, 
  2. drop @XmlRootBinding
  3. update samples 
  4. update test cases
  5. update docs

Let me know if you have anything specific with the Tasks and anything you want to add
Comment 15 Kamesh Sampath CLA 2011-10-28 04:52:50 EDT
Created attachment 206118 [details]
Patch_v0.1

Attached is the first patch fore your review, it contains a lots of changes as we need to touch files which were using @XmlRootBinding and replace them with @XmlBinding.

Please have a look at it and let me know if I am going in the right direction.

Note: some of the test cases failed roughly 7 of them, in which 2 are related to XML not sure that is the problem with this changes, but your thought needed to see if its this fix caused issue

Query:
Do we need to support multiple schema declarations ? @XmlSchemas(@XmlSchma[]), because some of the XML files e.g. Spring beans will have multiple schema declarations. Let me know your thoughts on this too, may be we could take this up as separate enhancement too.
Comment 16 Kamesh Sampath CLA 2011-11-02 23:14:10 EDT
Did you get a chance to review these enhancements ?
Comment 17 Konstantin Komissarchik CLA 2011-11-02 23:46:21 EDT
I haven't tried running this patch, but I have not identified any obvious issues in the initial review. 

> Note: some of the test cases failed roughly 7 of them, in which 2 are related
> to XML not sure that is the problem with this changes, but your thought needed
> to see if its this fix caused issue

All of the tests cases pass currently, so any failures are the result of this work. Note that many of the test cases in non-XML areas indirectly leverage XML functionality.

> Do we need to support multiple schema declarations ? @XmlSchemas(@XmlSchma[]),
> because some of the XML files e.g. Spring beans will have multiple schema
> declarations. Let me know your thoughts on this too, may be we could take this
> up as separate enhancement too.

Let's go ahead an add @XmlSchemas as part of this one.
Comment 18 Kamesh Sampath CLA 2011-11-03 22:17:21 EDT
(In reply to comment #17)
> > Do we need to support multiple schema declarations ? @XmlSchemas(@XmlSchma[]),
> > because some of the XML files e.g. Spring beans will have multiple schema
> > declarations. Let me know your thoughts on this too, may be we could take this
> > up as separate enhancement too.
> 
> Let's go ahead an add @XmlSchemas as part of this one.

When I was thinking more on these lines I see that we can adopt the following Annotation structure for the @XmlSchema

@XmlSchema( rootElementName="root",
            @XmlNamespace(uri="http://www.eclipse.org/sapphire",prefix="sph"),
            location="http://www/eclipse.org/sapphire/test.xsd",
            target=true)

Since @XmlNamespace will not have any use unless and until we use schema, i personally feel its better to make the annotation come under @XmlSchema and we shall even drop the @XmlNamespaces, since we are going to introduce @XmlSchemas(@XmlSchma[])that will take care of handling multiple namespaces. 

This will also in kind provide a simpler declarative for users and help them understand the context of @XmlNamespace. 

From the implementor point of view it there will be only Annotation processing from which we can get all the required properties for constructing the root element and we dont need to change the existing functionality of @XmlBinding by making it support @ Type level

Please let me know your thoughts.
Comment 19 Konstantin Komissarchik CLA 2011-11-04 10:37:21 EDT
No. That does not work. The namespace concept is independent of the schema concept. Consider that you can have a document with namespaces that doesn't use a schema or uses another form of content description.

The @XmlNamespace and @XmlSchema annotations need to stay separate.
Comment 20 Kamesh Sampath CLA 2011-11-04 12:42:55 EDT
(In reply to comment #19)
> No. That does not work. The namespace concept is independent of the schema
> concept. Consider that you can have a document with namespaces that doesn't use
> a schema or uses another form of content description.
> 
> The @XmlNamespace and @XmlSchema annotations need to stay separate.

Agreed! thanks

I have a small query, in one of the test cases which fails i see the failing test case model object (B) is extending from another model object(A),the A has a unqualified root binding, where B has qualified root binding, so as a result of extension and when we read from the parent properties we get a unqualified name but we are expecting a qualified name. 

Is there any place I need to look in to for this scenario ? Any updates for dropping @XmlRootBinding?

Test Model : org.eclipse.sapphire.tests.modeling.xml.XmlBindingTestModel
Failing test: testValueProperties3
Comment 21 Konstantin Komissarchik CLA 2011-11-04 14:42:30 EDT
Short of stepping through your code changes, I couldn't tell you where the bug might be...
Comment 22 Kamesh Sampath CLA 2011-11-09 05:16:59 EST
I want to push this fix for 0.4, as per the forum post http://www.eclipse.org/forums/index.php/t/261466/ i see very little time left. I am still struck up with the last error i told you. I am trying debug and fix that today if you have time can you please have a look at it ?

~kamesh
Comment 23 Kamesh Sampath CLA 2011-11-09 10:35:30 EST
Further analysis

I found that when the child model which is extending from a parent model is not getting serialized with name spaces :( .. 

I guess am making some mistake when handling it @ the RootXmlResource class, becos right now we dont have @XmlRootBinding .. all is done by @XmlBinding whether at root or at property levels,

In the scenario where test case is failing , parent does not have @XmlNamespaces or @XmlSchema and there is no prefix for the same. 

Ideally (am not sure), the annotations from the child class should override the parent ones right ? Correct me if am wrong ..

Thats the reason its not able to compare the expected output which has namespace with the unqualified elements.
Comment 24 Konstantin Komissarchik CLA 2011-11-09 22:14:13 EST
I am working on this now. The cause of unit test failures was largely in RootXmlResource changes. The logic in that class wasn't handling prefixes and namespace resolution correctly, so information passed to StandardRootElementController was incorrect.
Comment 25 Kamesh Sampath CLA 2011-11-09 22:33:44 EST
(In reply to comment #24)
> I am working on this now. The cause of unit test failures was largely in
> RootXmlResource changes. The logic in that class wasn't handling prefixes and
> namespace resolution correctly, so information passed to
> StandardRootElementController was incorrect.
I had the same doubt, let me if you need to take some rest, i will debug the class and try to fix it. Anyways thanks a lot for take some time to look into it.
Comment 26 Kamesh Sampath CLA 2011-11-09 22:50:54 EST
(In reply to comment #24)
> I am working on this now. The cause of unit test failures was largely in
> RootXmlResource changes. The logic in that class wasn't handling prefixes and
> namespace resolution correctly, so information passed to
> StandardRootElementController was incorrect.
I kind of corrected to make the test case work :) as is .. fixed some cases in RootXmlResource, but feel there needs some more clean up. I will fix it and send it for your review. you can then review and update if needed.. Thanks once again for pointing it out and authenticating my doubt.
Comment 27 Kamesh Sampath CLA 2011-11-09 23:13:00 EST
i guess i made some mess with the debugging and testing, esp. on code format and other stuff. 

will reset my local copy yo HEAD , apply patch_v0.1 and then will reapply my current changes to avoid any discrepancies while merging. 

Sorry about it :(
Comment 28 Konstantin Komissarchik CLA 2011-11-09 23:27:18 EST
Don't worry about trying to make another patch for now. I have a working set of changes based on your original patch. I will try to wrap it up tomorrow. If I have to set it down and hand it back to you, I will attach a revised patch so that you can pick up where I left off.
Comment 29 Kamesh Sampath CLA 2011-11-09 23:31:01 EST
(In reply to comment #28)
> Don't worry about trying to make another patch for now. I have a working set of
> changes based on your original patch. I will try to wrap it up tomorrow. If I
> have to set it down and hand it back to you, I will attach a revised patch so
> that you can pick up where I left off.

Thanks a lot. I will wait for your revised patch and will work on it starting from there.

thanks once again for the help.
Comment 30 Konstantin Komissarchik CLA 2011-11-10 02:07:55 EST
I fixed the logic error in RootXmlResource, reverted improper changes to unit test expected files, added @XmlSchemas annotation and related logic, and done some general cleanup.

All unit tests pass. The code changes have now been committed. The only thing left to do here is to write a section for the migration guide. I will do that tomorrow.
Comment 31 Kamesh Sampath CLA 2011-11-10 02:48:35 EST
(In reply to comment #30)
> I fixed the logic error in RootXmlResource, reverted improper changes to unit
> test expected files, added @XmlSchemas annotation and related logic, and done
> some general cleanup.
> 
> All unit tests pass. The code changes have now been committed. The only thing
> left to do here is to write a section for the migration guide. I will do that
> tomorrow.

Wonderful and Thanks! I will work on the the doc changes for @XmlSchema and @XmlSchemas that needs to get into 0.4/enhancements.html and send you a patch of it.
Comment 32 Kamesh Sampath CLA 2011-11-10 06:13:19 EST
I have a small question: whats the use of hudson-build target in the build?
Comment 33 Kamesh Sampath CLA 2011-11-10 06:47:52 EST
Created attachment 206780 [details]
Enhancement Documentation

The 0.4 enhancements documentation updated for @XmlSchema and @XmlSchemas annotations
Comment 34 Konstantin Komissarchik CLA 2011-11-10 21:51:01 EST
I accepted half of the patch for the enhancement document (the @XmlSchema section) with a few changes. I replaced the section on @XmlSchemas with a single sentence.

In addition to the above, I added content to the migration guide and fixed references @XmlRootBinding in the documentation.

This item can be considered complete. Please verify.
Comment 35 Konstantin Komissarchik CLA 2011-11-10 21:55:10 EST
*** Bug 342487 has been marked as a duplicate of this bug. ***
Comment 36 Kamesh Sampath CLA 2011-11-10 23:51:24 EST
(In reply to comment #34)
> I accepted half of the patch for the enhancement document (the @XmlSchema
> section) with a few changes. I replaced the section on @XmlSchemas with a
> single sentence.
> 
> In addition to the above, I added content to the migration guide and fixed
> references @XmlRootBinding in the documentation.
> 
> This item can be considered complete. Please verify.

Looks good, but a small suggestion in the migration guide, can we add a word saying the @XmlRootBinding is dropped and @XmlBinding is used in place. Tough its implied by the Before/After section but we can be explicit here to avoid any ambiguity.
Comment 37 Konstantin Komissarchik CLA 2011-11-10 23:54:05 EST
The migration guide already contains essentially such wording:

"Scenarios previously handled by @XmlRootBinding annotation are now handled by different combinations of @XmlBinding, @XmlNamespace, @XmlSchema and @XmlDocumentType annotations."

Between this and the before/after table, I don't think we have any ambiguity issues to worry about.
Comment 38 Kamesh Sampath CLA 2011-11-10 23:56:21 EST
(In reply to comment #37)
> The migration guide already contains essentially such wording:
> 
> "Scenarios previously handled by @XmlRootBinding annotation are now handled by
> different combinations of @XmlBinding, @XmlNamespace, @XmlSchema and
> @XmlDocumentType annotations."
> 
> Between this and the before/after table, I don't think we have any ambiguity
> issues to worry about.

Great then, I have verified it. Thanks.
Comment 39 Konstantin Komissarchik CLA 2011-11-11 10:08:44 EST
Closing.