User: salborini
Date: 00/09/26 13:18:49
Modified: src/main/org/jboss/ejb CacheKey.java ContainerFactory.java
EnterpriseContext.java EntityContainer.java
Log:
Removed DOS ^M at the end of each line
Revision Changes Path
1.3 +101 -101 jboss/src/main/org/jboss/ejb/CacheKey.java
Index: CacheKey.java
===================================================================
RCS file: /products/cvs/ejboss/jboss/src/main/org/jboss/ejb/CacheKey.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- CacheKey.java 2000/09/26 17:38:31 1.2
+++ CacheKey.java 2000/09/26 20:18:48 1.3
@@ -1,101 +1,101 @@
-
-
-/*
-* jBoss, the OpenSource EJB server
-*
-* Distributable under GPL license.
-* See terms of license at gnu.org.
-*/
-package org.jboss.ejb;
-
-/**
-* CacheKey
-*
-* CacheKey is an encapsulation of both the PrimaryKey and a cache specific key
-*
-* This implementation is a safe implementation in the sense that it doesn't rely
-* on the user supplied hashcode and equals. It is also fast since the hashCode
operation
-* is pre-calculated.
-*
-* @see org.jboss.ejb.plugins.NoPassivationInstanceCache.java
-* @author <a href="[EMAIL PROTECTED]">Marc Fleury</a>
-* @version $Revision: 1.2 $
-*/
-public class CacheKey
- implements java.io.Externalizable
-{
- // Constants -----------------------------------------------------
-
- // Attributes ----------------------------------------------------
-
- // The database primaryKey
- public Object id;
-
- private int hashCode;
-
- // Static --------------------------------------------------------
-
- // Public --------------------------------------------------------
-
- public CacheKey() {
- // For externalization only
- }
- public CacheKey(Object id) {
-
- if (id == null) throw new Error("id may not be null");
-
- this.id = id;
-
- try {
- hashCode = new java.rmi.MarshalledObject(id).hashCode();
- }
- catch (Exception e) {e.printStackTrace();}
- }
-
- // Z implementation ----------------------------------------------
-
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
- // Private -------------------------------------------------------
-
- public void writeExternal(java.io.ObjectOutput out)
- throws java.io.IOException
- {
- out.writeObject(id);
- out.write(hashCode);
- }
-
- public void readExternal(java.io.ObjectInput in)
- throws java.io.IOException, ClassNotFoundException
- {
- id = in.readObject();
- hashCode = in.read();
- }
-
- // HashCode and Equals over write --------------------------------
-
- /**
- * these should be overwritten by extending Cache key
- * since they define what the cache does in the first place
- */
- public int hashCode() {
-
- // we default to the pK id
- return hashCode;
- }
-
-
- public boolean equals(Object object) {
-
- if (object instanceof CacheKey) {
-
- return (hashCode ==(((CacheKey) object).hashCode));
- }
- return false;
- }
-
- // Inner classes -------------------------------------------------
-}
-
+
+
+/*
+* jBoss, the OpenSource EJB server
+*
+* Distributable under GPL license.
+* See terms of license at gnu.org.
+*/
+package org.jboss.ejb;
+
+/**
+* CacheKey
+*
+* CacheKey is an encapsulation of both the PrimaryKey and a cache specific key
+*
+* This implementation is a safe implementation in the sense that it doesn't rely
+* on the user supplied hashcode and equals. It is also fast since the hashCode
operation
+* is pre-calculated.
+*
+* @see org.jboss.ejb.plugins.NoPassivationInstanceCache.java
+* @author <a href="[EMAIL PROTECTED]">Marc Fleury</a>
+* @version $Revision: 1.3 $
+*/
+public class CacheKey
+ implements java.io.Externalizable
+{
+ // Constants -----------------------------------------------------
+
+ // Attributes ----------------------------------------------------
+
+ // The database primaryKey
+ public Object id;
+
+ private int hashCode;
+
+ // Static --------------------------------------------------------
+
+ // Public --------------------------------------------------------
+
+ public CacheKey() {
+ // For externalization only
+ }
+ public CacheKey(Object id) {
+
+ if (id == null) throw new Error("id may not be null");
+
+ this.id = id;
+
+ try {
+ hashCode = new java.rmi.MarshalledObject(id).hashCode();
+ }
+ catch (Exception e) {e.printStackTrace();}
+ }
+
+ // Z implementation ----------------------------------------------
+
+ // Package protected ---------------------------------------------
+
+ // Protected -----------------------------------------------------
+
+ // Private -------------------------------------------------------
+
+ public void writeExternal(java.io.ObjectOutput out)
+ throws java.io.IOException
+ {
+ out.writeObject(id);
+ out.write(hashCode);
+ }
+
+ public void readExternal(java.io.ObjectInput in)
+ throws java.io.IOException, ClassNotFoundException
+ {
+ id = in.readObject();
+ hashCode = in.read();
+ }
+
+ // HashCode and Equals over write --------------------------------
+
+ /**
+ * these should be overwritten by extending Cache key
+ * since they define what the cache does in the first place
+ */
+ public int hashCode() {
+
+ // we default to the pK id
+ return hashCode;
+ }
+
+
+ public boolean equals(Object object) {
+
+ if (object instanceof CacheKey) {
+
+ return (hashCode ==(((CacheKey) object).hashCode));
+ }
+ return false;
+ }
+
+ // Inner classes -------------------------------------------------
+}
+
1.41 +686 -686 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.40
retrieving revision 1.41
diff -u -r1.40 -r1.41
--- ContainerFactory.java 2000/09/26 17:41:23 1.40
+++ ContainerFactory.java 2000/09/26 20:18:48 1.41
@@ -1,686 +1,686 @@
-/*
-* jBoss, the OpenSource EJB server
-*
-* Distributable under GPL license.
-* See terms of license at gnu.org.
-*/
-package org.jboss.ejb;
-
-import java.beans.Beans;
-import java.beans.beancontext.BeanContextServicesSupport;
-import java.net.URL;
-import java.net.URLClassLoader;
-import java.net.MalformedURLException;
-import java.io.File;
-import java.io.InputStream;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.rmi.RemoteException;
-import java.rmi.ServerException;
-import java.rmi.server.UnicastRemoteObject;
-import java.util.Properties;
-import java.util.Iterator;
-import java.util.HashMap;
-import java.util.ArrayList;
-import java.util.StringTokenizer;
-import java.util.jar.JarFile;
-import java.util.jar.Manifest;
-import java.util.jar.Attributes;
-
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.Name;
-import javax.naming.NameNotFoundException;
-import javax.naming.NamingException;
-import javax.management.MBeanServer;
-import javax.management.MBeanRegistration;
-import javax.management.ObjectName;
-import javax.transaction.TransactionManager;
-
-import org.jboss.logging.Log;
-import org.jboss.logging.ConsoleLogging;
-import org.jboss.logging.ConsoleLoggingMBean;
-
-import org.jboss.util.MBeanProxy;
-import org.jboss.web.WebServiceMBean;
-
-import org.jboss.ejb.plugins.*;
-
-import org.jboss.verifier.BeanVerifier;
-import org.jboss.verifier.event.VerificationEvent;
-import org.jboss.verifier.event.VerificationListener;
-
-import org.jboss.system.EJBSecurityManager;
-import org.jboss.system.RealmMapping;
-
-import org.jboss.metadata.ApplicationMetaData;
-import org.jboss.metadata.BeanMetaData;
-import org.jboss.metadata.SessionMetaData;
-import org.jboss.metadata.EntityMetaData;
-import org.jboss.metadata.ConfigurationMetaData;
-import org.jboss.metadata.XmlLoadable;
-import org.jboss.metadata.XmlFileLoader;
-import org.jboss.logging.Logger;
-
-
-
-/**
-* 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>
-* @author <a href="mailto:[EMAIL PROTECTED]">Sebastien Alborini</a>
-*
-* @version $Revision: 1.40 $
-*/
-public class ContainerFactory
- extends org.jboss.util.ServiceMBeanSupport
- implements ContainerFactoryMBean
-{
- // Constants -----------------------------------------------------
- public static String DEFAULT_STATELESS_CONFIGURATION = "Default Stateless
SessionBean";
- 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 ----------------------------------------------------
- // Temp directory where deployed jars are stored
- File tmpDir;
-
- // 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 --------------------------------------------------------
-
- /**
- * Implements the abstract <code>getObjectName()</code> method in superclass
- * to return this service's name.
- *
- * @param server
- * @param name
- *
- * @exception MalformedObjectNameException
- * @return
- */
- public ObjectName getObjectName(MBeanServer server, ObjectName name)
- throws javax.management.MalformedObjectNameException
- {
- return new ObjectName(OBJECT_NAME);
- }
-
- /**
- * Implements the abstract <code>getName()</code> method in superclass to
- * return the name of this object.
- *
- * @return <tt>'Container factory'</code>
- */
- public String getName()
- {
- return "Container factory";
- }
-
- /**
- * Implements the template method in superclass. This method inits the factory
- */
- public void initService()
- {
- URL tmpFile = getClass().getResource("/tmp.properties");
- if (tmpFile != null)
- {
- tmpDir = new File(new File(tmpFile.getFile()).getParent(),"deploy/");
- tmpDir.mkdirs();
-
- log.log("Temporary directory set to:"+tmpDir);
-
- // Clear tmp directory of previously deployed files
- // This is to clear up if jBoss previously crashed, hence not removing
files properly
- File[] files = tmpDir.listFiles();
- for (int i = 0; i < files.length; i++)
- {
- files[i].delete();
- }
-
- if (files.length > 0)
- {
- log.log("Previous deployments removed");
- }
- } else
- {
- log.log("Using the systems temporary directory");
- }
- }
-
- /**
- * Implements the template method in superclass. This method stops all the
- * applications in this server.
- */
- public void stopService()
- {
- Iterator apps = deployments.values().iterator();
- while (apps.hasNext())
- {
- Application app = (Application)apps.next();
- app.stop();
- }
- }
-
- /**
- * Implements the template method in superclass. This method destroys all
- * the applications in this server and clears the deployments list.
- */
- public void destroyService()
- {
- Iterator apps = deployments.values().iterator();
- while (apps.hasNext())
- {
- Application app = (Application)apps.next();
- app.destroy();
- }
-
- deployments.clear();
- }
-
- /**
- * Enables/disables the application bean verification upon deployment.
- *
- * @param verify true to enable; false to disable
- */
- public void setVerifyDeployments(boolean verify)
- {
- verifyDeployments = verify;
- }
-
- /**
- * Returns the state of bean verifier (on/off)
- *
- * @param true if enabled; false otherwise
- */
- 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
- */
- public void deploy(String url)
- throws MalformedURLException, DeploymentException
- {
- // 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
- */
- public void undeploy(String url)
- throws MalformedURLException, DeploymentException
- {
- // 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
- * whose structure resembles that of an EJB-JAR. <p>
- *
- * The latter is useful for development since no packaging is required.
- *
- * @param url URL where EJB deployment information is contained
- *
- * @exception DeploymentException
- */
- public synchronized void deploy(URL url)
- throws DeploymentException
- {
- // Create application
- Application app = new Application();
-
- try
- {
- Log.setLog(log);
-
- // Check if already deployed -> undeploy first, this is re-deploy
- if (deployments.containsKey(url))
- undeploy(url);
-
-
- app.setURL(url);
-
- log.log("Deploying:"+url);
-
- // URL's to put in classloader
- URL[] urls;
-
- // save the name of the jar before copying -> undeploy with the same name
- URL origUrl = url;
-
- // copy the jar file to prevent locking - redeploy failure
- if (url.getProtocol().startsWith("file") && !url.getFile().endsWith("/"))
- {
- System.out.println(tmpDir);
-
- File jarFile = new File(url.getFile());
- File tmp;
- if (tmpDir == null)
- {
- tmp = File.createTempFile("tmpejbjar",".jar");
- } else
- {
- tmp = File.createTempFile("tmpejbjar",".jar", tmpDir);
- }
- tmp.deleteOnExit();
- FileInputStream fin = new FileInputStream(jarFile);
- byte[] bytes = new byte[(int)jarFile.length()];
- fin.read(bytes);
- FileOutputStream fout = new FileOutputStream(tmp);
- fout.write(bytes);
- fin.close();
- fout.close();
-
- // Get the URL's from the deployments Class-Path: manifest file.
- // These should be added to the classloader
- JarFile jar = new JarFile(tmp);
- Manifest mf = jar.getManifest();
- ArrayList urlList = new ArrayList();
- if (mf != null)
- {
- Attributes attributes = mf.getMainAttributes();
- String classPath = attributes.getValue(Attributes.Name.CLASS_PATH);
- if (classPath != null)
- {
- StringTokenizer classPathTokens = new StringTokenizer(classPath,
" ");
- while (classPathTokens.hasMoreTokens())
- {
- String classPathEntry = classPathTokens.nextToken();
- try
- {
- urlList.add(new URL(url, classPathEntry));
- log.log("Added "+ classPathEntry);
- } catch (MalformedURLException e)
- {
- log.error("Could not add " + classPathEntry);
- }
- }
- }
- }
-
- // Add URL to tmp file
- url = tmp.toURL();
- urlList.add(url);
-
- urls = new URL[urlList.size()];
- urls = (URL[])urlList.toArray(urls);
- } else
- {
- urls = new URL[] { url };
- }
-
- // Create the ClassLoader for this application
- // TODO : the ClassLoader should come from the JMX manager if we want to
be able to share it (tomcat)
- ClassLoader cl = new URLClassLoader(urls,
Thread.currentThread().getContextClassLoader());
-
- // Create a file loader with which to load the files
- XmlFileLoader efm = new XmlFileLoader();
-
- // the file manager gets its file from the classloader
- efm.setClassLoader(cl);
-
- // Load XML
- ApplicationMetaData metaData = efm.load();
-
-
-
- // Check validity
- Log.setLog(new Log("Verifier"));
-
- // wrapping this into a try - catch block to prevent errors in
- // verifier from stopping the deployment
- try {
-
- if (verifyDeployments)
- {
- BeanVerifier verifier = new BeanVerifier();
-
- verifier.addVerificationListener(new VerificationListener()
- {
- public void beanChecked(VerificationEvent event)
- {
- Logger.log(event.getName() + ": " + event.getMessage());
- }
-
- public void specViolation(VerificationEvent event)
- {
- Logger.log(event.getName() + ": " + event.getMessage());
- }
- });
-
-
- Logger.log("Verifying " + url);
-
- verifier.verify(url, metaData);
- }
- }
- catch (Throwable t) {
- Logger.exception(t);
- }
-
- // unset verifier log
- Log.unsetLog();
-
- // Get list of beans for which we will create containers
- Iterator beans = metaData.getEnterpriseBeans();
-
- // Deploy beans
- Context ctx = new InitialContext();
- while(beans.hasNext())
- {
- BeanMetaData bean = (BeanMetaData)beans.next();
-
- log.log("Deploying "+bean.getEjbName());
-
- if (bean.isSession()) // Is session?
- {
- if (((SessionMetaData)bean).isStateless()) // Is stateless?
- {
- // Create container
- StatelessSessionContainer container = new
StatelessSessionContainer();
-
- // Create classloader for this container
- container.setClassLoader(new BeanClassLoader(cl));
-
- // Set metadata
- container.setBeanMetaData(bean);
-
- // get the container configuration for this bean
- // a default configuration is now always provided
- ConfigurationMetaData conf = bean.getContainerConfiguration();
-
- // Set transaction manager
- container.setTransactionManager((TransactionManager)new
InitialContext().lookup("TransactionManager"));
-
- // Set security manager (should be chosen based on container
config)
- container.setSecurityManager((EJBSecurityManager)new
InitialContext().lookup("EJBSecurityManager"));
-
- // Set realm mapping (should be chosen based on container
config)
- container.setRealmMapping( (RealmMapping)new
InitialContext().lookup("SimpleRealmMapping"));
-
- // Set container invoker
- ContainerInvoker ci =
(ContainerInvoker)cl.loadClass(conf.getContainerInvoker()).newInstance();
- if (ci instanceof XmlLoadable) {
- // the container invoker can load its configuration from the
jboss.xml element
- ((XmlLoadable)ci).importXml(conf.getContainerInvokerConf());
- }
- container.setContainerInvoker(ci);
-
- // Set instance pool
- InstancePool ip =
(InstancePool)cl.loadClass(conf.getInstancePool()).newInstance();
- if (ip instanceof XmlLoadable) {
- ((XmlLoadable)ip).importXml(conf.getContainerPoolConf());
- }
- container.setInstancePool(ip);
-
- // Create interceptors
-
- container.addInterceptor(new LogInterceptor());
- container.addInterceptor(new SecurityInterceptor());
-
- if (((SessionMetaData)bean).isContainerManagedTx()) {
- // CMT
- container.addInterceptor(new TxInterceptorCMT());
- container.addInterceptor(new
StatelessSessionInstanceInterceptor());
-
- } else {
- // BMT
- container.addInterceptor(new StatelessSessionInstanceInterceptor());
- container.addInterceptor(new TxInterceptorBMT());
- }
-
- // Finally we add the last interceptor from the container
- container.addInterceptor(container.createContainerInterceptor());
-
- // Add container to application
- app.addContainer(container);
- } else // Stateful
- {
- // Create container
- StatefulSessionContainer container = new
StatefulSessionContainer();
-
- // Create classloader for this container
- container.setClassLoader(new BeanClassLoader(cl));
-
- // Set metadata
- container.setBeanMetaData(bean);
-
- // Set transaction manager
- container.setTransactionManager((TransactionManager)new
InitialContext().lookup("TransactionManager"));
-
- // Set security manager (should be chosen based on container
config)
- container.setSecurityManager((EJBSecurityManager)new
InitialContext().lookup("EJBSecurityManager"));
-
- // Set realm mapping (should be chosen based on container
config)
- container.setRealmMapping( (RealmMapping)new
InitialContext().lookup("SimpleRealmMapping"));
-
- // Get container configuration
- ConfigurationMetaData conf = bean.getContainerConfiguration();
-
- // Set container invoker
- ContainerInvoker ci =
(ContainerInvoker)cl.loadClass(conf.getContainerInvoker()).newInstance();
- if (ci instanceof XmlLoadable) {
- // the container invoker can load its configuration from the
jboss.xml element
- ((XmlLoadable)ci).importXml(conf.getContainerInvokerConf());
- }
- container.setContainerInvoker(ci);
-
- // Set instance cache
- InstanceCache ic =
(InstanceCache)cl.loadClass(conf.getInstanceCache()).newInstance();
- if (ic instanceof XmlLoadable) {
- ((XmlLoadable)ic).importXml(conf.getContainerCacheConf());
- }
- container.setInstanceCache(ic);
-
- // No real instance pool, use the shadow class
- container.setInstancePool(new StatefulSessionInstancePool());
-
- // Set persistence manager
-
container.setPersistenceManager((StatefulSessionPersistenceManager)cl.loadClass(conf.getPersistenceManager()).newInstance());
-
- // Create interceptors
- container.addInterceptor(new LogInterceptor());
-
- if (((SessionMetaData)bean).isContainerManagedTx()) {
- // CMT
- container.addInterceptor(new TxInterceptorCMT());
- container.addInterceptor(new
StatefulSessionInstanceInterceptor());
-
- } else {
- // BMT : the tx interceptor needs the context from the instance
interceptor
- container.addInterceptor(new StatefulSessionInstanceInterceptor());
- container.addInterceptor(new TxInterceptorBMT());
- }
-
- container.addInterceptor(new SecurityInterceptor());
-
- container.addInterceptor(container.createContainerInterceptor());
-
- // Add container to application
- app.addContainer(container);
- }
- } else // Entity
- {
- // Create container
- EntityContainer container = new EntityContainer();
-
- // Create classloader for this container
- container.setClassLoader(new BeanClassLoader(cl));
-
- // Set metadata
- container.setBeanMetaData(bean);
-
- // Set transaction manager
- container.setTransactionManager((TransactionManager)new
InitialContext().lookup("TransactionManager"));
-
- // Set security manager (should be chosen based on container config)
- container.setSecurityManager((EJBSecurityManager)new
InitialContext().lookup("EJBSecurityManager"));
-
- // Set realm mapping (should be chosen based on container config)
- container.setRealmMapping( (RealmMapping)new
InitialContext().lookup("SimpleRealmMapping"));
-
- // Get container configuration
- ConfigurationMetaData conf = bean.getContainerConfiguration();
-
- // Set container invoker
- ContainerInvoker ci =
(ContainerInvoker)cl.loadClass(conf.getContainerInvoker()).newInstance();
- if (ci instanceof XmlLoadable) {
- // the container invoker can load its configuration from the
jboss.xml element
- ((XmlLoadable)ci).importXml(conf.getContainerInvokerConf());
- }
- container.setContainerInvoker(ci);
-
- // Set instance cache
- InstanceCache ic =
(InstanceCache)cl.loadClass(conf.getInstanceCache()).newInstance();
- if (ic instanceof XmlLoadable) {
- ((XmlLoadable)ic).importXml(conf.getContainerCacheConf());
- }
- container.setInstanceCache(ic);
-
- // Set instance pool
- InstancePool ip =
(InstancePool)cl.loadClass(conf.getInstancePool()).newInstance();
- if (ip instanceof XmlLoadable) {
- ((XmlLoadable)ip).importXml(conf.getContainerPoolConf());
- }
- container.setInstancePool(ip);
-
- // Set persistence manager
- if (((EntityMetaData) bean).isBMP()) {
-
- //Should be BMPPersistenceManager
-
container.setPersistenceManager((EntityPersistenceManager)cl.loadClass(conf.getPersistenceManager()).newInstance());
- }
- else {
-
- // CMP takes a manager and a store
- org.jboss.ejb.plugins.CMPPersistenceManager persistenceManager =
new org.jboss.ejb.plugins.CMPPersistenceManager();
-
- //Load the store from configuration
-
persistenceManager.setPersistenceStore((EntityPersistenceStore)cl.loadClass(conf.getPersistenceManager()).newInstance());
-
- // Set the manager on the container
- container.setPersistenceManager(persistenceManager);
- }
-
- // Create interceptors
- container.addInterceptor(new LogInterceptor());
- container.addInterceptor(new SecurityInterceptor());
-
- // entity beans are always CMT
- container.addInterceptor(new TxInterceptorCMT());
-
- 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. Use the original name in the hashtable
- deployments.put(origUrl, app);
- }
- catch (Throwable e)
- {
- if (e instanceof NullPointerException) {
- // Avoids useless 'null' messages on a server trace.
- // Let's be honest and spam them with a stack trace.
- // NPE should be considered an internal server error anyways.
- Logger.exception(e);
- }
-
- Logger.exception(e);
- //Logger.debug(e.getMessage());
-
- app.stop();
- app.destroy();
-
- throw new DeploymentException("Could not deploy "+url.toString());
- } finally
- {
- Log.unsetLog();
- }
- }
-
-
- /**
- * Remove previously deployed EJBs.
- *
- * @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 -----------------------------------------------------
-}
+/*
+* jBoss, the OpenSource EJB server
+*
+* Distributable under GPL license.
+* See terms of license at gnu.org.
+*/
+package org.jboss.ejb;
+
+import java.beans.Beans;
+import java.beans.beancontext.BeanContextServicesSupport;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.net.MalformedURLException;
+import java.io.File;
+import java.io.InputStream;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.rmi.RemoteException;
+import java.rmi.ServerException;
+import java.rmi.server.UnicastRemoteObject;
+import java.util.Properties;
+import java.util.Iterator;
+import java.util.HashMap;
+import java.util.ArrayList;
+import java.util.StringTokenizer;
+import java.util.jar.JarFile;
+import java.util.jar.Manifest;
+import java.util.jar.Attributes;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.Name;
+import javax.naming.NameNotFoundException;
+import javax.naming.NamingException;
+import javax.management.MBeanServer;
+import javax.management.MBeanRegistration;
+import javax.management.ObjectName;
+import javax.transaction.TransactionManager;
+
+import org.jboss.logging.Log;
+import org.jboss.logging.ConsoleLogging;
+import org.jboss.logging.ConsoleLoggingMBean;
+
+import org.jboss.util.MBeanProxy;
+import org.jboss.web.WebServiceMBean;
+
+import org.jboss.ejb.plugins.*;
+
+import org.jboss.verifier.BeanVerifier;
+import org.jboss.verifier.event.VerificationEvent;
+import org.jboss.verifier.event.VerificationListener;
+
+import org.jboss.system.EJBSecurityManager;
+import org.jboss.system.RealmMapping;
+
+import org.jboss.metadata.ApplicationMetaData;
+import org.jboss.metadata.BeanMetaData;
+import org.jboss.metadata.SessionMetaData;
+import org.jboss.metadata.EntityMetaData;
+import org.jboss.metadata.ConfigurationMetaData;
+import org.jboss.metadata.XmlLoadable;
+import org.jboss.metadata.XmlFileLoader;
+import org.jboss.logging.Logger;
+
+
+
+/**
+* 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>
+* @author <a href="mailto:[EMAIL PROTECTED]">Sebastien Alborini</a>
+*
+* @version $Revision: 1.41 $
+*/
+public class ContainerFactory
+ extends org.jboss.util.ServiceMBeanSupport
+ implements ContainerFactoryMBean
+{
+ // Constants -----------------------------------------------------
+ public static String DEFAULT_STATELESS_CONFIGURATION = "Default Stateless
SessionBean";
+ 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 ----------------------------------------------------
+ // Temp directory where deployed jars are stored
+ File tmpDir;
+
+ // 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 --------------------------------------------------------
+
+ /**
+ * Implements the abstract <code>getObjectName()</code> method in superclass
+ * to return this service's name.
+ *
+ * @param server
+ * @param name
+ *
+ * @exception MalformedObjectNameException
+ * @return
+ */
+ public ObjectName getObjectName(MBeanServer server, ObjectName name)
+ throws javax.management.MalformedObjectNameException
+ {
+ return new ObjectName(OBJECT_NAME);
+ }
+
+ /**
+ * Implements the abstract <code>getName()</code> method in superclass to
+ * return the name of this object.
+ *
+ * @return <tt>'Container factory'</code>
+ */
+ public String getName()
+ {
+ return "Container factory";
+ }
+
+ /**
+ * Implements the template method in superclass. This method inits the factory
+ */
+ public void initService()
+ {
+ URL tmpFile = getClass().getResource("/tmp.properties");
+ if (tmpFile != null)
+ {
+ tmpDir = new File(new File(tmpFile.getFile()).getParent(),"deploy/");
+ tmpDir.mkdirs();
+
+ log.log("Temporary directory set to:"+tmpDir);
+
+ // Clear tmp directory of previously deployed files
+ // This is to clear up if jBoss previously crashed, hence not removing
files properly
+ File[] files = tmpDir.listFiles();
+ for (int i = 0; i < files.length; i++)
+ {
+ files[i].delete();
+ }
+
+ if (files.length > 0)
+ {
+ log.log("Previous deployments removed");
+ }
+ } else
+ {
+ log.log("Using the systems temporary directory");
+ }
+ }
+
+ /**
+ * Implements the template method in superclass. This method stops all the
+ * applications in this server.
+ */
+ public void stopService()
+ {
+ Iterator apps = deployments.values().iterator();
+ while (apps.hasNext())
+ {
+ Application app = (Application)apps.next();
+ app.stop();
+ }
+ }
+
+ /**
+ * Implements the template method in superclass. This method destroys all
+ * the applications in this server and clears the deployments list.
+ */
+ public void destroyService()
+ {
+ Iterator apps = deployments.values().iterator();
+ while (apps.hasNext())
+ {
+ Application app = (Application)apps.next();
+ app.destroy();
+ }
+
+ deployments.clear();
+ }
+
+ /**
+ * Enables/disables the application bean verification upon deployment.
+ *
+ * @param verify true to enable; false to disable
+ */
+ public void setVerifyDeployments(boolean verify)
+ {
+ verifyDeployments = verify;
+ }
+
+ /**
+ * Returns the state of bean verifier (on/off)
+ *
+ * @param true if enabled; false otherwise
+ */
+ 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
+ */
+ public void deploy(String url)
+ throws MalformedURLException, DeploymentException
+ {
+ // 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
+ */
+ public void undeploy(String url)
+ throws MalformedURLException, DeploymentException
+ {
+ // 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
+ * whose structure resembles that of an EJB-JAR. <p>
+ *
+ * The latter is useful for development since no packaging is required.
+ *
+ * @param url URL where EJB deployment information is contained
+ *
+ * @exception DeploymentException
+ */
+ public synchronized void deploy(URL url)
+ throws DeploymentException
+ {
+ // Create application
+ Application app = new Application();
+
+ try
+ {
+ Log.setLog(log);
+
+ // Check if already deployed -> undeploy first, this is re-deploy
+ if (deployments.containsKey(url))
+ undeploy(url);
+
+
+ app.setURL(url);
+
+ log.log("Deploying:"+url);
+
+ // URL's to put in classloader
+ URL[] urls;
+
+ // save the name of the jar before copying -> undeploy with the same name
+ URL origUrl = url;
+
+ // copy the jar file to prevent locking - redeploy failure
+ if (url.getProtocol().startsWith("file") && !url.getFile().endsWith("/"))
+ {
+ System.out.println(tmpDir);
+
+ File jarFile = new File(url.getFile());
+ File tmp;
+ if (tmpDir == null)
+ {
+ tmp = File.createTempFile("tmpejbjar",".jar");
+ } else
+ {
+ tmp = File.createTempFile("tmpejbjar",".jar", tmpDir);
+ }
+ tmp.deleteOnExit();
+ FileInputStream fin = new FileInputStream(jarFile);
+ byte[] bytes = new byte[(int)jarFile.length()];
+ fin.read(bytes);
+ FileOutputStream fout = new FileOutputStream(tmp);
+ fout.write(bytes);
+ fin.close();
+ fout.close();
+
+ // Get the URL's from the deployments Class-Path: manifest file.
+ // These should be added to the classloader
+ JarFile jar = new JarFile(tmp);
+ Manifest mf = jar.getManifest();
+ ArrayList urlList = new ArrayList();
+ if (mf != null)
+ {
+ Attributes attributes = mf.getMainAttributes();
+ String classPath = attributes.getValue(Attributes.Name.CLASS_PATH);
+ if (classPath != null)
+ {
+ StringTokenizer classPathTokens = new StringTokenizer(classPath,
" ");
+ while (classPathTokens.hasMoreTokens())
+ {
+ String classPathEntry = classPathTokens.nextToken();
+ try
+ {
+ urlList.add(new URL(url, classPathEntry));
+ log.log("Added "+ classPathEntry);
+ } catch (MalformedURLException e)
+ {
+ log.error("Could not add " + classPathEntry);
+ }
+ }
+ }
+ }
+
+ // Add URL to tmp file
+ url = tmp.toURL();
+ urlList.add(url);
+
+ urls = new URL[urlList.size()];
+ urls = (URL[])urlList.toArray(urls);
+ } else
+ {
+ urls = new URL[] { url };
+ }
+
+ // Create the ClassLoader for this application
+ // TODO : the ClassLoader should come from the JMX manager if we want to
be able to share it (tomcat)
+ ClassLoader cl = new URLClassLoader(urls,
Thread.currentThread().getContextClassLoader());
+
+ // Create a file loader with which to load the files
+ XmlFileLoader efm = new XmlFileLoader();
+
+ // the file manager gets its file from the classloader
+ efm.setClassLoader(cl);
+
+ // Load XML
+ ApplicationMetaData metaData = efm.load();
+
+
+
+ // Check validity
+ Log.setLog(new Log("Verifier"));
+
+ // wrapping this into a try - catch block to prevent errors in
+ // verifier from stopping the deployment
+ try {
+
+ if (verifyDeployments)
+ {
+ BeanVerifier verifier = new BeanVerifier();
+
+ verifier.addVerificationListener(new VerificationListener()
+ {
+ public void beanChecked(VerificationEvent event)
+ {
+ Logger.log(event.getName() + ": " + event.getMessage());
+ }
+
+ public void specViolation(VerificationEvent event)
+ {
+ Logger.log(event.getName() + ": " + event.getMessage());
+ }
+ });
+
+
+ Logger.log("Verifying " + url);
+
+ verifier.verify(url, metaData);
+ }
+ }
+ catch (Throwable t) {
+ Logger.exception(t);
+ }
+
+ // unset verifier log
+ Log.unsetLog();
+
+ // Get list of beans for which we will create containers
+ Iterator beans = metaData.getEnterpriseBeans();
+
+ // Deploy beans
+ Context ctx = new InitialContext();
+ while(beans.hasNext())
+ {
+ BeanMetaData bean = (BeanMetaData)beans.next();
+
+ log.log("Deploying "+bean.getEjbName());
+
+ if (bean.isSession()) // Is session?
+ {
+ if (((SessionMetaData)bean).isStateless()) // Is stateless?
+ {
+ // Create container
+ StatelessSessionContainer container = new
StatelessSessionContainer();
+
+ // Create classloader for this container
+ container.setClassLoader(new BeanClassLoader(cl));
+
+ // Set metadata
+ container.setBeanMetaData(bean);
+
+ // get the container configuration for this bean
+ // a default configuration is now always provided
+ ConfigurationMetaData conf = bean.getContainerConfiguration();
+
+ // Set transaction manager
+ container.setTransactionManager((TransactionManager)new
InitialContext().lookup("TransactionManager"));
+
+ // Set security manager (should be chosen based on container
config)
+ container.setSecurityManager((EJBSecurityManager)new
InitialContext().lookup("EJBSecurityManager"));
+
+ // Set realm mapping (should be chosen based on container
config)
+ container.setRealmMapping( (RealmMapping)new
InitialContext().lookup("SimpleRealmMapping"));
+
+ // Set container invoker
+ ContainerInvoker ci =
(ContainerInvoker)cl.loadClass(conf.getContainerInvoker()).newInstance();
+ if (ci instanceof XmlLoadable) {
+ // the container invoker can load its configuration from the
jboss.xml element
+ ((XmlLoadable)ci).importXml(conf.getContainerInvokerConf());
+ }
+ container.setContainerInvoker(ci);
+
+ // Set instance pool
+ InstancePool ip =
(InstancePool)cl.loadClass(conf.getInstancePool()).newInstance();
+ if (ip instanceof XmlLoadable) {
+ ((XmlLoadable)ip).importXml(conf.getContainerPoolConf());
+ }
+ container.setInstancePool(ip);
+
+ // Create interceptors
+
+ container.addInterceptor(new LogInterceptor());
+ container.addInterceptor(new SecurityInterceptor());
+
+ if (((SessionMetaData)bean).isContainerManagedTx()) {
+ // CMT
+ container.addInterceptor(new TxInterceptorCMT());
+ container.addInterceptor(new
StatelessSessionInstanceInterceptor());
+
+ } else {
+ // BMT
+ container.addInterceptor(new StatelessSessionInstanceInterceptor());
+ container.addInterceptor(new TxInterceptorBMT());
+ }
+
+ // Finally we add the last interceptor from the container
+ container.addInterceptor(container.createContainerInterceptor());
+
+ // Add container to application
+ app.addContainer(container);
+ } else // Stateful
+ {
+ // Create container
+ StatefulSessionContainer container = new
StatefulSessionContainer();
+
+ // Create classloader for this container
+ container.setClassLoader(new BeanClassLoader(cl));
+
+ // Set metadata
+ container.setBeanMetaData(bean);
+
+ // Set transaction manager
+ container.setTransactionManager((TransactionManager)new
InitialContext().lookup("TransactionManager"));
+
+ // Set security manager (should be chosen based on container
config)
+ container.setSecurityManager((EJBSecurityManager)new
InitialContext().lookup("EJBSecurityManager"));
+
+ // Set realm mapping (should be chosen based on container
config)
+ container.setRealmMapping( (RealmMapping)new
InitialContext().lookup("SimpleRealmMapping"));
+
+ // Get container configuration
+ ConfigurationMetaData conf = bean.getContainerConfiguration();
+
+ // Set container invoker
+ ContainerInvoker ci =
(ContainerInvoker)cl.loadClass(conf.getContainerInvoker()).newInstance();
+ if (ci instanceof XmlLoadable) {
+ // the container invoker can load its configuration from the
jboss.xml element
+ ((XmlLoadable)ci).importXml(conf.getContainerInvokerConf());
+ }
+ container.setContainerInvoker(ci);
+
+ // Set instance cache
+ InstanceCache ic =
(InstanceCache)cl.loadClass(conf.getInstanceCache()).newInstance();
+ if (ic instanceof XmlLoadable) {
+ ((XmlLoadable)ic).importXml(conf.getContainerCacheConf());
+ }
+ container.setInstanceCache(ic);
+
+ // No real instance pool, use the shadow class
+ container.setInstancePool(new StatefulSessionInstancePool());
+
+ // Set persistence manager
+
container.setPersistenceManager((StatefulSessionPersistenceManager)cl.loadClass(conf.getPersistenceManager()).newInstance());
+
+ // Create interceptors
+ container.addInterceptor(new LogInterceptor());
+
+ if (((SessionMetaData)bean).isContainerManagedTx()) {
+ // CMT
+ container.addInterceptor(new TxInterceptorCMT());
+ container.addInterceptor(new
StatefulSessionInstanceInterceptor());
+
+ } else {
+ // BMT : the tx interceptor needs the context from the instance
interceptor
+ container.addInterceptor(new StatefulSessionInstanceInterceptor());
+ container.addInterceptor(new TxInterceptorBMT());
+ }
+
+ container.addInterceptor(new SecurityInterceptor());
+
+ container.addInterceptor(container.createContainerInterceptor());
+
+ // Add container to application
+ app.addContainer(container);
+ }
+ } else // Entity
+ {
+ // Create container
+ EntityContainer container = new EntityContainer();
+
+ // Create classloader for this container
+ container.setClassLoader(new BeanClassLoader(cl));
+
+ // Set metadata
+ container.setBeanMetaData(bean);
+
+ // Set transaction manager
+ container.setTransactionManager((TransactionManager)new
InitialContext().lookup("TransactionManager"));
+
+ // Set security manager (should be chosen based on container config)
+ container.setSecurityManager((EJBSecurityManager)new
InitialContext().lookup("EJBSecurityManager"));
+
+ // Set realm mapping (should be chosen based on container config)
+ container.setRealmMapping( (RealmMapping)new
InitialContext().lookup("SimpleRealmMapping"));
+
+ // Get container configuration
+ ConfigurationMetaData conf = bean.getContainerConfiguration();
+
+ // Set container invoker
+ ContainerInvoker ci =
(ContainerInvoker)cl.loadClass(conf.getContainerInvoker()).newInstance();
+ if (ci instanceof XmlLoadable) {
+ // the container invoker can load its configuration from the
jboss.xml element
+ ((XmlLoadable)ci).importXml(conf.getContainerInvokerConf());
+ }
+ container.setContainerInvoker(ci);
+
+ // Set instance cache
+ InstanceCache ic =
(InstanceCache)cl.loadClass(conf.getInstanceCache()).newInstance();
+ if (ic instanceof XmlLoadable) {
+ ((XmlLoadable)ic).importXml(conf.getContainerCacheConf());
+ }
+ container.setInstanceCache(ic);
+
+ // Set instance pool
+ InstancePool ip =
(InstancePool)cl.loadClass(conf.getInstancePool()).newInstance();
+ if (ip instanceof XmlLoadable) {
+ ((XmlLoadable)ip).importXml(conf.getContainerPoolConf());
+ }
+ container.setInstancePool(ip);
+
+ // Set persistence manager
+ if (((EntityMetaData) bean).isBMP()) {
+
+ //Should be BMPPersistenceManager
+
container.setPersistenceManager((EntityPersistenceManager)cl.loadClass(conf.getPersistenceManager()).newInstance());
+ }
+ else {
+
+ // CMP takes a manager and a store
+ org.jboss.ejb.plugins.CMPPersistenceManager persistenceManager =
new org.jboss.ejb.plugins.CMPPersistenceManager();
+
+ //Load the store from configuration
+
persistenceManager.setPersistenceStore((EntityPersistenceStore)cl.loadClass(conf.getPersistenceManager()).newInstance());
+
+ // Set the manager on the container
+ container.setPersistenceManager(persistenceManager);
+ }
+
+ // Create interceptors
+ container.addInterceptor(new LogInterceptor());
+ container.addInterceptor(new SecurityInterceptor());
+
+ // entity beans are always CMT
+ container.addInterceptor(new TxInterceptorCMT());
+
+ 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. Use the original name in the hashtable
+ deployments.put(origUrl, app);
+ }
+ catch (Throwable e)
+ {
+ if (e instanceof NullPointerException) {
+ // Avoids useless 'null' messages on a server trace.
+ // Let's be honest and spam them with a stack trace.
+ // NPE should be considered an internal server error anyways.
+ Logger.exception(e);
+ }
+
+ Logger.exception(e);
+ //Logger.debug(e.getMessage());
+
+ app.stop();
+ app.destroy();
+
+ throw new DeploymentException("Could not deploy "+url.toString());
+ } finally
+ {
+ Log.unsetLog();
+ }
+ }
+
+
+ /**
+ * Remove previously deployed EJBs.
+ *
+ * @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 -----------------------------------------------------
+}
1.10 +302 -302 jboss/src/main/org/jboss/ejb/EnterpriseContext.java
Index: EnterpriseContext.java
===================================================================
RCS file: /products/cvs/ejboss/jboss/src/main/org/jboss/ejb/EnterpriseContext.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- EnterpriseContext.java 2000/09/26 19:23:14 1.9
+++ EnterpriseContext.java 2000/09/26 20:18:49 1.10
@@ -1,302 +1,302 @@
-
-/*
- * jBoss, the OpenSource EJB server
- *
- * Distributable under GPL license.
- * See terms of license at gnu.org.
- */
-package org.jboss.ejb;
-
-import java.rmi.RemoteException;
-import java.security.Identity;
-import java.security.Principal;
-import java.util.Properties;
-
-import javax.ejb.EJBHome;
-import javax.ejb.EJBContext;
-import javax.ejb.EJBException;
-import javax.transaction.Status;
-import javax.transaction.Transaction;
-import javax.transaction.UserTransaction;
-import javax.transaction.Synchronization;
-import javax.transaction.NotSupportedException;
-import javax.transaction.SystemException;
-import javax.transaction.RollbackException;
-import javax.transaction.HeuristicMixedException;
-import javax.transaction.HeuristicRollbackException;
-
-import org.jboss.logging.Logger;
-
-/**
- * The EnterpriseContext is used to associate EJB instances with metadata about
it.
- *
- * @see StatefulSessionEnterpriseContext
- * @see StatelessSessionEnterpriseContext
- * @see EntityEnterpriseContext
- * @author Rickard �berg ([EMAIL PROTECTED])
- * @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>
- * @author <a href="mailto:[EMAIL PROTECTED]">Sebastien Alborini</a>
- * @version $Revision: 1.9 $
- */
-public abstract class EnterpriseContext
-{
- // Constants -----------------------------------------------------
-
- // Attributes ----------------------------------------------------
- // The EJB instanfce
- Object instance;
-
- // The container using this context
- Container con;
-
- // Set to the synchronization currently associated with this context. May be
null
- Synchronization synch;
-
- // The transaction associated with the instance
- Transaction transaction;
-
- // The principal associated with the call
- Principal principal;
-
- // Only StatelessSession beans have no Id, stateful and entity do
- Object id;
-
- // The instance is being used. This locks it's state
- int locked = 0;
-
- // Static --------------------------------------------------------
-
- // Constructors --------------------------------------------------
- public EnterpriseContext(Object instance, Container con)
- {
- this.instance = instance;
- this.con = con;
- }
-
- // Public --------------------------------------------------------
- public Object getInstance()
- {
- return instance;
- }
-
- public abstract void discard()
- throws RemoteException;
-
- public void setId(Object id) {
- this.id = id;
- }
-
- public Object getId() {
- return id;
- }
-
- public void setTransaction(Transaction transaction) {
-
- Logger.log("EnterpriseContext.setTransaction "+((transaction == null) ?
"null" : Integer.toString(transaction.hashCode())));
- this.transaction = transaction;
- }
-
- public Transaction getTransaction() {
- return transaction;
- }
-
- public void setPrincipal(Principal principal) {
-
- this.principal = principal;
- }
-
- public synchronized void lock()
- {
- locked ++;
-
- //new Exception().printStackTrace();
-
- Logger.log("EnterpriseContext.lock() "+hashCode()+" "+locked);
- }
-
- public void unlock() {
-
- // release a lock
- locked --;
-
- if (locked <0) new Exception().printStackTrace();
-
- Logger.log("EnterpriseContext.unlock() "+hashCode()+" "+locked);
- }
-
- public boolean isLocked() {
-
- //DEBUG Logger.log("EnterpriseContext.isLocked() at "+locked);
- Logger.log("EnterpriseContext.isLocked() at "+locked);
-
- return locked != 0;
- }
-
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
- // Private -------------------------------------------------------
-
- // Inner classes -------------------------------------------------
- protected class EJBContextImpl
- implements EJBContext
- {
- /**
- *
- *
- * @deprecated
- */
- public Identity getCallerIdentity()
- {
- throw new EJBException("Deprecated");
- }
-
- public Principal getCallerPrincipal()
- {
- return principal;
- }
-
- public EJBHome getEJBHome()
- {
- if (con instanceof EntityContainer)
- {
- return ((EntityContainer)con).getContainerInvoker().getEJBHome();
- }
- else if (con instanceof StatelessSessionContainer)
- {
- return
((StatelessSessionContainer)con).getContainerInvoker().getEJBHome();
- }
- else if (con instanceof StatefulSessionContainer)
- {
- return
((StatefulSessionContainer)con).getContainerInvoker().getEJBHome();
- }
- {
- // Should never get here
- throw new EJBException("No EJBHome available (BUG!)");
- }
- }
-
- /**
- *
- *
- * @deprecated
- */
- public Properties getEnvironment()
- {
- throw new EJBException("Deprecated");
- }
-
- public boolean getRollbackOnly()
- {
- try
- {
- return con.getTransactionManager().getStatus() ==
Status.STATUS_MARKED_ROLLBACK;
- } catch (SystemException e)
- {
- Logger.debug(e);
- return true;
- }
- }
-
- public void setRollbackOnly()
- {
- try
- {
- con.getTransactionManager().setRollbackOnly();
- } catch (SystemException e)
- {
- Logger.debug(e);
- }
- }
-
- /**
- *
- *
- * @deprecated
- */
- public boolean isCallerInRole(Identity id)
- {
- throw new EJBException("Deprecated");
- }
-
- // TODO - how to handle this best?
- public boolean isCallerInRole(String id)
- {
- return false;
- }
-
- // TODO - how to handle this best?
- public UserTransaction getUserTransaction()
- {
- return new UserTransactionImpl();
- }
- }
-
- // Inner classes -------------------------------------------------
-
-
- // SA MF FIXME: the usertransaction is only used for session beans with BMT.
- // This does not belong here (getUserTransaction is properly implemented in
subclasses)
-
- class UserTransactionImpl
- implements UserTransaction
- {
- public void begin()
- throws NotSupportedException,SystemException
- {
- con.getTransactionManager().begin();
-
- // keep track of the transaction in enterprise context for BMT
- setTransaction(con.getTransactionManager().getTransaction());
-
-
- // DEBUG Logger.debug("UserTransactionImpl.begin " + transaction.hashCode()
+ " in UserTransactionImpl " + this.hashCode());
- Logger.debug("UserTransactionImpl.begin " + transaction.hashCode() + " in
UserTransactionImpl " + this.hashCode());
-
- }
-
- public void commit()
- throws RollbackException,
- HeuristicMixedException,
- HeuristicRollbackException,
- java.lang.SecurityException,
- java.lang.IllegalStateException,
- SystemException
- {
- // DEBUG Logger.debug("UserTransactionImpl.commit " +
transaction.hashCode() + " in UserTransactionImpl " + this.hashCode());
- Logger.debug("UserTransactionImpl.commit " + transaction.hashCode() + " in
UserTransactionImpl " + this.hashCode());
-
- con.getTransactionManager().commit();
- }
-
- public void rollback()
- throws java.lang.IllegalStateException,
- java.lang.SecurityException,
- SystemException
- {
- // DEBUG Logger.debug("UserTransactionImpl.rollback " +
transaction.hashCode() + " in UserTransactionImpl " + this.hashCode());
- Logger.debug("UserTransactionImpl.rollback " + transaction.hashCode() + "
in UserTransactionImpl " + this.hashCode());
-
- con.getTransactionManager().rollback();
- }
-
- public void setRollbackOnly()
- throws java.lang.IllegalStateException, SystemException
- {
- con.getTransactionManager().setRollbackOnly();
- }
-
- public int getStatus()
- throws SystemException
- {
- return con.getTransactionManager().getStatus();
- }
-
- public void setTransactionTimeout(int seconds)
- throws SystemException
- {
- con.getTransactionManager().setTransactionTimeout(seconds);
- }
- }
-}
+
+/*
+ * jBoss, the OpenSource EJB server
+ *
+ * Distributable under GPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.ejb;
+
+import java.rmi.RemoteException;
+import java.security.Identity;
+import java.security.Principal;
+import java.util.Properties;
+
+import javax.ejb.EJBHome;
+import javax.ejb.EJBContext;
+import javax.ejb.EJBException;
+import javax.transaction.Status;
+import javax.transaction.Transaction;
+import javax.transaction.UserTransaction;
+import javax.transaction.Synchronization;
+import javax.transaction.NotSupportedException;
+import javax.transaction.SystemException;
+import javax.transaction.RollbackException;
+import javax.transaction.HeuristicMixedException;
+import javax.transaction.HeuristicRollbackException;
+
+import org.jboss.logging.Logger;
+
+/**
+ * The EnterpriseContext is used to associate EJB instances with metadata about
it.
+ *
+ * @see StatefulSessionEnterpriseContext
+ * @see StatelessSessionEnterpriseContext
+ * @see EntityEnterpriseContext
+ * @author Rickard �berg ([EMAIL PROTECTED])
+ * @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>
+ * @author <a href="mailto:[EMAIL PROTECTED]">Sebastien Alborini</a>
+ * @version $Revision: 1.10 $
+ */
+public abstract class EnterpriseContext
+{
+ // Constants -----------------------------------------------------
+
+ // Attributes ----------------------------------------------------
+ // The EJB instanfce
+ Object instance;
+
+ // The container using this context
+ Container con;
+
+ // Set to the synchronization currently associated with this context. May be
null
+ Synchronization synch;
+
+ // The transaction associated with the instance
+ Transaction transaction;
+
+ // The principal associated with the call
+ Principal principal;
+
+ // Only StatelessSession beans have no Id, stateful and entity do
+ Object id;
+
+ // The instance is being used. This locks it's state
+ int locked = 0;
+
+ // Static --------------------------------------------------------
+
+ // Constructors --------------------------------------------------
+ public EnterpriseContext(Object instance, Container con)
+ {
+ this.instance = instance;
+ this.con = con;
+ }
+
+ // Public --------------------------------------------------------
+ public Object getInstance()
+ {
+ return instance;
+ }
+
+ public abstract void discard()
+ throws RemoteException;
+
+ public void setId(Object id) {
+ this.id = id;
+ }
+
+ public Object getId() {
+ return id;
+ }
+
+ public void setTransaction(Transaction transaction) {
+
+ Logger.log("EnterpriseContext.setTransaction "+((transaction == null) ?
"null" : Integer.toString(transaction.hashCode())));
+ this.transaction = transaction;
+ }
+
+ public Transaction getTransaction() {
+ return transaction;
+ }
+
+ public void setPrincipal(Principal principal) {
+
+ this.principal = principal;
+ }
+
+ public synchronized void lock()
+ {
+ locked ++;
+
+ //new Exception().printStackTrace();
+
+ Logger.log("EnterpriseContext.lock() "+hashCode()+" "+locked);
+ }
+
+ public void unlock() {
+
+ // release a lock
+ locked --;
+
+ if (locked <0) new Exception().printStackTrace();
+
+ Logger.log("EnterpriseContext.unlock() "+hashCode()+" "+locked);
+ }
+
+ public boolean isLocked() {
+
+ //DEBUG Logger.log("EnterpriseContext.isLocked() at "+locked);
+ Logger.log("EnterpriseContext.isLocked() at "+locked);
+
+ return locked != 0;
+ }
+
+ // Package protected ---------------------------------------------
+
+ // Protected -----------------------------------------------------
+
+ // Private -------------------------------------------------------
+
+ // Inner classes -------------------------------------------------
+ protected class EJBContextImpl
+ implements EJBContext
+ {
+ /**
+ *
+ *
+ * @deprecated
+ */
+ public Identity getCallerIdentity()
+ {
+ throw new EJBException("Deprecated");
+ }
+
+ public Principal getCallerPrincipal()
+ {
+ return principal;
+ }
+
+ public EJBHome getEJBHome()
+ {
+ if (con instanceof EntityContainer)
+ {
+ return ((EntityContainer)con).getContainerInvoker().getEJBHome();
+ }
+ else if (con instanceof StatelessSessionContainer)
+ {
+ return
((StatelessSessionContainer)con).getContainerInvoker().getEJBHome();
+ }
+ else if (con instanceof StatefulSessionContainer)
+ {
+ return
((StatefulSessionContainer)con).getContainerInvoker().getEJBHome();
+ }
+ {
+ // Should never get here
+ throw new EJBException("No EJBHome available (BUG!)");
+ }
+ }
+
+ /**
+ *
+ *
+ * @deprecated
+ */
+ public Properties getEnvironment()
+ {
+ throw new EJBException("Deprecated");
+ }
+
+ public boolean getRollbackOnly()
+ {
+ try
+ {
+ return con.getTransactionManager().getStatus() ==
Status.STATUS_MARKED_ROLLBACK;
+ } catch (SystemException e)
+ {
+ Logger.debug(e);
+ return true;
+ }
+ }
+
+ public void setRollbackOnly()
+ {
+ try
+ {
+ con.getTransactionManager().setRollbackOnly();
+ } catch (SystemException e)
+ {
+ Logger.debug(e);
+ }
+ }
+
+ /**
+ *
+ *
+ * @deprecated
+ */
+ public boolean isCallerInRole(Identity id)
+ {
+ throw new EJBException("Deprecated");
+ }
+
+ // TODO - how to handle this best?
+ public boolean isCallerInRole(String id)
+ {
+ return false;
+ }
+
+ // TODO - how to handle this best?
+ public UserTransaction getUserTransaction()
+ {
+ return new UserTransactionImpl();
+ }
+ }
+
+ // Inner classes -------------------------------------------------
+
+
+ // SA MF FIXME: the usertransaction is only used for session beans with BMT.
+ // This does not belong here (getUserTransaction is properly implemented in
subclasses)
+
+ class UserTransactionImpl
+ implements UserTransaction
+ {
+ public void begin()
+ throws NotSupportedException,SystemException
+ {
+ con.getTransactionManager().begin();
+
+ // keep track of the transaction in enterprise context for BMT
+ setTransaction(con.getTransactionManager().getTransaction());
+
+
+ // DEBUG Logger.debug("UserTransactionImpl.begin " + transaction.hashCode()
+ " in UserTransactionImpl " + this.hashCode());
+ Logger.debug("UserTransactionImpl.begin " + transaction.hashCode() + " in
UserTransactionImpl " + this.hashCode());
+
+ }
+
+ public void commit()
+ throws RollbackException,
+ HeuristicMixedException,
+ HeuristicRollbackException,
+ java.lang.SecurityException,
+ java.lang.IllegalStateException,
+ SystemException
+ {
+ // DEBUG Logger.debug("UserTransactionImpl.commit " +
transaction.hashCode() + " in UserTransactionImpl " + this.hashCode());
+ Logger.debug("UserTransactionImpl.commit " + transaction.hashCode() + " in
UserTransactionImpl " + this.hashCode());
+
+ con.getTransactionManager().commit();
+ }
+
+ public void rollback()
+ throws java.lang.IllegalStateException,
+ java.lang.SecurityException,
+ SystemException
+ {
+ // DEBUG Logger.debug("UserTransactionImpl.rollback " +
transaction.hashCode() + " in UserTransactionImpl " + this.hashCode());
+ Logger.debug("UserTransactionImpl.rollback " + transaction.hashCode() + "
in UserTransactionImpl " + this.hashCode());
+
+ con.getTransactionManager().rollback();
+ }
+
+ public void setRollbackOnly()
+ throws java.lang.IllegalStateException, SystemException
+ {
+ con.getTransactionManager().setRollbackOnly();
+ }
+
+ public int getStatus()
+ throws SystemException
+ {
+ return con.getTransactionManager().getStatus();
+ }
+
+ public void setTransactionTimeout(int seconds)
+ throws SystemException
+ {
+ con.getTransactionManager().setTransactionTimeout(seconds);
+ }
+ }
+}
1.26 +647 -647 jboss/src/main/org/jboss/ejb/EntityContainer.java
Index: EntityContainer.java
===================================================================
RCS file: /products/cvs/ejboss/jboss/src/main/org/jboss/ejb/EntityContainer.java,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -r1.25 -r1.26
--- EntityContainer.java 2000/09/26 18:20:59 1.25
+++ EntityContainer.java 2000/09/26 20:18:49 1.26
@@ -1,647 +1,647 @@
-/*
-* jBoss, the OpenSource EJB server
-*
-* Distributable under GPL license.
-* See terms of license at gnu.org.
-*/
-package org.jboss.ejb;
-
-import java.lang.reflect.Method;
-import java.lang.reflect.InvocationTargetException;
-import java.security.Principal;
-import java.util.Map;
-import java.util.HashMap;
-import java.util.Enumeration;
-import java.util.Collection;
-import java.util.ArrayList;
-
-import javax.ejb.Handle;
-import javax.ejb.HomeHandle;
-import javax.ejb.EJBObject;
-import javax.ejb.EJBHome;
-import javax.ejb.EJBMetaData;
-import javax.ejb.CreateException;
-import javax.ejb.FinderException;
-import javax.ejb.RemoveException;
-
-import org.jboss.logging.Logger;
-import org.jboss.util.SerializableEnumeration;
-
-/**
-* This is a Container for EntityBeans (both BMP and CMP).
-*
-* @see Container
-* @see EntityEnterpriseContext
-* @author Rickard �berg ([EMAIL PROTECTED])
-* @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>
-* @author <a href="mailto:[EMAIL PROTECTED]">Sebastien Alborini</a>
-* @version $Revision: 1.25 $
-*/
-public class EntityContainer
-extends Container
-implements ContainerInvokerContainer, InstancePoolContainer
-{
- // Constants -----------------------------------------------------
-
- // Attributes ----------------------------------------------------
-
- // These are the mappings between the home interface methods and the container
methods
- protected Map homeMapping;
-
- // These are the mappings between the remote interface methods and the bean
methods
- protected Map beanMapping;
-
- // This is the container invoker for this container
- protected ContainerInvoker containerInvoker;
-
- // This is the persistence manager for this container
- protected EntityPersistenceManager persistenceManager;
-
- // This is the instance cache for this container
- protected InstanceCache instanceCache;
-
- // This is the instancepool that is to be used
- protected InstancePool instancePool;
-
- // This is the first interceptor in the chain. The last interceptor must be
provided by the container itself
- protected Interceptor interceptor;
-
- // Public --------------------------------------------------------
- public void setContainerInvoker(ContainerInvoker ci)
- {
- if (ci == null)
- throw new IllegalArgumentException("Null invoker");
-
- this.containerInvoker = ci;
- ci.setContainer(this);
- }
-
- public ContainerInvoker getContainerInvoker()
- {
- return containerInvoker;
- }
-
- public void setInstancePool(InstancePool ip)
- {
- if (ip == null)
- throw new IllegalArgumentException("Null pool");
-
- this.instancePool = ip;
- ip.setContainer(this);
- }
-
- public InstancePool getInstancePool()
- {
- return instancePool;
- }
-
- public void setInstanceCache(InstanceCache ic)
- {
- if (ic == null)
- throw new IllegalArgumentException("Null cache");
-
- this.instanceCache = ic;
- ic.setContainer(this);
- }
-
- public InstanceCache getInstanceCache()
- {
- return instanceCache;
- }
-
- public EntityPersistenceManager getPersistenceManager()
- {
- return persistenceManager;
- }
-
- public void setPersistenceManager(EntityPersistenceManager pm)
- {
- if (pm == null)
- throw new IllegalArgumentException("Null persistence manager");
-
- persistenceManager = pm;
- pm.setContainer(this);
- }
-
- public void addInterceptor(Interceptor in)
- {
- if (interceptor == null)
- {
- interceptor = in;
- } else
- {
-
- Interceptor current = interceptor;
- while ( current.getNext() != null)
- {
- current = current.getNext();
- }
-
- current.setNext(in);
- }
- }
-
- public Interceptor getInterceptor()
- {
- return interceptor;
- }
-
- public Class getHomeClass()
- {
- return homeInterface;
- }
-
- public Class getRemoteClass()
- {
- return remoteInterface;
- }
-
- // Container implementation --------------------------------------
- public void init()
- throws Exception
- {
- // Associate thread with classloader
- ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
- Thread.currentThread().setContextClassLoader(getClassLoader());
-
- // Acquire classes from CL
- homeInterface = classLoader.loadClass(metaData.getHome());
- remoteInterface = classLoader.loadClass(metaData.getRemote());
-
- // Call default init
- super.init();
-
- // Map the bean methods
- setupBeanMapping();
-
- // Map the home methods
- setupHomeMapping();
-
- // Initialize pool
- instancePool.init();
-
- // Init container invoker
- containerInvoker.init();
-
- // Init instance cache
- instanceCache.init();
-
- // Init persistence
- persistenceManager.init();
-
- // Initialize the interceptor by calling the chain
- Interceptor in = interceptor;
- while (in != null)
- {
- in.setContainer(this);
- in.init();
- in = in.getNext();
- }
-
- // Reset classloader
- Thread.currentThread().setContextClassLoader(oldCl);
- }
-
- public void start()
- throws Exception
- {
- // Associate thread with classloader
- ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
- Thread.currentThread().setContextClassLoader(getClassLoader());
-
- // Call default start
- super.start();
-
- // Start container invoker
- containerInvoker.start();
-
- // Start instance cache
- instanceCache.start();
-
- // Start persistence
- persistenceManager.start();
-
- // Start the instance pool
- instancePool.start();
-
- // Start all interceptors in the chain
- Interceptor in = interceptor;
- while (in != null)
- {
- in.start();
- in = in.getNext();
- }
-
- // Reset classloader
- Thread.currentThread().setContextClassLoader(oldCl);
- }
-
- public void stop()
- {
- // Associate thread with classloader
- ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
- Thread.currentThread().setContextClassLoader(getClassLoader());
-
- // Call default stop
- super.stop();
-
- // Stop container invoker
- containerInvoker.stop();
-
- // Stop instance cache
- instanceCache.stop();
-
- // Stop persistence
- persistenceManager.stop();
-
- // Stop the instance pool
- instancePool.stop();
-
- // Stop all interceptors in the chain
- Interceptor in = interceptor;
- while (in != null)
- {
- in.stop();
- in = in.getNext();
- }
-
- // Reset classloader
- Thread.currentThread().setContextClassLoader(oldCl);
- }
-
- public void destroy()
- {
- // Associate thread with classloader
- ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
- Thread.currentThread().setContextClassLoader(getClassLoader());
-
- // Call default destroy
- super.destroy();
-
- // Destroy container invoker
- containerInvoker.destroy();
-
- // Destroy instance cache
- instanceCache.destroy();
-
- // Destroy persistence
- persistenceManager.destroy();
-
- // Destroy the pool
- instancePool.destroy();
-
- // Destroy all the interceptors in the chain
- Interceptor in = interceptor;
- while (in != null)
- {
- in.destroy();
- in = in.getNext();
- }
-
- // Reset classloader
- Thread.currentThread().setContextClassLoader(oldCl);
- }
-
- public Object invokeHome(MethodInvocation mi)
- throws Exception
- {
-
- Logger.log("invokeHome");
- try { return getInterceptor().invokeHome(mi); }
- catch (Exception e) {e.printStackTrace(); throw e;}
-
- // return getInterceptor().invokeHome(mi);
-
- }
-
- public Object invoke(MethodInvocation mi)
- throws Exception
- {
- try { return getInterceptor().invoke(mi); }
- catch (Exception e) {e.printStackTrace();throw e;}
-
-
- // Invoke through interceptors
- // return getInterceptor().invoke(mi);
- }
-
- // EJBObject implementation --------------------------------------
- public void remove(MethodInvocation mi)
- throws java.rmi.RemoteException, RemoveException
- {
- // Get the persistence manager to do the dirty work
-
getPersistenceManager().removeEntity((EntityEnterpriseContext)mi.getEnterpriseContext());
-
- // We signify "removed" with a null id
- mi.getEnterpriseContext().setId(null);
- }
-
- /**
- * MF FIXME these are implemented on the client
- */
- public Handle getHandle(MethodInvocation mi)
- throws java.rmi.RemoteException
- {
- // TODO
- throw new Error("Not yet implemented");
- }
-
- public Object getPrimaryKey(MethodInvocation mi)
- throws java.rmi.RemoteException
- {
- // TODO
- throw new Error("Not yet implemented");
- }
-
- public EJBHome getEJBHome(MethodInvocation mi)
- throws java.rmi.RemoteException
- {
- return containerInvoker.getEJBHome();
- }
-
-
- public boolean isIdentical(MethodInvocation mi)
- throws java.rmi.RemoteException
- {
- return
((EJBObject)mi.getArguments()[0]).getPrimaryKey().equals(mi.getEnterpriseContext().getId());
- // TODO - should also check type
- }
-
- /**
- * MF FIXME these are implemented on the client
- */
-
-
- // Home interface implementation ---------------------------------
-
- /*
- * find(MethodInvocation)
- *
- * This methods finds the target instances by delegating to the persistence
manager
- * It then manufactures EJBObject for all the involved instances found
- */
-
- public Object find(MethodInvocation mi)
- throws java.rmi.RemoteException, FinderException
- {
-
- // Multi-finder?
- if (!mi.getMethod().getReturnType().equals(getRemoteClass()))
- {
- // Iterator finder
- Collection c = getPersistenceManager().findEntities(mi.getMethod(),
mi.getArguments(), (EntityEnterpriseContext)mi.getEnterpriseContext());
-
- // Get the EJBObjects with that
- Collection ec = containerInvoker.getEntityCollection(c);
-
- // BMP entity finder methods are allowed to return
java.util.Enumeration.
- // We need a serializable Enumeration, so we can't use
Collections.enumeration()
- try {
- if
(mi.getMethod().getReturnType().equals(Class.forName("java.util.Enumeration"))) {
- return new SerializableEnumeration(ec);
- } else {
- return ec;
- }
- } catch (ClassNotFoundException e) {
- // shouldn't happen
- return ec;
- }
-
- } else
- {
-
- // Single entity finder
- Object id = getPersistenceManager().findEntity(mi.getMethod(),
- mi.getArguments(),
- (EntityEnterpriseContext)mi.getEnterpriseContext());
-
- //create the EJBObject
- return (EJBObject)containerInvoker.getEntityEJBObject(id);
- }
- }
-
- /**
- * createHome(MethodInvocation)
- *
- * This method takes care of the wiring of the "EJBObject" trio (target,
context, proxy)
- * It delegates to the persistence manager.
- *
- */
-
- public EJBObject createHome(MethodInvocation mi)
- throws java.rmi.RemoteException, CreateException
- {
-
- // The persistence manager takes care of the wiring and creating the
EJBObject
- getPersistenceManager().createEntity(mi.getMethod(),mi.getArguments(),
- (EntityEnterpriseContext) mi.getEnterpriseContext());
-
- // The context implicitely carries the EJBObject
- return ((EntityEnterpriseContext)mi.getEnterpriseContext()).getEJBObject();
- }
-
- /**
- * A method for the getEJBObject from the handle
- *
- */
- public EJBObject getEJBObject(MethodInvocation mi)
- throws java.rmi.RemoteException {
-
- // All we need is an EJBObject for this Id;
- return
(EJBObject)containerInvoker.getEntityEJBObject(((EntityInstanceCache)
instanceCache).createCacheKey(mi.getId()));
- }
-
-
-
- // EJBHome implementation ----------------------------------------
-
-
- public void removeHome(MethodInvocation mi)
- throws java.rmi.RemoteException, RemoveException
- {
- throw new Error("Not yet implemented");
- }
-
- public EJBMetaData getEJBMetaDataHome(MethodInvocation mi)
- throws java.rmi.RemoteException
- {
- return getContainerInvoker().getEJBMetaData();
- }
-
- public HomeHandle getHomeHandleHome(MethodInvocation mi)
- throws java.rmi.RemoteException
- {
- // TODO
- throw new Error("Not yet implemented");
- }
-
-
- // Private -------------------------------------------------------
- protected void setupHomeMapping()
- throws DeploymentException
- {
- Map map = new HashMap();
-
- Method[] m = homeInterface.getMethods();
- for (int i = 0; i < m.length; i++)
- {
- try
- {
- // Implemented by container (in both cases)
- if (m[i].getName().startsWith("find"))
- map.put(m[i], this.getClass().getMethod("find", new Class[] {
MethodInvocation.class }));
- else
- map.put(m[i], this.getClass().getMethod(m[i].getName()+"Home",
new Class[] { MethodInvocation.class }));
- } catch (NoSuchMethodException e)
- {
- throw new DeploymentException("Could not find matching method for
"+m[i]);
- }
- }
-
- // Special methods
-
- try {
-
- // Get the One on Handle (getEJBObject), get the class
- Class handleClass = Class.forName("javax.ejb.Handle");
-
- // Get the methods (there is only one)
- Method[] handleMethods = handleClass.getMethods();
-
- //Just to make sure let's iterate
- for (int j=0; j<handleMethods.length ;j++) {
-
- try {
-
- //Get only the one called handle.getEJBObject
- if (handleMethods[j].getName().equals("getEJBObject")) {
-
- //Map it in the home stuff
- map.put(handleMethods[j],
this.getClass().getMethod("getEJBObject", new Class[] {MethodInvocation.class}));
- }
- }
- catch (NoSuchMethodException e) {
- throw new DeploymentException("Couldn't find getEJBObject
method on container");
- }
- }
- }
- catch (Exception e) {
- // DEBUG Logger.exception(e);
- }
-
- // We are done keep the home map
- homeMapping = map;
- }
-
- protected void setupBeanMapping()
- throws DeploymentException
- {
- Map map = new HashMap();
-
- Method[] m = remoteInterface.getMethods();
- for (int i = 0; i < m.length; i++)
- {
- try
- {
- if
(!m[i].getDeclaringClass().getName().equals("javax.ejb.EJBObject"))
- {
- // Implemented by bean
- map.put(m[i], beanClass.getMethod(m[i].getName(),
m[i].getParameterTypes()));
- }
- else
- {
- // Implemented by container
- map.put(m[i], getClass().getMethod(m[i].getName(), new Class[]
{ MethodInvocation.class }));
- }
- } catch (NoSuchMethodException e)
- {
- throw new DeploymentException("Could not find matching method for
"+m[i], e);
- }
- }
-
- beanMapping = map;
-
- }
-
- public Interceptor createContainerInterceptor()
- {
- return new ContainerInterceptor();
- }
-
- // Inner classes -------------------------------------------------
- // This is the last step before invocation - all interceptors are done
- class ContainerInterceptor
- implements Interceptor
- {
- public void setContainer(Container con) {}
-
- public void setNext(Interceptor interceptor) {}
- public Interceptor getNext() { return null; }
-
- public void init() {}
- public void start() {}
- public void stop() {}
- public void destroy() {}
-
- public Object invokeHome(MethodInvocation mi)
- throws Exception
- {
- // Invoke and handle exceptions
- Method m = (Method)homeMapping.get(mi.getMethod());
-
- try
- {
- return m.invoke(EntityContainer.this, new Object[] { mi });
- } catch (InvocationTargetException e)
- {
- Throwable ex = e.getTargetException();
- if (ex instanceof Exception)
- throw (Exception)ex;
- else
- throw (Error)ex;
- }
- }
-
- public Object invoke(MethodInvocation mi)
- throws Exception
- {
- // Get method
- Method m = (Method)beanMapping.get(mi.getMethod());
-
- // Select instance to invoke (container or bean)
- if (m.getDeclaringClass().equals(EntityContainer.class))
- {
- // Invoke and handle exceptions
- try
- {
- return m.invoke(EntityContainer.this, new Object[] { mi });
- } catch (InvocationTargetException e)
- {
- Throwable ex = e.getTargetException();
- if (ex instanceof Exception)
- throw (Exception)ex;
- else
- throw (Error)ex;
- }
- } else
- {
- //wire the transaction on the context, this is how the instance
remember the tx
- if (mi.getEnterpriseContext().getTransaction() == null)
mi.getEnterpriseContext().setTransaction(mi.getTransaction());
-
- // Invoke and handle exceptions
- try
- {
- return m.invoke(mi.getEnterpriseContext().getInstance(),
mi.getArguments());
- } catch (InvocationTargetException e)
- {
- Throwable ex = e.getTargetException();
- if (ex instanceof Exception)
- throw (Exception)ex;
- else
- throw (Error)ex;
- }
- }
- }
- }
-}
-
+/*
+* jBoss, the OpenSource EJB server
+*
+* Distributable under GPL license.
+* See terms of license at gnu.org.
+*/
+package org.jboss.ejb;
+
+import java.lang.reflect.Method;
+import java.lang.reflect.InvocationTargetException;
+import java.security.Principal;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.Enumeration;
+import java.util.Collection;
+import java.util.ArrayList;
+
+import javax.ejb.Handle;
+import javax.ejb.HomeHandle;
+import javax.ejb.EJBObject;
+import javax.ejb.EJBHome;
+import javax.ejb.EJBMetaData;
+import javax.ejb.CreateException;
+import javax.ejb.FinderException;
+import javax.ejb.RemoveException;
+
+import org.jboss.logging.Logger;
+import org.jboss.util.SerializableEnumeration;
+
+/**
+* This is a Container for EntityBeans (both BMP and CMP).
+*
+* @see Container
+* @see EntityEnterpriseContext
+* @author Rickard �berg ([EMAIL PROTECTED])
+* @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>
+* @author <a href="mailto:[EMAIL PROTECTED]">Sebastien Alborini</a>
+* @version $Revision: 1.26 $
+*/
+public class EntityContainer
+extends Container
+implements ContainerInvokerContainer, InstancePoolContainer
+{
+ // Constants -----------------------------------------------------
+
+ // Attributes ----------------------------------------------------
+
+ // These are the mappings between the home interface methods and the container
methods
+ protected Map homeMapping;
+
+ // These are the mappings between the remote interface methods and the bean
methods
+ protected Map beanMapping;
+
+ // This is the container invoker for this container
+ protected ContainerInvoker containerInvoker;
+
+ // This is the persistence manager for this container
+ protected EntityPersistenceManager persistenceManager;
+
+ // This is the instance cache for this container
+ protected InstanceCache instanceCache;
+
+ // This is the instancepool that is to be used
+ protected InstancePool instancePool;
+
+ // This is the first interceptor in the chain. The last interceptor must be
provided by the container itself
+ protected Interceptor interceptor;
+
+ // Public --------------------------------------------------------
+ public void setContainerInvoker(ContainerInvoker ci)
+ {
+ if (ci == null)
+ throw new IllegalArgumentException("Null invoker");
+
+ this.containerInvoker = ci;
+ ci.setContainer(this);
+ }
+
+ public ContainerInvoker getContainerInvoker()
+ {
+ return containerInvoker;
+ }
+
+ public void setInstancePool(InstancePool ip)
+ {
+ if (ip == null)
+ throw new IllegalArgumentException("Null pool");
+
+ this.instancePool = ip;
+ ip.setContainer(this);
+ }
+
+ public InstancePool getInstancePool()
+ {
+ return instancePool;
+ }
+
+ public void setInstanceCache(InstanceCache ic)
+ {
+ if (ic == null)
+ throw new IllegalArgumentException("Null cache");
+
+ this.instanceCache = ic;
+ ic.setContainer(this);
+ }
+
+ public InstanceCache getInstanceCache()
+ {
+ return instanceCache;
+ }
+
+ public EntityPersistenceManager getPersistenceManager()
+ {
+ return persistenceManager;
+ }
+
+ public void setPersistenceManager(EntityPersistenceManager pm)
+ {
+ if (pm == null)
+ throw new IllegalArgumentException("Null persistence manager");
+
+ persistenceManager = pm;
+ pm.setContainer(this);
+ }
+
+ public void addInterceptor(Interceptor in)
+ {
+ if (interceptor == null)
+ {
+ interceptor = in;
+ } else
+ {
+
+ Interceptor current = interceptor;
+ while ( current.getNext() != null)
+ {
+ current = current.getNext();
+ }
+
+ current.setNext(in);
+ }
+ }
+
+ public Interceptor getInterceptor()
+ {
+ return interceptor;
+ }
+
+ public Class getHomeClass()
+ {
+ return homeInterface;
+ }
+
+ public Class getRemoteClass()
+ {
+ return remoteInterface;
+ }
+
+ // Container implementation --------------------------------------
+ public void init()
+ throws Exception
+ {
+ // Associate thread with classloader
+ ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
+ Thread.currentThread().setContextClassLoader(getClassLoader());
+
+ // Acquire classes from CL
+ homeInterface = classLoader.loadClass(metaData.getHome());
+ remoteInterface = classLoader.loadClass(metaData.getRemote());
+
+ // Call default init
+ super.init();
+
+ // Map the bean methods
+ setupBeanMapping();
+
+ // Map the home methods
+ setupHomeMapping();
+
+ // Initialize pool
+ instancePool.init();
+
+ // Init container invoker
+ containerInvoker.init();
+
+ // Init instance cache
+ instanceCache.init();
+
+ // Init persistence
+ persistenceManager.init();
+
+ // Initialize the interceptor by calling the chain
+ Interceptor in = interceptor;
+ while (in != null)
+ {
+ in.setContainer(this);
+ in.init();
+ in = in.getNext();
+ }
+
+ // Reset classloader
+ Thread.currentThread().setContextClassLoader(oldCl);
+ }
+
+ public void start()
+ throws Exception
+ {
+ // Associate thread with classloader
+ ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
+ Thread.currentThread().setContextClassLoader(getClassLoader());
+
+ // Call default start
+ super.start();
+
+ // Start container invoker
+ containerInvoker.start();
+
+ // Start instance cache
+ instanceCache.start();
+
+ // Start persistence
+ persistenceManager.start();
+
+ // Start the instance pool
+ instancePool.start();
+
+ // Start all interceptors in the chain
+ Interceptor in = interceptor;
+ while (in != null)
+ {
+ in.start();
+ in = in.getNext();
+ }
+
+ // Reset classloader
+ Thread.currentThread().setContextClassLoader(oldCl);
+ }
+
+ public void stop()
+ {
+ // Associate thread with classloader
+ ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
+ Thread.currentThread().setContextClassLoader(getClassLoader());
+
+ // Call default stop
+ super.stop();
+
+ // Stop container invoker
+ containerInvoker.stop();
+
+ // Stop instance cache
+ instanceCache.stop();
+
+ // Stop persistence
+ persistenceManager.stop();
+
+ // Stop the instance pool
+ instancePool.stop();
+
+ // Stop all interceptors in the chain
+ Interceptor in = interceptor;
+ while (in != null)
+ {
+ in.stop();
+ in = in.getNext();
+ }
+
+ // Reset classloader
+ Thread.currentThread().setContextClassLoader(oldCl);
+ }
+
+ public void destroy()
+ {
+ // Associate thread with classloader
+ ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
+ Thread.currentThread().setContextClassLoader(getClassLoader());
+
+ // Call default destroy
+ super.destroy();
+
+ // Destroy container invoker
+ containerInvoker.destroy();
+
+ // Destroy instance cache
+ instanceCache.destroy();
+
+ // Destroy persistence
+ persistenceManager.destroy();
+
+ // Destroy the pool
+ instancePool.destroy();
+
+ // Destroy all the interceptors in the chain
+ Interceptor in = interceptor;
+ while (in != null)
+ {
+ in.destroy();
+ in = in.getNext();
+ }
+
+ // Reset classloader
+ Thread.currentThread().setContextClassLoader(oldCl);
+ }
+
+ public Object invokeHome(MethodInvocation mi)
+ throws Exception
+ {
+
+ Logger.log("invokeHome");
+ try { return getInterceptor().invokeHome(mi); }
+ catch (Exception e) {e.printStackTrace(); throw e;}
+
+ // return getInterceptor().invokeHome(mi);
+
+ }
+
+ public Object invoke(MethodInvocation mi)
+ throws Exception
+ {
+ try { return getInterceptor().invoke(mi); }
+ catch (Exception e) {e.printStackTrace();throw e;}
+
+
+ // Invoke through interceptors
+ // return getInterceptor().invoke(mi);
+ }
+
+ // EJBObject implementation --------------------------------------
+ public void remove(MethodInvocation mi)
+ throws java.rmi.RemoteException, RemoveException
+ {
+ // Get the persistence manager to do the dirty work
+
getPersistenceManager().removeEntity((EntityEnterpriseContext)mi.getEnterpriseContext());
+
+ // We signify "removed" with a null id
+ mi.getEnterpriseContext().setId(null);
+ }
+
+ /**
+ * MF FIXME these are implemented on the client
+ */
+ public Handle getHandle(MethodInvocation mi)
+ throws java.rmi.RemoteException
+ {
+ // TODO
+ throw new Error("Not yet implemented");
+ }
+
+ public Object getPrimaryKey(MethodInvocation mi)
+ throws java.rmi.RemoteException
+ {
+ // TODO
+ throw new Error("Not yet implemented");
+ }
+
+ public EJBHome getEJBHome(MethodInvocation mi)
+ throws java.rmi.RemoteException
+ {
+ return containerInvoker.getEJBHome();
+ }
+
+
+ public boolean isIdentical(MethodInvocation mi)
+ throws java.rmi.RemoteException
+ {
+ return
((EJBObject)mi.getArguments()[0]).getPrimaryKey().equals(mi.getEnterpriseContext().getId());
+ // TODO - should also check type
+ }
+
+ /**
+ * MF FIXME these are implemented on the client
+ */
+
+
+ // Home interface implementation ---------------------------------
+
+ /*
+ * find(MethodInvocation)
+ *
+ * This methods finds the target instances by delegating to the persistence
manager
+ * It then manufactures EJBObject for all the involved instances found
+ */
+
+ public Object find(MethodInvocation mi)
+ throws java.rmi.RemoteException, FinderException
+ {
+
+ // Multi-finder?
+ if (!mi.getMethod().getReturnType().equals(getRemoteClass()))
+ {
+ // Iterator finder
+ Collection c = getPersistenceManager().findEntities(mi.getMethod(),
mi.getArguments(), (EntityEnterpriseContext)mi.getEnterpriseContext());
+
+ // Get the EJBObjects with that
+ Collection ec = containerInvoker.getEntityCollection(c);
+
+ // BMP entity finder methods are allowed to return
java.util.Enumeration.
+ // We need a serializable Enumeration, so we can't use
Collections.enumeration()
+ try {
+ if
(mi.getMethod().getReturnType().equals(Class.forName("java.util.Enumeration"))) {
+ return new SerializableEnumeration(ec);
+ } else {
+ return ec;
+ }
+ } catch (ClassNotFoundException e) {
+ // shouldn't happen
+ return ec;
+ }
+
+ } else
+ {
+
+ // Single entity finder
+ Object id = getPersistenceManager().findEntity(mi.getMethod(),
+ mi.getArguments(),
+ (EntityEnterpriseContext)mi.getEnterpriseContext());
+
+ //create the EJBObject
+ return (EJBObject)containerInvoker.getEntityEJBObject(id);
+ }
+ }
+
+ /**
+ * createHome(MethodInvocation)
+ *
+ * This method takes care of the wiring of the "EJBObject" trio (target,
context, proxy)
+ * It delegates to the persistence manager.
+ *
+ */
+
+ public EJBObject createHome(MethodInvocation mi)
+ throws java.rmi.RemoteException, CreateException
+ {
+
+ // The persistence manager takes care of the wiring and creating the
EJBObject
+ getPersistenceManager().createEntity(mi.getMethod(),mi.getArguments(),
+ (EntityEnterpriseContext) mi.getEnterpriseContext());
+
+ // The context implicitely carries the EJBObject
+ return ((EntityEnterpriseContext)mi.getEnterpriseContext()).getEJBObject();
+ }
+
+ /**
+ * A method for the getEJBObject from the handle
+ *
+ */
+ public EJBObject getEJBObject(MethodInvocation mi)
+ throws java.rmi.RemoteException {
+
+ // All we need is an EJBObject for this Id;
+ return
(EJBObject)containerInvoker.getEntityEJBObject(((EntityInstanceCache)
instanceCache).createCacheKey(mi.getId()));
+ }
+
+
+
+ // EJBHome implementation ----------------------------------------
+
+
+ public void removeHome(MethodInvocation mi)
+ throws java.rmi.RemoteException, RemoveException
+ {
+ throw new Error("Not yet implemented");
+ }
+
+ public EJBMetaData getEJBMetaDataHome(MethodInvocation mi)
+ throws java.rmi.RemoteException
+ {
+ return getContainerInvoker().getEJBMetaData();
+ }
+
+ public HomeHandle getHomeHandleHome(MethodInvocation mi)
+ throws java.rmi.RemoteException
+ {
+ // TODO
+ throw new Error("Not yet implemented");
+ }
+
+
+ // Private -------------------------------------------------------
+ protected void setupHomeMapping()
+ throws DeploymentException
+ {
+ Map map = new HashMap();
+
+ Method[] m = homeInterface.getMethods();
+ for (int i = 0; i < m.length; i++)
+ {
+ try
+ {
+ // Implemented by container (in both cases)
+ if (m[i].getName().startsWith("find"))
+ map.put(m[i], this.getClass().getMethod("find", new Class[] {
MethodInvocation.class }));
+ else
+ map.put(m[i], this.getClass().getMethod(m[i].getName()+"Home",
new Class[] { MethodInvocation.class }));
+ } catch (NoSuchMethodException e)
+ {
+ throw new DeploymentException("Could not find matching method for
"+m[i]);
+ }
+ }
+
+ // Special methods
+
+ try {
+
+ // Get the One on Handle (getEJBObject), get the class
+ Class handleClass = Class.forName("javax.ejb.Handle");
+
+ // Get the methods (there is only one)
+ Method[] handleMethods = handleClass.getMethods();
+
+ //Just to make sure let's iterate
+ for (int j=0; j<handleMethods.length ;j++) {
+
+ try {
+
+ //Get only the one called handle.getEJBObject
+ if (handleMethods[j].getName().equals("getEJBObject")) {
+
+ //Map it in the home stuff
+ map.put(handleMethods[j],
this.getClass().getMethod("getEJBObject", new Class[] {MethodInvocation.class}));
+ }
+ }
+ catch (NoSuchMethodException e) {
+ throw new DeploymentException("Couldn't find getEJBObject
method on container");
+ }
+ }
+ }
+ catch (Exception e) {
+ // DEBUG Logger.exception(e);
+ }
+
+ // We are done keep the home map
+ homeMapping = map;
+ }
+
+ protected void setupBeanMapping()
+ throws DeploymentException
+ {
+ Map map = new HashMap();
+
+ Method[] m = remoteInterface.getMethods();
+ for (int i = 0; i < m.length; i++)
+ {
+ try
+ {
+ if
(!m[i].getDeclaringClass().getName().equals("javax.ejb.EJBObject"))
+ {
+ // Implemented by bean
+ map.put(m[i], beanClass.getMethod(m[i].getName(),
m[i].getParameterTypes()));
+ }
+ else
+ {
+ // Implemented by container
+ map.put(m[i], getClass().getMethod(m[i].getName(), new Class[]
{ MethodInvocation.class }));
+ }
+ } catch (NoSuchMethodException e)
+ {
+ throw new DeploymentException("Could not find matching method for
"+m[i], e);
+ }
+ }
+
+ beanMapping = map;
+
+ }
+
+ public Interceptor createContainerInterceptor()
+ {
+ return new ContainerInterceptor();
+ }
+
+ // Inner classes -------------------------------------------------
+ // This is the last step before invocation - all interceptors are done
+ class ContainerInterceptor
+ implements Interceptor
+ {
+ public void setContainer(Container con) {}
+
+ public void setNext(Interceptor interceptor) {}
+ public Interceptor getNext() { return null; }
+
+ public void init() {}
+ public void start() {}
+ public void stop() {}
+ public void destroy() {}
+
+ public Object invokeHome(MethodInvocation mi)
+ throws Exception
+ {
+ // Invoke and handle exceptions
+ Method m = (Method)homeMapping.get(mi.getMethod());
+
+ try
+ {
+ return m.invoke(EntityContainer.this, new Object[] { mi });
+ } catch (InvocationTargetException e)
+ {
+ Throwable ex = e.getTargetException();
+ if (ex instanceof Exception)
+ throw (Exception)ex;
+ else
+ throw (Error)ex;
+ }
+ }
+
+ public Object invoke(MethodInvocation mi)
+ throws Exception
+ {
+ // Get method
+ Method m = (Method)beanMapping.get(mi.getMethod());
+
+ // Select instance to invoke (container or bean)
+ if (m.getDeclaringClass().equals(EntityContainer.class))
+ {
+ // Invoke and handle exceptions
+ try
+ {
+ return m.invoke(EntityContainer.this, new Object[] { mi });
+ } catch (InvocationTargetException e)
+ {
+ Throwable ex = e.getTargetException();
+ if (ex instanceof Exception)
+ throw (Exception)ex;
+ else
+ throw (Error)ex;
+ }
+ } else
+ {
+ //wire the transaction on the context, this is how the instance
remember the tx
+ if (mi.getEnterpriseContext().getTransaction() == null)
mi.getEnterpriseContext().setTransaction(mi.getTransaction());
+
+ // Invoke and handle exceptions
+ try
+ {
+ return m.invoke(mi.getEnterpriseContext().getInstance(),
mi.getArguments());
+ } catch (InvocationTargetException e)
+ {
+ Throwable ex = e.getTargetException();
+ if (ex instanceof Exception)
+ throw (Exception)ex;
+ else
+ throw (Error)ex;
+ }
+ }
+ }
+ }
+}
+