Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » MOXy example missing?
MOXy example missing? [message #558563] Mon, 13 September 2010 14:01 Go to next message
Matti Hansson is currently offline Matti Hansson
Messages: 68
Registered: July 2009
Member
Hi!
I've previously been using MOXy in Eclipselink 1.1.2, but now a new project is starting so I want to evaluate how the new mapping-through-xml functionality in Eclipselink 2.1.1 works compared to the old way using descriptors.

I'm having a bit of trouble setting things up though. I'm currently trying this code:

Class[] supported = new Class[] {
  com.foo.domain.model.Bar.class,
  com.foo.query.BarRequest.class,
  com.foo.query.BarResponse.class
};

Map<String, Source> mappingMetadata = new HashMap<String, Source>();
mappingMetadata.put("com.foo.domain.model", new StreamSource("/com/foo/domain/model/eclipselink-oxm.xml"));
mappingMetadata.put("com.foo.query", new StreamSource("/META-INF/eclipselink-oxm.xml"));
// Do you have to have one eclipselink-oxm.xml for each package?

Map<String, Object> properties = new HashMap<String, Object>();
properties.put(JAXBContextFactory.ECLIPSELINK_OXM_XML_KEY, mappingMetadata);

jaxbContext = JAXBContext.newInstance(supported, properties);


This results in a FileNotFoundException: \META-INF\eclipselink-oxm.xml

I also tried changing the last line to
jaxbContext = JAXBContext.newInstance("com.foo.domain.model:com.foo.query", JAXBContext.class.getClassLoader(), properties);

but that gives me a javax.xml.bind.JAXBException: Provider org.eclipse.persistence.jaxb.JAXBContextFactory not found

Many of the wiki documentation pages refer to an example project in a zip file and points to the download page, but I can't find it anywhere. Such an example project would be a great help in getting things started.

Anyway, if someone could help me out, it'd be greatly appreciated.
Thanks!
/Matti
Re: MOXy example missing? [message #558650 is a reply to message #558563] Mon, 13 September 2010 19:38 Go to previous messageGo to next message
Blaise Doughan is currently offline Blaise Doughan
Messages: 163
Registered: July 2009
Senior Member

Hello,

Do you mean to load the metadata as files or as InputStreams from the classpath? Both will work.

As files, you will need to ensure that those paths are relative to your working directory. For example in EclipseLink the default working directory is the project home so you may need to add the "src" directory to the beginning of the path.

From the classpath you could do the following:

InputStream meta = Thread.currentThread().getContextClassLoader().getResourceAsStream("com/foo/domain/model/eclipselink-oxm.xml");
new StreamSource(meta);


You do need to have a metadata file per package. This is to handle the content of JAXB's package level annotations.

I think you are going to enjoy the new XML metadata. We're looking at making the bootstrapping easier. You can refer to the following enhancement request:

- https://bugs.eclipse.org/bugs/show_bug.cgi?id=319052

-Blaise
Re: MOXy example missing? [message #558809 is a reply to message #558650] Tue, 14 September 2010 14:08 Go to previous message
Matti Hansson is currently offline Matti Hansson
Messages: 68
Registered: July 2009
Member
Thanks a bunch, Blaise! I'm now well on my way to discovering the wonders of the new MOXy Very Happy

However, I have a few more questions. First off, is there a more comprehensive documentation on using eclipselink-oxm.xml avaliable? Something akin to Introduction to XML Mappings (ELUG)? I can read the schemas but they only tell me that, for example, the element "xml-element" has an attribute named "type". I still have no idea what that attribute does.

Second, I want all my elements namespace qualified. I see that using the "namespace" attribute on xml-root-element and xml-element does accomplish this, but do I have to write the long namespace string for every element? Understandable, but it gets a bit tedious. Also, the namespace attribute seems to have no effect when the xml-path attribute is used. Maybe I should always use xml-path="ns0:thePath" and skip writing the namespace instead?

Third and last, I have some complex classes from the old projects that are going to be brought over to the new project. Those classes were quite difficult to map so, if possible, I'd like to reuse the old descriptors in conjunction with the new eclipselink-oxm.xml mappings. How would I go about that?

I am indeed enjoying the new way of mapping objects to XML and I'm looking forward to delving even deeper.
Thanks!
/Matti
Previous Topic:Query with multiple matches in collection
Next Topic:Are UnitOfWork#hasChanges side effects a bug?
Goto Forum:
  


Current Time: Wed Sep 17 13:39:18 GMT 2014

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

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