1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
|
import java.util.Date;
import java.util.Hashtable;
import java.util.List;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
public class DataManager
{
private static Hashtable<String, String> jndiProperties = new Hashtable<String, String>();
private static Context context;
private PortailApplicationsFacadeRemote facade;
public DataManager()
{
String remoteServer = System.getProperty("REMOTE_SERVER");
jndiProperties.put( Context.PROVIDER_URL, "remote://" + remoteServer + ":4447" );
jndiProperties.put( Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming" );
jndiProperties.put( "jboss.naming.client.ejb.context", "true" );
jndiProperties.put( Context.SECURITY_PRINCIPAL, "..." );
jndiProperties.put( Context.SECURITY_CREDENTIALS, "..." );
jndiProperties.put( Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory" );
}
public Context getContext()
{
if (context == null)
{
try
{
context = new InitialContext(jndiProperties);
}
catch (Exception e)
{
e.printStackTrace();
}
}
return context;
}
private PortailApplicationsFacadeRemote getFacade() throws NamingException
{
if (facade == null)
{
facade = (PortailApplicationsFacadeRemote) getContext().lookup("ejb:Applications/ApplicationsEJB/ApplicationsFacade!com.dsi.applications.ejb.client.session.ApplicationsFacadeRemote");
}
return facade;
}
private void releaseFacade()
{
try
{
context.close();
context = null;
facade = null;
}
catch (Exception e)
{
e.printStackTrace();
}
}
/*
* ----- getter/setter
*/
public DTOMnu getMnu(String user, String osName, String osVersion) throws NamingException
{
DTOMnu dtoMnu = getFacade().getUserMenu(user, osName, osVersion);
releaseFacade();
return dtoMnu;
}
public void saveMnu(DTOMnu dtoMnu) throws NamingException
{
getFacade().saveUserOptions(dtoMnu);
releaseFacade();
}
} |
Partager