|
Re: Can I use .xsd2ecore to specify class names to generate [message #529286 is a reply to message #529234] |
Fri, 23 April 2010 17:01 |
Ed Merks Messages: 33264 Registered: July 2009 |
Senior Member |
|
|
This is a multi-part message in MIME format.
--------------090601060605030507050706
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Swavek,
Using ecore:name annotations you should be able to produce whatever name
your want. Using ecore:package you could just redirect to a different
package and not worry about the class names.:
XML Schema to Ecore Mapping
< http://www.eclipse.org/modeling/emf/docs/overviews/XMLSchema ToEcoreMapping.pdf>
Swavek wrote:
> I have a project which uses both EMF & JAXB serialization. The JAXB
> serialization is used by our engine so I can't just rely on EMF
> serialization because it would require massive changes in the engine.
> EMF serialization has been introduced via GMF because I am building a
> graphical editor which will create input for our engine. I generated
> ecore model from the XSD files and the same files are used to generate
> JAXB classes. The initial result was that EMF and JAXB classes were
> named the same and were located in the same packages although in
> different plugins. However since I need to use some engine code in
> the diagramming code I need to pull the plugins which have JAXB
> generated classes and that causes compile errors.
> My initial solution to this was to change the package names so I ended
> up with classes like this.
> generated.export.dpf.XmlProcessingNode (for JAXB)
> generated.gmf.export.dpf.XmlProcessingNode (for EMF)
>
> This worked for a while. I was able to work on my diagram editor and
> create xml files using just the EMF set of generated classes. However
> as soon as I attempted to read the xml files created by EMF with JAXB
> classes I ran into problem because my xml namespaces were different
> and JAXB deserialization didn't work at all.
>
> I discovered that I can create a set of EMF classes that would be in
> the same package as those in JAXB but I have to change their names to
> say start with Emf instead of Xml. During serialization via EMF
> classes I can alter the names of elements that will be written out via
> save options, so that a class EmfProcessingNode will be written out as
> <XmlProcessingNode>
> I am doing this by specifying custom metadata in my domain model
> factory derived from ResourceFactoryImpl like so:
>
> public Resource createResource(URI uri) {
> XMLResource result = new NetworkResourceImpl(uri);
>
> final ExtendedMetaData ext = new BasicExtendedMetaData(
> ExtendedMetaData.ANNOTATION_URI,
> EPackage.Registry.INSTANCE, new
> HashMap());
>
> ext.setName(NetworkPackage.Literals.EMF_PROCESSING_NODE,
> "XmlProcessingNode");
> result.getDefaultSaveOptions().put(XMLResource.OPTION_EXTEND
> ED_META_DATA, ext);
> result.getDefaultLoadOptions().put(XMLResource.OPTION_EXTEND
> ED_META_DATA, ext);
>
> return result;
> }
>
> I think this approach will let me serialize and deserialize the same
> xml file using either JAXB or EMF classes. My question is regarding
> preserving the renaming of classes from Xml.. to Emf..
>
> I know that if I manually rename these classes in .ecore file they
> will be propagated to .genmodel and further to GMF generator.
>
> What I would like to know is if I can specify the Emf names in
> .xsd2ecore so that when I change the .xsd files (as they will for
> sure) and I need to regenerate the .ecore files these changes will not
> have to be done manually again. Is this what .xsd2ecore file is for
> or is it for something else?
>
> Thanks,
> Swavek
>
>
--------------090601060605030507050706
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 8bit
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=UTF-8" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Swavek,<br>
<br>
Using ecore:name annotations you should be able to produce whatever
name your want. Using ecore:package you could just redirect to a
different package and not worry about the class names.:<br>
<blockquote><a
href=" http://www.eclipse.org/modeling/emf/docs/overviews/XMLSchema ToEcoreMapping.pdf">XML
Schema to Ecore Mapping</a><br>
</blockquote>
<br>
Swavek wrote:
<blockquote cite="mid:hqsaj9$8in$1@build.eclipse.org" type="cite">I
have a project which uses both EMF & JAXB serialization. The JAXB
serialization is used by our engine so I can't just rely on EMF
serialization because it would require massive changes in the engine.
EMF serialization has been introduced via GMF because I am building a
graphical editor which will create input for our engine. I generated
ecore model from the XSD files and the same files are used to generate
JAXB classes. The initial result was that EMF and JAXB classes were
named the same and were located in the same packages although in
different plugins. However since I need to use some engine code in the
diagramming code I need to pull the plugins which have JAXB generated
classes and that causes compile errors. <br>
My initial solution to this was to change the package names so I ended
up with classes like this.
<br>
generated.export.dpf.XmlProcessingNode (for JAXB)
<br>
generated.gmf.export.dpf.XmlProcessingNode (for EMF)
<br>
<br>
This worked for a while. I was able to work on my diagram editor and
create xml files using just the EMF set of generated classes. However
as soon as I attempted to read the xml files created by EMF with JAXB
classes I ran into problem because my xml namespaces were different and
JAXB deserialization didn't work at all.
<br>
<br>
I discovered that I can create a set of EMF classes that would be in
the same package as those in JAXB but I have to change their names to
say start with Emf instead of Xml. During serialization via EMF
classes I can alter the names of elements that will be written out via
save options, so that a class EmfProcessingNode will be written out as
<XmlProcessingNode>
<br>
I am doing this by specifying custom metadata in my domain model
factory derived from ResourceFactoryImpl like so:
<br>
<br>
public Resource createResource(URI uri) {
<br>
XMLResource result = new NetworkResourceImpl(uri);
<br>
<br>
final ExtendedMetaData ext = new BasicExtendedMetaData(
<br>
ExtendedMetaData.ANNOTATION_URI,
<br>
EPackage.Registry.INSTANCE, new
HashMap());
<br>
<br>
ext.setName(NetworkPackage.Literals.EMF_PROCESSING_NODE,
"XmlProcessingNode");
<br>
result.getDefaultSaveOptions().put(XMLResource.OPTION_EXTEND
ED_META_DATA, ext);
<br>
result.getDefaultLoadOptions().put(XMLResource.OPTION_EXTEND
ED_META_DATA, ext);
<br>
<br>
return result;
<br>
}
<br>
<br>
I think this approach will let me serialize and deserialize the same
xml file using either JAXB or EMF classes. My question is regarding
preserving the renaming of classes from Xml.. to Emf..
<br>
<br>
I know that if I manually rename these classes in .ecore file they will
be propagated to .genmodel and further to GMF generator.
<br>
<br>
What I would like to know is if I can specify the Emf names in
..xsd2ecore so that when I change the .xsd files (as they will for sure)
and I need to regenerate the .ecore files these changes will not have
to be done manually again. Is this what .xsd2ecore file is for or is
it for something else?
<br>
<br>
Thanks,
<br>
Swavek
<br>
<br>
<br>
</blockquote>
</body>
</html>
--------------090601060605030507050706--
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Powered by
FUDForum. Page generated in 0.02358 seconds