Copying/Cloning Annotations [message #64960] |
Tue, 08 November 2005 10:06  |
Eclipse User |
|
|
|
When I'm serliazing the new schema, none of the annotations that I'm
setting are showing up. I realize when you clone ConcreteComponent that
the new component will not contain any of the annotations and you have to
create those. However, the following code adds the annotations to the
cloned node, but for some reason they aren't serialized. Here is the
corresponding code:
XSDComplexTypeDefinition clonedType =
(XSDComplexTypeDefinition)component.cloneConcreteComponent(t rue, false);
XSDComplexTypeDefinition type = (XSDComplexTypeDefinition) component;
XSDAnnotation annotation = type.getAnnotation();
if (annotation != null) {
XSDAnnotation clonedAnno = XSDFactory.eINSTANCE.createXSDAnnotation();
clonedType.setAnnotation(clonedAnno);
for (Iterator it = annotation.getUserInformation().iterator();
it.hasNext();) {
Element docuElements = (Element) it.next();
Element docCloned = (Element)docuElements.cloneNode(true);
clonedType.getAnnotation().setElement(docCloned);
}
}
This looks like it should work, any idea why the annotations aren't
serialized with the rest of the schema.
|
|
|
Re: Copying/Cloning Annotations [message #64974 is a reply to message #64960] |
Tue, 08 November 2005 10:42  |
Eclipse User |
|
|
|
Originally posted by: merks.ca.ibm.com
Dave,
Sorry, my advice to use cloneNode wasn't so good. :-(
What I think you need to do is as follows. Make sure that clonedType is
added to the xsdSchema before you try to set its annotations. Use
xsdSchema.getDocument().importNode(annotation.getElement(), true) to get
a clone that will work in the target Document. And use
clonedAnno.getElement().getParent().replaceChild(clonedAnn.g etElement(),
<result import node>). If you get stuck and have a sample project I can
run locally, I'll see what's wrong and try to make it work.
(Note that setElement is really only useful applied directly to an
XSDSchema instance; for children of the schema, their elements must be
set by the framework itself.)
Dave Carver wrote:
> When I'm serliazing the new schema, none of the annotations that I'm
> setting are showing up. I realize when you clone ConcreteComponent
> that the new component will not contain any of the annotations and you
> have to create those. However, the following code adds the
> annotations to the cloned node, but for some reason they aren't
> serialized. Here is the corresponding code:
>
> XSDComplexTypeDefinition clonedType =
> (XSDComplexTypeDefinition)component.cloneConcreteComponent(t rue, false);
> XSDComplexTypeDefinition type = (XSDComplexTypeDefinition) component;
> XSDAnnotation annotation = type.getAnnotation();
> if (annotation != null) {
> XSDAnnotation clonedAnno = XSDFactory.eINSTANCE.createXSDAnnotation();
> clonedType.setAnnotation(clonedAnno);
> for (Iterator it = annotation.getUserInformation().iterator();
> it.hasNext();) {
> Element docuElements = (Element) it.next();
> Element docCloned = (Element)docuElements.cloneNode(true);
> clonedType.getAnnotation().setElement(docCloned);
> }
> }
>
> This looks like it should work, any idea why the annotations aren't
> serialized with the rest of the schema.
>
>
>
|
|
|
Re: Copying/Cloning Annotations [message #597145 is a reply to message #64960] |
Tue, 08 November 2005 10:42  |
Eclipse User |
|
|
|
Dave,
Sorry, my advice to use cloneNode wasn't so good. :-(
What I think you need to do is as follows. Make sure that clonedType is
added to the xsdSchema before you try to set its annotations. Use
xsdSchema.getDocument().importNode(annotation.getElement(), true) to get
a clone that will work in the target Document. And use
clonedAnno.getElement().getParent().replaceChild(clonedAnn.g etElement(),
<result import node>). If you get stuck and have a sample project I can
run locally, I'll see what's wrong and try to make it work.
(Note that setElement is really only useful applied directly to an
XSDSchema instance; for children of the schema, their elements must be
set by the framework itself.)
Dave Carver wrote:
> When I'm serliazing the new schema, none of the annotations that I'm
> setting are showing up. I realize when you clone ConcreteComponent
> that the new component will not contain any of the annotations and you
> have to create those. However, the following code adds the
> annotations to the cloned node, but for some reason they aren't
> serialized. Here is the corresponding code:
>
> XSDComplexTypeDefinition clonedType =
> (XSDComplexTypeDefinition)component.cloneConcreteComponent(t rue, false);
> XSDComplexTypeDefinition type = (XSDComplexTypeDefinition) component;
> XSDAnnotation annotation = type.getAnnotation();
> if (annotation != null) {
> XSDAnnotation clonedAnno = XSDFactory.eINSTANCE.createXSDAnnotation();
> clonedType.setAnnotation(clonedAnno);
> for (Iterator it = annotation.getUserInformation().iterator();
> it.hasNext();) {
> Element docuElements = (Element) it.next();
> Element docCloned = (Element)docuElements.cloneNode(true);
> clonedType.getAnnotation().setElement(docCloned);
> }
> }
>
> This looks like it should work, any idea why the annotations aren't
> serialized with the rest of the schema.
>
>
>
|
|
|
Powered by
FUDForum. Page generated in 0.03321 seconds