views:

195

answers:

4

Hello,

I have a schema in xsd file. once in a while a new version of the schema is created, and I need to update my .ecore (and .genmodel). How do I update them, without deleting them and re-generate them. I have made some manual modification to the ecore, and i want to keep this modifications.

Ido.

A: 

I've never tried this, but the XSD FAQ says this:

JAXB produces a simple Java API given an XML Schema and it does so using essentially a black box design. EMF produces an Ecore model given an XML Schema and then uses template-based generator technology to generate a rich Java API (of hand written quality). The XML Schema to Ecore conversion can be tailored, the templates used to generate the Java API can be tailored, and the resulting Java API can be tailored. The generator supports merging regeneration so that it will preserve your hand written changes. In other words, EMF is far richer and more flexible, and supports a broader subset of XML Schema (especially in 2.0, where wildcards and mixed content will be supported).

If I were you, I'd try some experiments to see how well this process works, and what the practical limitations are.

Stephen C
I think that it means that it can regenerate the java code from the ecore.
Ido
@Ido: don't assume. Try it out.
Stephen C
A: 

You can regenerate using the context menu options. To preserve your modifications:

  • If there is a method that has "Gen" added to the name -- e.g. setWhateverGen in addition to setWhatever -- new code will be generated to the "Gen" method. So leave the "Gen" method alone so that it can be overwritten, and then call it from the non-Gen method, which you can modify.
  • All the generated methods are annotated with @generated. If you add "NOT" -- @generated NOT -- it will not be overwritten.

All other content should be merged. Go ahead and experiment -- that's what version control is for....

Ken
I guess it will work, but I wanted to make changes in the ecore and not in the generated code. is it possible to add annotated like @generated NOT to the .ecore file?
Ido
A: 

Use the Reload... action on the *.genmodel to update the *.ecore based on the new version of the *.xsd.

A: 

And don't change the .ecore directly. Using ecore: annotations in the schema. http://www.eclipse.org/modeling/emf/docs/overviews/XMLSchemaToEcoreMapping.pdf

I cann't change the schema. Someone else update it.
Ido
There's no support for https://bugs.eclipse.org/bugs/show_bug.cgi?id=197943 yet. Of course you can change a copy of the schema, and by keeping the old/original schema version around, you can keep track of what changed so you can add annotations to the changes.
B.T.WIf I will add my elements to the .ecore file or to the schema using ecore annotations, will the result be that my xml files will break the original schema on validation?
Ido
It's not clear what you're adding or why. Annotations on modify the mapping and won't impact the XML serialization. Note that I'm more likely to see your questions if you use the EMF newsgroup to ask them.