Use DMT Framework out of  box


To use DMT Framework out of box it will perform same function as default Java Serialization, but you can gain small data transfer size.
Since any of your object will be encoded and put into a DMTCart, the command parttern will be perfect fit for DMT Framework. We strongly recommand you use Command Pattern.

Example:

Surppose you want get an UserAccount Object back to client use Command pattern, the command implementation should be:
Command interface
GetUserAccountCommand


import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.io.Serializable;
import org.dmdf.dmt.DMTVisitor;

public class UserAccount implements Externalizable{

//your object attributes here

public UserAccount() {
super();
}
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
if (in instanceof DMTVisitor) {
((DMTVisitor) in).accept(this);
return;
}
// TODO: you can add your own implementation here, but it will only be
// used if you don't use DMTFramework
}

public void writeExternal(ObjectOutput out) throws IOException {

if (out instanceof DMTVisitor) {
((DMTVisitor) out).accept(this);
return;
}
// TODO: you can add your own implementation here, but it will only be
// used if you don't use DMTFramework
}
}


import java.io.Serializable;

public interface Command extends Serializable{

    public void excute() throws Exception;
}

import java.io.Externalizable;

import org.dmdf.dmt.DMT;
import org.dmdf.dmt.DMTCart;

public class GetUserAccountCommand implements Command {
       private String userId;
    private DMTCart cart;

    private GetUserAccountCommand() {
        super();
    }

    public GetUserAccountCommand(String userId) {
        this.userId = userId;
    }

    public void excute() throws Exception {

        // get object from your server interface e.g Hibernate or EJB
        Externalizable userAccount = null;
        this.cart = new DMT().encode(userAccount);
    }

    public UserAccount getUserAccount() throws Exception {
        return (UserAccount) new DMT().decode(this.cart);
    }
}


Now you can use your project's implementation/framework/EJB interface, let client side create this command, sent to server excute, and return it back to client.