Hi Vlad
Good catch. The fact that
insertNewExpression(0) does not insert at the 0th position in this
case is another bug. Radu has checked in the fix for that (but not for the
previous bugs on this thread) at SVN# 376503. Unfortunately the fix was to the
code-generation code and hence you’ll have to recompile your schemas with
scomp to pick up the change.
It only affects you if you have a) an
array setter and b) the element of the array is a member of a substitution group.
We were failing to pass the QNameSet defining the set of members of the substitution
group to the insert_element_user() method and hence it ignored any elements which
weren’t the substitution group head in deciding what position to insert
the element.
After that your code should work. However to
do what you want to do I’d recommend something more like this:
ExpressionType inserted = apply.insertNewExpression(0);
QName newName = new QName("urn:oasis:names:tc:xacml:2.0:policy:schema:os",
"Apply");
ApplyType insertedApply = (ApplyType)inserted.substitute(newName,
ApplyType.type);
insertedApply.setFunctionId("this element should be first!!!");
I know you’ve had trouble with
substitute() but I think it should work here.
Thanks for finding and reporting the bugs J.
Cheers,
Lawrence
From: Vlad Mangeym
[mailto:[EMAIL PROTECTED]]
Sent: Thursday, February 09, 2006
7:00 AM
To: [email protected]
Subject: RE: Need help with
substitutionGroup
Correction about insertNewElement: my code does not illustrate the bug
it should be like this:
// if I need to insert
a new element
apply.insertNewExpression(0);
newName = new
QName(apply.getDomNode().getNamespaceURI(), "Apply");
applyDoc =
ApplyDocument.Factory.newInstance();
newApply =
applyDoc.addNewApply();
newApply.setFunctionId("this element should be first!!!");
apply.getExpressionArray(0).newCursor().setName(newName);
apply.setExpressionArray(0, newApply);
System.out.println(apply);
This shows that insert added an element to the end of the array.
(So, still a bug)
Vlad Mangeym <[EMAIL PROTECTED]> wrote:
Lawrence,
Thank you for the very detailed explanation/analysis.
I think I have figured out how to do it with setName() and not to have
xsi:type:
// if I need to add a
new element
apply.addNewExpression();
newName = new
QName(apply.getDomNode().getNamespaceURI(), "Apply");
ApplyDocument applyDoc
= ApplyDocument.Factory.newInstance();
ApplyType newApply =
applyDoc.addNewApply();
newApply.setFunctionId("someFunction");
apply.getExpressionArray(2).newCursor().setName(newName);
apply.setExpressionArray(2, newApply);
System.out.println(apply);
Basically, I just switched two lines:
apply.getExpressionArray(2).newCursor().setName(newName);
apply.setExpressionArray(2,
newApply);
I understand the benefits of using substitute instead, but unfortunately, the
way I have it designed is that I only get one array element at a time with it's
index, so replacing the whole array is not an option.
Also, I have found another bug:
// if I need to insert
a new element
apply.insertNewExpression(0);
newName = new
QName(apply.getDomNode().getNamespaceURI(), "Apply");
applyDoc =
ApplyDocument.Factory.newInstance();
newApply =
applyDoc.addNewApply();
newApply.setFunctionId("this element should be first!!!");
apply.getExpressionArray(2).newCursor().setName(newName);
apply.setExpressionArray(2, newApply);
System.out.println(apply);
apply.insertNewExpression(0); call is always inserting new element at the end,
it seems to ignore the index completely.
Also, I am a bit confused about applyChild.getDomNode().getNamespaceURI() returning null - I have checked it aga in and it seems to be
always returning the correct value for me.
Can it be a difference in versions? (I am using version 2.1.0-r330131)
Thanks,
Vlad
Yahoo!
Mail - Helps protect you from nasty viruses.