User: mulder
Date: 00/07/03 17:18:10
Modified: src/main/org/jboss/ejb Container.java ContainerFactory.java
Log:
Update TxManager to use new MetaData and actually work (for both EJB
methods and Home methods). Required changes to file manager, container
factory, and container to actually load the metadata and make it
accessible.
Revision Changes Path
1.18 +94 -83 jboss/src/main/org/jboss/ejb/Container.java
Index: Container.java
===================================================================
RCS file: /products/cvs/ejboss/jboss/src/main/org/jboss/ejb/Container.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- Container.java 2000/06/21 11:51:29 1.17
+++ Container.java 2000/07/04 00:18:10 1.18
@@ -44,6 +44,7 @@
import org.jboss.ejb.deployment.JDBCResource;
import org.jboss.ejb.deployment.URLResource;
import org.jboss.logging.Logger;
+import org.jboss.metadata.BeanMetaData;
import org.jnp.interfaces.Naming;
import org.jnp.interfaces.java.javaURLContextFactory;
@@ -63,113 +64,123 @@
* @see ContainerFactory
* @author Rickard �berg ([EMAIL PROTECTED])
* @author <a href="[EMAIL PROTECTED]">Marc Fleury</a>
- * @version $Revision: 1.17 $
+ * @version $Revision: 1.18 $
*/
public abstract class Container
{
// Constants -----------------------------------------------------
// Attributes ----------------------------------------------------
-
+
// This is the application that this container is a part of
protected Application application;
-
+
// 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 jBoss-specific metadata. Note that it extends the generic EJB
1.1 class from EJX
protected jBossEnterpriseBean metaData;
-
+
// This is the Home interface class
protected Class homeInterface;
-
+
// This is the Remote interface class
protected Class remoteInterface;
-
+
// This is the EnterpriseBean class
protected Class beanClass;
-
+
// This is the TransactionManager
protected TransactionManager tm;
-
+
+ // This is the new MetaData construct
+ protected BeanMetaData newMetaData;
+
// Public --------------------------------------------------------
-
+
public void setTransactionManager(TransactionManager tm)
{
this.tm = tm;
}
-
+
public TransactionManager getTransactionManager()
{
return tm;
}
-
- public void setApplication(Application app)
- {
+
+ public void setApplication(Application app)
+ {
if (app == null)
throw new IllegalArgumentException("Null application");
-
- application = app;
+
+ application = app;
}
-
- public Application getApplication()
- {
- return application;
+
+ public Application getApplication()
+ {
+ return application;
}
-
- public void setClassLoader(ClassLoader cl)
- {
- this.classLoader = cl;
+
+ public void setClassLoader(ClassLoader cl)
+ {
+ this.classLoader = cl;
}
-
- public ClassLoader getClassLoader()
- {
- return classLoader;
+
+ public ClassLoader getClassLoader()
+ {
+ return classLoader;
}
-
- public void setMetaData(jBossEnterpriseBean metaData)
- {
- this.metaData = metaData;
+
+ public void setMetaData(jBossEnterpriseBean metaData)
+ {
+ this.metaData = metaData;
}
-
- public jBossEnterpriseBean getMetaData()
- {
- return metaData;
- }
-
+
+ public jBossEnterpriseBean getMetaData()
+ {
+ return metaData;
+ }
+
+ public void setBeanMetaData(BeanMetaData metaData) {
+ newMetaData = metaData;
+ }
+ public BeanMetaData getBeanMetaData() {
+ return newMetaData;
+ }
+
public Class getBeanClass()
{
return beanClass;
}
/**
- * The ContainerFactory calls this method. The ContainerFactory has set all
the
+ * 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.
*
- * @exception Exception
+ * @exception Exception
*/
public void init()
throws Exception
{
// Acquire classes from CL
beanClass = classLoader.loadClass(metaData.getEjbClass());
-
+
// Setup "java:" namespace
- setupEnvironment();
+ setupEnvironment();
}
-
+
public void start()
throws Exception
{
}
-
- public void stop()
+
+ public void stop()
{
}
-
- public void destroy()
+
+ public void destroy()
{
}
@@ -180,7 +191,7 @@
*
* @param mi the object holding all info about this invocation
* @return the result of the home invocation
- * @exception Exception
+ * @exception Exception
*/
public abstract Object invokeHome(MethodInvocation mi)
throws Exception;
@@ -194,25 +205,25 @@
* @param method the method being invoked
* @param args the parameters
* @return the result of the invocation
- * @exception Exception
+ * @exception Exception
*/
public abstract Object invoke(MethodInvocation mi)
throws Exception;
-
+
// Protected -----------------------------------------------------
-
+
abstract Interceptor createContainerInterceptor();
-
+
// Private -------------------------------------------------------
-
+
/*
* setupEnvironment
*
* This method sets up the naming environment of the bean.
* it sets the root it creates for the naming in the "BeanClassLoader"
- * that loader shares the root for all instances of the bean and
+ * that loader shares the root for all instances of the bean and
* is part of the "static" metaData of the bean.
- * We create the java: namespace with properties, EJB-References, and
+ * We create the java: namespace with properties, EJB-References, and
* DataSource ressources.
*
*/
@@ -223,15 +234,15 @@
{
// Create a new java: namespace root
NamingServer root = new NamingServer();
-
+
// Associate this root with the classloader of the bean
((BeanClassLoader)getClassLoader()).setJNDIRoot(root);
-
+
// Since the BCL is already associated with this thread we can start
using the java: namespace directly
Context ctx = (Context) new InitialContext().lookup("java:/");
ctx.createSubcontext("comp");
ctx = ctx.createSubcontext("comp/env");
-
+
// Bind environment properties
{
Iterator enum = getMetaData().getEnvironmentEntries();
@@ -267,18 +278,18 @@
}
}
}
-
+
// Bind EJB references
{
Iterator enum = getMetaData().getEjbReferences();
while(enum.hasNext())
{
-
+
jBossEjbReference ref = (jBossEjbReference)enum.next();
System.out.println("Binding an EJBReference "+ref);
-
+
Name n = ctx.getNameParser("").parse(ref.getLink());
-
+
if (!ref.getJndiName().equals(""))
{
// External link
@@ -289,26 +300,26 @@
{
// Internal link
Logger.debug("Bind "+ref.getName() +" to "+ref.getLink());
-
+
final Container con =
getApplication().getContainer(ref.getLink());
-
- // Use Reference to link to ensure lazyloading.
+
+ // Use Reference to link to ensure lazyloading.
// Otherwise we might try to get EJBHome from not yet
initialized container
// will would result in nullpointer exception
RefAddr refAddr = new RefAddr("EJB")
{
- public Object getContent()
+ public Object getContent()
{
return con;
}
};
Reference reference = new
Reference("javax.ejb.EJBObject",refAddr, new
EjbReferenceFactory().getClass().getName(), null);
-
+
bind(ctx, ref.getName(), reference);
}
}
}
-
+
// Bind resource references
{
Iterator enum = getMetaData().getResourceReferences();
@@ -316,9 +327,9 @@
while(enum.hasNext())
{
jBossResourceReference ref = (jBossResourceReference)enum.next();
-
+
ResourceManager rm = rms.getResourceManager(ref.getResourceName());
-
+
if (rm == null)
{
// Try to locate defaults
@@ -347,9 +358,9 @@
Logger.debug(e);
}
}
-
+
}
-
+
// Default failed? Warn user and move on
// POTENTIALLY DANGEROUS: should this be a critical error?
if (rm == null)
@@ -358,15 +369,15 @@
continue;
}
}
-
+
if (rm.getType().equals("javax.sql.DataSource"))
{
- // Datasource bindings
+ // Datasource bindings
JDBCResource res = (JDBCResource)rm;
bind(ctx, ref.getName(), new LinkRef(res.getJndiName()));
} else if (rm.getType().equals("java.net.URL"))
{
- // URL bindings
+ // URL bindings
try
{
URLResource res = (URLResource)rm;
@@ -385,16 +396,16 @@
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
+ * @param ctx
+ * @param name
+ * @param val
+ * @exception NamingException
*/
private void bind(Context ctx, String name, Object val)
throws NamingException
@@ -413,10 +424,10 @@
}
n = n.getSuffix(1);
}
-
+
ctx.bind(n.get(0), val);
}
-
+
public static class EjbReferenceFactory
implements ObjectFactory
{
1.23 +112 -108 jboss/src/main/org/jboss/ejb/ContainerFactory.java
Index: ContainerFactory.java
===================================================================
RCS file: /products/cvs/ejboss/jboss/src/main/org/jboss/ejb/ContainerFactory.java,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -r1.22 -r1.23
--- ContainerFactory.java 2000/06/21 11:51:29 1.22
+++ ContainerFactory.java 2000/07/04 00:18:10 1.23
@@ -57,16 +57,16 @@
/**
-* A ContainerFactory is used to deploy EJB applications. It can be given a URL to
+* A ContainerFactory is used to deploy EJB applications. It can be given a URL to
* an EJB-jar or EJB-JAR XML file, which will be used to instantiate containers
and make
* them available for invocation.
-*
+*
* @see Container
* @author Rickard �berg ([EMAIL PROTECTED])
* @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Juha Lindfors</a>
*
-* @version $Revision: 1.22 $
+* @version $Revision: 1.23 $
*/
public class ContainerFactory
extends org.jboss.util.ServiceMBeanSupport
@@ -77,30 +77,30 @@
public static String DEFAULT_STATEFUL_CONFIGURATION = "Default Stateful
SessionBean";
public static String DEFAULT_ENTITY_BMP_CONFIGURATION = "Default BMP
EntityBean";
public static String DEFAULT_ENTITY_CMP_CONFIGURATION = "Default CMP
EntityBean";
-
+
// Attributes ----------------------------------------------------
// The logger of this service
Log log = new Log(getName());
-
+
// A map of current deployments. If a deployment is made and it is already in
this map,
// then undeploy it first (i.e. make it a re-deploy).
HashMap deployments = new HashMap();
-
+
// Verify EJB-jar contents on deployments
boolean verifyDeployments = false;
-
+
// Public --------------------------------------------------------
public ObjectName getObjectName(MBeanServer server, ObjectName name)
throws javax.management.MalformedObjectNameException
{
return new ObjectName(OBJECT_NAME);
}
-
+
public String getName()
{
return "Container factory";
}
-
+
public void stopService()
{
Iterator apps = deployments.values().iterator();
@@ -110,7 +110,7 @@
app.stop();
}
}
-
+
public void destroyService()
{
Iterator apps = deployments.values().iterator();
@@ -119,27 +119,27 @@
Application app = (Application)apps.next();
app.destroy();
}
-
+
deployments.clear();
}
-
+
public void setVerifyDeployments(boolean verify)
{
verifyDeployments = verify;
}
-
+
public boolean getVerifyDeployments()
{
return verifyDeployments;
}
-
+
/**
* Deploy the file at this URL. This method is typically called from
remote administration
* tools that cannot handle java.net.URL's as parameters to methods
*
- * @param url
- * @exception MalformedURLException
- * @exception DeploymentException
+ * @param url
+ * @exception MalformedURLException
+ * @exception DeploymentException
*/
public void deploy(String url)
throws MalformedURLException, DeploymentException
@@ -147,15 +147,15 @@
// Delegate to "real" deployment
deploy(new URL(url));
}
-
-
+
+
/**
* Undeploy the file at this URL. This method is typically called from
remote administration
* tools that cannot handle java.net.URL's as parameters to methods
*
- * @param url
- * @exception MalformedURLException
- * @exception DeploymentException
+ * @param url
+ * @exception MalformedURLException
+ * @exception DeploymentException
*/
public void undeploy(String url)
throws MalformedURLException, DeploymentException
@@ -163,7 +163,7 @@
// Delegate to "real" undeployment
undeploy(new URL(url));
}
-
+
/**
* Deploy EJBs pointed to by an URL.
* The URL may point to an EJB-JAR, an EAR-JAR, or an codebase
@@ -173,14 +173,14 @@
*
* @param url URL where EJB deployment information is contained
* @return The created containers
- * @exception DeploymentException
+ * @exception DeploymentException
*/
public synchronized void deploy(URL url)
throws DeploymentException
{
// Create application
Application app = new Application();
-
+
try
{
Log.setLog(log);
@@ -189,35 +189,35 @@
if (deployments.containsKey(url))
undeploy(url);
- // Check validity
- if (verifyDeployments)
+ // Check validity
+ if (verifyDeployments)
{
BeanVerifier verifier = new BeanVerifier();
-
- verifier.addVerificationListener(new VerificationListener()
+
+ verifier.addVerificationListener(new VerificationListener()
{
- public void beanChecked(VerificationEvent event)
+ public void beanChecked(VerificationEvent event)
{
System.out.println(event.getMessage());
}
});
-
+
verifier.verify(url);
}
-
+
app.setURL(url);
-
+
log.log("Deploying:"+url);
-
+
// Create a file manager with which to load the files
jBossFileManagerFactory fact = new jBossFileManagerFactory();
jBossFileManager efm =
(jBossFileManager)fact.createFileManager();
-
+
// Setup beancontext
BeanContextServicesSupport beanCtx = new
BeanContextServicesSupport();
beanCtx.add(Beans.instantiate(getClass().getClassLoader(),
"com.dreambean.ejx.xml.ProjectX"));
beanCtx.add(efm);
-
+
// Load XML
jBossEjbJar jar;
if (url.getProtocol().startsWith("file"))
@@ -230,123 +230,126 @@
{
jar = efm.load(url);
}
-
+
// Create classloader for this application
// ClassLoader cl = new EJBClassLoader(new URL[] {url}, null,
jar.isSecure());
ClassLoader cl = efm.getClassLoader();
-
+
// Get list of beans for which we will create containers
Iterator beans = jar.getEnterpriseBeans().iterator();
-
+
// Deploy beans
Context ctx = new InitialContext();
while(beans.hasNext())
{
jBossEnterpriseBean bean =
(jBossEnterpriseBean)beans.next();
-
+
log.log("Deploying "+bean.getEjbName());
-
+
if (bean instanceof jBossSession) // Is session?
{
if
(((jBossSession)bean).getSessionType().equals("Stateless")) // Is stateless?
{
// Create container
StatelessSessionContainer container =
new StatelessSessionContainer();
-
+
// Create classloader for this
container
container.setClassLoader(new
BeanClassLoader(cl));
-
+
// Set metadata
container.setMetaData(bean);
-
+
+
container.setBeanMetaData(efm.getMetaData().getBean(bean.getEjbName()));
+
// Set transaction manager
container.setTransactionManager((TransactionManager)new
InitialContext().lookup("TransactionManager"));
-
+
// Get container configuration
ContainerConfiguration conf =
bean.getContainerConfiguration();
-
+
// Make sure we have a default
configuration
- if (conf == null)
+ if (conf == null)
{
log.warning("No configuration
chosen. Using default configuration");
-
+
// Get the container default
configuration
conf =
jar.getContainerConfigurations().getContainerConfiguration(DEFAULT_STATELESS_CONFIGURATION);
-
+
// Make sure this bean knows
the configuration he is using
bean.setConfigurationName(DEFAULT_STATELESS_CONFIGURATION);
}
-
+
// Set container invoker
container.setContainerInvoker((ContainerInvoker)cl.loadClass(conf.getContainerInvoker()).newInstance());
-
+
// Set instance pool
container.setInstancePool((InstancePool)cl.loadClass(conf.getInstancePool()).newInstance());
-
+
// Create interceptors
-
+
container.addInterceptor(new
LogInterceptor());
container.addInterceptor(new
SecurityInterceptor());
container.addInterceptor(new
TxInterceptor());
container.addInterceptor(new
StatelessSessionInstanceInterceptor());
-
+
// Finally we add the last interceptor
from the container
container.addInterceptor(container.createContainerInterceptor());
-
+
// Add container to application
app.addContainer(container);
} else // Stateful
{
boolean implemented = false;
-
+
//if (!implemented) throw new
Error("Stateful Container not implemented yet");
-
+
// Create container
StatefulSessionContainer container =
new StatefulSessionContainer();
-
+
// Create classloader for this
container
container.setClassLoader(new
BeanClassLoader(cl));
-
+
// Set metadata
container.setMetaData(bean);
-
+
container.setBeanMetaData(efm.getMetaData().getBean(bean.getEjbName()));
+
// Set transaction manager
container.setTransactionManager((TransactionManager)new
InitialContext().lookup("TransactionManager"));
-
+
// Get container configuration
ContainerConfiguration conf =
bean.getContainerConfiguration();
-
+
// Make sure we have a default
configuration
- if (conf == null)
+ if (conf == null)
{
log.warning("No configuration
chosen. Using default configuration");
-
+
conf =
jar.getContainerConfigurations().getContainerConfiguration(DEFAULT_STATEFUL_CONFIGURATION);
-
+
// Make sure this bean knows
the configuration he is using
-
bean.setConfigurationName(DEFAULT_STATEFUL_CONFIGURATION);
+
bean.setConfigurationName(DEFAULT_STATEFUL_CONFIGURATION);
}
-
+
// Set container invoker
container.setContainerInvoker((ContainerInvoker)cl.loadClass(conf.getContainerInvoker()).newInstance());
-
+
// Set instance cache
container.setInstanceCache((InstanceCache)cl.loadClass(conf.getInstanceCache()).newInstance());
-
+
// Set instance pool
container.setInstancePool((InstancePool)cl.loadClass(conf.getInstancePool()).newInstance());
-
+
// Set persistence manager
container.setPersistenceManager((StatefulSessionPersistenceManager)cl.loadClass(conf.getPersistenceManager()).newInstance());
-
+
// Create interceptors
container.addInterceptor(new
LogInterceptor());
container.addInterceptor(new
TxInterceptor());
container.addInterceptor(new
StatefulSessionInstanceInterceptor());
container.addInterceptor(new
SecurityInterceptor());
-
+
container.addInterceptor(container.createContainerInterceptor());
-
+
// Add container to application
app.addContainer(container);
}
@@ -354,129 +357,130 @@
{
// Create container
EntityContainer container = new
EntityContainer();
-
+
// Create classloader for this container
container.setClassLoader(new
BeanClassLoader(cl));
-
+
// Set metadata
container.setMetaData(bean);
-
+
container.setBeanMetaData(efm.getMetaData().getBean(bean.getEjbName()));
+
// Set transaction manager
container.setTransactionManager((TransactionManager)new
InitialContext().lookup("TransactionManager"));
-
+
// Get container configuration
ContainerConfiguration conf =
bean.getContainerConfiguration();
-
+
// Make sure we have a default configuration
- if (conf == null)
+ if (conf == null)
{
log.warning("No configuration chosen.
Using default configuration");
- if (((jBossEntity)
bean).getPersistenceType().equals("Bean"))
+ if (((jBossEntity)
bean).getPersistenceType().equals("Bean"))
{
// BMP case
conf =
jar.getContainerConfigurations().getContainerConfiguration(DEFAULT_ENTITY_BMP_CONFIGURATION);
-
+
// Make sure this bean knows
the configuration he is using
bean.setConfigurationName(DEFAULT_ENTITY_BMP_CONFIGURATION);
}
- else
- {
+ else
+ {
// CMP case
conf =
jar.getContainerConfigurations().getContainerConfiguration(DEFAULT_ENTITY_CMP_CONFIGURATION);
-
+
// Make sure this bean knows
the configuration he is using
bean.setConfigurationName(DEFAULT_ENTITY_CMP_CONFIGURATION);
}
}
-
+
// Set container invoker
container.setContainerInvoker((ContainerInvoker)cl.loadClass(conf.getContainerInvoker()).newInstance());
-
+
// Set instance cache
container.setInstanceCache((InstanceCache)cl.loadClass(conf.getInstanceCache()).newInstance());
-
+
// Set instance pool
container.setInstancePool((InstancePool)cl.loadClass(conf.getInstancePool()).newInstance());
-
+
// Set persistence manager
container.setPersistenceManager((EntityPersistenceManager)cl.loadClass(conf.getPersistenceManager()).newInstance());
-
+
// Create interceptors
container.addInterceptor(new LogInterceptor());
container.addInterceptor(new
SecurityInterceptor());
container.addInterceptor(new TxInterceptor());
container.addInterceptor(new
EntityInstanceInterceptor());
container.addInterceptor(new
EntitySynchronizationInterceptor());
-
+
container.addInterceptor(container.createContainerInterceptor());
-
+
// Add container to application
app.addContainer(container);
}
}
-
+
// Init application
app.init();
-
+
// Start application
app.start();
-
+
// Add to webserver so client can access classes through
dynamic class downloading
WebServiceMBean webServer =
(WebServiceMBean)MBeanProxy.create(WebServiceMBean.class, WebServiceMBean.OBJECT_NAME);
webServer.addClassLoader(cl);
-
+
// Done
log.log("Deployed application: "+app.getName());
-
+
// Register deployment
deployments.put(url, app);
} catch (Throwable e)
{
e.printStackTrace();
-
+
app.stop();
app.destroy();
-
+
throw new DeploymentException("Could not deploy
"+url.toString());
} finally
{
Log.unsetLog();
}
}
-
-
+
+
/**
* Remove previously deployed EJBs.
*
- * @param url
- * @exception DeploymentException
+ * @param url
+ * @exception DeploymentException
*/
public void undeploy(URL url)
throws DeploymentException
{
// Get application from table
Application app = (Application)deployments.get(url);
-
+
// Check if deployed
if (app == null)
{
throw new DeploymentException("URL not deployed");
}
-
+
// Undeploy application
Log.setLog(log);
log.log("Undeploying:"+url);
app.stop();
app.destroy();
-
+
// Remove deployment
deployments.remove(url);
-
+
// Done
log.log("Undeployed application: "+app.getName());
-
+
Log.unsetLog();
}
-
+
// Protected -----------------------------------------------------
}