Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » XML Schema Definition (XSD) » Copying/Cloning Annotations
Copying/Cloning Annotations [message #64960] Tue, 08 November 2005 15:06 Go to next message
David Carver is currently offline David CarverFriend
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 15:42 Go to previous message
Eclipse UserFriend
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 15:42 Go to previous message
Ed Merks is currently online Ed MerksFriend
Messages: 33108
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.
>
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Copying/Cloning Annotations
Next Topic:Load Performance
Goto Forum:
  


Current Time: Tue Mar 19 09:59:27 GMT 2024

Powered by FUDForum. Page generated in 0.01712 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top