ReportTypeClient.java from Negest at Krugle
Show ReportTypeClient.java syntax highlighted
package tk.sabreWulf.negest.test;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.rmi.PortableRemoteObject;
import tk.sabreWulf.negest.entity.reports.ReportTypeEJB;
import tk.sabreWulf.negest.entity.security.UsuarioEJB;
import tk.sabreWulf.negest.reports.ReportTypeAgentRemote;
public class ReportTypeClient {
private static ReportTypeAgentRemote remote;
public static void main(String[] args){
launch();
}
public static void launch(){
try {
Context jndiContext = getInitialContext();
Object ref = jndiContext.lookup("negestSvr/ReportTypeAgentBean/remote");
remote = (ReportTypeAgentRemote) PortableRemoteObject.narrow(ref, ReportTypeAgentRemote.class);
createReportType();
ReportTypeEJB reportType2 = remote.getReportTypeByPK(2);
if (reportType2 != null){
System.out.println(reportType2.getName());
deleteReportType(reportType2);
}
reportType2 = remote.getReportTypeByPK(19);
if (reportType2 != null){
// System.out.println("Empresa asociada: " + reportType2.getFirms().iterator().next().getNombre());
// System.out.println("Rol asociado: " + reportType2.getRoles().iterator().next().getDescripcion());
}
} catch (NamingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static Context getInitialContext() throws NamingException{
java.util.Properties properties = new java.util.Properties();
properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
properties.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
properties.put(Context.PROVIDER_URL, "jnp://localhost:1099");
return new InitialContext(properties);
}
private static ReportTypeEJB createReportType(){
ReportTypeEJB reportType = new ReportTypeEJB();
reportType.setName("Name");
System.out.println(reportType.getName());
reportType = remote.createReportType(reportType);
System.out.println("Report created, Id:" + reportType.getId());
return reportType;
}
private static void modifyReportType(ReportTypeEJB reportType){
reportType.setName(reportType.getName() +"a");
remote.modifyReportType(reportType);
System.out.println("ReportType modified, Id:" + reportType.getId());
}
private static void deleteReportType(ReportTypeEJB reportType){
remote.deleteReportType(reportType);
System.out.println("Report deleted, Id:" + reportType.getId());
}
}
See more files for this project here