package samples.ejb;
import javax.ejb.*;
import javax.rmi.PortableRemoteObject;
import javax.naming.NamingException;
import javax.naming.InitialContext;
import javax.transaction.UserTransaction;
import samples.cli.UserManager;
import net.sf.voruta.*;
/**
* demonstarates Voruta for J2EE
* @author user
*/
public class Main {
public static void performActions(UserManager manager,String args[]){
if(args.length == 3 && "addUser".equals(args[0]) ){
manager.addUser( args[1],args[2]);
}else {
throw new IllegalArgumentException("unknown action");
}
}
/** Creates a new instance of Main */
public Main() {
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws Exception{
InitialContext initialContext = new InitialContext();
Client client = null;
try {
client = Client.getInstance(UserManager.class);
UserTransaction tx = (UserTransaction)initialContext.lookup("UserTransaction");
UserManager manager = (UserManager)client.create();
try{
tx.begin();
performActions(manager,args);
tx.commit();
}catch(Throwable e){
tx.rollback();
throw new DbException(e);
}
} finally { //release resources
initialContext.close();
if(client != null){
client.remove();
}
}
System.out.println("OK");
}
}