[jboss-user] [EJB 3.0] - Re: JBoss 5.0.0.CR1, @LocalBinding

gla-001 do-not-reply at jboss.com
Tue Sep 9 06:19:09 EDT 2008


Oh sorry! It's quite basic stuff in this bean:


  | package com.abc.server.configurationMgr.bean;
  | 
  | import his.base.Category;
  | import his.base.DBIdList;
  | 
  | import java.sql.Connection;
  | import java.sql.DatabaseMetaData;
  | import java.sql.SQLException;
  | import java.text.SimpleDateFormat;
  | import java.util.Date;
  | import java.util.Enumeration;
  | import java.util.Properties;
  | import java.util.StringTokenizer;
  | import java.util.Vector;
  | 
  | import javax.annotation.PostConstruct;
  | import javax.ejb.EJBException;
  | import javax.ejb.SessionContext;
  | import javax.ejb.Stateless;
  | import javax.naming.InitialContext;
  | import javax.naming.NamingException;
  | import javax.sql.DataSource;
  | 
  | import org.jboss.ejb3.annotation.LocalBinding;
  | import org.jboss.ejb3.annotation.Pool;
  | import org.jboss.ejb3.annotation.RemoteBinding;
  | 
  | import com.abc.base.Trace;
  | import com.abc.base.Util;
  | import com.abc.server.configurationMgr.ConfigurationDB;
  | import com.abc.server.configurationMgr.interfaces.ConfigurationManagerDefinition;
  | import com.abc.server.configurationMgr.interfaces.ConfigurationManagerLocal;
  | import com.abc.server.configurationMgr.interfaces.ConfigurationManagerRemote;
  | 
  | 
  | 
  | 
  | public class ConfigurationManagerBean 
  |         implements ConfigurationManagerLocal, ConfigurationManagerRemote {
  |     private Properties configuration;
  |     private Properties defaultConfiguration;
  |     private transient InitialContext namingContext;
  | 
  |     private DataSource datasource;
  | 
  |     @PostConstruct
  |     public void ejbCreate() {
  |         try {
  |             namingContext = new InitialContext();
  |         } catch (NamingException e) {
  |             throw new EJBException(e);
  |         }
  |         initDefaultconfiguration();
  |         try {
  | namingContext.lookup("java:comp/env/jdbc/XY");
  |             datasource = (DataSource) namingContext.lookup("java:XY4");
  |             
  |             Connection connection = datasource.getConnection();
  |             DatabaseMetaData dmd = connection.getMetaData();
  | 
  |         } catch (Exception e) {
  |             trc.error("Cannot load Datasource!");
  |             Trace.error(e);
  |         }
  |         
  |         try {
  |             load();
  |         } catch (Exception e) {
  |             throw new EJBException(e);
  |         }
  |     }
  | 
  |     public void ejbActivate() throws EJBException {
  |         try {
  |             namingContext = new InitialContext();
  |         } catch (NamingException e) {
  |             throw new EJBException(e);
  |         }
  |     }
  | 
  |     public void ejbPassivate() throws EJBException {
  |         datasource = null;
  |     }
  |     public void ejbRemove() throws EJBException {
  |         Trace.info(tXY, "ejbRemove: ConfigurationManagerBean");
  |     }
  | 
  |     public void setSessionContext(SessionContext arg0)
  |             throws EJBException {
  |     }
  | 
  |     public DataSource getConnectionPool() {
  |         return datasource;
  |     }
  | 
  |     public DataSource getDataSource() /*throws Exception */ {
  |         return datasource;
  |     }
  | 
  |     public int getInt(String key, int defaultValue) {
  |         String strValue = configuration.getProperty(key);
  |         if (strValue == null) {
  |             return defaultValue;
  |         } else {
  |             Integer i = new Integer(strValue);
  |             return i.intValue();
  |         }
  |     }
  | 
  |     public DBIdList getIntList(String key, DBIdList defaultValue) {
  |         String strValue = configuration.getProperty(key);
  |         if (strValue == null) {
  |             return defaultValue;
  |         }
  |         DBIdList result = new DBIdList();
  |         StringTokenizer tokenizer = new StringTokenizer(strValue, ",");
  |         while (tokenizer.hasMoreTokens()) {
  |             try {
  |                 result.add(new Integer(tokenizer.nextToken().trim()));
  |             } catch (Exception e) {
  |                 System.out.println("Value \"" + strValue + "\" for key \"" + key +
  |                         "\" could not parsed! (exception: " + e.getMessage() + ")");
  |                 return defaultValue;
  |             }
  |         }
  |         return result;
  |     }
  | 
  |     public Vector getStringList(String key, Vector defaultValue) {
  |         String strValue = configuration.getProperty(key);
  |         if (strValue == null) {
  |             return defaultValue;
  |         }
  |         Vector result = new Vector();
  |         StringTokenizer tokenizer = new StringTokenizer(strValue, ",");
  |         while (tokenizer.hasMoreTokens()) {
  |             result.add(tokenizer.nextToken().trim());
  |         }
  |         return result;
  |     }
  | 
  | 
  |     public String getString(String key, String defaultValue) {
  |         String strValue = configuration.getProperty(key);
  |         if (strValue == null) {
  |             strValue = defaultValue;
  |         }
  |         return strValue;
  |     }
  | 
  |     public boolean getBoolean(String key, boolean defaultValue) {
  |         String strValue = configuration.getProperty(key);
  | 
  |         if (strValue == null) return defaultValue;
  |         strValue = strValue.toLowerCase();
  | 
  |         if (strValue.charAt(0) == 't'
  |                 || strValue.charAt(0) == '1'
  |                 || strValue.charAt(0) == 'y'
  |                 || strValue.charAt(0) == 'j')
  |             return true;
  | 
  |         if (strValue.charAt(0) == 'f'
  |                 || strValue.charAt(0) == '0'
  |                 || strValue.charAt(0) == 'n')
  |             return false;
  | 
  |         return defaultValue;
  |     }
  | 
  |     public Properties load() /*throws RemoteException*/ {
  |         try {
  |             Properties conf = new Properties(defaultConfiguration);
  |             Connection connection = datasource.getConnection();
  |             Properties newConfiguration = ConfigurationDB.load(connection);
  |             for (Enumeration enumeration = newConfiguration.propertyNames(); enumeration.hasMoreElements();) {
  |                 String key = (String) enumeration.nextElement();
  |                 String value = newConfiguration.getProperty(key);
  |                 conf.setProperty(key, Util.notNULL(value));
  |             }
  |             configuration = conf; // nur wenn die Konfiguration erfolgreich geladen werden konnte!
  |             connection.close();
  |         } catch (SQLException e) {
  |             Trace.error("Problems encountered during closing the connection!", e);
  |         }
  |         return configuration;
  |     }
  | 
  |     public void save(Properties config) {
  |         try {
  |             Connection connection = datasource.getConnection();
  |             ConfigurationDB.save(connection, config);
  |             configuration = new Properties(defaultConfiguration);
  |             for (Enumeration enumeration = config.propertyNames(); enumeration.hasMoreElements();) {
  |                 String key = (String) enumeration.nextElement();
  |                 String value = config.getProperty(key);
  |                 configuration.setProperty(key, Util.notNULL(value));
  |             }
  |             connection.close();
  |         } catch (Exception e) {
  |             Trace.error(e);
  |         }
  |     }
  | 
  |     public Properties getProperties() {
  |         return new Properties(configuration);
  |     }
  | 
  |     private String getStringEnvEntry(String name) {
  |         String envEntry = null;
  |         try {
  |             envEntry = (String) namingContext.lookup(name);
  |         } catch (NamingException e) {
  |             throw new EJBException(e);
  |         }
  |         return envEntry;
  |     }
  | 
  |     private int getIntEnvEntry(String name) {
  |         Integer envEntry = null;
  |         try {
  |             envEntry = (Integer) namingContext.lookup(name);
  |         } catch (NamingException e) {
  |             throw new EJBException(e);
  |         }
  |         if (envEntry != null) {
  |             return envEntry.intValue();
  |         } else {
  |             return 0;
  |         }
  |     }
  | 
  |     private boolean getBooleanEnvEntry(String name) {
  |         Boolean envEntry;
  |         try {
  |             envEntry = (Boolean) namingContext.lookup(name);
  |         } catch (NamingException e) {
  |             throw new EJBException(e);
  |         }
  |         if (envEntry != null) {
  |             return envEntry.booleanValue();
  |         } else {
  |             return false;
  |         }
  |     }
  | 
  | 
  | 
  |     private void initDefaultconfiguration() {
  |         defaultConfiguration = new Properties();
  |         defaultConfiguration.setProperty(ConfigurationManagerDefinition.GLOBAL_RELOADPROPERTIESTIMEOUT, "180");
  |     }
  | }
  | 
  | 

anonymous wrote : 
  | 2008-09-09 12:18:03,375 INFO  [org.jboss.ejb3.deployers.JBossASKernel] (main) installing bean: jboss.j2ee:ear=ringfoto.ear,jar=ringfoto-ejb-beans.jar,name=ConfigurationManagerBean,service=EJB3
  | 2008-09-09 12:18:03,375 INFO  [org.jboss.ejb3.deployers.JBossASKernel] (main)   with dependencies:
  | 2008-09-09 12:18:03,375 INFO  [org.jboss.ejb3.deployers.JBossASKernel] (main)   and demands:
  | 2008-09-09 12:18:03,375 INFO  [org.jboss.ejb3.deployers.JBossASKernel] (main) 	jboss.ejb:service=EJBTimerService
  | 2008-09-09 12:18:03,375 INFO  [org.jboss.ejb3.deployers.JBossASKernel] (main)   and supplies:
  | 2008-09-09 12:18:03,375 INFO  [org.jboss.ejb3.deployers.JBossASKernel] (main) 	jndi:ringfoto/ConfigurationManagerBean/remote
  | 2008-09-09 12:18:03,375 INFO  [org.jboss.ejb3.deployers.JBossASKernel] (main) 	jndi:ConfigurationManagerBean
  | 2008-09-09 12:18:03,375 INFO  [org.jboss.ejb3.deployers.JBossASKernel] (main) 	jndi:ringfoto/ConfigurationManagerBean/local
  | 2008-09-09 12:18:03,375 INFO  [org.jboss.ejb3.deployers.JBossASKernel] (main) 	jndi:ringfoto/ConfigurationManagerBean/remote-com.dept101.server.configurationMgr.interfaces.ConfigurationManagerRemote
  | 2008-09-09 12:18:03,375 INFO  [org.jboss.ejb3.deployers.JBossASKernel] (main) 	Class:com.dept101.server.configurationMgr.interfaces.ConfigurationManagerRemote
  | 2008-09-09 12:18:03,375 INFO  [org.jboss.ejb3.deployers.JBossASKernel] (main) 	Class:com.dept101.server.configurationMgr.interfaces.ConfigurationManagerLocal
  | 2008-09-09 12:18:03,375 INFO  [org.jboss.ejb3.deployers.JBossASKernel] (main) 	jndi:ringfoto/ConfigurationManagerBean/local-com.dept101.server.configurationMgr.interfaces.ConfigurationManagerLocal
  | 2008-09-09 12:18:03,375 INFO  [org.jboss.ejb3.deployers.JBossASKernel] (main) Added bean(jboss.j2ee:ear=ringfoto.ear,jar=ringfoto-ejb-beans.jar,name=ConfigurationManagerBean,service=EJB3) to KernelDeployment of: ringfoto-ejb-beans.jar
  | 2008-09-09 12:18:03,375 DEBUG [org.jboss.ejb3.Ejb3Deployment] (main) Bound ejb3 container jboss.j2ee:ear=ringfoto.ear,jar=ringfoto-ejb-beans.jar,name=ConfigurationManagerBean,service=EJB3
  | 

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4175257#4175257

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4175257



More information about the jboss-user mailing list