2

Problem

Given a technology specific Java Model T, I want to have:

  • a technology agnostic model A to use in my code (i.e. the M in MVC).
  • a persistence mechanism P to store my model A.

Approach

Currently I have figured out some options:

Option 1:

  • Manually create the classes for A
  • Manually create the code to translate T to A
  • Manually create an XSD of a third JAXB-Model J
  • Generate JAXB-Model-Classes from J
  • Manually create the code to translate A to J
  • Use JAXB to automatically save J
  • When loading all translations have to be created into the other direction manually.
  • Advantage: can't see one. Thats my question :)
  • Disadvantage: most developing effort of all Options.

Option 2:

  • Manually create an XSD of a JAXB-Model of A
  • Generate JAXB-Model-Classes for A
  • Manually create the code to translate T to A
  • Use JAXB to automatically save A
  • When loading the translations has to be created into the other direction manually.
  • Advantage: Low developing effort. A can be persisted directly.
  • Disadvantage: I read, that it's a bad Idea, to use JAXB-classes as modell. But I don't understand why.

Option 3:

  • Manually create the Model of A as an eCore-Model
  • Generate the classes of A from the ecore-Model
  • Manually create the code to translate T to A
  • Use eCore-resources to automatically save A
  • When loading the translations has to be created into the other direction manually.
  • Advantage: Low developing effort. A can be persisted directly.
  • Disadvantage: None?

Looking at the advantages and disadvatages, I it seems like I should definitly use eCore instead of JAXB.

Question

  • Is it really that clear, to use eCore? Or are there advantages/disadvantages I should also think about?
  • Is here an easier way to translate from the technology specific model T to the technology agnostic modell A. Currenly I have to implement A and the translation A <-> T myself. Some easier way would be nice.
Waog
  • 7,127
  • 5
  • 25
  • 37
  • maybe it's because I personally know neither technology, but... Why would you need a model to be persistable in two different technology specifics? or rather why would you need two persisting technologies in the same project? – Vogel612 Aug 13 '14 at 14:05
  • I only want to use one of the technologies. **either eCore or JAXB**. But whant your help to decide on one of those. What part of my question made you think I want both technologies? – Waog Aug 13 '14 at 14:08
  • The problem you describe has a language-agnostic description and several attempts for language-agnostic solution (no Java and no Eclipse). Search for terms "Model Driven Architecture" and "Platform Independent Model" (perhaps also "Object Relational Mapper") for some more best practices outside the world of the 2 frameworks you consider – xmojmr Aug 17 '14 at 05:22

1 Answers1

2

You could use JAXB to convert your Model A to XML. This leverages the Java first aspect of JAXB instead if the schema first in your question.

bdoughan
  • 147,609
  • 23
  • 300
  • 400