Skip to main content

JAXB object interfaces and implementations

1 reply [Last post]
Joined: 2005-06-07

Hi, i have a problem that i can't solve, perhaps someone could help me:

I have a schema type , let's imagine its this one :

i used xjc to compile a java interface and a java implementation from this schema, and i got something like that:

public interface Root {
public String getPersonne();
public void setPersonne(String personne);

and this implementation:

public class RootImpl
extends requesturi.impl.RootTypeImpl
implements requesturi.Root, etc. {

This is really what i needed, but now the problem is that I use a third party program that defines an interface like this:

public interface iface {
void method(Root root);

I have to provide an implementation of this interface in order to be called by this program (web service program) on service invocation:

public class implementationOfIface implements iface {
public void method(Root root) {
// at this stage, the third party program provides me a valid implementation of root type, but this is NOT RootImpl, this is an internal implementation ...

This program will call my implementation with an internal "Root" implementation.

As we both implements Root interface, i wonder if it was possible to create a (JAXB) RootImpl implementation object from the "root" parameter ...
In fact i tried the following code:

public class implementationOfIface implements iface {
public void method(Root root) {
try {
JAXBContext jc = JAXBContext.newInstance("");
ObjectFactory factory = new ObjectFactory();
RootImpl root = (RootImpl) factory.newInstance(root.getClass());
} catch ...

And this result in an exception ...
Is there a way to achieve this ??

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2003-06-09

How does that 3rd party library knows how to implement an interface generated by JAXB?

Or is that interface implemented by a proxy?

If you can touch that implementation, you can use JAXB annotations directly on those implementations.

I can't think of an easy way to do this. Perhaps you can come up with an utility that copies the object field-by-field into JAXB objects?