Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » XML Schema Definition (XSD) » Copying/Cloning Annotations
Copying/Cloning Annotations [message #64960] Tue, 08 November 2005 10:06 Go to next message
David Carver is currently offline David Carver
Messages: 174
Registered: July 2009
Senior Member
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 Go to previous message
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 Go to previous message
Ed Merks is currently offline Ed Merks
Messages: 26000
Registered: July 2009
Senior Member
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.
>
>
>
Previous Topic:Copying/Cloning Annotations
Next Topic:Load Performance
Goto Forum:
  


Current Time: Sat Aug 23 15:31:25 EDT 2014

Powered by FUDForum. Page generated in 0.01753 seconds