User: user57
Date: 01/07/09 22:10:54
Modified: src/main/org/jboss/ejb Container.java
Log:
o changed logging to log4j
o changed some comments to javadocs
Revision Changes Path
1.47 +212 -195 jboss/src/main/org/jboss/ejb/Container.java
Index: Container.java
===================================================================
RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/ejb/Container.java,v
retrieving revision 1.46
retrieving revision 1.47
diff -u -r1.46 -r1.47
--- Container.java 2001/06/24 03:06:45 1.46
+++ Container.java 2001/07/10 05:10:54 1.47
@@ -40,7 +40,8 @@
import javax.transaction.TransactionManager;
import javax.sql.DataSource;
-import org.jboss.logging.Logger;
+import org.apache.log4j.Category;
+
import org.jboss.security.EJBSecurityManager;
import org.jboss.security.RealmMapping;
@@ -59,21 +60,23 @@
import org.jboss.ejb.plugins.local.BaseLocalContainerInvoker;
/**
- * This is the base class for all EJB-containers in JBoss. A Container
- * functions as the central hub of all metadata and plugins. Through this
- * the container plugins can get hold of the other plugins and any metadata they
need.
- *
- * The ContainerFactory creates instances of subclasses of this class and calls
the appropriate
- * initialization methods.
+ * This is the base class for all EJB-containers in JBoss. A Container
+ * functions as the central hub of all metadata and plugins. Through this
+ * the container plugins can get hold of the other plugins and any metadata
+ * they need.
*
- * A Container does not perform any significant work, but instead delegates to
the plugins to provide for
- * all kinds of algorithmic functionality.
+ * <p>The ContainerFactory creates instances of subclasses of this class
+ * and calls the appropriate initialization methods.
+ *
+ * <p>A Container does not perform any significant work, but instead delegates
+ * to the plugins to provide for all kinds of algorithmic functionality.
*
- * @see ContainerFactory
- * @author <a href="mailto:[EMAIL PROTECTED]">Rickard �berg</a>
- * @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>
- * @author <a href="mailto:[EMAIL PROTECTED]">Scott Stark</a>.
- * @version $Revision: 1.46 $
+ * @see ContainerFactory
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Rickard �berg</a>
+ * @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>
+ * @author <a href="mailto:[EMAIL PROTECTED]">Scott Stark</a>.
+ * @version $Revision: 1.47 $
*/
public abstract class Container
{
@@ -81,47 +84,61 @@
// Attributes ----------------------------------------------------
- // This is the application that this container is a part of
+ /** Instance logger. */
+ protected Category log = Category.getInstance(this.getClass());
+
+ /** This is the application that this container is a part of */
protected Application application;
- // This is the local classloader of this container. Used for loading resources
that
- // must come from the local jar file for the container. NOT for loading classes!
+ /**
+ * This is the local classloader of this container. Used for loading
+ * resources that must come from the local jar file for the container.
+ * NOT for loading classes!
+ */
protected ClassLoader localClassLoader;
- // This is the classloader of this container. All classes and resources that
- // the bean uses will be loaded from here. By doing this we make the bean
re-deployable
+ /**
+ * This is the classloader of this container. All classes and resources that
+ * the bean uses will be loaded from here. By doing this we make the bean
+ * re-deployable
+ */
protected ClassLoader classLoader;
- // This is the new metadata. it includes information from both ejb-jar and
jboss.xml
- // the metadata for the application can be accessed trough
metaData.getApplicationMetaData()
+ /**
+ * This is the new metadata. it includes information from both ejb-jar and
+ * jboss.xml the metadata for the application can be accessed trough
+ * metaData.getApplicationMetaData()
+ */
protected BeanMetaData metaData;
- // This is the EnterpriseBean class
+ /** This is the EnterpriseBean class */
protected Class beanClass;
- // This is the TransactionManager
+ /** This is the TransactionManager */
protected TransactionManager tm;
- // This is the SecurityManager
+ /** This is the SecurityManager */
protected EJBSecurityManager sm;
- // This is the realm mapping
+ /** This is the realm mapping */
protected RealmMapping rm;
/** The custom security proxy used by the SecurityInterceptor */
protected Object securityProxy;
-
+
+ /** ??? */
protected LocalContainerInvoker localContainerInvoker =
new BaseLocalContainerInvoker();
- // This is a cache for method permissions
+ /** This is a cache for method permissions */
private HashMap methodPermissionsCache = new HashMap();
+ /** ??? */
protected Class localHomeInterface;
+ /** ??? */
protected Class localInterface;
-
// Public --------------------------------------------------------
public Class getLocalClass()
@@ -134,24 +151,23 @@
return localHomeInterface;
}
-
/**
- * Sets a transaction manager for this container.
- *
- * @see javax.transaction.TransactionManager
- *
- * @param tm
- */
+ * Sets a transaction manager for this container.
+ *
+ * @see javax.transaction.TransactionManager
+ *
+ * @param tm
+ */
public void setTransactionManager(TransactionManager tm)
{
this.tm = tm;
}
/**
- * Returns this container's transaction manager.
- *
- * @return a concrete instance of javax.transaction.TransactionManager
- */
+ * Returns this container's transaction manager.
+ *
+ * @return a concrete instance of javax.transaction.TransactionManager
+ */
public TransactionManager getTransactionManager()
{
return tm;
@@ -179,19 +195,20 @@
public void setSecurityProxy(Object proxy)
{
- this.securityProxy = proxy;
+ this.securityProxy = proxy;
}
+
public Object getSecurityProxy()
{
- return securityProxy;
+ return securityProxy;
}
/**
- * Sets the application deployment unit for this container. All the bean
- * containers within the same application unit share the same instance.
- *
- * @param app application for this container
- */
+ * Sets the application deployment unit for this container. All the bean
+ * containers within the same application unit share the same instance.
+ *
+ * @param app application for this container
+ */
public void setApplication(Application app)
{
if (app == null)
@@ -201,84 +218,84 @@
}
/**
- * Returns the application for this container.
- *
- * @return
- */
+ * Returns the application for this container.
+ *
+ * @return
+ */
public Application getApplication()
{
return application;
}
/**
- * Sets the local class loader for this container.
- * Used for loading resources from the local jar file for this container.
- * NOT for loading classes!
- *
- * @param cl
- */
+ * Sets the local class loader for this container.
+ * Used for loading resources from the local jar file for this container.
+ * NOT for loading classes!
+ *
+ * @param cl
+ */
public void setLocalClassLoader(ClassLoader cl)
{
this.localClassLoader = cl;
}
/**
- * Returns the local classloader for this container.
- *
- * @return
- */
+ * Returns the local classloader for this container.
+ *
+ * @return
+ */
public ClassLoader getLocalClassLoader()
{
return localClassLoader;
}
/**
- * Sets the class loader for this container. All the classes and resources
- * used by the bean in this container will use this classloader.
- *
- * @param cl
- */
+ * Sets the class loader for this container. All the classes and resources
+ * used by the bean in this container will use this classloader.
+ *
+ * @param cl
+ */
public void setClassLoader(ClassLoader cl)
{
this.classLoader = cl;
}
/**
- * Returns the classloader for this container.
- *
- * @return
- */
+ * Returns the classloader for this container.
+ *
+ * @return
+ */
public ClassLoader getClassLoader()
{
return classLoader;
}
/**
- * Sets the meta data for this container. The meta data consists of the
- * properties found in the XML descriptors.
- *
- * @param metaData
- */
+ * Sets the meta data for this container. The meta data consists of the
+ * properties found in the XML descriptors.
+ *
+ * @param metaData
+ */
public void setBeanMetaData(BeanMetaData metaData)
{
this.metaData = metaData;
}
/**
- * Returns the metadata of this container.
- *
- * @return metaData;
- */
+ * Returns the metadata of this container.
+ *
+ * @return metaData;
+ */
public BeanMetaData getBeanMetaData()
{
return metaData;
}
/**
- * Returns the permissions for a method. (a set of roles)
- *
- * @return assemblyDescriptor;
- */
+ * Returns the permissions for a method. (a set of roles)
+ *
+ * @return assemblyDescriptor;
+ */
public Set getMethodPermissions( Method m, boolean home )
{
Set permissions;
@@ -294,41 +311,43 @@
}
/**
- * Returns the bean class instance of this container.
- *
- * @return instance of the Enterprise bean class
- */
+ * Returns the bean class instance of this container.
+ *
+ * @return instance of the Enterprise bean class
+ */
public Class getBeanClass()
{
return beanClass;
}
+
+ /**
+ * Returns a new instance of the bean class or a subclass of the bean class.
+ * This factory style method is speciffically used by a container to supply
+ * an implementation of the abstract accessors in EJB2.0, but could be usefull
+ * in other situations. This method should ALWAYS be used instead of
+ * getBeanClass().newInstance();
+ *
+ * @see java.lang.Class#newInstance
+ * @return the new instance
+ */
+ public Object createBeanClassInstance() throws Exception {
+ return getBeanClass().newInstance();
+ }
- /**
- * Returns a new instance of the bean class or a subclass of the bean class.
- * This factory style method is speciffically used by a container to supply
- * an implementation of the abstract accessors in EJB2.0, but could be usefull
- * in other situations. This method should ALWAYS be used instead of
- * getBeanClass().newInstance();
- *
- * @see java.lang.Class#newInstance
- * @return the new instance
- */
- public Object createBeanClassInstance() throws Exception {
- return getBeanClass().newInstance();
- }
-
- /**
- * The ContainerFactory calls this method. The ContainerFactory has set all the
- * plugins and interceptors that this bean requires and now proceeds to initialize
- * the chain. The method looks for the standard classes in the URL, sets up
- * the naming environment of the bean. The concrete container classes should
- * override this method to introduce implementation specific initialization
behaviour.
- *
- * @exception Exception if loading the bean class failed
(ClassNotFoundException)
- * or setting up "java:" naming environment failed
(DeploymentException)
- */
+ /**
+ * The ContainerFactory calls this method. The ContainerFactory has set
+ * all the plugins and interceptors that this bean requires and now proceeds
+ * to initialize the chain. The method looks for the standard classes in
+ * the URL, sets up the naming environment of the bean. The concrete
+ * container classes should override this method to introduce implementation
+ * specific initialization behaviour.
+ *
+ * @exception Exception if loading the bean class failed
+ * (ClassNotFoundException) or setting up "java:"
+ * naming environment failed (DeploymentException)
+ */
public void init()
- throws Exception
+ throws Exception
{
// Acquire classes from CL
beanClass = classLoader.loadClass(metaData.getEjbClass());
@@ -347,33 +366,33 @@
}
/**
- * A default implementation of starting the container service (no-op). The
concrete
- * container classes should override this method to introduce implementation
specific
- * start behaviour.
- *
- * @exception Exception an exception that occured during start
- */
+ * A default implementation of starting the container service (no-op). The
concrete
+ * container classes should override this method to introduce implementation
specific
+ * start behaviour.
+ *
+ * @exception Exception an exception that occured during start
+ */
public void start()
- throws Exception
+ throws Exception
{
localContainerInvoker.start();
}
/**
- * A default implementation of stopping the container service (no-op). The
concrete
- * container classes should override this method to introduce implementation
specific
- * stop behaviour.
- */
+ * A default implementation of stopping the container service (no-op). The
concrete
+ * container classes should override this method to introduce implementation
specific
+ * stop behaviour.
+ */
public void stop()
{
localContainerInvoker.stop();
}
/**
- * A default implementation of destroying the container service (no-op). The
concrete
- * container classes should override this method to introduce implementation
specific
- * destroy behaviour.
- */
+ * A default implementation of destroying the container service (no-op). The
concrete
+ * container classes should override this method to introduce implementation
specific
+ * destroy behaviour.
+ */
public void destroy()
{
localContainerInvoker.destroy();
@@ -381,30 +400,30 @@
}
/**
- * This method is called by the ContainerInvoker when a method call comes in on
the Home object.
- *
- * The Container forwards this call to the interceptor chain for further
processing.
- *
- * @param mi the object holding all info about this invocation
- * @return the result of the home invocation
- * @exception Exception
- */
+ * This method is called by the ContainerInvoker when a method call comes in on
the Home object.
+ *
+ * The Container forwards this call to the interceptor chain for further
processing.
+ *
+ * @param mi the object holding all info about this invocation
+ * @return the result of the home invocation
+ * @exception Exception
+ */
public abstract Object invokeHome(MethodInvocation mi)
- throws Exception;
+ throws Exception;
/**
- * This method is called by the ContainerInvoker when a method call comes in on
an EJBObject.
- *
- * The Container forwards this call to the interceptor chain for further
processing.
- *
- * @param id the id of the object being invoked. May be null if
stateless
- * @param method the method being invoked
- * @param args the parameters
- * @return the result of the invocation
- * @exception Exception
- */
+ * This method is called by the ContainerInvoker when a method call comes in on
an EJBObject.
+ *
+ * The Container forwards this call to the interceptor chain for further
processing.
+ *
+ * @param id the id of the object being invoked. May be null if
stateless
+ * @param method the method being invoked
+ * @param args the parameters
+ * @return the result of the invocation
+ * @exception Exception
+ */
public abstract Object invoke(MethodInvocation mi)
- throws Exception;
+ throws Exception;
// Protected -----------------------------------------------------
@@ -414,21 +433,21 @@
// Private -------------------------------------------------------
/*
- * setupEnvironment
- *
- * This method sets up the naming environment of the bean.
- * We create the java:comp/env namespace with properties, EJB-References, and
- * DataSource ressources.
- *
- */
+ * setupEnvironment
+ *
+ * This method sets up the naming environment of the bean.
+ * We create the java:comp/env namespace with properties, EJB-References, and
+ * DataSource ressources.
+ *
+ */
private void setupEnvironment()
- throws DeploymentException
+ throws DeploymentException
{
try
{
BeanMetaData beanMetaData = getBeanMetaData();
- Logger.debug("Begin java:comp/env for EJB: "+beanMetaData.getEjbName());
- Logger.debug("TCL: "+Thread.currentThread().getContextClassLoader());
+ log.debug("Begin java:comp/env for EJB: "+beanMetaData.getEjbName());
+ log.debug("TCL: "+Thread.currentThread().getContextClassLoader());
// Since the BCL is already associated with this thread we can start using
the java: namespace directly
Context ctx = (Context) new InitialContext().lookup("java:comp");
Context envCtx = ctx.createSubcontext("env");
@@ -441,13 +460,13 @@
EnvEntryMetaData entry = (EnvEntryMetaData)enum.next();
try
{
- Logger.debug("Binding env-entry: "+entry.getName()+" of type:
"+entry.getType()+" to value:"+entry.getValue());
- EnvEntryMetaData.bindEnvEntry(envCtx, entry);
+ log.debug("Binding env-entry: "+entry.getName()+" of type:
"+entry.getType()+" to value:"+entry.getValue());
+ EnvEntryMetaData.bindEnvEntry(envCtx, entry);
}
catch(ClassNotFoundException e)
{
- Logger.exception(e);
- throw new DeploymentException("Could not set up environment", e);
+ log.error("Could not set up environment", e);
+ throw new DeploymentException("Could not set up environment", e);
}
}
}
@@ -459,12 +478,12 @@
{
EjbRefMetaData ref = (EjbRefMetaData)enum.next();
- Logger.debug("Binding an EJBReference "+ref.getName());
+ log.debug("Binding an EJBReference "+ref.getName());
if (ref.getLink() != null)
{
// Internal link
- Logger.debug("Binding "+ref.getName()+" to internal JNDI source:
"+ref.getLink());
+ log.debug("Binding "+ref.getName()+" to internal JNDI source:
"+ref.getLink());
Container refContainer =
getApplication().getContainer(ref.getLink());
if (refContainer == null)
throw new DeploymentException ("Bean "+ref.getLink()+" not
found within this application.");
@@ -480,7 +499,7 @@
{
throw new DeploymentException("ejb-ref "+ref.getName()+",
expected either ejb-link in ejb-jar.xml or jndi-name in jboss.xml");
}
- Logger.debug("Binding "+ref.getName()+" to external JNDI source:
"+ref.getJndiName());
+ log.debug("Binding "+ref.getName()+" to external JNDI source:
"+ref.getJndiName());
bind(envCtx, ref.getName(), new LinkRef(ref.getJndiName()));
}
}
@@ -495,21 +514,21 @@
{
EjbLocalRefMetaData ref = (EjbLocalRefMetaData)enum.next();
- Logger.debug("Binding an EJBLocalReference "+ref.getName());
+ log.debug("Binding an EJBLocalReference "+ref.getName());
if (ref.getLink() != null)
{
// Internal link
- Logger.debug("Binding "+ref.getName()+" to bean source:
"+ref.getLink());
+ log.debug("Binding "+ref.getName()+" to bean source:
"+ref.getLink());
if (getApplication().getContainer(ref.getLink()) == null)
throw new DeploymentException ("Bean "+ref.getLink()+" not
found within this application.");
// get local home
// bind it into the local namespace
LocalHomeObjectFactory.rebind( uniqueKey + ref.getName(),
- getApplication(), getApplication().getContainer(ref.getLink())
);
+ getApplication(),
getApplication().getContainer(ref.getLink()) );
StringRefAddr refAddr = new StringRefAddr("nns",
uniqueKey+ref.getName() );
Reference jndiRef = new Reference(ref.getLocalHome(),
- refAddr, LocalHomeObjectFactory.class.getName(), null );
+ refAddr,
LocalHomeObjectFactory.class.getName(), null );
bind(envCtx, ref.getName(), jndiRef );
}
@@ -534,9 +553,9 @@
String resourceName = ref.getResourceName();
String finalName = application.getResourceByName(resourceName);
/* If there was no resource-manager specified then an immeadiate
- jndi-name or res-url name should have been given */
+ jndi-name or res-url name should have been given */
if (finalName == null)
- finalName = ref.getJndiName();
+ finalName = ref.getJndiName();
if (finalName == null)
{
@@ -554,7 +573,7 @@
finalName = "java:/DefaultDS";
} catch (Exception e)
{
- Logger.debug(e);
+ log.debug("failed to lookup DefaultDS; ignoring", e);
}
}
@@ -562,7 +581,7 @@
// POTENTIALLY DANGEROUS: should this be a critical error?
if (finalName == null)
{
- Logger.warning("No resource manager found for
"+ref.getResourceName());
+ log.warn("No resource manager found for
"+ref.getResourceName());
continue;
}
}
@@ -572,7 +591,7 @@
// URL bindings
try
{
- Logger.debug("Binding URL: "+finalName+ " to JDNI ENC as: "
+ref.getRefName());
+ log.debug("Binding URL: "+finalName+ " to JDNI ENC as: "
+ref.getRefName());
bind(envCtx, ref.getRefName(), new URL(finalName));
} catch (MalformedURLException e)
{
@@ -582,7 +601,7 @@
else
{
// Resource Manager bindings, should validate the type...
- Logger.debug("Binding resource manager: "+finalName+ " to JDNI
ENC as: " +ref.getRefName());
+ log.debug("Binding resource manager: "+finalName+ " to JDNI ENC
as: " +ref.getRefName());
bind(envCtx, ref.getRefName(), new LinkRef(finalName));
}
}
@@ -593,12 +612,12 @@
Iterator enum = beanMetaData.getResourceEnvReferences();
while( enum.hasNext() )
{
- ResourceEnvRefMetaData resRef = (ResourceEnvRefMetaData)
enum.next();
- String encName = resRef.getRefName();
- String jndiName = resRef.getJndiName();
- // Should validate the type...
- Logger.debug("Binding env resource: "+jndiName+ " to JDNI ENC as: "
+encName);
- bind(envCtx, encName, new LinkRef(jndiName));
+ ResourceEnvRefMetaData resRef = (ResourceEnvRefMetaData) enum.next();
+ String encName = resRef.getRefName();
+ String jndiName = resRef.getJndiName();
+ // Should validate the type...
+ log.debug("Binding env resource: "+jndiName+ " to JDNI ENC as: "
+encName);
+ bind(envCtx, encName, new LinkRef(jndiName));
}
}
@@ -608,34 +627,33 @@
*/
String securityDomain =
metaData.getContainerConfiguration().getSecurityDomain();
if( securityDomain == null )
- securityDomain = metaData.getApplicationMetaData().getSecurityDomain();
+ securityDomain = metaData.getApplicationMetaData().getSecurityDomain();
if( securityDomain != null )
{
- Logger.debug("Binding securityDomain: "+securityDomain+ " to JDNI ENC
as: security-domain");
- bind(envCtx, "security-domain", new LinkRef(securityDomain));
+ log.debug("Binding securityDomain: "+securityDomain+ " to JDNI ENC as:
security-domain");
+ bind(envCtx, "security-domain", new LinkRef(securityDomain));
}
- Logger.debug("End java:comp/env for EJB: "+beanMetaData.getEjbName());
+ log.debug("End java:comp/env for EJB: "+beanMetaData.getEjbName());
} catch (NamingException e)
{
- Logger.exception(e);
- e.getRootCause().printStackTrace();
+ log.error("Could not set up environment", e);
+ log.error("root cause", e.getRootCause());
throw new DeploymentException("Could not set up environment", e);
}
-
}
/**
- * Bind a value to a name in a JNDI-context, and create any missing subcontexts
- *
- * @param ctx
- * @param name
- * @param val
- * @exception NamingException
- */
+ * Bind a value to a name in a JNDI-context, and create any missing subcontexts
+ *
+ * @param ctx
+ * @param name
+ * @param val
+ * @exception NamingException
+ */
private void bind(Context ctx, String name, Object val)
- throws NamingException
+ throws NamingException
{
// Bind val to name in ctx, and make sure that all intermediate contexts exist
Name n = ctx.getNameParser("").parse(name);
@@ -655,4 +673,3 @@
ctx.bind(n.get(0), val);
}
}
-
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-development