Rar.java

00001 
00027 package org.objectweb.jonas.resource;
00028 
00029 import java.io.File;
00030 import java.net.URL;
00031 import java.util.Enumeration;
00032 import java.util.Hashtable;
00033 import java.util.Iterator;
00034 import java.util.List;
00035 import java.util.Properties;
00036 import java.util.Vector;
00037 import java.util.jar.JarEntry;
00038 
00039 import javax.management.InstanceNotFoundException;
00040 import javax.management.MBeanRegistrationException;
00041 import javax.management.MBeanServer;
00042 import javax.management.MalformedObjectNameException;
00043 import javax.management.ObjectName;
00044 import javax.management.modelmbean.ModelMBean;
00045 import javax.naming.Context;
00046 import javax.naming.InitialContext;
00047 import javax.naming.NamingException;
00048 import javax.naming.Reference;
00049 import javax.naming.StringRefAddr;
00050 import javax.resource.Referenceable;
00051 import javax.resource.spi.ActivationSpec;
00052 import javax.resource.spi.ConnectionManager;
00053 import javax.resource.spi.ManagedConnectionFactory;
00054 import javax.resource.spi.ResourceAdapter;
00055 import javax.resource.spi.ResourceAdapterAssociation;
00056 import javax.resource.spi.ResourceAllocationException;
00057 
00058 import org.apache.commons.modeler.ManagedBean;
00059 import org.apache.commons.modeler.Registry;
00060 import org.objectweb.jonas.common.JJarFile;
00061 import org.objectweb.jonas.common.Log;
00062 import org.objectweb.jonas.ear.EarServiceImpl;
00063 import org.objectweb.jonas.jmx.J2eeObjectName;
00064 import org.objectweb.jonas.jmx.JmxService;
00065 import org.objectweb.jonas.jmx.JonasObjectName;
00066 import org.objectweb.jonas.jtm.TransactionService;
00067 import org.objectweb.jonas.management.JonasMBeanTools;
00068 import org.objectweb.jonas.service.ServiceException;
00069 import org.objectweb.jonas.service.ServiceManager;
00070 import org.objectweb.jonas_ejb.deployment.api.ActivationConfigPropertyDesc;
00071 import org.objectweb.jonas_rar.deployment.api.RarDeploymentDesc;
00072 import org.objectweb.jonas_rar.deployment.lib.wrapper.RarManagerWrapper;
00073 import org.objectweb.jonas_rar.deployment.api.AdminobjectDesc;
00074 import org.objectweb.jonas_rar.deployment.api.AuthenticationMechanismDesc;
00075 import org.objectweb.jonas_rar.deployment.api.ConfigPropertyDesc;
00076 import org.objectweb.jonas_rar.deployment.api.ConnectionDefinitionDesc;
00077 import org.objectweb.jonas_rar.deployment.api.ConnectorDesc;
00078 import org.objectweb.jonas_rar.deployment.api.InboundResourceadapterDesc;
00079 import org.objectweb.jonas_rar.deployment.api.JonasActivationspecDesc;
00080 import org.objectweb.jonas_rar.deployment.api.JonasAdminobjectDesc;
00081 import org.objectweb.jonas_rar.deployment.api.JonasConnectionDefinitionDesc;
00082 import org.objectweb.jonas_rar.deployment.api.JonasConnectorDesc;
00083 import org.objectweb.jonas_rar.deployment.api.MessageadapterDesc;
00084 import org.objectweb.jonas_rar.deployment.api.MessagelistenerDesc;
00085 import org.objectweb.jonas_rar.deployment.api.OutboundResourceadapterDesc;
00086 import org.objectweb.jonas_rar.deployment.api.RequiredConfigPropertyDesc;
00087 import org.objectweb.jonas_rar.deployment.api.ResourceadapterDesc;
00088 import org.objectweb.transaction.jta.TransactionManager;
00089 import org.objectweb.util.monolog.api.BasicLevel;
00090 import org.objectweb.util.monolog.api.Logger;
00091 
00099 public class Rar {
00100 
00104     private static Logger logger = null;
00108     private static Logger poolLogger = null;
00112     private static Logger setterLogger = null;
00116     private static Logger manageLogger = null;
00117 
00118     String rarFileName = null;
00119     ClassLoader curLoader = null;
00120     boolean isInEar;
00121     URL earUrl = null;
00122     Context rCtx = null;
00123     String jDomain = null;
00124     String jServer = null;
00125     Vector jndinames = new Vector();
00126     
00127     String lnkJndiName = "";
00128     String lnkRarFilename = "";
00129 
00130     JCAResource jcaResourceMBean = null;
00131     String JCAResourceName = null;
00132     Registry oRegistry = null;
00133 
00134     // J2EE CA 1.5 objects
00135     private ResourceWorkManager workMgr = null;
00136     private ResourceBootstrapContext bootCtx = null;
00137 
00138     // Properties for inits
00139 
00140     // JCA resource service configuration parameters
00141     public static final String CLASS = "jonas.service.resource.class";
00142     public static final String JNDI_NAME = "jndiname";
00143     public static final String RAR_FILENAME = "rarfilename";
00144     public static final String LNK_JNDI_NAME = "lnkjndiname";
00145     public static final String LNK_RAR_FILENAME = "lnkrarfilename";
00146     public static final String OBJ_TYPE = "objtype";
00147     public static final String RESOURCE_LIST = "jonas.service.resource.resources";
00148 
00149     public static final int DEF_WRK_THREADS = 5;
00150     public static final int DEF_EXEC_TIME = 0;
00151 
00152     public static final String JCD = "JCD";
00153     public static final String JAS = "JAS";
00154     public static final String JAO = "JAO";
00155 
00156     public String objectName = null;
00157     public String pathName = null;
00158     public ResourceAdapter resAdp = null;
00159     public ConnectorDesc raConn = null;
00160     public JonasConnectorDesc lnkJonasConn = null;
00161     public JonasConnectorDesc jonasConn = null;
00162 
00163     public String xmlContent = null;
00164     public String jonasXmlContent = null;
00165 
00166 
00167     private class ConfigObj {
00168         public String type;
00169         public int offset;
00170         public String jndiName;
00171         public String rarFilename;
00172         public String lnkJndiName;
00173         public String lnkRarFilename;
00174         public String interfaceStr;
00175         public String classStr;
00176         public Object factory;
00177         public ConnectionManager cm;
00178         public boolean basicPass;
00179         public boolean defaultAS;
00180         public List reqConfigProps;
00181         public ConfigObj(String fType, int off, String jndi, String fName,
00182                           String intStr, String clsStr, Object fact) {
00183             type = fType;
00184             offset = off;
00185             jndiName = jndi;
00186             rarFilename = fName;
00187             interfaceStr = intStr;
00188             classStr = clsStr;
00189             factory = fact;
00190             cm = null;
00191             reqConfigProps = null;
00192             lnkJndiName = "";
00193             lnkRarFilename = "";
00194             defaultAS = false;
00195         }
00196     }
00197 
00201     private static Vector defaultAS = new Vector();
00202 
00206     public static Hashtable fileName2RA = new Hashtable();
00210     public static Hashtable jndiName2RA = new Hashtable();
00211     
00212     private Hashtable cfgObjs = new Hashtable();
00216     private static Hashtable jndiName2Factory = new Hashtable();
00217 
00221     private TransactionManager tm = null;
00222 
00226     private MBeanServer mbeanServer = null;
00227 
00231     private String jcaResourceObjectName = null;
00232 
00238     private ConnectionManagerImpl cm = null;
00239 
00243     private Context ictx = null;
00244 
00248     ResourceUtility ru = null;
00249 
00258     public Rar() {
00259         if (logger == null) {
00260             logger = Log.getLogger(Log.JONAS_JCA_PREFIX+".process");
00261         }
00262         if (poolLogger == null) {
00263             poolLogger = Log.getLogger(Log.JONAS_JCA_PREFIX+".pool");
00264         }
00265         if (setterLogger == null) {
00266             setterLogger = Log.getLogger(Log.JONAS_JCA_PREFIX+".setters");
00267         }
00268         if (manageLogger == null) {
00269             manageLogger = Log.getLogger(Log.JONAS_JCA_PREFIX+".management");
00270         }
00271 
00272         curLoader = Thread.currentThread().getContextClassLoader();
00273 
00274         ru = new ResourceUtility(null, null, logger, setterLogger, manageLogger);
00275     }
00276 
00285     public Rar(Context ctx, String jDom, String jServ,
00286                 ResourceWorkManager wrkMgr, ResourceBootstrapContext btCtx) {
00287         if (logger == null) {
00288             logger = Log.getLogger(Log.JONAS_JCA_PREFIX + ".process");
00289         }
00290         if (poolLogger == null) {
00291             poolLogger = Log.getLogger(Log.JONAS_JCA_PREFIX + ".pool");
00292         }
00293         if (setterLogger == null) {
00294             setterLogger = Log.getLogger(Log.JONAS_JCA_PREFIX + ".setters");
00295         }
00296         if (manageLogger == null) {
00297             manageLogger = Log.getLogger(Log.JONAS_JCA_PREFIX + ".management");
00298         }
00299 
00300         try {
00301             rarFileName = (String) ctx.lookup("rarFileName");
00302             isInEar = ((Boolean) ctx.lookup("isInEar")).booleanValue();
00303             if (isInEar) {
00304                 earUrl = (URL) ctx.lookup("earUrl");
00305             }
00306             curLoader = (ClassLoader) ctx.lookup("classloader");
00307         } catch (NamingException e) {
00308             String err = "Error while getting parameter from context param.";
00309             logger.log(BasicLevel.ERROR, err + e.getMessage());
00310             throw new ResourceServiceException(err, e);
00311         } catch (Exception ex) {
00312             String err = "Error while getting parameter from context param.";
00313             logger.log(BasicLevel.ERROR, err + ex.getMessage());
00314             throw new ResourceServiceException(err, ex);
00315         }
00316 
00317         workMgr = wrkMgr;
00318         bootCtx = btCtx;
00319         rCtx = ctx;
00320         jDomain = jDom;
00321         jServer = jServ;
00322 
00323         // Avoid using NamingManager here: performance is not a goal here.
00324         try {
00325             ictx = new InitialContext();
00326         } catch (NamingException e) {
00327             logger.log(BasicLevel.ERROR, "Cannot create initial context when Resource service initializing");
00328             throw new ServiceException("Cannot create initial context when Resource service initializing", e);
00329         }
00330 
00331         // Get a reference to the Transaction service
00332         try {
00333             ServiceManager sm = ServiceManager.getInstance();
00334             TransactionService ts = (TransactionService) sm.getTransactionService();
00335             tm = ts.getTransactionManager();
00336         } catch (Exception e) {
00337             logger.log(BasicLevel.ERROR, "Cannot get the Transaction service: " + e);
00338             throw new ServiceException("Cannot get the Transaction service: ", e);
00339         }
00340 
00341         // Get the JMX Server via JMX Service
00342         try {
00343             mbeanServer =
00344                 ((JmxService) ServiceManager.getInstance().getJmxService()).getJmxServer();
00345         } catch (Exception e) {
00346             // the JMX service may not be started
00347             mbeanServer = null;
00348         }
00349 
00350         // Use Jakarta Common Modeler API
00351         oRegistry = JonasMBeanTools.getRegistry();
00352 
00353         ru = new ResourceUtility(mbeanServer, oRegistry, logger, setterLogger, manageLogger);
00354     }
00355 
00360     public Context processRar() throws Exception {
00361 
00362         String onRar = null;
00363         // Get the ra.xml and jonas-ra.xml descriptions
00364         RarDeploymentDesc radesc = null;
00365         ConnectorDesc conn = null;
00366         JonasConnectorDesc jConn = null;
00367         xmlContent = null;
00368         jonasXmlContent = null;
00369         ConnectionManager cm = null;
00370         ManagedConnectionFactory mcf = null;
00371 
00372         radesc = RarManagerWrapper.getInstance(rCtx);
00373         conn = radesc.getConnectorDesc();
00374         jConn = radesc.getJonasConnectorDesc();
00375         xmlContent = radesc.getXmlContent();
00376         jonasXmlContent = radesc.getJOnASXmlContent();
00377 
00378         if(conn == null && jConn == null) {
00379             logger.log(BasicLevel.ERROR, "Rar.processRar: Resource (" + rarFileName
00380                                          + ") must be a valid RAR file.");
00381             throw new Exception("resource input file incorrect");
00382         }
00383 
00384         // Need to check if rarlink is specified.  If yes and has been processed, then get the correct
00385         // Connector object and continue, if it has not been processed, then add this rar to the
00386         // deferred list and it will be processed at end of the rar files.  If no rarlink, then
00387         // make sure that the connector object is valid.
00388         String rarVal = null;
00389         if (jConn != null) {
00390             rarVal = (jConn.getRarlink() == null
00391                       ? null
00392                       : jConn.getRarlink());
00393             if (rarVal != null && rarVal.length() > 0) {
00394                 lnkJndiName = rarVal;
00395                 conn = getConnectorDesc(rarVal);
00396                 if (conn == null) {
00397                     return rCtx;
00398                 }
00399                 ConfigObj co = (ConfigObj) getConfigObject(rarVal);
00400                 lnkRarFilename = co.rarFilename;
00401                 xmlContent = getXmlContent(rarVal);
00402                 // Get the config parameters
00403                 lnkJonasConn = getJonasConnectorDesc(rarVal);
00404             } else if (conn == null) {
00405                 logger.log(BasicLevel.ERROR, "Rar.processRar: Resource (" + rarFileName
00406                                              + ") is not valid.");
00407                 throw new Exception("resource input file incorrect: no ra.xml file");
00408             }
00409             bldSecurityTable(lnkJonasConn, jConn);
00410             raConn = conn;
00411             jonasConn = jConn;
00412         } else {
00413             logger.log(BasicLevel.ERROR, "Rar.processRar: Resource (" + rarFileName
00414                                          + ") must be a valid RAR file, there must be jonas-ra.xml file.");
00415             throw new Exception("resource input file incorrect: no jonas-ra.xml file");
00416         }
00417 
00418         // Setup the global pool parameters
00419         ConnectionManagerPoolParams pParams =
00420                 ru.configurePoolParams(jConn.getPoolParamsDesc(),
00421                                        jConn.getJdbcConnParamsDesc(),
00422                                        null);
00423 
00424         // Process the RAR file adding each of the jar files into the classloader and if the
00425         // native-lib is defined then place all other files into that directory.
00426 
00427         extractJars(rarFileName, jConn);
00428 
00429         // Process the config values
00430         ResourceadapterDesc ra = conn.getResourceadapterDesc();
00431 
00432         // Check Authentication Mechanisms, must if some exist then BasicPassword
00433         // must be present
00434         boolean basicPass = true;
00435         List authList = ra.getAuthenticationMechanismList();
00436         if (authList != null && authList.size() > 0) {
00437             basicPass = false;
00438             for (Iterator i = authList.iterator(); i.hasNext();) {
00439                 AuthenticationMechanismDesc am = (AuthenticationMechanismDesc) i.next();
00440                 if (am.getAuthenticationMechanismType().equalsIgnoreCase("BasicPassword")) {
00441                     basicPass = true;
00442                     break;
00443                 }
00444             }
00445             if (!basicPass) {
00446                 logger.log(BasicLevel.ERROR, "Rar.processRar: Resource (" + rarFileName + ") doesn't contain an AuthenticationMechanismType that is supported by JOnAS(BasicPassword).");
00447                 throw new Exception("No AuthenticationMechanismType that is supported by JOnAS(BasicPassword).");
00448             }
00449         }
00450 
00451         ConfigPropertyDesc [] cfgRaJonas = null;
00452 
00453         String logEnabled = null;
00454         if (jConn.getLogEnabled() != null) {
00455             logEnabled = jConn.getLogEnabled().trim();
00456         }
00457         String logTopic = null;
00458         if (jConn.getLogTopic() != null) {
00459             logTopic = jConn.getLogTopic().trim();
00460         }
00461 
00462         Referenceable cf = null;
00463         String jndiName = null;
00464         String mcfc = null;
00465         ConfigObj cObj = null;
00466 
00467         if (lnkJonasConn != null) {
00468             cfgRaJonas = ru.buildConfigProperty(ra.getConfigPropertyList(),
00469                                                 jConn.getJonasConfigPropertyList(),
00470                                                 lnkJonasConn.getJonasConfigPropertyList());
00471         } else {
00472             cfgRaJonas = ru.buildConfigProperty(ra.getConfigPropertyList(),
00473                                                 jConn.getJonasConfigPropertyList(),
00474                                                 null);
00475         }
00476         if (conn.getSpecVersion().equals("1.0")) {
00477             onRar = registerRarMBean(cfgRaJonas);
00478             cm = ru.createConnectionManager(ra.getTransactionSupport(), tm,
00479                                             logger, poolLogger);
00480             ConnectionManagerPoolParams cmpp = ru.configurePoolParams(jConn.getPoolParamsDesc(),
00481                                                                       jConn.getJdbcConnParamsDesc(),
00482                                                                       null);
00483             // Only need to build an MCF for a 1.0 resource adapter
00484             jndiName = jConn.getJndiName().trim();
00485             mcfc = ra.getManagedconnectionfactoryClass();
00486             mcf = (ManagedConnectionFactory) ru.processMCF(conn, jConn, cm, curLoader, rarFileName,
00487                                                            mcfc,
00488                                                            jndiName, logEnabled, logTopic,
00489                                                            cfgRaJonas, resAdp, 0);
00490             ((ConnectionManagerImpl) cm).setResourceAdapter(mcf, cmpp);
00491 
00492             cf = (Referenceable) mcf.createConnectionFactory(cm);
00493 
00494             // Add entry to list of configured objects
00495             cObj = new ConfigObj(JCD, 0, jndiName, rarFileName, null, mcfc, cf);
00496             cObj.cm = cm;
00497             cObj.basicPass = basicPass;
00498 
00499             cfgObjs.put(jndiName, cObj);
00500 
00501             jndinames.add(jndiName);
00502 
00503             ru.registerMBean(cf, jndiName, onRar, conn, jonasConn, JCD, 0,
00504                              jcaResourceMBean, JCAResourceName, jDomain, jServer, ictx);
00505             ((ConnectionManagerImpl) cm).setXAName(ru.getJcaMcfName(jndiName));
00506             ((ConnectionManagerImpl) cm).registerXAResource();
00507 
00508         } else if (conn.getSpecVersion().equals("1.5")) {
00509             String raStr = conn.getResourceadapterDesc().getResourceadapterClass().trim();
00510             boolean isResAdapt = false;
00511             logger.log(BasicLevel.INFO, "Starting deployment of " + rarFileName);
00512             if (raStr != null && raStr.length() > 0) {
00513                 isResAdapt = true;
00514 
00515                 // Instantiate the resource adapter class
00516                 Class raClass = curLoader.loadClass(raStr);
00517                 resAdp = (ResourceAdapter) raClass.newInstance();
00518 
00519                 ru.processSetters(raClass, resAdp, rarFileName, cfgRaJonas);
00520 
00521                 // Call Resourceadapter start method
00522                 try {
00523                     resAdp.start(bootCtx);
00524                 } catch (Exception ex) {
00525                     logger.log(BasicLevel.ERROR, "Rar: Error from resource ("
00526                                                  + rarFileName + ") start method.");
00527                     throw new Exception("Error from start method. " + ex);
00528                 } catch (Throwable th) {
00529                     logger.log(BasicLevel.ERROR, "Rar: Error from resource ("
00530                                                  + rarFileName + ") start method.");
00531                     throw new Exception("Error from start method. ", th);
00532                 }
00533             }
00534 
00535             onRar = registerRarMBean(cfgRaJonas);
00536 
00537             // Loop thru ConnectionDefinition(outbound) factories
00538             OutboundResourceadapterDesc outRa = ra.getOutboundResourceadapterDesc();
00539             List cdList = null;
00540             if (outRa != null) {
00541                 cdList = outRa.getConnectionDefinitionList();
00542             }
00543             ConnectionDefinitionDesc conDef = null;
00544             JonasConnectionDefinitionDesc jConDef = null;
00545             String id = null;
00546             int idOffset = -1;
00547             if (cdList != null) {
00548                 for (int cd = 0; cd < cdList.size(); cd++) {
00549                     conDef = (ConnectionDefinitionDesc) cdList.get(cd);
00550                     id = conDef.getId();
00551                     idOffset++;
00552                     jConDef = (JonasConnectionDefinitionDesc)
00553                                ru.getJonasXML(jConn, id, idOffset, JCD);
00554 
00555 
00556                     if (jConDef.getLogEnabled() != null) {
00557                         logEnabled = jConDef.getLogEnabled().trim();
00558                     }
00559                     if (jConDef.getLogTopic() != null) {
00560                         logTopic = jConDef.getLogTopic().trim();
00561                     }
00562                     ConfigPropertyDesc [] cfgCdDesc =
00563                                  ru.buildConfigProperty(conDef.getConfigPropertyList(),
00564                                                         jConDef.getJonasConfigPropertyList(),
00565                                                         null);
00566                     ConnectionManagerPoolParams pool =
00567                         ru.configurePoolParams(jConDef.getPoolParamsDesc(),
00568                                                jConDef.getJdbcConnParamsDesc(),
00569                                                pParams);
00570                     cm = ru.createConnectionManager(outRa.getTransactionSupport(), tm,
00571                             logger, poolLogger);
00572 
00573                     jndiName = jConDef.getJndiName().trim();
00574                     mcfc = conDef.getManagedconnectionfactoryClass();
00575                     mcf = (ManagedConnectionFactory)
00576                                      ru.processMCF(conn, jConn, cm, curLoader, rarFileName,
00577                                                    mcfc, jndiName, logEnabled, logTopic,
00578                                                    cfgCdDesc, resAdp, idOffset);
00579                     ((ConnectionManagerImpl) cm).setResourceAdapter(mcf, pool);
00580 
00581                     cf = (Referenceable) mcf.createConnectionFactory(cm);
00582 
00583                     // Add entry to list of configured objects
00584                     cObj = new ConfigObj(JCD, idOffset, jndiName, rarFileName, null, mcfc, cf);
00585                     cObj.cm = cm;
00586                     cObj.basicPass = basicPass;
00587 
00588                     cfgObjs.put(jndiName, cObj);
00589 
00590                     jndinames.add(jndiName);
00591 
00592                     ru.registerMBean(cf, jndiName, onRar, conn, jonasConn, JCD, idOffset,
00593                             jcaResourceMBean, JCAResourceName, jDomain, jServer, ictx);
00594 
00595                     ((ConnectionManagerImpl) cm).setXAName(ru.getJcaMcfName(jndiName));
00596                     ((ConnectionManagerImpl) cm).registerXAResource();
00597                 }
00598             }
00599 
00600             // We only want to do anything with Inbound or Adminobjects if the Resourceadapter
00601             // class was specified, otherwise it is a 1.0 RAR with a 1.5 ra.xml
00602             if (isResAdapt) {
00603                 // Loop thru Messagelisteners (inbound) factories
00604                 InboundResourceadapterDesc inAdapt = ra.getInboundResourceadapterDesc();
00605                 MessageadapterDesc msgAdapt = null;
00606                 List mlList = null;
00607                 if (inAdapt != null) {
00608                     msgAdapt = inAdapt.getMessageadapterDesc();
00609                     mlList = null;
00610                     if (msgAdapt != null) {
00611                         mlList = msgAdapt.getMessagelistenerList();
00612                     }
00613                 }
00614                 MessagelistenerDesc msgList = null;
00615                 JonasActivationspecDesc jAct = null;
00616                 id = null;
00617                 idOffset = -1;
00618                 if (mlList != null) {
00619                     for (int ml = 0; ml < mlList.size(); ml++) {
00620                         msgList = (MessagelistenerDesc) mlList.get(ml);
00621                         id = msgList.getId();
00622                         idOffset++;
00623                         jAct = (JonasActivationspecDesc)
00624                                 ru.getJonasXML(jConn, id, idOffset, JAS);
00625 
00626                         processJAS(rarFileName, msgList, jAct, idOffset);
00627                     }
00628                 }
00629 
00630                 // Loop thru Adminobjects
00631                 List aoList = ra.getAdminobjectList();
00632                 AdminobjectDesc admObj = null;
00633                 JonasAdminobjectDesc jAObj = null;
00634                 id = null;
00635                 idOffset = -1;
00636                 if (aoList != null) {
00637                     for (int ao = 0; ao < aoList.size(); ao++) {
00638                         admObj = (AdminobjectDesc) aoList.get(ao);
00639                         id = admObj.getId();
00640                         idOffset++;
00641                         jAObj = (JonasAdminobjectDesc)
00642                                  ru.getJonasXML(jConn, id, idOffset, JAO);
00643 
00644                         ConfigPropertyDesc [] cfgCdDesc =
00645                                      ru.buildConfigProperty(admObj.getConfigPropertyList(),
00646                                                             jAObj.getJonasConfigPropertyList(),
00647                                                             null);
00648 
00649                         processJAO(rarFileName, admObj, jAObj, cfgCdDesc, idOffset);
00650                     }
00651                 }
00652 
00653                 // Set initialized when everything is deployed
00654                 workMgr.setInited();
00655             }
00656         } else {
00657             logger.log(BasicLevel.ERROR, "ResourceService.createRA: Resource ("
00658                                          + rarFileName
00659                                          + ") must be specify a valid specification of 1.0 or 1.5.");
00660             throw new Exception("resource input file incorrect: invalid specification support(only 1.0 & 1.5 are valid)");
00661         }
00662 
00663         logger.log(BasicLevel.INFO, rarFileName + " available");
00664         try {
00665             rCtx.rebind("onRar", onRar);
00666             rCtx.rebind("deployed", new Boolean(true));
00667         } catch (Exception ex) {
00668             String err = "Error while getting parameter from context param.";
00669             logger.log(BasicLevel.ERROR, err + ex.getMessage());
00670             throw new ResourceServiceException(err, ex);
00671         }
00672         return rCtx;
00673     }
00674 
00675 
00676 
00683     private String registerRarMBean(ConfigPropertyDesc [] cfgRaJonas) throws Exception {
00684 
00685         String jndiName = null;  // Just for now to get thru the compile
00686 
00687         // --------------------------
00688         // Register MBeans cf. JSR 77
00689         // --------------------------
00690         if (mbeanServer != null) {
00691 
00692             // ------------------------------------------------
00693             // Register this ResourceAdapter with JMX - old way
00694             // ------------------------------------------------
00695             String raName = null; // ResourceAdapter name
00696             Properties p = buildProp(cfgRaJonas);
00697 
00698             // MBean resourcesource registering
00699             String jmxRaName = (new File(rarFileName)).toURL().getFile().replace(':', '|');
00700             mbeanServer.registerMBean(new JmxResourceAdapter(p, jndiName, rarFileName, isInEar, earUrl),
00701                                       JonasObjectName.resourceAdapter(jmxRaName));
00702 
00703             // ResourceAdapterModule MBean
00704             // ---------------------------
00705             String appName = null;
00706             if (isInEar) {
00707                 appName = EarServiceImpl.buildJ2eeApplicationName(earUrl);
00708             }
00709 
00710             // ResourceAdapter Module name
00711             String resourceAdapaterModuleName = buildModuleName(jmxRaName);
00712             ObjectName onResourceAdapterModule =
00713                 J2eeObjectName.getResourceAdapterModule(jDomain,
00714                                                         jServer,
00715                                                         appName,
00716                                                         resourceAdapaterModuleName);
00717 
00718             if (manageLogger.isLoggable(BasicLevel.DEBUG)) {
00719                 manageLogger.log(BasicLevel.DEBUG, "ObjectName created for ResourceAdapterModule: " + onResourceAdapterModule.toString());
00720             }
00721 
00722             ResourceAdapterModule raModuleMBean = new ResourceAdapterModule(onResourceAdapterModule.toString(),
00723                                                                             isInEar, earUrl);
00724             raModuleMBean.setFileName(jmxRaName);
00725             raModuleMBean.setDeploymentDescriptor(xmlContent);
00726             raModuleMBean.setJonasDeploymentDescriptor(jonasXmlContent);
00727             ManagedBean oManaged = oRegistry.findManagedBean("ResourceAdapterModule");
00728 
00729             ModelMBean oMBean = oManaged.createMBean(raModuleMBean);
00730 
00731             mbeanServer.registerMBean(oMBean, onResourceAdapterModule);
00732             if (manageLogger.isLoggable(BasicLevel.DEBUG)) {
00733                 manageLogger.log(BasicLevel.DEBUG, "ResourceAdapterModule MBean created");
00734             }
00735 
00736             // ResourceAdapter MBean
00737             // ---------------------
00738             raName = resourceAdapaterModuleName;
00739             ObjectName onResourceAdapter = J2eeObjectName.getResourceAdapter(jDomain,
00740                                                                              resourceAdapaterModuleName,
00741                                                                              appName,
00742                                                                              jServer,
00743                                                                              raName);
00744             org.objectweb.jonas.resource.ResourceAdapter raMBean =
00745                            new org.objectweb.jonas.resource.ResourceAdapter(onResourceAdapter.toString(),
00746                                                                             p,
00747                                                                             jndiName,
00748                                                                             jmxRaName,
00749                                                                             isInEar,
00750                                                                             earUrl);
00751             oManaged = oRegistry.findManagedBean("ResourceAdapter");
00752             oMBean = oManaged.createMBean(raMBean);
00753             if (manageLogger.isLoggable(BasicLevel.DEBUG)) {
00754                 manageLogger.log(BasicLevel.DEBUG, "ResourceAdapter ManagedBean created");
00755             }
00756             mbeanServer.registerMBean(oMBean, onResourceAdapter);
00757 
00758             // Update the ResourceAdapterModule MBean with the ResourceAdapter MBean's OBJECT_NAME
00759             raModuleMBean.setResourceAdapter(onResourceAdapter.toString());
00760             if (manageLogger.isLoggable(BasicLevel.DEBUG)) {
00761                 manageLogger.log(BasicLevel.DEBUG, "ResourceAdapterModule ManagedBean updated");
00762             }
00763 
00764             // JCA Resource implemented by this ResourceAdapter
00765             // ------------------------------------------------
00766             JCAResourceName = raName; // TO BE IMPLEMENTED
00767             ObjectName onJCAResource =
00768                 J2eeObjectName.getJCAResource(jDomain,
00769                                               jServer,
00770                                               raName,
00771                                               JCAResourceName);
00772             jcaResourceMBean = new JCAResource(onJCAResource.toString());
00773             oManaged = oRegistry.findManagedBean("JCAResource");
00774             oMBean = oManaged.createMBean(jcaResourceMBean);
00775             if (manageLogger.isLoggable(BasicLevel.DEBUG)) {
00776                 manageLogger.log(BasicLevel.DEBUG, "JCAResource J2EEResource created");
00777             }
00778             mbeanServer.registerMBean(oMBean, onJCAResource);
00779 
00780             // Update the ResourceAdapter MBean with the JCAResource MBean's OBJECT_NAME
00781             raMBean.setJcaResource(onJCAResource.toString());
00782             if (manageLogger.isLoggable(BasicLevel.DEBUG)) {
00783                 manageLogger.log(BasicLevel.DEBUG, "JCAResource J2EEResource updated");
00784             }
00785 
00786             return onResourceAdapterModule.toString();
00787         } else {
00788             String jmxRaName = (new File(rarFileName)).toURL().getFile().replace(':', '|');
00789             return jmxRaName;
00790         }
00791     }
00792 
00793 
00799     public void unRegister() throws Exception {
00800 
00801         for (int i = 0; i < jndinames.size(); i++) {
00802             String jName = (String) jndinames.get(i);
00803             ConfigObj co = (ConfigObj) cfgObjs.get(jName);
00804             try {
00805                 // Unbind from jndi
00806                 ictx.unbind(jName);
00807             } catch (NamingException ex) {
00808                 logger.log(BasicLevel.DEBUG, "ResourceService: cannot unbind jndiname of "
00809                             + jName + " for ResourceAdapter "
00810                             + rarFileName + " :\n" + ex);
00811                 throw new ServiceException(ex.getMessage());
00812             }
00813 
00814             if (co.defaultAS) {
00815                 removeDefaultAS(jName);
00816             }
00817             if (co != null) {  // Add for now, take out for final
00818                 if (co.cm != null) {
00819                     // The connection manger must stop managing the RA
00820                     ((ConnectionManagerImpl) co.cm).cleanResourceAdapter();
00821                 }
00822             }
00823 
00824         }
00825         cfgObjs.clear();
00826 
00827         // --------------------------
00828         // unregister MBeans cf. JSR 77
00829         // --------------------------
00830         if (mbeanServer != null) {
00831             // MBean resourcesource registering
00832             String jmxRaName = (new File(rarFileName)).toURL().getFile().replace(':', '|');
00833             mbeanServer.unregisterMBean(JonasObjectName.resourceAdapter(jmxRaName));
00834 
00835             // Construct ResourceAdapterModule MBean name
00836             // ------------------------------------------
00837             String appName = null;
00838             if (isInEar) {
00839                 appName = EarServiceImpl.buildJ2eeApplicationName(earUrl);
00840             }
00841             // ResourceAdapter Module name
00842             String resourceAdapaterModuleName = buildModuleName(jmxRaName);
00843             ObjectName onResourceAdapterModule =
00844                 J2eeObjectName.getResourceAdapterModule(jDomain,
00845                                                     jServer,
00846                                                     appName,
00847                                                     resourceAdapaterModuleName);
00848             try {
00849                 String[] resourceAdapaterNames = (String[]) mbeanServer.getAttribute(onResourceAdapterModule, "resourceAdapters");
00850 
00851                 // Unregister ResourceAdapterModule MBean
00852                 mbeanServer.unregisterMBean(onResourceAdapterModule);
00853 
00854                 // Unregister ResourceAdapters
00855                 for (int i = 0; i < resourceAdapaterNames.length; i++) {
00856                     String resourceAdapaterName = resourceAdapaterNames[i];
00857                     ObjectName onResourceAdapater = new ObjectName(resourceAdapaterName);
00858                     // Determine this ResourceAdapter's JCAResource
00859                     String jcaResourceName = (String) mbeanServer.getAttribute(onResourceAdapater, "jcaResource");
00860                     // Update the list of resources in the J2EEServer MBean with the JCAResource MBean's OBJECT_NAME
00861                     mbeanServer.unregisterMBean(onResourceAdapater);
00862                     ObjectName onJCAResource = new ObjectName(jcaResourceName);
00863                     String[] connectionFactoriesNames = (String[]) mbeanServer.getAttribute(onJCAResource, "connectionFactories");
00864                     // Unregister the JCA ConnectionFactories of this JCAResource
00865                     for (int j = 0; j < connectionFactoriesNames.length; j++) {
00866                         String connectionFactoryName = connectionFactoriesNames[j];
00867                         ObjectName onJCAConnectionFactory = new ObjectName(connectionFactoryName);
00868                         String managedConnectionFactoryName = (String) mbeanServer.getAttribute(onJCAConnectionFactory, "managedConnectionFactory");
00869                         mbeanServer.unregisterMBean(onJCAConnectionFactory);
00870                         mbeanServer.unregisterMBean(new ObjectName(managedConnectionFactoryName));
00871                     }
00872                     String[] adminObjectNames = (String[]) mbeanServer.getAttribute(onJCAResource, "adminObjects");
00873                     // Unregister the JCA AdminObjects of this JCAResource
00874                     for (int j = 0; j < adminObjectNames.length; j++) {
00875                         String adminObjectName = adminObjectNames[j];
00876                         ObjectName onJCAAdminObject = new ObjectName(adminObjectName);
00877                         mbeanServer.unregisterMBean(onJCAAdminObject);
00878                     }
00879                     String[] activationSpecNames = (String[]) mbeanServer.getAttribute(onJCAResource, "activationSpecs");
00880                     // Unregister the JCA ActivationSpecs of this JCAResource
00881                     for (int j = 0; j < activationSpecNames.length; j++) {
00882                         String activationSpecName = activationSpecNames[j];
00883                         ObjectName onJCAActivationSpec = new ObjectName(activationSpecName);
00884                         mbeanServer.unregisterMBean(onJCAActivationSpec);
00885                     }
00886                     mbeanServer.unregisterMBean(onJCAResource);
00887                 }
00888             } catch (MalformedObjectNameException ma) {
00889                 logger.log(BasicLevel.ERROR, "Cannot cleanly unregister RAR: "
00890                            + ma.getMessage());
00891                 ma.printStackTrace();
00892             } catch (MBeanRegistrationException mr) {
00893                 logger.log(BasicLevel.ERROR, "Cannot cleanly unregister RAR: "
00894                            + mr.getMessage());
00895                 mr.printStackTrace();
00896             } catch (InstanceNotFoundException infe) {
00897                 logger.log(BasicLevel.ERROR, "Cannot cleanly unregister RAR: "
00898                            + infe.getMessage());
00899                 infe.printStackTrace();
00900             } catch (Exception e) {
00901                logger.log(BasicLevel.ERROR, "Cannot cleanly unregister RAR: "
00902                            + e.getMessage());
00903                e.printStackTrace();
00904             }
00905         }
00906 
00907         //   Call Resourceadapter stop
00908         if (resAdp != null) {
00909             resAdp.stop();
00910         }
00911 
00912     }
00913 
00914     //--------------------------------------------------------------
00915     //           Other Method
00916     //--------------------------------------------------------------
00917 
00924     public Object getConfigObj(String jndiName) {
00925         synchronized (cfgObjs) {
00926             ConfigObj co = (ConfigObj) cfgObjs.get(jndiName);
00927             return co;
00928         }
00929     }
00930 
00936     public ConnectorDesc getConnectorDesc() {
00937         return raConn;
00938     }
00939 
00945     public void setConnectorDesc(ConnectorDesc cd) {
00946         raConn = cd;
00947     }
00948 
00954     public String getXmlContent() {
00955         return xmlContent;
00956     }
00957 
00963     public JonasConnectorDesc getJonasConnectorDesc() {
00964         return jonasConn;
00965     }
00966 
00972     public void setJonasConnectorDesc(JonasConnectorDesc jcd) {
00973         jonasConn = jcd;
00974     }
00975 
00976     public Object getFactory(String jndiname) {
00977         ConfigObj co = (ConfigObj) cfgObjs.get(jndiname);
00978         return (co == null ? null : co.factory );
00979     }
00980 
00981     public String getInterface(String jndiname) {
00982         ConfigObj co = (ConfigObj) cfgObjs.get(jndiname);
00983         return (co == null ? null : co.interfaceStr );
00984     }
00985 
00986     public Vector getJndinames() {
00987         return jndinames;
00988     }
00989 
00990     public ResourceAdapter getResourceAdapter() {
00991         return resAdp;
00992     }
00993 
00994     public void configureAS(ActivationSpec as, List acp, List jacp, String jndiname,
00995                              String ejbName) throws Exception {
00996         ConfigPropertyDesc [] asCp = ru.buildConfigProperty(null, acp, jacp);
00997         ((ResourceAdapterAssociation) as).setResourceAdapter(resAdp);
00998         ru.processSetters(as.getClass(), as, ejbName, asCp);
00999         validateAS(as, jndiname, acp, jacp);
01000     }
01001 
01002     //--------------------------------------------------------------
01003     //           Private Methods
01004     //--------------------------------------------------------------
01005 
01006     private void validateAS(ActivationSpec as, String jndiname,
01007                              List acp, List jacp) throws Exception {
01008         boolean found = false;
01009         String reqName = null;
01010         RequiredConfigPropertyDesc rcProp = null;
01011         ActivationConfigPropertyDesc acProp = null;
01012         // Check that the req properties have been satisfied
01013         ConfigObj co = (ConfigObj) cfgObjs.get(jndiname);
01014         for (Iterator r = co.reqConfigProps.iterator(); r.hasNext();) {
01015             rcProp = (RequiredConfigPropertyDesc) r.next();
01016             found = false;
01017             reqName = rcProp.getConfigPropertyName();
01018             if (acp != null) {
01019                 for (Iterator i = acp.iterator(); i.hasNext();) {
01020                     acProp = (ActivationConfigPropertyDesc) i.next();
01021                     if (reqName.equals(acProp.getActivationConfigPropertyName())) {
01022                         found = true;
01023                         break;
01024                     }
01025                 }
01026             }
01027             if (!found && jacp != null) {
01028                 for (Iterator i = jacp.iterator(); i.hasNext();) {
01029                     acProp = (ActivationConfigPropertyDesc) i.next();
01030                     if (reqName.equals(acProp.getActivationConfigPropertyName())) {
01031                         found = true;
01032                         break;
01033                     }
01034                 }
01035             }
01036             if (!found) {
01037                 logger.log(BasicLevel.ERROR, "Required property " + reqName + " not specified ");
01038                 throw new ResourceAllocationException("Required property " + reqName + " not specified ");
01039             }
01040         }
01041 
01042         // Call validate
01043         try {
01044             as.validate();
01045         } catch (UnsupportedOperationException uoe) {
01046             // treat this as no error from validate
01047         } catch (Exception ex) {
01048             logger.log(BasicLevel.ERROR, "Error from ActivationSpec.validate(). " + ex);
01049             throw new ResourceAllocationException("Error from ActivationSpec.validate(). ", ex);
01050         }
01051 
01052     }
01053 
01054 
01055     // Needs to be implemented
01059     private void bldSecurityTable(JonasConnectorDesc lnkJCon, JonasConnectorDesc jCon) {
01060     }
01061 
01067     public static String buildModuleName(String rarFileName) {
01068         String sName = null;
01069         try {
01070             sName = new File(rarFileName).getName();
01071             int iPos = sName.lastIndexOf('.');
01072             if (iPos > -1) {
01073                 sName = sName.substring(0, iPos);
01074             }
01075         } catch (NullPointerException e) {
01076             // none action
01077         }
01078         return sName;
01079     }
01080 
01081     /* Static methods
01082      *
01083      */
01084 
01097     public Object createFactory(String jndiName, String rarObjectName, int factoryOffset,
01098                                 String factoryType, ConnectorDesc conn, JonasConnectorDesc jConn)
01099                  throws Exception {
01100 
01101         ResourceUtility ru = new ResourceUtility(null, null, logger, setterLogger, manageLogger);
01102         Object factory = null;
01103         ManagedConnectionFactory mcf = null;
01104         ResourceadapterDesc ra = conn.getResourceadapterDesc();
01109         boolean basicPass = true;
01113         ResourceAdapter resAdp = null;
01114 
01115         String logEnabled = null;
01116         if (jConn.getLogEnabled() != null) {
01117             logEnabled = jConn.getLogEnabled().trim();
01118         }
01119         String logTopic = null;
01120         if (jConn.getLogTopic() != null) {
01121             logTopic = jConn.getLogTopic().trim();
01122         }
01123         String specVersion = conn.getSpecVersion();
01124 
01125         ConnectionManager cm = null;
01126         String jBase = null;
01127         try {
01128             jBase = System.getProperty("jonas.base");
01129             if (jBase != null) {
01130                 // Get a reference to the Transaction service
01131                 try {
01132                     ServiceManager sm = ServiceManager.getInstance();
01133                     TransactionService ts = (TransactionService) sm.getTransactionService();
01134                     tm = ts.getTransactionManager();
01135                 } catch (Exception e) {
01136                     logger.log(BasicLevel.ERROR, "Cannot get the Transaction service: " + e);
01137                     throw new Exception("Cannot get the Transaction service: ", e);
01138                 }
01139 
01140                 cm = ru.createConnectionManager(ra.getTransactionSupport(), tm,
01141                                                              logger, poolLogger);
01142             }
01143         } catch (Exception ex) {
01144             logger.log(BasicLevel.ERROR, "Use default ConnectionManager: " + rarObjectName);
01145         }
01146 
01147         // Build the global config and pool values
01148         ConfigPropertyDesc [] cfgRaJonas =
01149                      ru.buildConfigProperty(ra.getConfigPropertyList(),
01150                                             jConn.getJonasConfigPropertyList(),
01151                                             null);
01152         ConnectionManagerPoolParams cmpp = ru.configurePoolParams(jConn.getPoolParamsDesc(),
01153                                                                   jConn.getJdbcConnParamsDesc(),
01154                                                                   null);
01155         if (specVersion.equals("1.0")) {
01156             // Only need to build an MCF for a 1.0 resource adapter
01157             mcf = (ManagedConnectionFactory) ru.processMCF(conn, jConn, cm, curLoader, rarObjectName,
01158                                                            ra.getManagedconnectionfactoryClass(),
01159                                                            jndiName, logEnabled, logTopic,
01160                                                            cfgRaJonas, resAdp, 0);
01161             if (cm != null) {
01162                 ((ConnectionManagerImpl) cm).setResourceAdapter(mcf, cmpp);
01163             }
01164 
01165             factory = mcf.createConnectionFactory(cm);
01166         } else if (specVersion.equals("1.5")) {
01167             // Need to figure out how to call RA.start() under some circumstances
01168             boolean callStart = false;
01169 
01170             String raStr = conn.getResourceadapterDesc().getResourceadapterClass().trim();
01171             if (raStr != null && raStr.length() > 0) {
01172 
01173                 // Instantiate the resource adapter class
01174                 Class raClass = curLoader.loadClass(raStr);
01175                 resAdp = (ResourceAdapter) raClass.newInstance();
01176 
01177                 ru.processSetters(raClass, resAdp, rarObjectName, cfgRaJonas);
01178 
01179                 // Call Resourceadapter start method
01180                 try {
01181                     if (callStart) {
01182                         resAdp.start(bootCtx);
01183                     }
01184                 } catch (Exception ex) {
01185                     logger.log(BasicLevel.ERROR, "Rar: Error from resource (" + rarObjectName
01186                                                  + ") start method.");
01187                     throw new Exception("Error from start method. " + ex);
01188                 } catch (Throwable th) {
01189                     logger.log(BasicLevel.ERROR, "Rar: Error from resource (" + rarObjectName
01190                                                  + ") start method.");
01191                     throw new Exception("Error from start method. ", th);
01192                 }
01193             }
01194 
01195             // Determine type
01196             if (factoryType.equals(ru.JCD)) {
01197                 OutboundResourceadapterDesc outRa = ra.getOutboundResourceadapterDesc();
01198                 List cdList = null;
01199                 if (outRa != null) {
01200                     cdList = outRa.getConnectionDefinitionList();
01201                 }
01202                 ConnectionDefinitionDesc conDef = null;
01203                 JonasConnectionDefinitionDesc jConDef = null;
01204                 String id = null;
01205                 if (cdList != null) {
01206                     conDef = (ConnectionDefinitionDesc) cdList.get(factoryOffset);
01207                     id = conDef.getId();
01208                     jConDef = (JonasConnectionDefinitionDesc)
01209                                   ru.getJonasXML(jConn, id, factoryOffset, ru.JCD);
01210 
01211                     if (jConDef.getLogEnabled() != null) {
01212                         logEnabled = jConDef.getLogEnabled().trim();
01213                     }
01214                     if (jConDef.getLogTopic() != null) {
01215                         logTopic = jConDef.getLogTopic().trim();
01216                     }
01217 
01218                     // Create Config Property List
01219                     ConfigPropertyDesc [] cfgCdDesc =
01220                                  ru.buildConfigProperty(conDef.getConfigPropertyList(),
01221                                                         jConDef.getJonasConfigPropertyList(),
01222                                                         null);
01223 
01224                     // Only need to build an MCF for a 1.0 resource adapter
01225                     mcf = (ManagedConnectionFactory) ru.processMCF(conn, jConn, cm, curLoader, rarObjectName,
01226                                                                    conDef.getManagedconnectionfactoryClass(),
01227                                                                    jndiName, logEnabled, logTopic,
01228                                                                    cfgCdDesc, resAdp, factoryOffset);
01229                     if (cm != null) {
01230                         ConnectionManagerPoolParams pool =
01231                               ru.configurePoolParams(jConDef.getPoolParamsDesc(),
01232                                                      jConDef.getJdbcConnParamsDesc(),
01233                                                      cmpp);
01234                         ((ConnectionManagerImpl) cm).setResourceAdapter(mcf, pool);
01235                     }
01236 
01237                     factory = mcf.createConnectionFactory(cm);
01238                 }
01239             } else if (factoryType.equals(ru.JAO)) {
01240                 logger.log(BasicLevel.DEBUG, "Cannot lookup remote admin object of " + jndiName);
01241                 return null;
01242             } else if (factoryType.equals(ru.JAS)) {
01243                 logger.log(BasicLevel.DEBUG, "Cannot lookup remote activationspec of " + jndiName);
01244                 return null;
01245             }
01246         }
01247 
01248         logger.log(BasicLevel.DEBUG, "cf = " + factory);
01249         // Need to register the RM with JOTM
01250         if (factoryType.equals(ru.JCD) && cm != null) {
01251             // Call CM to register with JOTM
01252             ((ConnectionManagerImpl) cm).setXAName(ru.getJcaMcfName(jndiName));
01253             ((ConnectionManagerImpl) cm).registerXAResource();
01254         }
01255         return factory;
01256     }
01257 
01263     public static void addDefaultAS(String jndiName) {
01264         defaultAS.add(jndiName);
01265     }
01266 
01271     public static String getDefaultAS() {
01272         String ret = null;
01273         try {
01274             ret = (String) defaultAS.firstElement();
01275         } catch (Exception ex) {
01276             logger.log(BasicLevel.DEBUG, "No default activationspec");
01277         }
01278         return ret;
01279     }
01280 
01285     public static void removeDefaultAS(String jndiName) {
01286         try {
01287             defaultAS.remove(jndiName);
01288         } catch (Exception ex) {
01289             logger.log(BasicLevel.DEBUG, "Unable to remove default activationspec");
01290         }
01291     }
01292 
01298     public static ConnectorDesc getConnectorDesc(String jndiName) {
01299         synchronized (jndiName2RA) {
01300             Rar rar = (Rar) jndiName2RA.get(jndiName);
01301             if (rar != null) {
01302                 return (rar.getConnectorDesc());
01303             }
01304             logger.log(BasicLevel.DEBUG, "Can't find " + jndiName + " in " + jndiName2RA);
01305             return null;
01306         }
01307     }
01308 
01314     public static JonasConnectorDesc getJonasConnectorDesc(String jndiName) {
01315         synchronized (jndiName2RA) {
01316             Rar rar = (Rar) jndiName2RA.get(jndiName);
01317             if (rar != null) {
01318                 return (rar.getJonasConnectorDesc());
01319             }
01320             return null;
01321         }
01322     }
01323 
01330     public static Rar getRar(String jndiName) {
01331         synchronized (jndiName2RA) {
01332             Rar ra = (Rar) jndiName2RA.get(jndiName);
01333             return (ra);
01334         }
01335     }
01336 
01343     public static Object getResourceObject(String jndiName) {
01344         Rar ra = null;
01345         synchronized (jndiName2RA) {
01346             ra = (Rar) jndiName2RA.get(jndiName);
01347         }
01348         if (ra != null) {
01349             return (ra.getFactory(jndiName));
01350         }
01351         Object fact = null;
01352         synchronized (jndiName2Factory) {
01353             fact = jndiName2Factory.get(jndiName);
01354         }
01355         return fact;
01356     }
01357 
01358     /* Private Methods
01359      *
01360      */
01361 
01365     private Properties buildProp(ConfigPropertyDesc [] cfgRaJonas) {
01366       Properties ret = new Properties();
01367       if (cfgRaJonas != null) {
01368           for (int i = 0; i < cfgRaJonas.length; i++) {
01369               String val = cfgRaJonas[i].getConfigPropertyValue() != null ?
01370                                      cfgRaJonas[i].getConfigPropertyValue() : "";
01371               ret.setProperty(cfgRaJonas[i].getConfigPropertyName(), val);
01372             }
01373       }
01374       return ret;
01375     }
01376 
01385     private void extractJars(String resFileName, JonasConnectorDesc jonasConn)
01386                  throws ResourceServiceException {
01387 
01388         String jarPath = ResourceServiceImpl.WORK_RARS_DIR + File.separator + "jonas" + File.separator;
01389         String binPath = null;
01390         if (jonasConn.getNativeLib() != null  && jonasConn.getNativeLib().trim().length() > 0) {
01391             binPath = jonasConn.getNativeLib().trim() + File.separator;
01392             if (binPath.startsWith("/") || binPath.startsWith("\\")
01393                 || binPath.charAt(1) == ':') {
01394                 ;
01395             } else {
01396                 binPath = ResourceServiceImpl.JONAS_BASE + File.separator + binPath;
01397             }
01398 
01399         }
01400 
01401         //Get RAR name
01402         String rarName = resFileName;
01403         if (rarName.endsWith(".rar")) {
01404             rarName = resFileName.substring(0, resFileName.lastIndexOf('.'));
01405         }
01406 
01407         int off = rarName.lastIndexOf(File.separator);
01408         rarName = rarName.substring(++off);
01409         if (File.separatorChar == '\\') {
01410             off = rarName.lastIndexOf("/");
01411             rarName = rarName.substring(++off);
01412         }
01413 
01414         JJarFile jjar = null;
01415 
01416         try {
01417             jjar = new JJarFile(resFileName);
01418             for (Enumeration ent = jjar.entries(); ent.hasMoreElements();) {
01419                 JarEntry je = (JarEntry) ent.nextElement();
01420                 if (!je.isDirectory() && je.getName().endsWith(".jar")) {
01421                     File newd = new File(jarPath);
01422                     if (!newd.exists()) {
01423                         newd.mkdirs();
01424                     }
01425 
01426                     String fileName = jarPath + "_" + rarName + "_" + je.getName();
01427                     jjar.extract(je, fileName);
01428                     ((org.objectweb.jonas.server.JClassLoader) curLoader).addURL((new File(fileName)).toURL());
01429                 } else if (!je.isDirectory() && !je.getName().startsWith("META-INF")
01430                             && binPath != null) {
01431                     File newf = new File(binPath);
01432                     if (!newf.exists()) {
01433                         newf.mkdirs();
01434                     }
01435                     String fileName = binPath + je.getName();
01436                     jjar.extract(je, fileName);
01437                 }
01438             }
01439         } catch (Exception ex) {
01440             String err = "Error while extracting the files from " + resFileName;
01441             logger.log(BasicLevel.ERROR, err + ex.getMessage());
01442             throw new ResourceServiceException(err, ex);
01443         }
01444 
01445     }
01446 
01453     private Object getConfigObject(String jndiName) {
01454         Rar ra = null;
01455         synchronized (jndiName2RA) {
01456             ra = (Rar) jndiName2RA.get(jndiName);
01457         }
01458         if (ra != null) {
01459             return (ra.getConfigObj(jndiName));
01460         }
01461         return null;
01462     }
01463 
01470     private String getXmlContent(String jndiName) {
01471         synchronized (jndiName2RA) {
01472             Rar rar = (Rar) jndiName2RA.get(jndiName);
01473             if (rar != null) {
01474                 return (rar.getXmlContent());
01475             }
01476             return null;
01477         }
01478     }
01479 
01480     private void processJAO(String rarFilename, AdminobjectDesc aObj, JonasAdminobjectDesc jao, 
01481                             ConfigPropertyDesc [] cfgRaJonas, int idOff) throws Exception {
01482 
01483         ConfigObj cObj = null;
01484         String jndiName = jao.getJndiName();
01485         if (jndiName == null || jndiName.length() == 0) {
01486             logger.log(BasicLevel.ERROR,
01487                   "Rar: jndi-name not set in jonas-ra.xml for Adminobject: " + idOff);
01488             throw new Exception("configuration file incorrect");
01489         }
01490 
01491         // Instantiate into the currect loader
01492         String admObj = aObj.getAdminobjectClass();
01493         Class aoClass = curLoader.loadClass(admObj);
01494         Object ao = aoClass.newInstance();
01495 
01496         ru.processSetters(aoClass, ao, rarFileName, cfgRaJonas);
01497 
01498         jndinames.add(jndiName);
01499         logger.log(BasicLevel.DEBUG, "jndiName=" + jndiName);
01500 
01501         // Add entry to list of configured objects
01502         cObj = new ConfigObj(JAO, idOff, jndiName, rarFileName, aObj.getAdminobjectInterface(), admObj, ao);
01503 
01504         cfgObjs.put(jndiName, cObj);
01505         //
01506         // Register into Jndi
01507         try {
01508             ictx.rebind(jndiName, ao);
01509 
01510         } catch (Exception e) {
01511             logger.log(BasicLevel.ERROR, "Rar: Cannot register ResourceAdapter with the name "
01512                                          + jndiName);
01513             logger.log(BasicLevel.ERROR, "Rar: Exception caught : " + e);
01514             return;
01515         }
01516 
01517         // --------------------------
01518         // Register MBeans cf. JSR 77
01519         // --------------------------
01520         if (mbeanServer != null) {
01521 
01522             // Available Adminobjects
01523             // ------------------------------------------------------------
01524             // Adminobject MBean
01525             // -----------------------
01526             String jcaAdminobjectName = jndiName;
01527             ObjectName onJCAAdminobject =
01528                 J2eeObjectName.getJCAAdminObject(jDomain,
01529                                                  JCAResourceName,
01530                                                  jServer,
01531                                                  jcaAdminobjectName);
01532             JCAAdminObject jcaAdminobjectMBean = new JCAAdminObject(onJCAAdminobject.toString());
01533             ManagedBean oManaged = oRegistry.findManagedBean("JCAAdminObject");
01534             ModelMBean oMBean = oManaged.createMBean(jcaAdminobjectMBean);
01535             if (manageLogger.isLoggable(BasicLevel.DEBUG)) {
01536                 manageLogger.log(BasicLevel.DEBUG, "JCAAdminObject created");
01537             }
01538             mbeanServer.registerMBean(oMBean, onJCAAdminobject);
01539 
01540             // Update the list of connection factories in the JCAResource MBean with the JCAConnectionFactory
01541             // MBean's OBJECT_NAME
01542             jcaResourceMBean.setAdminObjects(onJCAAdminobject.toString());
01543 
01544         } // end JMX registration
01545 
01546     }
01547 
01548     private void processJAS(String rarFilename, MessagelistenerDesc mlst, JonasActivationspecDesc jas, 
01549                              int idOff) throws Exception {
01550 
01551         ConfigObj cObj = null;
01552         String jndiName = jas.getJndiName();
01553         if (jndiName == null || jndiName.length() == 0) {
01554             logger.log(BasicLevel.ERROR,
01555                 "Rar: jndi-name not set in jonas-ra.xml for Activationspec: " + idOff);
01556             throw new Exception("configuration file incorrect");
01557         }
01558 
01559         // Instantiate into the currect loader
01560         String mlIntf = mlst.getMessagelistenerType();
01561         String actSpec = mlst.getActivationspecDesc().getActivationspecClass();
01562         Class asClass = curLoader.loadClass(actSpec);
01563         ActivationSpec as =
01564             (ActivationSpec) asClass.newInstance();
01565 
01566         jndinames.add(jndiName);
01567         logger.log(BasicLevel.DEBUG, "jndiName=" + jndiName);
01568 
01569         // Add entry to list of configured objects
01570         cObj = new ConfigObj(JAS, idOff, jndiName, rarFilename, mlIntf, actSpec, as);
01571         cObj.reqConfigProps = mlst.getActivationspecDesc().getRequiredConfigPropertyList();
01572         if (jas.getDefaultAS() != null && jas.getDefaultAS().equals("true")) {
01573             cObj.defaultAS = true;
01574             addDefaultAS(jndiName);
01575         }
01576 
01577         cfgObjs.put(jndiName, cObj);
01578         //
01579         // Register into Jndi
01580         try {
01581             ictx.rebind(jndiName, as);
01582 
01583         } catch (Exception e) {
01584             logger.log(BasicLevel.ERROR, "Rar.processJAS: Cannot register ResourceAdapter with the name " + jndiName);
01585             logger.log(BasicLevel.ERROR, "Rar.processJAS: Exception caught : " + e);
01586             return;
01587         }
01588 
01589         // --------------------------
01590         // Register MBeans cf. JSR 77
01591         // --------------------------
01592         if (mbeanServer != null) {
01593 
01594             // Available ActivationSpecs
01595             // ------------------------------------------------------------
01596             // ActivationSpec MBean
01597             // -----------------------
01598             String jcaActivationSpecName = jndiName;
01599             ObjectName onJCAActivationSpec =
01600                 J2eeObjectName.getJCAActivationSpec(jDomain,
01601                                                        JCAResourceName,
01602                                                        jServer,
01603                                                        jcaActivationSpecName);
01604             JCAActivationSpec jcaActivationSpecMBean = new JCAActivationSpec(onJCAActivationSpec.toString());
01605             ManagedBean oManaged = oRegistry.findManagedBean("JCAActivationSpec");
01606             ModelMBean oMBean = oManaged.createMBean(jcaActivationSpecMBean);
01607             if (manageLogger.isLoggable(BasicLevel.DEBUG)) {
01608                 manageLogger.log(BasicLevel.DEBUG, "JCAActivationSpec created");
01609             }
01610             mbeanServer.registerMBean(oMBean, onJCAActivationSpec);
01611 
01612             // Update the list of connection factories in the JCAResource MBean with the JCAConnectionFactory
01613             // MBean's OBJECT_NAME
01614             jcaResourceMBean.setActivationSpecs(onJCAActivationSpec.toString());
01615 
01616         } // end JMX registration
01617 
01618     }
01619 
01620 }
01621 
01622 

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