You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xmlbeans.apache.org by "Andreas Loew (JIRA)" <xm...@xml.apache.org> on 2005/11/23 13:49:39 UTC
[jira] Created: (XMLBEANS-228) Element order is mixed up on document creation after calling substitute()
Element order is mixed up on document creation after calling substitute()
-------------------------------------------------------------------------
Key: XMLBEANS-228
URL: http://issues.apache.org/jira/browse/XMLBEANS-228
Project: XMLBeans
Type: Bug
Components: XmlObject
Versions: Version 2.1, Version 2
Environment: N/A
Reporter: Andreas Loew
Fix For: Version 2.1, Version 2
When trying to create XML documents with XMLBeans 2.x using xmlText() or save() that use substitution groups, usage of the substitute() method will mix up the order of the XML document (the order will remain correct when substitute() will not be called).
We have attached a test case (schema XSD, JUnit test) that demonstrates the failure and also attached a patch against plain XMLBeans 2.0.0 that shows where the problem is and what is needed to fix problem (although currently at the cost of a quite severe perfomance penalty, as I am not an expert in XMLBeans internals):
For the test case, XMLBeans 2.0.0 as well as the current SVN snapshot both fail as they return
<?xml version="1.0" encoding="UTF-8"?>
<Person xmlns="urn:www-apache-org:SubstitutionGroup/substitutionGroupInSequence">
<FirstCommentElement>ThirdElement</FirstCommentElement>
<FirstName>FirstElement</FirstName>
<LastName>SecondElement</LastName>
</Person>
instead of
<?xml version="1.0" encoding="UTF-8"?>
<Person xmlns="urn:www-apache-org:SubstitutionGroup/substitutionGroupInSequence">
<FirstName>FirstElement</FirstName>
<LastName>SecondElement</LastName>
<FirstCommentElement>ThirdElement</FirstCommentElement>
</Person>
as would be correct (and will be returned after applying the patches provided).
Basically, the main problem is that XmlObjectBase#getElementEndingDelimiters() after having called SchemaProperty#getJavaSetterDelimiter(), does not take into account that the QNameSet returned by getJavaSetterDelimiter() does not yet include the "alias names" - i.e. possible substitutions - of those elements that happen to be heads of substitution groups.
The patch for XmlObjectBase adds the missing substitutions to this QNameSet. This will fix the base problem, but so far at the cost of performance: In order to simulate a (non-existing) QNameSet iterator on the set of JavaSetterDelimiters, we have not been able to find a more intelligent solution than to iterate over the complete array of SchemaGlobalElements and check each head of a substitution group for inclusion in the QNameSet (using QNameSet#contains()). This definitely is suboptimal and should be replaced by an optimized implementation done by somebody who is familiar with the internals of XMLBeans. (Sorry!)
Unfortunately, while creating the first fix, we ran into a second (small) issue:
The static method QNameSet#forArray() does mistakenly pass null instead of new HashSet() to the private constructor, which results in a NullPointerException. The second fix (also included in the patch) will fix this problem.
Please get back to me in case you need any additional details.
Thanks & best regards,
Andreas Loew & Patrik Streicher
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: dev-help@xmlbeans.apache.org
[jira] Commented: (XMLBEANS-228) Element order is mixed up on
document creation after calling substitute()
Posted by "Radu Preotiuc-Pietro (JIRA)" <xm...@xml.apache.org>.
[ https://issues.apache.org/jira/browse/XMLBEANS-228?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12491035 ]
Radu Preotiuc-Pietro commented on XMLBEANS-228:
-----------------------------------------------
I have reviewed the patches and even though I don't think I was the comitter that Lawrence was referring to in "this patch is not consistent with a chat I had with one of the committers", I do agree with the opinion that having substitution group members show up alongside the head element in content models is the 0.1% case and it's not worth the memory penalty of keeping track when substitution groups were used.
So I would propose we don't worry about this 0.1% case and we fix the more common case where you have substitution groups, but members of the substitution group can't appear in the same content model with the head. I have a fix for that and will check it in soon.
> Element order is mixed up on document creation after calling substitute()
> -------------------------------------------------------------------------
>
> Key: XMLBEANS-228
> URL: https://issues.apache.org/jira/browse/XMLBEANS-228
> Project: XMLBeans
> Issue Type: Bug
> Components: XmlObject
> Affects Versions: Version 2, Version 2.1
> Environment: N/A
> Reporter: Andreas Loew
> Fix For: Version 2, Version 2.1
>
> Attachments: substGroupTests.xsd, substitutionGroupFix.patch, substitutionGroupInSequence.xsd, SubstitutionGroupTest.java, xmlbeans228.patch, xmlbeans228_QNameSet.patch
>
>
> When trying to create XML documents with XMLBeans 2.x using xmlText() or save() that use substitution groups, usage of the substitute() method will mix up the order of the XML document (the order will remain correct when substitute() will not be called).
> We have attached a test case (schema XSD, JUnit test) that demonstrates the failure and also attached a patch against plain XMLBeans 2.0.0 that shows where the problem is and what is needed to fix problem (although currently at the cost of a quite severe perfomance penalty, as I am not an expert in XMLBeans internals):
> For the test case, XMLBeans 2.0.0 as well as the current SVN snapshot both fail as they return
> <?xml version="1.0" encoding="UTF-8"?>
> <Person xmlns="urn:www-apache-org:SubstitutionGroup/substitutionGroupInSequence">
> <FirstCommentElement>ThirdElement</FirstCommentElement>
> <FirstName>FirstElement</FirstName>
> <LastName>SecondElement</LastName>
> </Person>
> instead of
> <?xml version="1.0" encoding="UTF-8"?>
> <Person xmlns="urn:www-apache-org:SubstitutionGroup/substitutionGroupInSequence">
> <FirstName>FirstElement</FirstName>
> <LastName>SecondElement</LastName>
> <FirstCommentElement>ThirdElement</FirstCommentElement>
> </Person>
> as would be correct (and will be returned after applying the patches provided).
> Basically, the main problem is that XmlObjectBase#getElementEndingDelimiters() after having called SchemaProperty#getJavaSetterDelimiter(), does not take into account that the QNameSet returned by getJavaSetterDelimiter() does not yet include the "alias names" - i.e. possible substitutions - of those elements that happen to be heads of substitution groups.
> The patch for XmlObjectBase adds the missing substitutions to this QNameSet. This will fix the base problem, but so far at the cost of performance: In order to simulate a (non-existing) QNameSet iterator on the set of JavaSetterDelimiters, we have not been able to find a more intelligent solution than to iterate over the complete array of SchemaGlobalElements and check each head of a substitution group for inclusion in the QNameSet (using QNameSet#contains()). This definitely is suboptimal and should be replaced by an optimized implementation done by somebody who is familiar with the internals of XMLBeans. (Sorry!)
> Unfortunately, while creating the first fix, we ran into a second (small) issue:
> The static method QNameSet#forArray() does mistakenly pass null instead of new HashSet() to the private constructor, which results in a NullPointerException. The second fix (also included in the patch) will fix this problem.
> Please get back to me in case you need any additional details.
> Thanks & best regards,
> Andreas Loew & Patrik Streicher
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: dev-help@xmlbeans.apache.org
[jira] Closed: (XMLBEANS-228) Element order is mixed up on document
creation after calling substitute()
Posted by "Wing Yew Poon (JIRA)" <xm...@xml.apache.org>.
[ https://issues.apache.org/jira/browse/XMLBEANS-228?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Wing Yew Poon closed XMLBEANS-228.
----------------------------------
Verified the fix using the repro from Andreas Loew. Submitted the repro as a test case.
> Element order is mixed up on document creation after calling substitute()
> -------------------------------------------------------------------------
>
> Key: XMLBEANS-228
> URL: https://issues.apache.org/jira/browse/XMLBEANS-228
> Project: XMLBeans
> Issue Type: Bug
> Components: XmlObject
> Affects Versions: Version 2, Version 2.1
> Environment: N/A
> Reporter: Andreas Loew
> Fix For: Version 2, Version 2.1
>
> Attachments: substGroupTests.xsd, substitutionGroupFix.patch, substitutionGroupInSequence.xsd, SubstitutionGroupTest.java, xmlbeans228.patch, xmlbeans228_QNameSet.patch
>
>
> When trying to create XML documents with XMLBeans 2.x using xmlText() or save() that use substitution groups, usage of the substitute() method will mix up the order of the XML document (the order will remain correct when substitute() will not be called).
> We have attached a test case (schema XSD, JUnit test) that demonstrates the failure and also attached a patch against plain XMLBeans 2.0.0 that shows where the problem is and what is needed to fix problem (although currently at the cost of a quite severe perfomance penalty, as I am not an expert in XMLBeans internals):
> For the test case, XMLBeans 2.0.0 as well as the current SVN snapshot both fail as they return
> <?xml version="1.0" encoding="UTF-8"?>
> <Person xmlns="urn:www-apache-org:SubstitutionGroup/substitutionGroupInSequence">
> <FirstCommentElement>ThirdElement</FirstCommentElement>
> <FirstName>FirstElement</FirstName>
> <LastName>SecondElement</LastName>
> </Person>
> instead of
> <?xml version="1.0" encoding="UTF-8"?>
> <Person xmlns="urn:www-apache-org:SubstitutionGroup/substitutionGroupInSequence">
> <FirstName>FirstElement</FirstName>
> <LastName>SecondElement</LastName>
> <FirstCommentElement>ThirdElement</FirstCommentElement>
> </Person>
> as would be correct (and will be returned after applying the patches provided).
> Basically, the main problem is that XmlObjectBase#getElementEndingDelimiters() after having called SchemaProperty#getJavaSetterDelimiter(), does not take into account that the QNameSet returned by getJavaSetterDelimiter() does not yet include the "alias names" - i.e. possible substitutions - of those elements that happen to be heads of substitution groups.
> The patch for XmlObjectBase adds the missing substitutions to this QNameSet. This will fix the base problem, but so far at the cost of performance: In order to simulate a (non-existing) QNameSet iterator on the set of JavaSetterDelimiters, we have not been able to find a more intelligent solution than to iterate over the complete array of SchemaGlobalElements and check each head of a substitution group for inclusion in the QNameSet (using QNameSet#contains()). This definitely is suboptimal and should be replaced by an optimized implementation done by somebody who is familiar with the internals of XMLBeans. (Sorry!)
> Unfortunately, while creating the first fix, we ran into a second (small) issue:
> The static method QNameSet#forArray() does mistakenly pass null instead of new HashSet() to the private constructor, which results in a NullPointerException. The second fix (also included in the patch) will fix this problem.
> Please get back to me in case you need any additional details.
> Thanks & best regards,
> Andreas Loew & Patrik Streicher
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: dev-help@xmlbeans.apache.org
[jira] Updated: (XMLBEANS-228) Element order is mixed up on document creation after calling substitute()
Posted by "Andreas Loew (JIRA)" <xm...@xml.apache.org>.
[ http://issues.apache.org/jira/browse/XMLBEANS-228?page=all ]
Andreas Loew updated XMLBEANS-228:
----------------------------------
Attachment: substitutionGroupFix.patch
Patch to fix the substitution group element ordering issue (XMLBEANS-228)
> Element order is mixed up on document creation after calling substitute()
> -------------------------------------------------------------------------
>
> Key: XMLBEANS-228
> URL: http://issues.apache.org/jira/browse/XMLBEANS-228
> Project: XMLBeans
> Type: Bug
> Components: XmlObject
> Versions: Version 2.1, Version 2
> Environment: N/A
> Reporter: Andreas Loew
> Fix For: Version 2.1, Version 2
> Attachments: substitutionGroupFix.patch
>
> When trying to create XML documents with XMLBeans 2.x using xmlText() or save() that use substitution groups, usage of the substitute() method will mix up the order of the XML document (the order will remain correct when substitute() will not be called).
> We have attached a test case (schema XSD, JUnit test) that demonstrates the failure and also attached a patch against plain XMLBeans 2.0.0 that shows where the problem is and what is needed to fix problem (although currently at the cost of a quite severe perfomance penalty, as I am not an expert in XMLBeans internals):
> For the test case, XMLBeans 2.0.0 as well as the current SVN snapshot both fail as they return
> <?xml version="1.0" encoding="UTF-8"?>
> <Person xmlns="urn:www-apache-org:SubstitutionGroup/substitutionGroupInSequence">
> <FirstCommentElement>ThirdElement</FirstCommentElement>
> <FirstName>FirstElement</FirstName>
> <LastName>SecondElement</LastName>
> </Person>
> instead of
> <?xml version="1.0" encoding="UTF-8"?>
> <Person xmlns="urn:www-apache-org:SubstitutionGroup/substitutionGroupInSequence">
> <FirstName>FirstElement</FirstName>
> <LastName>SecondElement</LastName>
> <FirstCommentElement>ThirdElement</FirstCommentElement>
> </Person>
> as would be correct (and will be returned after applying the patches provided).
> Basically, the main problem is that XmlObjectBase#getElementEndingDelimiters() after having called SchemaProperty#getJavaSetterDelimiter(), does not take into account that the QNameSet returned by getJavaSetterDelimiter() does not yet include the "alias names" - i.e. possible substitutions - of those elements that happen to be heads of substitution groups.
> The patch for XmlObjectBase adds the missing substitutions to this QNameSet. This will fix the base problem, but so far at the cost of performance: In order to simulate a (non-existing) QNameSet iterator on the set of JavaSetterDelimiters, we have not been able to find a more intelligent solution than to iterate over the complete array of SchemaGlobalElements and check each head of a substitution group for inclusion in the QNameSet (using QNameSet#contains()). This definitely is suboptimal and should be replaced by an optimized implementation done by somebody who is familiar with the internals of XMLBeans. (Sorry!)
> Unfortunately, while creating the first fix, we ran into a second (small) issue:
> The static method QNameSet#forArray() does mistakenly pass null instead of new HashSet() to the private constructor, which results in a NullPointerException. The second fix (also included in the patch) will fix this problem.
> Please get back to me in case you need any additional details.
> Thanks & best regards,
> Andreas Loew & Patrik Streicher
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: dev-help@xmlbeans.apache.org
[jira] Updated: (XMLBEANS-228) Element order is mixed up on document creation after calling substitute()
Posted by "Andreas Loew (JIRA)" <xm...@xml.apache.org>.
[ http://issues.apache.org/jira/browse/XMLBEANS-228?page=all ]
Andreas Loew updated XMLBEANS-228:
----------------------------------
Attachment: substitutionGroupInSequence.xsd
Sample XSD file as needed for the JUnit test case
> Element order is mixed up on document creation after calling substitute()
> -------------------------------------------------------------------------
>
> Key: XMLBEANS-228
> URL: http://issues.apache.org/jira/browse/XMLBEANS-228
> Project: XMLBeans
> Type: Bug
> Components: XmlObject
> Versions: Version 2.1, Version 2
> Environment: N/A
> Reporter: Andreas Loew
> Fix For: Version 2.1, Version 2
> Attachments: SubstitutionGroupTest.java, substitutionGroupFix.patch, substitutionGroupInSequence.xsd
>
> When trying to create XML documents with XMLBeans 2.x using xmlText() or save() that use substitution groups, usage of the substitute() method will mix up the order of the XML document (the order will remain correct when substitute() will not be called).
> We have attached a test case (schema XSD, JUnit test) that demonstrates the failure and also attached a patch against plain XMLBeans 2.0.0 that shows where the problem is and what is needed to fix problem (although currently at the cost of a quite severe perfomance penalty, as I am not an expert in XMLBeans internals):
> For the test case, XMLBeans 2.0.0 as well as the current SVN snapshot both fail as they return
> <?xml version="1.0" encoding="UTF-8"?>
> <Person xmlns="urn:www-apache-org:SubstitutionGroup/substitutionGroupInSequence">
> <FirstCommentElement>ThirdElement</FirstCommentElement>
> <FirstName>FirstElement</FirstName>
> <LastName>SecondElement</LastName>
> </Person>
> instead of
> <?xml version="1.0" encoding="UTF-8"?>
> <Person xmlns="urn:www-apache-org:SubstitutionGroup/substitutionGroupInSequence">
> <FirstName>FirstElement</FirstName>
> <LastName>SecondElement</LastName>
> <FirstCommentElement>ThirdElement</FirstCommentElement>
> </Person>
> as would be correct (and will be returned after applying the patches provided).
> Basically, the main problem is that XmlObjectBase#getElementEndingDelimiters() after having called SchemaProperty#getJavaSetterDelimiter(), does not take into account that the QNameSet returned by getJavaSetterDelimiter() does not yet include the "alias names" - i.e. possible substitutions - of those elements that happen to be heads of substitution groups.
> The patch for XmlObjectBase adds the missing substitutions to this QNameSet. This will fix the base problem, but so far at the cost of performance: In order to simulate a (non-existing) QNameSet iterator on the set of JavaSetterDelimiters, we have not been able to find a more intelligent solution than to iterate over the complete array of SchemaGlobalElements and check each head of a substitution group for inclusion in the QNameSet (using QNameSet#contains()). This definitely is suboptimal and should be replaced by an optimized implementation done by somebody who is familiar with the internals of XMLBeans. (Sorry!)
> Unfortunately, while creating the first fix, we ran into a second (small) issue:
> The static method QNameSet#forArray() does mistakenly pass null instead of new HashSet() to the private constructor, which results in a NullPointerException. The second fix (also included in the patch) will fix this problem.
> Please get back to me in case you need any additional details.
> Thanks & best regards,
> Andreas Loew & Patrik Streicher
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: dev-help@xmlbeans.apache.org
[jira] Commented: (XMLBEANS-228) Element order is mixed up on document creation after calling substitute()
Posted by "Andreas Loew (JIRA)" <xm...@xml.apache.org>.
[ http://issues.apache.org/jira/browse/XMLBEANS-228?page=comments#action_12361189 ]
Andreas Loew commented on XMLBEANS-228:
---------------------------------------
Lawrence,
many thanks for looking into this truly rather complex issue.
first of all, just shortly regarding the QName set patch, I am also comfortable with your way of doing it.
Secondly, unfortunately, your short-term workaround is not applicable to our scenario, because we are using a generic (and schema-agnostic) bean converter (based on the reflection API) which copies plain old JavaBeans into XMLBeans based on reflection and matching getter/setter method names, so we won't be able to determine the order in which we will call the XMLBeans setters from the schema.
Sadly, I won't have enough time before the Christmas holidays to have a truly detailed look into what you are saying. Let me just quickly reply that, after a first glance, I think your current view on the issue still was not fully correct, but your proposed solution is:
While I got your point and fully agree that, based on the substGroupTests.xsd schema that you have attached, my suggested patch will still fail to produce a valid document, I think you were wrong when concluding the following about my patch:
"Your suggested solution (as far as I can see) is to not worry about this [i.e. inserting elements into the store at their proper place when calling a setter], but when it comes time to marshal the object, collect all the instances of "things in the same substitution group" together and output them as if they were all in the one place (the place where the substitution group head would be in the schema)."
My patch also has already tried fo fix insertion into the store: It was adding the additional checks to XmlObjectBase#get_element_ending_delimiters(QName eltname) which will exactly be called in order to calculate the position within the store where the element will be inserted.
>From what I think to have understood now, the problem rather seems to be that, even with my patch included, for your sample schema, this method would still calculate the wrong place for insertion of Subst1Element and Subst2Element, because it would try to insert these elements at the same position where SubstHead would have been inserted/stored before.
So I fully agree again with your conclusion about the correct solution that is needed: It is simply not sufficient to only store the element name for which an element is substituting in the JavaElementSetterModel, but this store will have to contain the original element name, as you have pointed out correctly.
Trying to fix this issue in XmlObjectBase simply was too late to distinguish whether we have happened to run into a SubstHead, a Subst1Element or a Subst2Element - as the only information available from the current JavaElementSetterModel is that it is "a SubstHead or any of its legal substitutions".
Just one more suggestion: Maybe rather than storing both QNames - the element's own name and the name of the associated head of its substitution group - in the store, it would also be possible to only store the leaf element's QName (in order not to change the type structure of the store), but to calculate the element QName for which it is substituting (i.e. the head its substitution group) on demand from the leaf element in case that the SG head QName is needed for marshalling and/or querying.
So what do you think about this?
I'll be back at work on January 2nd, and be able to invest some time to see whether my new suggestion seems feasible.
Happy holidays & thanks again,
Andreas
> Element order is mixed up on document creation after calling substitute()
> -------------------------------------------------------------------------
>
> Key: XMLBEANS-228
> URL: http://issues.apache.org/jira/browse/XMLBEANS-228
> Project: XMLBeans
> Type: Bug
> Components: XmlObject
> Versions: Version 2, Version 2.1
> Environment: N/A
> Reporter: Andreas Loew
> Fix For: Version 2, Version 2.1
> Attachments: SubstitutionGroupTest.java, substGroupTests.xsd, substitutionGroupFix.patch, substitutionGroupInSequence.xsd, xmlbeans228_QNameSet.patch
>
> When trying to create XML documents with XMLBeans 2.x using xmlText() or save() that use substitution groups, usage of the substitute() method will mix up the order of the XML document (the order will remain correct when substitute() will not be called).
> We have attached a test case (schema XSD, JUnit test) that demonstrates the failure and also attached a patch against plain XMLBeans 2.0.0 that shows where the problem is and what is needed to fix problem (although currently at the cost of a quite severe perfomance penalty, as I am not an expert in XMLBeans internals):
> For the test case, XMLBeans 2.0.0 as well as the current SVN snapshot both fail as they return
> <?xml version="1.0" encoding="UTF-8"?>
> <Person xmlns="urn:www-apache-org:SubstitutionGroup/substitutionGroupInSequence">
> <FirstCommentElement>ThirdElement</FirstCommentElement>
> <FirstName>FirstElement</FirstName>
> <LastName>SecondElement</LastName>
> </Person>
> instead of
> <?xml version="1.0" encoding="UTF-8"?>
> <Person xmlns="urn:www-apache-org:SubstitutionGroup/substitutionGroupInSequence">
> <FirstName>FirstElement</FirstName>
> <LastName>SecondElement</LastName>
> <FirstCommentElement>ThirdElement</FirstCommentElement>
> </Person>
> as would be correct (and will be returned after applying the patches provided).
> Basically, the main problem is that XmlObjectBase#getElementEndingDelimiters() after having called SchemaProperty#getJavaSetterDelimiter(), does not take into account that the QNameSet returned by getJavaSetterDelimiter() does not yet include the "alias names" - i.e. possible substitutions - of those elements that happen to be heads of substitution groups.
> The patch for XmlObjectBase adds the missing substitutions to this QNameSet. This will fix the base problem, but so far at the cost of performance: In order to simulate a (non-existing) QNameSet iterator on the set of JavaSetterDelimiters, we have not been able to find a more intelligent solution than to iterate over the complete array of SchemaGlobalElements and check each head of a substitution group for inclusion in the QNameSet (using QNameSet#contains()). This definitely is suboptimal and should be replaced by an optimized implementation done by somebody who is familiar with the internals of XMLBeans. (Sorry!)
> Unfortunately, while creating the first fix, we ran into a second (small) issue:
> The static method QNameSet#forArray() does mistakenly pass null instead of new HashSet() to the private constructor, which results in a NullPointerException. The second fix (also included in the patch) will fix this problem.
> Please get back to me in case you need any additional details.
> Thanks & best regards,
> Andreas Loew & Patrik Streicher
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: dev-help@xmlbeans.apache.org
[jira] Updated: (XMLBEANS-228) Element order is mixed up on document creation after calling substitute()
Posted by "Lawrence Jones (JIRA)" <xm...@xml.apache.org>.
[ http://issues.apache.org/jira/browse/XMLBEANS-228?page=all ]
Lawrence Jones updated XMLBEANS-228:
------------------------------------
Attachment: xmlbeans228_QNameSet.patch
Suggested alternative patch for the QNameSet part of the problem
> Element order is mixed up on document creation after calling substitute()
> -------------------------------------------------------------------------
>
> Key: XMLBEANS-228
> URL: http://issues.apache.org/jira/browse/XMLBEANS-228
> Project: XMLBeans
> Type: Bug
> Components: XmlObject
> Versions: Version 2, Version 2.1
> Environment: N/A
> Reporter: Andreas Loew
> Fix For: Version 2, Version 2.1
> Attachments: SubstitutionGroupTest.java, substGroupTests.xsd, substitutionGroupFix.patch, substitutionGroupInSequence.xsd, xmlbeans228_QNameSet.patch
>
> When trying to create XML documents with XMLBeans 2.x using xmlText() or save() that use substitution groups, usage of the substitute() method will mix up the order of the XML document (the order will remain correct when substitute() will not be called).
> We have attached a test case (schema XSD, JUnit test) that demonstrates the failure and also attached a patch against plain XMLBeans 2.0.0 that shows where the problem is and what is needed to fix problem (although currently at the cost of a quite severe perfomance penalty, as I am not an expert in XMLBeans internals):
> For the test case, XMLBeans 2.0.0 as well as the current SVN snapshot both fail as they return
> <?xml version="1.0" encoding="UTF-8"?>
> <Person xmlns="urn:www-apache-org:SubstitutionGroup/substitutionGroupInSequence">
> <FirstCommentElement>ThirdElement</FirstCommentElement>
> <FirstName>FirstElement</FirstName>
> <LastName>SecondElement</LastName>
> </Person>
> instead of
> <?xml version="1.0" encoding="UTF-8"?>
> <Person xmlns="urn:www-apache-org:SubstitutionGroup/substitutionGroupInSequence">
> <FirstName>FirstElement</FirstName>
> <LastName>SecondElement</LastName>
> <FirstCommentElement>ThirdElement</FirstCommentElement>
> </Person>
> as would be correct (and will be returned after applying the patches provided).
> Basically, the main problem is that XmlObjectBase#getElementEndingDelimiters() after having called SchemaProperty#getJavaSetterDelimiter(), does not take into account that the QNameSet returned by getJavaSetterDelimiter() does not yet include the "alias names" - i.e. possible substitutions - of those elements that happen to be heads of substitution groups.
> The patch for XmlObjectBase adds the missing substitutions to this QNameSet. This will fix the base problem, but so far at the cost of performance: In order to simulate a (non-existing) QNameSet iterator on the set of JavaSetterDelimiters, we have not been able to find a more intelligent solution than to iterate over the complete array of SchemaGlobalElements and check each head of a substitution group for inclusion in the QNameSet (using QNameSet#contains()). This definitely is suboptimal and should be replaced by an optimized implementation done by somebody who is familiar with the internals of XMLBeans. (Sorry!)
> Unfortunately, while creating the first fix, we ran into a second (small) issue:
> The static method QNameSet#forArray() does mistakenly pass null instead of new HashSet() to the private constructor, which results in a NullPointerException. The second fix (also included in the patch) will fix this problem.
> Please get back to me in case you need any additional details.
> Thanks & best regards,
> Andreas Loew & Patrik Streicher
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: dev-help@xmlbeans.apache.org
[jira] Updated: (XMLBEANS-228) Element order is mixed up on document creation after calling substitute()
Posted by "Andreas Loew (JIRA)" <xm...@xml.apache.org>.
[ http://issues.apache.org/jira/browse/XMLBEANS-228?page=all ]
Andreas Loew updated XMLBEANS-228:
----------------------------------
Attachment: SubstitutionGroupTest.java
JUnit test case that shows the problem - fails with an unpatched xbean.jar, but works as intended using a patched version
> Element order is mixed up on document creation after calling substitute()
> -------------------------------------------------------------------------
>
> Key: XMLBEANS-228
> URL: http://issues.apache.org/jira/browse/XMLBEANS-228
> Project: XMLBeans
> Type: Bug
> Components: XmlObject
> Versions: Version 2.1, Version 2
> Environment: N/A
> Reporter: Andreas Loew
> Fix For: Version 2.1, Version 2
> Attachments: SubstitutionGroupTest.java, substitutionGroupFix.patch, substitutionGroupInSequence.xsd
>
> When trying to create XML documents with XMLBeans 2.x using xmlText() or save() that use substitution groups, usage of the substitute() method will mix up the order of the XML document (the order will remain correct when substitute() will not be called).
> We have attached a test case (schema XSD, JUnit test) that demonstrates the failure and also attached a patch against plain XMLBeans 2.0.0 that shows where the problem is and what is needed to fix problem (although currently at the cost of a quite severe perfomance penalty, as I am not an expert in XMLBeans internals):
> For the test case, XMLBeans 2.0.0 as well as the current SVN snapshot both fail as they return
> <?xml version="1.0" encoding="UTF-8"?>
> <Person xmlns="urn:www-apache-org:SubstitutionGroup/substitutionGroupInSequence">
> <FirstCommentElement>ThirdElement</FirstCommentElement>
> <FirstName>FirstElement</FirstName>
> <LastName>SecondElement</LastName>
> </Person>
> instead of
> <?xml version="1.0" encoding="UTF-8"?>
> <Person xmlns="urn:www-apache-org:SubstitutionGroup/substitutionGroupInSequence">
> <FirstName>FirstElement</FirstName>
> <LastName>SecondElement</LastName>
> <FirstCommentElement>ThirdElement</FirstCommentElement>
> </Person>
> as would be correct (and will be returned after applying the patches provided).
> Basically, the main problem is that XmlObjectBase#getElementEndingDelimiters() after having called SchemaProperty#getJavaSetterDelimiter(), does not take into account that the QNameSet returned by getJavaSetterDelimiter() does not yet include the "alias names" - i.e. possible substitutions - of those elements that happen to be heads of substitution groups.
> The patch for XmlObjectBase adds the missing substitutions to this QNameSet. This will fix the base problem, but so far at the cost of performance: In order to simulate a (non-existing) QNameSet iterator on the set of JavaSetterDelimiters, we have not been able to find a more intelligent solution than to iterate over the complete array of SchemaGlobalElements and check each head of a substitution group for inclusion in the QNameSet (using QNameSet#contains()). This definitely is suboptimal and should be replaced by an optimized implementation done by somebody who is familiar with the internals of XMLBeans. (Sorry!)
> Unfortunately, while creating the first fix, we ran into a second (small) issue:
> The static method QNameSet#forArray() does mistakenly pass null instead of new HashSet() to the private constructor, which results in a NullPointerException. The second fix (also included in the patch) will fix this problem.
> Please get back to me in case you need any additional details.
> Thanks & best regards,
> Andreas Loew & Patrik Streicher
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: dev-help@xmlbeans.apache.org
[jira] Resolved: (XMLBEANS-228) Element order is mixed up on
document creation after calling substitute()
Posted by "Radu Preotiuc-Pietro (JIRA)" <xm...@xml.apache.org>.
[ https://issues.apache.org/jira/browse/XMLBEANS-228?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Radu Preotiuc-Pietro resolved XMLBEANS-228.
-------------------------------------------
Resolution: Fixed
Done with revision 531577.
> Element order is mixed up on document creation after calling substitute()
> -------------------------------------------------------------------------
>
> Key: XMLBEANS-228
> URL: https://issues.apache.org/jira/browse/XMLBEANS-228
> Project: XMLBeans
> Issue Type: Bug
> Components: XmlObject
> Affects Versions: Version 2, Version 2.1
> Environment: N/A
> Reporter: Andreas Loew
> Fix For: Version 2, Version 2.1
>
> Attachments: substGroupTests.xsd, substitutionGroupFix.patch, substitutionGroupInSequence.xsd, SubstitutionGroupTest.java, xmlbeans228.patch, xmlbeans228_QNameSet.patch
>
>
> When trying to create XML documents with XMLBeans 2.x using xmlText() or save() that use substitution groups, usage of the substitute() method will mix up the order of the XML document (the order will remain correct when substitute() will not be called).
> We have attached a test case (schema XSD, JUnit test) that demonstrates the failure and also attached a patch against plain XMLBeans 2.0.0 that shows where the problem is and what is needed to fix problem (although currently at the cost of a quite severe perfomance penalty, as I am not an expert in XMLBeans internals):
> For the test case, XMLBeans 2.0.0 as well as the current SVN snapshot both fail as they return
> <?xml version="1.0" encoding="UTF-8"?>
> <Person xmlns="urn:www-apache-org:SubstitutionGroup/substitutionGroupInSequence">
> <FirstCommentElement>ThirdElement</FirstCommentElement>
> <FirstName>FirstElement</FirstName>
> <LastName>SecondElement</LastName>
> </Person>
> instead of
> <?xml version="1.0" encoding="UTF-8"?>
> <Person xmlns="urn:www-apache-org:SubstitutionGroup/substitutionGroupInSequence">
> <FirstName>FirstElement</FirstName>
> <LastName>SecondElement</LastName>
> <FirstCommentElement>ThirdElement</FirstCommentElement>
> </Person>
> as would be correct (and will be returned after applying the patches provided).
> Basically, the main problem is that XmlObjectBase#getElementEndingDelimiters() after having called SchemaProperty#getJavaSetterDelimiter(), does not take into account that the QNameSet returned by getJavaSetterDelimiter() does not yet include the "alias names" - i.e. possible substitutions - of those elements that happen to be heads of substitution groups.
> The patch for XmlObjectBase adds the missing substitutions to this QNameSet. This will fix the base problem, but so far at the cost of performance: In order to simulate a (non-existing) QNameSet iterator on the set of JavaSetterDelimiters, we have not been able to find a more intelligent solution than to iterate over the complete array of SchemaGlobalElements and check each head of a substitution group for inclusion in the QNameSet (using QNameSet#contains()). This definitely is suboptimal and should be replaced by an optimized implementation done by somebody who is familiar with the internals of XMLBeans. (Sorry!)
> Unfortunately, while creating the first fix, we ran into a second (small) issue:
> The static method QNameSet#forArray() does mistakenly pass null instead of new HashSet() to the private constructor, which results in a NullPointerException. The second fix (also included in the patch) will fix this problem.
> Please get back to me in case you need any additional details.
> Thanks & best regards,
> Andreas Loew & Patrik Streicher
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: dev-help@xmlbeans.apache.org
[jira] Commented: (XMLBEANS-228) Element order is mixed up on document creation after calling substitute()
Posted by "Lawrence Jones (JIRA)" <xm...@xml.apache.org>.
[ http://issues.apache.org/jira/browse/XMLBEANS-228?page=comments#action_12361156 ]
Lawrence Jones commented on XMLBEANS-228:
-----------------------------------------
Have had a quick look at this. Thanks for the detailed repro - that helps a lot.
Here are the things I've discovered so far.
You're quite right about the QNameSet problem. I'd recommend a slightly different approach to fixing it. I attached a patch.
I can repro the substitution group problem. It arises because underlying every generated XmlBean is an in-memory store in which is kept the underlying XML (in object form). Thus getters actually query this store and setters insert/update data in the store. When you use a setter for the first time what you're actually doing is inserting data into the store.
But the solution you propose has a flaw (apart from any performance concerns). This gets prettty complicated and I'm not an expert on this code but I'll do my best to explain (I also attached a schema for which your proposed patch does not work).
The code uses what it knows about the schema from which you generated the XmlBean to compute where to insert the data into the store given the elements already inserted. Bear in mind that it must do this even if you are only half way through e.g. calling all the setters, i.e. the current state of the store may not be valid XML for that object (it will be, hopefully, when you are finished calling all the setters etc. but it isn't yet) but you must choose a place to insert the new element anyway.
To insert an element via a setter, the way the code works at the moment is to look up in the schema all the elements that must be _after_ the element you are inserting and ensure that the element is inserted just before any of them. (Also if there are any occurences of the element you are inserting in the store already, this new one will go at the end of them.) It does this using the _QName_ of the element you are inserting.
Now for a "normal" element there is no problem in defining the elements that "come after" within a given content model. However if you use substitution groups to replace the substitution group head with a replacement element then, as it currently stands, the code doesn't really know where to put that element (it's akin, as far as the store is concerned, to inserting some element that is not part of the content model of that part of the schema at all). The element just gets inserted wherever the cursor is at that point in time.
Your suggested solution (as far as I can see) is to not worry about this, but when it comes time to marshal the object, collect all the instances of "things in the same substitution group" together and output them as if they were all in the one place (the place where the substitution group head would be in the schema). Now that's fine if (as in your example schema) you only have one such place. But unfortunately it won't work if there are several places (see e.g. the schema I attached).
So I propose a couple of things:
1. Without any code changes, I found that by careful monitoring of the _order_ of setters you can achieve what you want e.g. if you change your example test case to the following then the object successfully marshals and validates:
PersonDocument personDocument = PersonDocument.Factory.newInstance();
PersonDocument.Person person = personDocument.addNewPerson();
person.setFirstName("FirstElement");
person.setLastName("SecondElement");
CommentType commentType = person.addNewComment();
QName qName = new QName("urn:www-apache-org:SubstitutionGroup/substitutionGroupInSequence", "FirstCommentElement");
Object resultObject = commentType.substitute(qName, FirstCommentType.type);
FirstCommentType firstCommentType = (FirstCommentType) resultObject;
firstCommentType.setStringValue("ThirdElement");
person.setComment(firstCommentType);
All I've changed is to call the commentType setter after I've set the other 2 types (i.e. in the same position as CommentType comes in the content model).
This is not ideal of course. XmlBeans users shouldn't have to worry about the order in which setters are called. However for right now that is (I think) a pretty general solution that will get you around this problem. (You could get even more complicated and explicitly move the XmlCursor to the correct position just before you call the setter which I think would have the same effect).
2. To solve the problem long term (so that users do not have to worry about the order in which they call the setters) I suggest a different approach. When something is inserted into the store which is a substitution for something else the store should keep track of the QNames for _both_ the element we're inserting _and_ the element for which it is substituting (the "original" QName). Then it can use the original name to decide ordering, but when it comes to marshalling (or any query on the store) we output the substituted name. This should allow multiple uses of the same replacement element name in different places in the content model.
I have started work on seeing what this means (there may of course be performance concerns on this too). Unfortunately it looks pretty complicated - a large change to the underlying store code - hence this may take some time to get done.
> Element order is mixed up on document creation after calling substitute()
> -------------------------------------------------------------------------
>
> Key: XMLBEANS-228
> URL: http://issues.apache.org/jira/browse/XMLBEANS-228
> Project: XMLBeans
> Type: Bug
> Components: XmlObject
> Versions: Version 2, Version 2.1
> Environment: N/A
> Reporter: Andreas Loew
> Fix For: Version 2, Version 2.1
> Attachments: SubstitutionGroupTest.java, substGroupTests.xsd, substitutionGroupFix.patch, substitutionGroupInSequence.xsd, xmlbeans228_QNameSet.patch
>
> When trying to create XML documents with XMLBeans 2.x using xmlText() or save() that use substitution groups, usage of the substitute() method will mix up the order of the XML document (the order will remain correct when substitute() will not be called).
> We have attached a test case (schema XSD, JUnit test) that demonstrates the failure and also attached a patch against plain XMLBeans 2.0.0 that shows where the problem is and what is needed to fix problem (although currently at the cost of a quite severe perfomance penalty, as I am not an expert in XMLBeans internals):
> For the test case, XMLBeans 2.0.0 as well as the current SVN snapshot both fail as they return
> <?xml version="1.0" encoding="UTF-8"?>
> <Person xmlns="urn:www-apache-org:SubstitutionGroup/substitutionGroupInSequence">
> <FirstCommentElement>ThirdElement</FirstCommentElement>
> <FirstName>FirstElement</FirstName>
> <LastName>SecondElement</LastName>
> </Person>
> instead of
> <?xml version="1.0" encoding="UTF-8"?>
> <Person xmlns="urn:www-apache-org:SubstitutionGroup/substitutionGroupInSequence">
> <FirstName>FirstElement</FirstName>
> <LastName>SecondElement</LastName>
> <FirstCommentElement>ThirdElement</FirstCommentElement>
> </Person>
> as would be correct (and will be returned after applying the patches provided).
> Basically, the main problem is that XmlObjectBase#getElementEndingDelimiters() after having called SchemaProperty#getJavaSetterDelimiter(), does not take into account that the QNameSet returned by getJavaSetterDelimiter() does not yet include the "alias names" - i.e. possible substitutions - of those elements that happen to be heads of substitution groups.
> The patch for XmlObjectBase adds the missing substitutions to this QNameSet. This will fix the base problem, but so far at the cost of performance: In order to simulate a (non-existing) QNameSet iterator on the set of JavaSetterDelimiters, we have not been able to find a more intelligent solution than to iterate over the complete array of SchemaGlobalElements and check each head of a substitution group for inclusion in the QNameSet (using QNameSet#contains()). This definitely is suboptimal and should be replaced by an optimized implementation done by somebody who is familiar with the internals of XMLBeans. (Sorry!)
> Unfortunately, while creating the first fix, we ran into a second (small) issue:
> The static method QNameSet#forArray() does mistakenly pass null instead of new HashSet() to the private constructor, which results in a NullPointerException. The second fix (also included in the patch) will fix this problem.
> Please get back to me in case you need any additional details.
> Thanks & best regards,
> Andreas Loew & Patrik Streicher
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: dev-help@xmlbeans.apache.org
[jira] Updated: (XMLBEANS-228) Element order is mixed up on document creation after calling substitute()
Posted by "Lawrence Jones (JIRA)" <xm...@xml.apache.org>.
[ http://issues.apache.org/jira/browse/XMLBEANS-228?page=all ]
Lawrence Jones updated XMLBEANS-228:
------------------------------------
Attachment: xmlbeans228.patch
I'm attaching a patch which I think fixes this problem. However that's the good news. The bad news is that this patch is not consistent with a chat I had with one of the committers and therefore it may not get applied.
My solution keeps an extra QName on every Xobj. It is null except in the case where you are substituting for some other element in which case it is the QName of the element you are substituting for. (You then make decisions at appropriate times pretty much as mentioned in the comments above.)
The original plan we came up with wanted to (rightly I believe) create a new class, SubstituteElementXobj, derived from ElementXobj and make it so that only that class has the extra QName on it to avoid the memory burden on _every_ Xobj. Unfortunately the way XmlBeans does substitution at the moment (the XmlObjectBase.substitute() method) is kind of like a "rename" of the underlying Xobj. In order for the SubstituteElementXobj approach to work, whenever you substitute you need to create a new SubstituteElementXobj and use it to _replace_ (not just "rename") the existing Xobj.
Unfortunately there are lots of links to the existing Xobj which all then need to be updated. I'm not convinced I can even get to all of them. I tried to get it to work but basically I was trying to swap out some Xobj, call it xobj1, from within xobj1 itself and it seemed like I'd be making changes to Xobj and Cur which could have huge consequences. Also I've run out of time for being able to work on this (I need to get back to my day job ;). So I'm attaching the work I've done so far in case it's useful. I think I need someone with a lot more experience with the store code to take a look at it and decide:
a) to apply this patch and put up with the possible memory consequences, or
b) to use the above work and generate a better solution based on the SubstituteElementXobj approach (or something new)
> Element order is mixed up on document creation after calling substitute()
> -------------------------------------------------------------------------
>
> Key: XMLBEANS-228
> URL: http://issues.apache.org/jira/browse/XMLBEANS-228
> Project: XMLBeans
> Type: Bug
> Components: XmlObject
> Versions: Version 2, Version 2.1
> Environment: N/A
> Reporter: Andreas Loew
> Fix For: Version 2, Version 2.1
> Attachments: SubstitutionGroupTest.java, substGroupTests.xsd, substitutionGroupFix.patch, substitutionGroupInSequence.xsd, xmlbeans228.patch, xmlbeans228_QNameSet.patch
>
> When trying to create XML documents with XMLBeans 2.x using xmlText() or save() that use substitution groups, usage of the substitute() method will mix up the order of the XML document (the order will remain correct when substitute() will not be called).
> We have attached a test case (schema XSD, JUnit test) that demonstrates the failure and also attached a patch against plain XMLBeans 2.0.0 that shows where the problem is and what is needed to fix problem (although currently at the cost of a quite severe perfomance penalty, as I am not an expert in XMLBeans internals):
> For the test case, XMLBeans 2.0.0 as well as the current SVN snapshot both fail as they return
> <?xml version="1.0" encoding="UTF-8"?>
> <Person xmlns="urn:www-apache-org:SubstitutionGroup/substitutionGroupInSequence">
> <FirstCommentElement>ThirdElement</FirstCommentElement>
> <FirstName>FirstElement</FirstName>
> <LastName>SecondElement</LastName>
> </Person>
> instead of
> <?xml version="1.0" encoding="UTF-8"?>
> <Person xmlns="urn:www-apache-org:SubstitutionGroup/substitutionGroupInSequence">
> <FirstName>FirstElement</FirstName>
> <LastName>SecondElement</LastName>
> <FirstCommentElement>ThirdElement</FirstCommentElement>
> </Person>
> as would be correct (and will be returned after applying the patches provided).
> Basically, the main problem is that XmlObjectBase#getElementEndingDelimiters() after having called SchemaProperty#getJavaSetterDelimiter(), does not take into account that the QNameSet returned by getJavaSetterDelimiter() does not yet include the "alias names" - i.e. possible substitutions - of those elements that happen to be heads of substitution groups.
> The patch for XmlObjectBase adds the missing substitutions to this QNameSet. This will fix the base problem, but so far at the cost of performance: In order to simulate a (non-existing) QNameSet iterator on the set of JavaSetterDelimiters, we have not been able to find a more intelligent solution than to iterate over the complete array of SchemaGlobalElements and check each head of a substitution group for inclusion in the QNameSet (using QNameSet#contains()). This definitely is suboptimal and should be replaced by an optimized implementation done by somebody who is familiar with the internals of XMLBeans. (Sorry!)
> Unfortunately, while creating the first fix, we ran into a second (small) issue:
> The static method QNameSet#forArray() does mistakenly pass null instead of new HashSet() to the private constructor, which results in a NullPointerException. The second fix (also included in the patch) will fix this problem.
> Please get back to me in case you need any additional details.
> Thanks & best regards,
> Andreas Loew & Patrik Streicher
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: dev-help@xmlbeans.apache.org
[jira] Updated: (XMLBEANS-228) Element order is mixed up on document creation after calling substitute()
Posted by "Lawrence Jones (JIRA)" <xm...@xml.apache.org>.
[ http://issues.apache.org/jira/browse/XMLBEANS-228?page=all ]
Lawrence Jones updated XMLBEANS-228:
------------------------------------
Attachment: substGroupTests.xsd
Schema showing problem with substitution in multiple places
> Element order is mixed up on document creation after calling substitute()
> -------------------------------------------------------------------------
>
> Key: XMLBEANS-228
> URL: http://issues.apache.org/jira/browse/XMLBEANS-228
> Project: XMLBeans
> Type: Bug
> Components: XmlObject
> Versions: Version 2, Version 2.1
> Environment: N/A
> Reporter: Andreas Loew
> Fix For: Version 2, Version 2.1
> Attachments: SubstitutionGroupTest.java, substGroupTests.xsd, substitutionGroupFix.patch, substitutionGroupInSequence.xsd, xmlbeans228_QNameSet.patch
>
> When trying to create XML documents with XMLBeans 2.x using xmlText() or save() that use substitution groups, usage of the substitute() method will mix up the order of the XML document (the order will remain correct when substitute() will not be called).
> We have attached a test case (schema XSD, JUnit test) that demonstrates the failure and also attached a patch against plain XMLBeans 2.0.0 that shows where the problem is and what is needed to fix problem (although currently at the cost of a quite severe perfomance penalty, as I am not an expert in XMLBeans internals):
> For the test case, XMLBeans 2.0.0 as well as the current SVN snapshot both fail as they return
> <?xml version="1.0" encoding="UTF-8"?>
> <Person xmlns="urn:www-apache-org:SubstitutionGroup/substitutionGroupInSequence">
> <FirstCommentElement>ThirdElement</FirstCommentElement>
> <FirstName>FirstElement</FirstName>
> <LastName>SecondElement</LastName>
> </Person>
> instead of
> <?xml version="1.0" encoding="UTF-8"?>
> <Person xmlns="urn:www-apache-org:SubstitutionGroup/substitutionGroupInSequence">
> <FirstName>FirstElement</FirstName>
> <LastName>SecondElement</LastName>
> <FirstCommentElement>ThirdElement</FirstCommentElement>
> </Person>
> as would be correct (and will be returned after applying the patches provided).
> Basically, the main problem is that XmlObjectBase#getElementEndingDelimiters() after having called SchemaProperty#getJavaSetterDelimiter(), does not take into account that the QNameSet returned by getJavaSetterDelimiter() does not yet include the "alias names" - i.e. possible substitutions - of those elements that happen to be heads of substitution groups.
> The patch for XmlObjectBase adds the missing substitutions to this QNameSet. This will fix the base problem, but so far at the cost of performance: In order to simulate a (non-existing) QNameSet iterator on the set of JavaSetterDelimiters, we have not been able to find a more intelligent solution than to iterate over the complete array of SchemaGlobalElements and check each head of a substitution group for inclusion in the QNameSet (using QNameSet#contains()). This definitely is suboptimal and should be replaced by an optimized implementation done by somebody who is familiar with the internals of XMLBeans. (Sorry!)
> Unfortunately, while creating the first fix, we ran into a second (small) issue:
> The static method QNameSet#forArray() does mistakenly pass null instead of new HashSet() to the private constructor, which results in a NullPointerException. The second fix (also included in the patch) will fix this problem.
> Please get back to me in case you need any additional details.
> Thanks & best regards,
> Andreas Loew & Patrik Streicher
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: dev-help@xmlbeans.apache.org
[jira] Commented: (XMLBEANS-228) Element order is mixed up on document creation after calling substitute()
Posted by "Lawrence Jones (JIRA)" <xm...@xml.apache.org>.
[ http://issues.apache.org/jira/browse/XMLBEANS-228?page=comments#action_12361916 ]
Lawrence Jones commented on XMLBEANS-228:
-----------------------------------------
Sorry - there are a lot of attachments now so just for the sake of clarity the patch referred to in the last comment by me is xmlbeans228.patch.
> Element order is mixed up on document creation after calling substitute()
> -------------------------------------------------------------------------
>
> Key: XMLBEANS-228
> URL: http://issues.apache.org/jira/browse/XMLBEANS-228
> Project: XMLBeans
> Type: Bug
> Components: XmlObject
> Versions: Version 2, Version 2.1
> Environment: N/A
> Reporter: Andreas Loew
> Fix For: Version 2, Version 2.1
> Attachments: SubstitutionGroupTest.java, substGroupTests.xsd, substitutionGroupFix.patch, substitutionGroupInSequence.xsd, xmlbeans228.patch, xmlbeans228_QNameSet.patch
>
> When trying to create XML documents with XMLBeans 2.x using xmlText() or save() that use substitution groups, usage of the substitute() method will mix up the order of the XML document (the order will remain correct when substitute() will not be called).
> We have attached a test case (schema XSD, JUnit test) that demonstrates the failure and also attached a patch against plain XMLBeans 2.0.0 that shows where the problem is and what is needed to fix problem (although currently at the cost of a quite severe perfomance penalty, as I am not an expert in XMLBeans internals):
> For the test case, XMLBeans 2.0.0 as well as the current SVN snapshot both fail as they return
> <?xml version="1.0" encoding="UTF-8"?>
> <Person xmlns="urn:www-apache-org:SubstitutionGroup/substitutionGroupInSequence">
> <FirstCommentElement>ThirdElement</FirstCommentElement>
> <FirstName>FirstElement</FirstName>
> <LastName>SecondElement</LastName>
> </Person>
> instead of
> <?xml version="1.0" encoding="UTF-8"?>
> <Person xmlns="urn:www-apache-org:SubstitutionGroup/substitutionGroupInSequence">
> <FirstName>FirstElement</FirstName>
> <LastName>SecondElement</LastName>
> <FirstCommentElement>ThirdElement</FirstCommentElement>
> </Person>
> as would be correct (and will be returned after applying the patches provided).
> Basically, the main problem is that XmlObjectBase#getElementEndingDelimiters() after having called SchemaProperty#getJavaSetterDelimiter(), does not take into account that the QNameSet returned by getJavaSetterDelimiter() does not yet include the "alias names" - i.e. possible substitutions - of those elements that happen to be heads of substitution groups.
> The patch for XmlObjectBase adds the missing substitutions to this QNameSet. This will fix the base problem, but so far at the cost of performance: In order to simulate a (non-existing) QNameSet iterator on the set of JavaSetterDelimiters, we have not been able to find a more intelligent solution than to iterate over the complete array of SchemaGlobalElements and check each head of a substitution group for inclusion in the QNameSet (using QNameSet#contains()). This definitely is suboptimal and should be replaced by an optimized implementation done by somebody who is familiar with the internals of XMLBeans. (Sorry!)
> Unfortunately, while creating the first fix, we ran into a second (small) issue:
> The static method QNameSet#forArray() does mistakenly pass null instead of new HashSet() to the private constructor, which results in a NullPointerException. The second fix (also included in the patch) will fix this problem.
> Please get back to me in case you need any additional details.
> Thanks & best regards,
> Andreas Loew & Patrik Streicher
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: dev-help@xmlbeans.apache.org