JContainer.java

00001 
00026 package org.objectweb.jonas_ejb.container;
00027 
00028 import java.lang.reflect.Method;
00029 import java.util.Collections;
00030 import java.util.Enumeration;
00031 import java.util.HashMap;
00032 import java.util.HashSet;
00033 import java.util.Iterator;
00034 import java.util.Properties;
00035 import java.util.Set;
00036 
00037 import javax.ejb.AccessLocalException;
00038 import javax.ejb.EJBException;
00039 import javax.naming.Context;
00040 import javax.naming.InitialContext;
00041 import javax.naming.LinkRef;
00042 import javax.naming.NamingException;
00043 import javax.naming.Reference;
00044 import javax.naming.StringRefAddr;
00045 import javax.resource.spi.ActivationSpec;
00046 import javax.security.jacc.PolicyContext;
00047 
00048 import org.objectweb.jonas.common.JProp;
00049 import org.objectweb.jonas.resource.Rar;
00050 import org.objectweb.jonas.ws.JServiceFactory;
00051 import org.objectweb.jonas.ws.JServiceFactoryFinder;
00052 import org.objectweb.jonas_ejb.container.jorm.RdbFactory;
00053 import org.objectweb.jonas_ejb.deployment.api.BeanDesc;
00054 import org.objectweb.jonas_ejb.deployment.api.EntityBmpDesc;
00055 import org.objectweb.jonas_ejb.deployment.api.EntityCmpDesc;
00056 import org.objectweb.jonas_ejb.deployment.api.EntityDesc;
00057 import org.objectweb.jonas_ejb.deployment.api.EntityJdbcCmp1Desc;
00058 import org.objectweb.jonas_ejb.deployment.api.EntityJdbcCmp2Desc;
00059 import org.objectweb.jonas_ejb.deployment.api.MessageDrivenDesc;
00060 import org.objectweb.jonas_ejb.deployment.api.SessionStatefulDesc;
00061 import org.objectweb.jonas_ejb.deployment.api.SessionStatelessDesc;
00062 import org.objectweb.jonas_ejb.lib.EJBInvocation;
00063 
00064 import org.objectweb.jonas_lib.deployment.api.EjbLocalRefDesc;
00065 import org.objectweb.jonas_lib.deployment.api.EjbRefDesc;
00066 import org.objectweb.jonas_lib.deployment.api.EnvEntryDesc;
00067 import org.objectweb.jonas_lib.deployment.api.MessageDestinationRefDesc;
00068 import org.objectweb.jonas_lib.deployment.api.ResourceEnvRefDesc;
00069 import org.objectweb.jonas_lib.deployment.api.ResourceRefDesc;
00070 import org.objectweb.jonas_lib.naming.ContainerNaming;
00071 import org.objectweb.jonas_lib.security.PermissionManagerException;
00072 
00073 import org.objectweb.jonas_jms.api.JmsManager;
00074 
00075 import org.objectweb.jonas_ws.deployment.api.ServiceRefDesc;
00076 
00077 import org.objectweb.transaction.jta.TransactionManager;
00078 
00079 import org.objectweb.util.monolog.api.BasicLevel;
00080 
00096 public class JContainer implements Container {
00097 
00101     public static final String DEFAULT_FACTORY_CLASS_NAME = "org.objectweb.jonas_ejb.container.JEntityFactory";
00102 
00107     private static final int DEFAULT_THREAD_POOL_SIZE = 10;
00108 
00112     private static ThreadPool threadpool = null;
00113 
00117     private HashMap beanList = new HashMap();
00118 
00122     private String earFileName = null;
00123 
00127     private String fileName;
00128 
00132     private String externalFileName;
00133 
00137     private JmsManager jms = null;
00138 
00142     private ClassLoader loader = null;
00143 
00147     private int maxthreadpoolsize = ThreadPool.DEFAULT_POOL_MAX_SIZE;
00148 
00152     private String myname;
00153 
00157     private ContainerNaming naming = null;
00158 
00162     private PermissionManager permissionManager = null;
00163 
00167     private PrincipalFactory principalFactory = null;
00168 
00172     private boolean securityFlag = true;
00173 
00177     private JStatefulPool statefulSessionPool = null;
00178 
00182     private Swapper swapper;
00183 
00187     private int threadpoolsize = DEFAULT_THREAD_POOL_SIZE;
00188 
00192     private TransactionManager tm = null;
00193 
00198     private static final String DEFAULT_ACTIVATION_SPEC_NAME = "joramActivationSpec";
00199 
00207     public JContainer(String name, String extFileName, String file, ClassLoader ld) {
00208         myname = name;
00209         externalFileName = extFileName;
00210         fileName = file;
00211         loader = ld;
00212         swapper = new Swapper(this);
00213         swapper.start();
00214         TraceEjb.interp.log(BasicLevel.DEBUG, "New Container extFN= " + externalFileName + " filename=" + fileName);
00215     }
00216 
00217     // -------------------------------------------------------------------
00218     // Methods used by JOnAS Server (but not part of JContainer interface)
00219     // -------------------------------------------------------------------
00220 
00230     public synchronized BeanFactory addBean(BeanDesc dd) {
00231         BeanFactory bf = null;
00232         String beanName = dd.getEjbName();
00233         if (dd instanceof SessionStatefulDesc) {
00234             TraceEjb.interp.log(BasicLevel.DEBUG, "add SessionStatefulBean " + beanName);
00235             if (statefulSessionPool == null) {
00236                 statefulSessionPool = new JStatefulPool();
00237             }
00238             bf = new JStatefulFactory((SessionStatefulDesc) dd, this, statefulSessionPool);
00239         } else if (dd instanceof SessionStatelessDesc) {
00240             TraceEjb.interp.log(BasicLevel.DEBUG, "add SessionStatelessBean " + beanName);
00241             bf = new JStatelessFactory((SessionStatelessDesc) dd, this);
00242         } else if (dd instanceof MessageDrivenDesc) {
00243             TraceEjb.interp.log(BasicLevel.DEBUG, "add MessageDrivenBean " + beanName);
00244             Object obj = null;
00245             InitialContext ictx = null;
00246             String destJName = ((MessageDrivenDesc) dd).getDestinationJndiName();
00247             try {
00248                 ictx = naming.getInitialContext();
00249                 obj = ictx.lookup(destJName);
00250             } catch (Exception ex) {
00251                 TraceEjb.interp.log(BasicLevel.DEBUG, "Can not find destination JNDI name " + destJName);
00252             }
00253             if (obj != null && obj instanceof ActivationSpec) {
00254                 bf = new JMdbEndpointFactory((MessageDrivenDesc) dd, this, (ActivationSpec) obj);
00255             } else if (getJmsManager() == null) {
00256                 // This is the case where we need to attach the MDB to an RAR, but it is either configured
00257                 // as an EJB 2.0 MDB or incorrectly for a 2.1 MDB.
00258                 if (((MessageDrivenDesc)  dd).getDestination() != null) {
00259                     TraceEjb.interp.log(BasicLevel.DEBUG, "JMS service not started and specified ActivationSpec(" + destJName + ") not deployed");
00260                     throw new EJBException("JMS service not started and specified ActivationSpec(" + destJName + ") not deployed");
00261                 }
00262 
00263                 // Get the default ActivationSpec name and attempt to configure it
00264                 String dest = Rar.getDefaultAS();  //default name
00265                 if (dest == null) {
00266                     dest = DEFAULT_ACTIVATION_SPEC_NAME;  //default name
00267                 }
00268 
00269                 try {
00270                     obj = ictx.lookup(dest);
00271                 } catch (Exception ex) {
00272                     TraceEjb.interp.log(BasicLevel.DEBUG, "JMS service not started and default ActivationSpec(" + dest + ") not deployed");
00273                     throw new EJBException("JMS service not started and default ActivationSpec(" + dest + ") not deployed", ex);
00274                 }
00275                 if (obj != null && obj instanceof ActivationSpec) {
00276                     bf = new JMdbEndpointFactory((MessageDrivenDesc) dd, dest, this, (ActivationSpec) obj);
00277                 } else {
00278                     TraceEjb.interp.log(BasicLevel.DEBUG, "Invalid destination: No ActivationSpec deployed matching " + dest);
00279                     throw new EJBException("Invalid destination: No ActivationSpec deployed matching " + dest);
00280                 }
00281             } else {
00282                 // This is the case where a 2.1 MDB is trying to connect to an RAR that isn't deployed
00283                 if (((MessageDrivenDesc)  dd).getDestination() != null) {
00284                     TraceEjb.interp.log(BasicLevel.DEBUG, "JMS service started and specified ActivationSpec(" + destJName + ") not deployed");
00285                     throw new EJBException("JMS service started and specified ActivationSpec(" + destJName + ") not deployed");
00286                 }
00287                 if (threadpool == null) {
00288                     threadpool = new ThreadPool(threadpoolsize, maxthreadpoolsize);
00289                 }
00290                 bf = new JMdbFactory((MessageDrivenDesc) dd, this, threadpool);
00291             }
00292         } else if (dd instanceof EntityJdbcCmp2Desc) {
00293             EntityJdbcCmp2Desc ecd = (EntityJdbcCmp2Desc) dd;
00294             // TODO We only manage "Jdbc" CMP2 entity beans today.
00295             TraceEjb.interp.log(BasicLevel.DEBUG, "add CMP2 EntityBean " + beanName);
00296             // Instanciate the Factory depending on the mapper
00297             String cn = null;
00298             try {
00299                 String dsn = ecd.getDatasourceJndiName();
00300                 // Pb: We need the mapper to instanciate the Factory.
00301                 // The mapper is in the Datasource. No way to get it in a
00302                 // standard way
00303                 // since Datasource interface is very simple (getConnection()
00304                 // only)
00305                 //
00306                 // This will now try to call a getMapperName method for the
00307                 // datasource,
00308                 // if it doesn't exist then get the mapper.properties file and
00309                 // look for the
00310                 // jndiname. This allows flexibility for additional data source
00311                 // support,
00312                 // but still is not perfect.
00313 
00314                 InitialContext ictx = naming.getInitialContext();
00315                 String mapperName = null;
00316                 // Attempt to call getMapperName method and if it doesn't exist
00317                 // then
00318                 // read the mapper.properties file
00319                 try {
00320                     Object cls = ictx.lookup(dsn);
00321                     Method meth = cls.getClass().getMethod("getMapperName", (Class[]) null);
00322                     mapperName = (String) meth.invoke(cls, (Object[]) null);
00323                 } catch (Exception e1) {
00324                     TraceEjb.interp.log(BasicLevel.DEBUG, "Cannot read mapper name : " + e1.getMessage());
00325                 }
00326                 if (mapperName == null || mapperName.trim().length() == 0) {
00327                     // Method doesn't exist so go read mapper.properties and
00328                     // look for jndiname mapping
00329                     try {
00330                         JProp dsProps = JProp.getInstance("mapper");
00331                         mapperName = dsProps.getValue(dsn, "");
00332                     } catch (Exception e2) {
00333                         throw new EJBException("Unable to retrieve mapperName for " + dsn);
00334                     }
00335                     if (mapperName == null) {
00336                         throw new EJBException("Unable to retrieve mapperName for " + dsn);
00337                     }
00338                 }
00339 
00340                 cn = ecd.getFactoryClassName();
00341                 bf = (JEntityFactory) loader.loadClass(cn).newInstance();
00342                 ((RdbFactory) bf).init(ecd, this, mapperName);
00343                 setSwapTime(((EntityDesc) ecd).getPassivationTimeout());
00344                 TraceEjb.interp.log(BasicLevel.INFO, beanName + " is loaded and using " + mapperName);
00345             } catch (Exception e) {
00346                 TraceEjb.interp.log(BasicLevel.ERROR, "Impossible to instanciate the entity factory: " + cn, e);
00347                 throw new EJBException("Impossible to instanciate the entity factory: " + cn, e);
00348             }
00349         } else if (dd instanceof EntityDesc) {
00350             TraceEjb.interp.log(BasicLevel.DEBUG, "add EntityBean " + beanName);
00351             // Instanciate the default factory
00352             String cn = null;
00353             try {
00354                 cn = DEFAULT_FACTORY_CLASS_NAME;
00355                 bf = (JEntityFactory) loader.loadClass(cn).newInstance();
00356             } catch (Exception e) {
00357                 throw new EJBException("Impossible to instanciate the specified entity factory: " + cn, e);
00358             }
00359             ((JEntityFactory) bf).init((EntityDesc) dd, this);
00360             setSwapTime(((EntityDesc) dd).getPassivationTimeout());
00361         } else {
00362             throw new EJBException("Bad Descriptor Type for " + beanName);
00363         }
00364         beanList.put(beanName, bf);
00365         TraceEjb.interp.log(BasicLevel.INFO, beanName + " available");
00366         return bf;
00367     }
00368 
00379     private Set beansDependence(Enumeration beanFactories, String rName, boolean isResRef) {
00380         HashSet result = new HashSet();
00381         BeanFactory bf = null;
00382         while (beanFactories.hasMoreElements()) {
00383             // for each bean,
00384             bf = (BeanFactory) beanFactories.nextElement();
00385             BeanDesc ejbDesc = bf.getDeploymentDescriptor();
00386 
00387             boolean isDependent = false; // suppose its not dependent
00388 
00389             // get its type from the DeploymentDescriptor
00390             String ejbType = null;
00391             if (bf instanceof JEntityFactory) {
00392                 if (ejbDesc instanceof EntityBmpDesc) {
00393                     ejbType = "ejbbmp";
00394                 }
00395                 if (ejbDesc instanceof EntityCmpDesc) {
00396                     ejbType = "ejbcmp";
00397                 }
00398             } else if (bf instanceof JStatefulFactory) {
00399                 ejbType = "ejbsbf";
00400             } else if (bf instanceof JStatelessFactory) {
00401                 ejbType = "ejbsbl";
00402             } else if (bf instanceof JMdbFactory || bf instanceof JMdbEndpointFactory) {
00403                 ejbType = "ejbmdb";
00404             }
00405 
00406             if (isResRef) {
00407                 // if this is a cmp bean, directly compare rName with the data
00408                 // source JNDI name
00409                 // from its deployment descriptor
00410                 if (ejbType.equals("ejbcmp")) {
00411                     String jndiName = null;
00412                     if (ejbDesc instanceof EntityJdbcCmp1Desc) {
00413                         jndiName = ((EntityJdbcCmp1Desc) ejbDesc).getDatasourceJndiName();
00414                     } else if (ejbDesc instanceof EntityJdbcCmp2Desc) {
00415                         jndiName = ((EntityJdbcCmp2Desc) ejbDesc).getDatasourceJndiName();
00416                     }
00417                     isDependent = rName.equals(jndiName);
00418                 }
00419                 // get the description of the bean's resource-refs
00420                 ResourceRefDesc[] rrDesc = ejbDesc.getResourceRefDesc();
00421                 for (int i = 0; i < rrDesc.length; i++) {
00422                     // for each resource-ref compare its name with rName
00423                     if (rrDesc[i].getJndiName().equals(rName)) {
00424                         isDependent = true;
00425                         break;
00426                     }
00427                 }
00428             } else {
00429                 if (ejbType.equals("ejbmdb")) {
00430                     if (rName.equals(((MessageDrivenDesc) ejbDesc).getDestinationJndiName())) {
00431                         isDependent = true;
00432                     }
00433                 }
00434                 // get the description of the bean's resource-env-refs
00435                 ResourceEnvRefDesc[] rerDesc = ejbDesc.getResourceEnvRefDesc();
00436                 for (int i = 0; i < rerDesc.length; i++) {
00437                     // for each resource-env-ref compare its name with rName
00438                     if (rerDesc[i].getJndiName().equals(rName)) {
00439                         isDependent = true;
00440                         break;
00441                     }
00442                 }
00443             }
00444 
00445             if (isDependent) {
00446                 Properties toAdd = new Properties();
00447                 toAdd.setProperty("type", ejbType);
00448                 toAdd.setProperty("fname", getFileName());
00449                 toAdd.setProperty("name", ejbDesc.getEjbName());
00450                 toAdd.setProperty("cname", getName());
00451                 String earFileName = getEarFileName();
00452                 if (earFileName != null) {
00453                     toAdd.setProperty("earFileName", earFileName);
00454                 }
00455                 result.add(toAdd);
00456             }
00457 
00458         }
00459         return result;
00460     }
00461 
00469     protected void checkSecurity(String ejbName, EJBInvocation ejbInv, boolean inRunAs) {
00470         String oldContextId = PolicyContext.getContextID();
00471 
00472         boolean accessIsOk = false;
00473         try {
00474             // Set contextID to PermissionManager contextID (EJB ContextID)
00475             if (permissionManager != null) {
00476                 accessIsOk = permissionManager.checkSecurity(ejbName, ejbInv, inRunAs);
00477             }
00478         } catch (Exception e) {
00479             TraceEjb.security.log(BasicLevel.ERROR, "Error while checking security : '" + e.getMessage() + "'.");
00480         } finally {
00481             PolicyContext.setContextID(oldContextId);
00482         }
00483         if (!accessIsOk) {
00484             throw new AccessLocalException("Access Denied");
00485         }
00486 
00487     }
00488 
00494     public BeanFactory getBeanFactory(String ejbName) {
00495         return (BeanFactory) beanList.get(ejbName);
00496     }
00497 
00501     public int getBeanNb() {
00502         return beanList.size();
00503     }
00504 
00508     public ClassLoader getClassLoader() {
00509         if (loader == null) {
00510             TraceEjb.logger.log(BasicLevel.ERROR, "container has been removed");
00511             //return Thread.currentThread().getContextClassLoader();
00512             return null;
00513         } else {
00514             return loader;
00515         }
00516     }
00517 
00522     public ContainerNaming getContainerNaming() {
00523         return naming;
00524     }
00525 
00532     public Set getDataSourceDependence(String dsName) {
00533         // the true param corresponds to a resource-ref
00534         return beansDependence(Collections.enumeration(beanList.values()), dsName, true);
00535     }
00536 
00541     public String getEarFileName() {
00542         return earFileName;
00543     }
00544 
00548     public int getEntityBMPNb() {
00549         BeanFactory bf;
00550         int total = 0;
00551         Iterator it = beanList.values().iterator();
00552         while (it.hasNext()) {
00553             bf = (BeanFactory) it.next();
00554             if (bf.getDeploymentDescriptor() instanceof EntityBmpDesc) {
00555                 total++;
00556             }
00557         }
00558         return total;
00559     }
00560 
00564     public int getEntityCMPNb() {
00565         BeanFactory bf;
00566         int total = 0;
00567         Iterator it = beanList.values().iterator();
00568         while (it.hasNext()) {
00569             bf = (BeanFactory) it.next();
00570             if (bf.getDeploymentDescriptor() instanceof EntityCmpDesc) {
00571                 total++;
00572             }
00573         }
00574         return total;
00575     }
00576 
00580     public String getFileName() {
00581         return fileName;
00582     }
00583 
00587     public String getExternalFileName() {
00588         return externalFileName;
00589     }
00590 
00598     public Set getJmsConnectionFactoryDependence(String cfName) {
00599         // the true param corresponds to a resource-ref
00600         return beansDependence(Collections.enumeration(beanList.values()), cfName, true);
00601     }
00602 
00610     public Set getJmsDestinationDependence(String destName) {
00611         // the true param corresponds to a resource-ref
00612         return beansDependence(Collections.enumeration(beanList.values()), destName, false);
00613     }
00614 
00619     public JmsManager getJmsManager() {
00620         return jms;
00621     }
00622 
00630     public Set getMailFactoryDependence(String mfName) {
00631         // the true param corresponds to a resource-ref
00632         return beansDependence(Collections.enumeration(beanList.values()), mfName, true);
00633     }
00634 
00639     public int getMaxThreadPoolSize() {
00640         return maxthreadpoolsize;
00641     }
00642 
00646     public int getMessageDrivenNb() {
00647         BeanFactory bf;
00648         int total = 0;
00649         Iterator it = beanList.values().iterator();
00650         while (it.hasNext()) {
00651             bf = (BeanFactory) it.next();
00652             if (bf.getDeploymentDescriptor() instanceof MessageDrivenDesc) {
00653                 total++;
00654             }
00655         }
00656         return total;
00657     }
00658 
00662     public String getName() {
00663         return myname;
00664     }
00665 
00670     public PermissionManager getPermissionManager() {
00671         return permissionManager;
00672     }
00673 
00677     public PrincipalFactory getPrincipalFactory() {
00678         return principalFactory;
00679     }
00680 
00684     public int getStatefulSessionNb() {
00685         BeanFactory bf;
00686         int total = 0;
00687         Iterator it = beanList.values().iterator();
00688         while (it.hasNext()) {
00689             bf = (BeanFactory) it.next();
00690             if (bf.getDeploymentDescriptor() instanceof SessionStatefulDesc) {
00691                 total++;
00692             }
00693         }
00694         return total;
00695     }
00696 
00700     public int getStatelessSessionNb() {
00701         BeanFactory bf;
00702         int total = 0;
00703         Iterator it = beanList.values().iterator();
00704         while (it.hasNext()) {
00705             bf = (BeanFactory) it.next();
00706             if (bf.getDeploymentDescriptor() instanceof SessionStatelessDesc) {
00707                 total++;
00708             }
00709         }
00710         return total;
00711     }
00712 
00716     public int getSwapTime() {
00717         return swapper.getSwapperTimeout();
00718     }
00719 
00725     public TransactionManager getTransactionManager() {
00726         return tm;
00727     }
00728 
00733     public boolean isInEarCase() {
00734         return (earFileName != null);
00735     }
00736 
00737     // ---------------------------------------------------------------
00738     // Container Implementation
00739     // ---------------------------------------------------------------
00740 
00744     public String[] listBeanNames() {
00745         return (String[]) beanList.keySet().toArray(new String[0]);
00746     }
00747 
00748     // -------------------------------------------------------------------
00749     // Other public methods, used internally in this package.
00750     // -------------------------------------------------------------------
00751 
00756     public void registerBF(BeanFactory bf) {
00757         swapper.addBeanFactory(bf);
00758     }
00759 
00764     public void registerBFS(BeanFactory bf) {
00765         swapper.addBeanFactorySync(bf);
00766     }
00767 
00771     public synchronized void remove() {
00772         TraceEjb.interp.log(BasicLevel.DEBUG, myname);
00773 
00774         // Stop the swapper.
00775         swapper.stopIt();
00776 
00777         // synchronize all entity beans before removing them.
00778         // must be done here, not in the swapper.
00779         syncAll(false);
00780 
00781         // remove all factories
00782         Iterator it = beanList.values().iterator();
00783         while (it.hasNext()) {
00784             BeanFactory bf = (BeanFactory) it.next();
00785             try {
00786                 bf.stop();
00787                 TraceEjb.interp.log(BasicLevel.INFO, myname + ": " + bf.getEJBName() + " no longer available");
00788             } catch (Exception e) {
00789                 TraceEjb.logger.log(BasicLevel.ERROR, myname, e);
00790             }
00791         }
00792         beanList.clear();
00793 
00794         // to unload all classes.
00795         loader = null;
00796 
00797         // Remove permission manager
00798         try {
00799             if (permissionManager != null) {
00800                 permissionManager.delete();
00801             }
00802         } catch (PermissionManagerException pme) {
00803             TraceEjb.logger.log(BasicLevel.ERROR, myname, pme);
00804         }
00805         permissionManager = null;
00806 
00807         // Run the garbage collector
00808         Runtime.getRuntime().gc();
00809     }
00810 
00817     public void setBeanEnvironment(Context ctx, BeanDesc dd) throws NamingException {
00818 
00819         // Set bean context
00820         // Build comp/env
00821         Context ctxold = naming.setComponentContext(ctx);
00822         Context envCtx = ctx.createSubcontext("comp/env");
00823 
00824         // Bean Environment
00825         EnvEntryDesc[] envt = dd.getEnvEntryDesc();
00826         for (int i = 0; i < envt.length; i++) {
00827             // get information in descriptor
00828             String name = envt[i].getName();
00829             Object obj = envt[i].getValue();
00830             // register object in JNDI
00831             if (TraceEjb.isDebugIc()) {
00832                 TraceEjb.interp.log(BasicLevel.DEBUG, myname + ": Binding object " + name + " -> " + obj);
00833             }
00834             envCtx.rebind(name, obj);
00835         }
00836 
00837         // Resource References
00838         ResourceRefDesc[] resref = dd.getResourceRefDesc();
00839         for (int i = 0; i < resref.length; i++) {
00840             // get information in descriptor
00841             String name = resref[i].getName();
00842             String resname = resref[i].getJndiName();
00843             String type = resref[i].getTypeName();
00844             // build the LinkRef that will be registered:
00845             // FactoryClassName = null, size = 1, refAddr = resname.
00846 
00847             // register object in JNDI
00848             if (TraceEjb.isDebugIc()) {
00849                 TraceEjb.interp.log(BasicLevel.DEBUG, myname + ": Linking resource " + name + " -> " + resname);
00850             }
00851 
00852             if (type.equalsIgnoreCase("java.net.URL")) {
00853                 // Specify the factory to use with the right URL
00854                 Reference ref = new Reference("java.net.URL", "org.objectweb.jonas_lib.naming.factory.URLFactory", null);
00855                 StringRefAddr refAddr = new StringRefAddr("url", resname);
00856                 ref.add(refAddr);
00857                 envCtx.rebind(name, ref);
00858             } else {
00859                 LinkRef lref = new LinkRef(resname);
00860                 envCtx.rebind(name, lref);
00861             }
00862         }
00863 
00864         // Resource Environment References
00865         ResourceEnvRefDesc[] resEnvref = dd.getResourceEnvRefDesc();
00866         for (int i = 0; i < resEnvref.length; i++) {
00867             // get information in descriptor
00868             String name = resEnvref[i].getName();
00869             String resname = resEnvref[i].getJndiName();
00870             LinkRef lref = new LinkRef(resname);
00871 
00872             if (TraceEjb.isDebugIc()) {
00873                 TraceEjb.interp.log(BasicLevel.DEBUG, myname + ": Linking resource environment " + name + " -> "
00874                         + resname);
00875             }
00876             envCtx.rebind(name, lref);
00877         }
00878 
00879         // EJB References
00880         EjbRefDesc[] ejbref = dd.getEjbRefDesc();
00881         for (int i = 0; i < ejbref.length; i++) {
00882             // get information in descriptor
00883             String name = ejbref[i].getEjbRefName();
00884             String ejbname = null;
00885             ejbname = ejbref[i].getJndiName();
00886             LinkRef lref = new LinkRef(ejbname);
00887 
00888             if (TraceEjb.isDebugIc()) {
00889                 TraceEjb.interp.log(BasicLevel.DEBUG, myname + ": Linking ejb " + name + " -> " + ejbname);
00890             }
00891             envCtx.rebind(name, lref);
00892         }
00893 
00894         // EJB Local Refs
00895         // We use here ejb-link tag. This should be used also for ejb-ref when
00896         // we are able to manage references to another jar file.
00897         EjbLocalRefDesc[] ejblocalref = dd.getEjbLocalRefDesc();
00898         for (int i = 0; i < ejblocalref.length; i++) {
00899             String name = ejblocalref[i].getEjbRefName();
00900             String ejbname = ejblocalref[i].getJndiLocalName();
00901             LinkRef lref = new LinkRef(ejbname);
00902             if (TraceEjb.isDebugIc()) {
00903                 TraceEjb.interp.log(BasicLevel.DEBUG, myname + ": Linking ejb " + name + " -> " + ejbname);
00904             }
00905             envCtx.rebind(name, lref);
00906         }
00907 
00908         // ServiceRef
00909         ServiceRefDesc[] serviceRefs = dd.getServiceRefDesc();
00910         if (serviceRefs.length != 0) {
00911 
00912             // get the JServiceFactory
00913             JServiceFactory factory = null;
00914             
00915             for (int i = 0; i < serviceRefs.length; i++) {
00916 
00917                 if (factory == null) {
00918                     factory = JServiceFactoryFinder.getJOnASServiceFactory();
00919                 }
00920                 // Create the Service from the ServiceRef description
00921                 String refname = serviceRefs[i].getServiceRefName();
00922 
00923                 // create a full Reference
00924                 Reference ref;
00925                 try {
00926                     ref = factory.getServiceReference(serviceRefs[i], loader);
00927                 } catch (Exception e1) {
00928                     throw new NamingException(e1.getMessage());
00929                 }
00930                 envCtx.rebind(refname, ref);
00931                 if (TraceEjb.isDebugIc()) {
00932                     TraceEjb.interp.log(BasicLevel.DEBUG, "Adding service-ref 'java:comp/env/" + refname + "'");
00933                 }
00934             }
00935         }
00936 
00937         // MessageDestination References
00938         MessageDestinationRefDesc[] mdref = dd.getMessageDestinationRefDesc();
00939         for (int i = 0; i < mdref.length; i++) {
00940             // get information in descriptor
00941             String name = mdref[i].getMessageDestinationRefName();
00942             String mdname = null;
00943             mdname = mdref[i].getJndiName();
00944             LinkRef lref = new LinkRef(mdname);
00945 
00946             if (TraceEjb.isDebugIc()) {
00947                 TraceEjb.interp.log(BasicLevel.DEBUG, myname + ": Linking message-destination " + name + " -> " + mdname);
00948             }
00949             envCtx.rebind(name, lref);
00950         }
00951 
00952         // Reset bean context
00953         naming.setComponentContext(ctxold);
00954     }
00955 
00961     public void setContainerNaming(ContainerNaming naming) {
00962         this.naming = naming;
00963     }
00964 
00970     public void setEarFileName(String fileName) {
00971         earFileName = fileName;
00972     }
00973 
00979     public void setJmsManager(JmsManager jms) {
00980         this.jms = jms;
00981     }
00982 
00987     public void setMaxThreadPoolSize(int sz) {
00988         maxthreadpoolsize = sz;
00989     }
00990 
00995     public void setPermissionManager(PermissionManager permissionManager) {
00996         this.permissionManager = permissionManager;
00997     }
00998 
01004     public void setPrincipalFactory(PrincipalFactory pf) {
01005         principalFactory = pf;
01006     }
01007 
01012     public void setSecurity(boolean b) {
01013         securityFlag = b;
01014     }
01015 
01020     public void setSwapTime(int t) {
01021         if (t > 0) {
01022             TraceEjb.swapper.log(BasicLevel.DEBUG, myname + " sec=" + t);
01023             swapper.setSwapperTimeout(t);
01024         }
01025     }
01026 
01031     public void setThreadPoolSize(int sz) {
01032         threadpoolsize = sz;
01033     }
01034 
01040     public void setTransactionManager(TransactionManager tm) {
01041         this.tm = tm;
01042     }
01043 
01049     public synchronized void syncAll(boolean passivate) {
01050         TraceEjb.interp.log(BasicLevel.DEBUG, myname);
01051         BeanFactory bf = null;
01052         Iterator it = beanList.values().iterator();
01053         while (it.hasNext()) {
01054             bf = (BeanFactory) it.next();
01055             if (passivate) {
01056                 bf.reduceCache();
01057             } else {
01058                 bf.sync();
01059             }
01060         }
01061     }
01062 
01067     public String getContextId() {
01068         return externalFileName;
01069     }
01070 }

Generated on Tue Feb 15 15:05:37 2005 for JOnAS by  doxygen 1.3.9.1