You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by Bill Lear <ra...@zopyra.com> on 2003/05/01 16:10:13 UTC

Question on object design with WSDL2java

I'm having some trouble deciding how to design using classes generated
by WSDL2java, and I think this might be a general problem when using
WSDL2Java to generate classes.  I feel I have uncovered a general flaw
in the design of WSDL2Java, as it simply copies class implementation,
rather than extends it, making reuse difficult.  Not sure about this,
but it appears this way to my ignorant eyes.

Anyway, here's my story:

My practice is to create a basic object model package, a transport
package and a store package.  The object model is, well, the object
model of the system (User, Address, Phone, Account, etc.).  The
transport package is where soap/Axis stuff lives, and the store
package is where the code for storing things to permanent storage
goes.

My problem is when I generate code using WSDL2java it does not extend
the classes in my model (User, for example), and that means that I
have to either 1) use the generated User as my model object, which
means my store package and transport implementation classes have to be
written to accept these objects; 2) modify the generated class
to extend the original model class, which involves cutting out the
data members, etc., and adding an "extends" clause.

Here's what I'm talking about, in somewhat contrived and very
simplified form:

Here's class model.User:

public class User {
    String name;
    String email;
    // ... get/set methods and constructor
}

Here's the storage interface store.IStore:

public interface IStore {
    User registerNewUser(User user, String password);
}

And here's the stuff in the transport package:

public interface IRegisterNewUser {
    User execute(User user, String password) throws java.rmi.RemoteException;
}

public class RegisterNewUser implements IRegisterNewUser {
    public RegisterNewUser(User user, String password) {
        this.user = user;
        this.password = password;
    }

    // fake getStore() method pulls an IStore instance from a hat ...
    public User execute() throws java.rmi.RemoteException {
        getStore().registerNewUser(user, password);
    }
}

Now, when I generate using WSDL2java (after using java2WSDL), I am
left with a OpSoapBindingImpl class that looks like this:

public class OpSoapBindingImpl implements
    transport.ws.IRegisterNewUser {
    public model.ws.User execute(model.ws.User user, String password)
        throws java.rmi.RemoteException {
        return null;
    }
}

To finish, I have to implement the above class, resulting in something
like this:

public class OpSoapBindingImpl implements
    transport.ws.IRegisterNewUser {

    transport.RegisterNewUser r = new transport.RegisterNewUser();

    public model.ws.User execute(model.ws.User user, String password)
        throws java.rmi.RemoteException {

        // XXXX

    }
}

In the above, XXXX represents my problem: I have to create a new
model.User class from the input model.ws.User class, and pass it
to the registration class, 'r', above.  It will return a model.User,
which I then have to convert to a model.ws.User instance in
order to return it.  This is tedious, error prone, and brittle
under change.

So, I'm wondering: how best to handle this?

Has anyone here dealt with this before?

It would be best if model.ws.User extended model.User instead of
copying the implementation.  If it does not, I need to copy as above,
or if I don't want to hassle with copying, I need to change the
interface in RegisterNewUser and IStore to use model.ws.User, which to
my mind seems to be the solution that is most flexible under change
and the least manual intervention (zero, in fact).  But this seems
rather untidy as well (perhaps I'm just being irrational, however).
If I could get WSDL2Java to extend my original class, I think things
would be fine, but it doesn't appear to be possible.

Sorry for the long post and thanks for any help you can offer.


Bill