MOXy: can't xml-bindings xml-transient parent class when it has same name in different package [message #667089] |
Tue, 26 April 2011 16:47 |
Ed Staub Messages: 16 Registered: April 2011 |
Junior Member |
|
|
I'm trying to use schemagen with an external <xml-bindings> file.
Class foo.MyOwnGrandpa extends class mumble.MyOwnGrandpa.
I can't really touch the classes involved - especially the parent class, which is generated.
If I set xml-transient on the parent class, I get an error out of the AnnotationsProcessor:
Exception Description: Name collision. Two classes have the XML type with uri and name myOwnGrandpa.
The bindings file for the mumble package has no effect in this context, because of xml-transient. The bindings passed in to the AnnotationsProcessor are for the child package. So the obvious workaround - change the parent-class xml name or namespace - can't be used.
Am I missing something?
Any suggestions for a workaround?
Should I report this as a bug?
[Updated on: Tue, 26 April 2011 19:06] Report message to a moderator
|
|
|
|
|
|
Re: MOXy: can't xml-bindings xml-transient parent class when it has same name in different package [message #667868 is a reply to message #667854] |
Mon, 02 May 2011 14:25 |
|
Hi Ed,
You can have a bindings file per package. The following describes how to do this using EclipseLink 2.2. This can also be done in EclipseLink 2.1, but the code required is more verbose:
package example;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.SchemaOutputResolver;
import javax.xml.transform.Result;
import javax.xml.transform.stream.StreamResult;
import org.eclipse.persistence.jaxb.JAXBContextFactory;
import example.b.MyOwnGrandpa;
public class Demo {
public static void main(String[] args) throws Exception {
Map<String, Object> properties = new HashMap<String, Object>(1);
List<File> bindingFiles = new ArrayList<File>();
bindingFiles.add(new File("src/example/a/binding-a.xml"));
bindingFiles.add(new File("src/example/b/binding-b.xml"));
properties.put(JAXBContextFactory.ECLIPSELINK_OXM_XML_KEY, bindingFiles);
JAXBContext jc = JAXBContext.newInstance(new Class[] {MyOwnGrandpa.class} , properties);
jc.generateSchema(new MySOR());
}
private static class MySOR extends SchemaOutputResolver {
@Override
public Result createOutput(String arg0, String arg1) throws IOException {
StreamResult result = new StreamResult(System.out);
result.setSystemId(arg1);
return result;
}
}
}
binding-a.xml
In EclipseLink 2.2, the package name can be specified in the bindings file:
<?xml version="1.0" encoding="UTF-8"?>
<xml-bindings
xmlns="http://www.eclipse.org/eclipselink/xsds/persistence/oxm"
package-name="example.a">
<java-types>
<java-type name="MyOwnGrandpa" xml-transient="true">
<xml-type name="MyOwnGrandpa2"/>
</java-type>
</java-types>
</xml-bindings>
binding-b.xml
<?xml version="1.0" encoding="UTF-8"?>
<xml-bindings
xmlns="http://www.eclipse.org/eclipselink/xsds/persistence/oxm"
package-name="example.b">
<java-types>
<java-type name="MyOwnGrandpa">
<java-attributes>
<xml-attribute java-attribute="b"/>
</java-attributes>
</java-type>
</java-types>
</xml-bindings>
-Blaise
|
|
|
Powered by
FUDForum. Page generated in 0.04298 seconds