User: user57
Date: 02/04/07 01:07:23
Modified: varia/src/main/org/jboss/jdo/castor CastorJDOImpl.java
Removed: varia/src/main/org/jboss/jdo/castor CastorJDOImplMBean.java
Log:
o Using XDoclet to generate *MBean interfaces
Revision Changes Path
1.11 +319 -281 contrib/varia/src/main/org/jboss/jdo/castor/CastorJDOImpl.java
Index: CastorJDOImpl.java
===================================================================
RCS file:
/cvsroot/jboss/contrib/varia/src/main/org/jboss/jdo/castor/CastorJDOImpl.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- CastorJDOImpl.java 24 Feb 2002 10:18:51 -0000 1.10
+++ CastorJDOImpl.java 7 Apr 2002 09:07:23 -0000 1.11
@@ -45,323 +45,361 @@
/**
- * Castor JDO support
+ * Castor JDO support.
*
- * @author Oleg Nitz ([EMAIL PROTECTED])
- * @version $Revision: 1.10 $
+ * @jmx:mbean name="jboss:type=Service,service=JDO,flavor=Castor"
+ * extends="org.jboss.system.ServiceMBean"
+ *
+ * @version <tt>$Revision: 1.11 $</tt>
+ * @author Oleg Nitz ([EMAIL PROTECTED])
*/
public class CastorJDOImpl extends ServiceMBeanSupport
- implements DataObjects, ObjectFactory, Referenceable, Serializable,
- CastorJDOImplMBean, MBeanRegistration, LogInterceptor {
+ implements DataObjects, ObjectFactory, Referenceable, Serializable,
+ CastorJDOImplMBean, MBeanRegistration, LogInterceptor {
- private String _jndiName;
+ private String _jndiName;
- private String _dbConf;
+ private String _dbConf;
- private JDO _jdo = new JDO();
+ private JDO _jdo = new JDO();
- private String _dataSourceName;
-
- private static HashMap _instances = new HashMap();
-
- private transient PrintWriter writer;
-
- /**
- * Do JDO classes should be loader by the global class loader
- * (the same class loader as Castor classes)?
- */
- private boolean _commonClassPath;
-
- /*
- * True if user prefer all reachable object to be stored automatically.
- * False (default) if user want only dependent object to be stored.
- */
- private boolean _autoStore = false;
-
- /*
- * True if user prefers application-server database pooling.
- * False (default) if user wants a new connection for each invocation of
- * getDatabase().
- */
- private boolean _dbPooling = false;
-
- public CastorJDOImpl() {
- }
-
- public ObjectName getObjectName(MBeanServer server, ObjectName name)
- throws javax.management.MalformedObjectNameException {
- return new ObjectName(OBJECT_NAME+",name="+_jndiName);
- }
-
- public String getName() {
- return "CastorJDO";
- }
-
- public void startService() throws Exception {
- org.exolab.castor.jdo.conf.Database database;
- Unmarshaller unm;
- int pos;
- Method m;
-
- boolean debug = log.isDebugEnabled();
-
- // Bind in JNDI
- bind(new InitialContext(), "java:/" + _jndiName, this);
-
- _jdo.setTransactionManager("java:/TransactionManager");
- _jdo.setConfiguration(_dbConf);
- unm = new Unmarshaller(org.exolab.castor.jdo.conf.Database.class);
- database = (org.exolab.castor.jdo.conf.Database) unm.unmarshal(new
InputSource(_dbConf));
- _jdo.setDatabaseName(database.getName());
- if (database.getJndi() != null) {
- _dataSourceName = database.getJndi().getName();
- }
- // Older Castor versions older don't have these methods,
- // we'll use reflection for backward compatibility
- //_jdo.setAutoStore(_autoStore);
- //_jdo.setDatabasePooling(_dbpooling);
- try {
- // 0.9.4
- m = _jdo.getClass().getMethod("setAutoStore",
- new Class[] {boolean.class});
- m.invoke(_jdo, new Object[] {new Boolean(_autoStore)});
- } catch (Exception ex) {
- if (debug)
- log.debug("couldn't invoke setAutoStore()");
- }
-
- try {
- // 0.9.3
- m = _jdo.getClass().getMethod("setDatabasePooling",
- new Class[] {boolean.class});
- m.invoke(_jdo, new Object[] {new Boolean(_dbPooling)});
- } catch (Exception ex) {
- if (debug)
- log.debug("couldn't invoke setDatabasePooling()");
- }
- _instances.put(_jndiName, this);
- if (debug)
- log.debug("DataObjects factory for " + _dataSourceName + " bound to " +
_jndiName);
- }
-
- public void stopService() {
- // Unbind from JNDI
- try {
- new InitialContext().unbind("java:/" + _jndiName);
- } catch (NamingException e) {
- }
- }
-
-
- // CastorJDOImplMBean implementation ---------------------------
-
- public void setJndiName(String jndiName) {
- _jndiName = jndiName;
- }
-
- public String getJndiName() {
- return _jndiName;
- }
-
- public void setConfiguration(String dbConf) {
- _dbConf = dbConf;
- }
-
- public String getConfiguration() {
- return _dbConf;
- }
-
- public void setLockTimeout(int lockTimeout) {
- _jdo.setLockTimeout(lockTimeout);
- }
-
- public int getLockTimeout() {
- return _jdo.getLockTimeout();
- }
-
- public void setLoggingEnabled(boolean loggingEnabled) {
- _jdo.setLogInterceptor(loggingEnabled ? this : null);
- }
-
- public boolean getLoggingEnabled() {
- return (_jdo.getLogInterceptor() != null);
- }
-
- public void setCommonClassPath(boolean commonClassPath) {
- _commonClassPath = commonClassPath;
- }
-
- public boolean getCommonClassPath() {
- return _commonClassPath;
- }
-
- /*
- * True if user prefer all reachable object to be stored automatically.
- * False if user want only dependent object to be stored.
- */
- public void setAutoStore( boolean autoStore ) {
- _autoStore = autoStore;
- }
-
- /*
- * Return if the next Database instance will be set to autoStore.
- */
- public boolean isAutoStore() {
- return _autoStore;
- }
-
- /*
- * True if user prefers to use application server database pools.
- * False if user wants a new connection for each call to getDatabase().
- */
- public void setDatabasePooling(boolean dbPooling) {
- _dbPooling = dbPooling;
- }
-
- /*
- * Return true if the Database instance uses the application server pooling.
- */
- public boolean isDatabasePooling() {
- return _dbPooling;
- }
-
- // DataObjects implementation ----------------------------------
- public Database getDatabase()
- throws DatabaseNotFoundException, PersistenceException {
- Method m;
-
- if (_commonClassPath) {
- _jdo.setClassLoader(null);
- } else {
- _jdo.setClassLoader(Thread.currentThread().getContextClassLoader());
- }
- return _jdo.getDatabase();
- }
-
-
- public void setDescription(String description) {
- _jdo.setDescription(description);
- }
-
-
- public String getDescription() {
- return _jdo.getDescription();
- }
-
- // Referenceable implementation ----------------------------------
- public Reference getReference() {
- return new Reference(getClass().getName(), getClass().getName(), null);
- }
-
- // ObjectFactory implementation ----------------------------------
- public Object getObjectInstance(Object obj,
- Name name,
- Context nameCtx,
- Hashtable environment)
- throws Exception {
- return _instances.get(name.toString());
- }
-
- // Private -------------------------------------------------------
- private void bind(Context ctx, String name, Object val)
- throws NamingException {
- // Bind val to name in ctx, and make sure that all intermediate contexts
exist
-
- Name n = ctx.getNameParser("").parse(name);
- while (n.size() > 1)
- {
+ private String _dataSourceName;
+
+ private static HashMap _instances = new HashMap();
+
+ private transient PrintWriter writer;
+
+ /**
+ * Do JDO classes should be loader by the global class loader
+ * (the same class loader as Castor classes)?
+ */
+ private boolean _commonClassPath;
+
+ /*
+ * True if user prefer all reachable object to be stored automatically.
+ * False (default) if user want only dependent object to be stored.
+ */
+ private boolean _autoStore = false;
+
+ /*
+ * True if user prefers application-server database pooling.
+ * False (default) if user wants a new connection for each invocation of
+ * getDatabase().
+ */
+ private boolean _dbPooling = false;
+
+ public CastorJDOImpl() {
+ }
+
+ public ObjectName getObjectName(MBeanServer server, ObjectName name)
+ throws javax.management.MalformedObjectNameException {
+ return new ObjectName(OBJECT_NAME+",name="+_jndiName);
+ }
+
+ protected void startService() throws Exception {
+ org.exolab.castor.jdo.conf.Database database;
+ Unmarshaller unm;
+ int pos;
+ Method m;
+
+ boolean debug = log.isDebugEnabled();
+
+ // Bind in JNDI
+ bind(new InitialContext(), "java:/" + _jndiName, this);
+
+ _jdo.setTransactionManager("java:/TransactionManager");
+ _jdo.setConfiguration(_dbConf);
+ unm = new Unmarshaller(org.exolab.castor.jdo.conf.Database.class);
+ database = (org.exolab.castor.jdo.conf.Database) unm.unmarshal(new
InputSource(_dbConf));
+ _jdo.setDatabaseName(database.getName());
+ if (database.getJndi() != null) {
+ _dataSourceName = database.getJndi().getName();
+ }
+ // Older Castor versions older don't have these methods,
+ // we'll use reflection for backward compatibility
+ //_jdo.setAutoStore(_autoStore);
+ //_jdo.setDatabasePooling(_dbpooling);
+ try {
+ // 0.9.4
+ m = _jdo.getClass().getMethod("setAutoStore",
+ new Class[] {boolean.class});
+ m.invoke(_jdo, new Object[] {new Boolean(_autoStore)});
+ } catch (Exception ex) {
+ if (debug)
+ log.debug("couldn't invoke setAutoStore()");
+ }
+
+ try {
+ // 0.9.3
+ m = _jdo.getClass().getMethod("setDatabasePooling",
+ new Class[] {boolean.class});
+ m.invoke(_jdo, new Object[] {new Boolean(_dbPooling)});
+ } catch (Exception ex) {
+ if (debug)
+ log.debug("couldn't invoke setDatabasePooling()");
+ }
+ _instances.put(_jndiName, this);
+ if (debug)
+ log.debug("DataObjects factory for " + _dataSourceName + " bound to " +
_jndiName);
+ }
+
+ public void stopService() {
+ // Unbind from JNDI
+ try {
+ new InitialContext().unbind("java:/" + _jndiName);
+ } catch (NamingException e) {
+ }
+ }
+
+
+ // CastorJDOImplMBean implementation ---------------------------
+
+ /**
+ * @jmx:managed-attribute
+ */
+ public void setJndiName(String jndiName) {
+ _jndiName = jndiName;
+ }
+
+ /**
+ * @jmx:managed-attribute
+ */
+ public String getJndiName() {
+ return _jndiName;
+ }
+
+ /**
+ * @jmx:managed-attribute
+ */
+ public void setConfiguration(String dbConf) {
+ _dbConf = dbConf;
+ }
+
+ /**
+ * @jmx:managed-attribute
+ */
+ public String getConfiguration() {
+ return _dbConf;
+ }
+
+ /**
+ * @jmx:managed-attribute
+ */
+ public void setLockTimeout(int lockTimeout) {
+ _jdo.setLockTimeout(lockTimeout);
+ }
+
+ /**
+ * @jmx:managed-attribute
+ */
+ public int getLockTimeout() {
+ return _jdo.getLockTimeout();
+ }
+
+ /**
+ * @jmx:managed-attribute
+ */
+ public void setLoggingEnabled(boolean loggingEnabled) {
+ _jdo.setLogInterceptor(loggingEnabled ? this : null);
+ }
+
+ /**
+ * @jmx:managed-attribute
+ */
+ public boolean getLoggingEnabled() {
+ return (_jdo.getLogInterceptor() != null);
+ }
+
+ /**
+ * @jmx:managed-attribute
+ */
+ public void setCommonClassPath(boolean commonClassPath) {
+ _commonClassPath = commonClassPath;
+ }
+
+ /**
+ * @jmx:managed-attribute
+ */
+ public boolean getCommonClassPath() {
+ return _commonClassPath;
+ }
+
+ /**
+ * @jmx:managed-attribute
+ *
+ * @param autoStore True if user prefer all reachable object to be stored
automatically.
+ * False if user want only dependent object to be stored.
+ */
+ public void setAutoStore( boolean autoStore ) {
+ _autoStore = autoStore;
+ }
+
+ /**
+ * @jmx:managed-attribute
+ *
+ * @return if the next Database instance will be set to autoStore.
+ */
+ public boolean isAutoStore() {
+ return _autoStore;
+ }
+
+ /**
+ * True if user prefers to use application server database pools.
+ * False if user wants a new connection for each call to getDatabase().
+ *
+ * @jmx:managed-attribute
+ */
+ public void setDatabasePooling(boolean dbPooling) {
+ _dbPooling = dbPooling;
+ }
+
+ /**
+ * Return true if the Database instance uses the application server pooling.
+ *
+ * @jmx:managed-attribute
+ */
+ public boolean isDatabasePooling() {
+ return _dbPooling;
+ }
+
+ // DataObjects implementation ----------------------------------
+
+ public Database getDatabase()
+ throws DatabaseNotFoundException, PersistenceException {
+ Method m;
+
+ if (_commonClassPath) {
+ _jdo.setClassLoader(null);
+ } else {
+ _jdo.setClassLoader(Thread.currentThread().getContextClassLoader());
+ }
+ return _jdo.getDatabase();
+ }
+
+
+ public void setDescription(String description) {
+ _jdo.setDescription(description);
+ }
+
+
+ public String getDescription() {
+ return _jdo.getDescription();
+ }
+
+ // Referenceable implementation ----------------------------------
+ public Reference getReference() {
+ return new Reference(getClass().getName(), getClass().getName(), null);
+ }
+
+ // ObjectFactory implementation ----------------------------------
+ public Object getObjectInstance(Object obj,
+ Name name,
+ Context nameCtx,
+ Hashtable environment)
+ throws Exception {
+ return _instances.get(name.toString());
+ }
+
+ // Private -------------------------------------------------------
+ private void bind(Context ctx, String name, Object val)
+ throws NamingException {
+ // Bind val to name in ctx, and make sure that all intermediate contexts exist
+
+ Name n = ctx.getNameParser("").parse(name);
+ while (n.size() > 1)
+ {
String ctxName = n.get(0);
try
- {
- ctx = (Context)ctx.lookup(ctxName);
- } catch (NameNotFoundException e)
- {
- ctx = ctx.createSubcontext(ctxName);
- }
+ {
+ ctx = (Context)ctx.lookup(ctxName);
+ } catch (NameNotFoundException e)
+ {
+ ctx = ctx.createSubcontext(ctxName);
+ }
n = n.getSuffix(1);
- }
+ }
- ctx.bind(n.get(0), val);
- }
+ ctx.bind(n.get(0), val);
+ }
- // LogInterceptor implementation for Castor 0.8 ----------------------
- public void loading(Class objClass, Object identity) {
- if (log.isDebugEnabled())
- log.debug( "Loading " + objClass.getName() + " (" + identity + ")" );
- }
+ // LogInterceptor implementation for Castor 0.8 ----------------------
+ public void loading(Class objClass, Object identity) {
+ if (log.isDebugEnabled())
+ log.debug( "Loading " + objClass.getName() + " (" + identity + ")" );
+ }
- public void creating(Class objClass, Object identity) {
- if (log.isDebugEnabled())
- log.debug( "Creating " + objClass.getName() + " (" + identity + ")" );
- }
+ public void creating(Class objClass, Object identity) {
+ if (log.isDebugEnabled())
+ log.debug( "Creating " + objClass.getName() + " (" + identity + ")" );
+ }
- public void removing(Class objClass, Object identity) {
- if (log.isDebugEnabled())
- log.debug( "Removing " + objClass.getName() + " (" + identity + ")" );
- }
+ public void removing(Class objClass, Object identity) {
+ if (log.isDebugEnabled())
+ log.debug( "Removing " + objClass.getName() + " (" + identity + ")" );
+ }
- public void storing(Class objClass, Object identity) {
- if (log.isDebugEnabled())
- log.debug( "Storing " + objClass.getName() + " (" + identity + ")" );
- }
+ public void storing(Class objClass, Object identity) {
+ if (log.isDebugEnabled())
+ log.debug( "Storing " + objClass.getName() + " (" + identity + ")" );
+ }
- // LogInterceptor implementation for Castor 0.9 ----------------------
- public void loading(Object objClass, Object identity) {
- if (log.isDebugEnabled())
- log.debug( "Loading " + objClass + " (" + identity + ")" );
- }
+ // LogInterceptor implementation for Castor 0.9 ----------------------
+ public void loading(Object objClass, Object identity) {
+ if (log.isDebugEnabled())
+ log.debug( "Loading " + objClass + " (" + identity + ")" );
+ }
- public void creating(Object objClass, Object identity) {
- if (log.isDebugEnabled())
- log.debug( "Creating " + objClass + " (" + identity + ")" );
- }
+ public void creating(Object objClass, Object identity) {
+ if (log.isDebugEnabled())
+ log.debug( "Creating " + objClass + " (" + identity + ")" );
+ }
- public void removing(Object objClass, Object identity) {
- if (log.isDebugEnabled())
- log.debug( "Removing " + objClass + " (" + identity + ")" );
- }
+ public void removing(Object objClass, Object identity) {
+ if (log.isDebugEnabled())
+ log.debug( "Removing " + objClass + " (" + identity + ")" );
+ }
- public void storing(Object objClass, Object identity) {
- if (log.isDebugEnabled())
- log.debug( "Storing " + objClass + " (" + identity + ")" );
- }
+ public void storing(Object objClass, Object identity) {
+ if (log.isDebugEnabled())
+ log.debug( "Storing " + objClass + " (" + identity + ")" );
+ }
- // LogInterceptor implementation - the rest part --------------------
+ // LogInterceptor implementation - the rest part --------------------
- public void storeStatement(String statement) {
- log.debug(statement);
- }
+ public void storeStatement(String statement) {
+ log.debug(statement);
+ }
- public void queryStatement(String statement) {
- log.debug(statement);
- }
+ public void queryStatement(String statement) {
+ log.debug(statement);
+ }
- public void message(String message) {
- log.debug(message);
- }
+ public void message(String message) {
+ log.debug(message);
+ }
- public void exception(Exception except) {
- log.error("Exception", except);
- }
+ public void exception(Exception except) {
+ log.error("Exception", except);
+ }
- public PrintWriter getPrintWriter()
- {
- if (writer == null)
- {
+ public PrintWriter getPrintWriter()
+ {
+ if (writer == null)
+ {
writer = new CategoryWriter(log.getCategory());
- }
- return writer;
- }
+ }
+ return writer;
+ }
}
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development