[exo-jcr-commits] exo-jcr SVN: r5774 - in kernel/branches/2.3.6-GA-JBAS7: exo.kernel.commons/src/main/java/org/exoplatform/services/log/impl and 11 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Sat Mar 3 07:27:02 EST 2012


Author: tolusha
Date: 2012-03-03 07:27:01 -0500 (Sat, 03 Mar 2012)
New Revision: 5774

Modified:
   kernel/branches/2.3.6-GA-JBAS7/exo.kernel.commons/src/main/java/org/exoplatform/commons/utils/Tools.java
   kernel/branches/2.3.6-GA-JBAS7/exo.kernel.commons/src/main/java/org/exoplatform/services/log/impl/Log4JConfigurator.java
   kernel/branches/2.3.6-GA-JBAS7/exo.kernel.component.cache/src/main/java/org/exoplatform/services/cache/impl/CacheServiceImpl.java
   kernel/branches/2.3.6-GA-JBAS7/exo.kernel.component.common/src/main/java/org/exoplatform/services/scheduler/CronJob.java
   kernel/branches/2.3.6-GA-JBAS7/exo.kernel.component.common/src/main/java/org/exoplatform/services/scheduler/PeriodJob.java
   kernel/branches/2.3.6-GA-JBAS7/exo.kernel.container/src/main/java/org/exoplatform/container/ConcurrentPicoContainer.java
   kernel/branches/2.3.6-GA-JBAS7/exo.kernel.container/src/main/java/org/exoplatform/container/jmx/MX4JComponentAdapter.java
   kernel/branches/2.3.6-GA-JBAS7/exo.kernel.container/src/main/java/org/exoplatform/container/monitor/jvm/J2EEServerInfo.java
   kernel/branches/2.3.6-GA-JBAS7/exo.kernel.container/src/main/java/org/exoplatform/container/util/ContainerUtil.java
   kernel/branches/2.3.6-GA-JBAS7/exo.kernel.container/src/main/java/org/exoplatform/container/xml/ObjectParam.java
   kernel/branches/2.3.6-GA-JBAS7/exo.kernel.container/src/main/java/org/exoplatform/services/log/LogConfigurationInitializer.java
   kernel/branches/2.3.6-GA-JBAS7/exo.kernel.container/src/main/java/org/exoplatform/xml/object/XMLCollection.java
   kernel/branches/2.3.6-GA-JBAS7/exo.kernel.container/src/main/java/org/exoplatform/xml/object/XMLMap.java
   kernel/branches/2.3.6-GA-JBAS7/exo.kernel.container/src/main/java/org/exoplatform/xml/object/XMLObject.java
   kernel/branches/2.3.6-GA-JBAS7/exo.kernel.container/src/test/java/org/exoplatform/container/TestExoContainer.java
   kernel/branches/2.3.6-GA-JBAS7/exo.kernel.container/src/test/resources/org/exoplatform/container/test-exo-container.xml
Log:
EXOJCR-1777: applied patches

Modified: kernel/branches/2.3.6-GA-JBAS7/exo.kernel.commons/src/main/java/org/exoplatform/commons/utils/Tools.java
===================================================================
--- kernel/branches/2.3.6-GA-JBAS7/exo.kernel.commons/src/main/java/org/exoplatform/commons/utils/Tools.java	2012-03-03 12:24:05 UTC (rev 5773)
+++ kernel/branches/2.3.6-GA-JBAS7/exo.kernel.commons/src/main/java/org/exoplatform/commons/utils/Tools.java	2012-03-03 12:27:01 UTC (rev 5774)
@@ -18,6 +18,9 @@
  */
 package org.exoplatform.commons.utils;
 
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Map;
@@ -31,7 +34,13 @@
  */
 public class Tools
 {
+
    /**
+    * The logger
+    */
+   private static final Log LOG = ExoLogger.getLogger("org.exoplatform.commons.utils.Tools");
+   
+   /**
     * All the time zones already registered
     */
    private static volatile Map<String, TimeZone> TIME_ZONES = new HashMap<String, TimeZone>();
@@ -191,4 +200,178 @@
       }
       return tz;
    }
+
+   /**
+    * Loads the class using the ClassLoader corresponding to the caller object first, 
+    * if class not found we try with Thread's context ClassLoader (TCCL).
+    * If the TCCL doesn't exist or the class still cannot be found, we use the 
+    * System class loader.
+    *
+    * @param type FQN of class to load
+    * @param callerObject the object from which we want to load the class
+    * @return Loaded class
+    * @throws ClassNotFoundException
+    */
+   public static Class<?> forName(String type, Object callerObject) throws ClassNotFoundException
+   {
+      return forName(type, callerObject.getClass());
+   }
+   
+   /**
+    * Loads the class using the ClassLoader corresponding to the caller class first, 
+    * if class not found we try with Thread's context ClassLoader (TCCL).
+    * If the TCCL doesn't exist or the class still cannot be found, we use the 
+    * System class loader.
+    *
+    * @param type FQN of class to load
+    * @param callerClass the class from which we want to load the class
+    * @return Loaded class
+    * @throws ClassNotFoundException
+    */
+   public static Class<?> forName(String type, Class<?> callerClass) throws ClassNotFoundException
+   {
+      try
+      {
+         // We first try with the local class loader
+         return Class.forName(type, true, callerClass.getClassLoader());
+      }
+      catch (ClassNotFoundException e)
+      {
+         if (LOG.isTraceEnabled())
+         {
+            LOG.trace("The class " + type + " could not be found in the Class loader of " + callerClass);
+         }
+         // Then we try with the Thread Context Class loader
+         ClassLoader cl = Thread.currentThread().getContextClassLoader();
+         try
+         {
+            if (cl != null)
+            {
+               return Class.forName(type, true, cl);
+            }
+            else if (LOG.isTraceEnabled())
+            {
+               LOG.trace("No thread context Class loader could be found to load the class " + type);
+            }
+         }
+         catch (ClassNotFoundException e1)
+         {
+            // ignore me
+            if (LOG.isTraceEnabled())
+            {
+               LOG.trace("The class " + type + " could not be found in the thread context Class loader");
+            }
+            cl = null;
+         }
+         // Finally we test with the system class loader
+         try
+         {
+            cl = ClassLoader.getSystemClassLoader();
+         }
+         catch (Exception e1)
+         {
+            // ignore me
+            if (LOG.isTraceEnabled())
+            {
+               LOG.trace("The system Class loader could not be found to load the class " + type, e1);
+            }
+         }
+         if (cl != null)
+         {
+            return Class.forName(type, true, cl);            
+         }
+         else if (LOG.isTraceEnabled())
+         {
+            LOG.trace("The system Class loader could not be found to load the class " + type);
+         }
+         throw e;
+      }
+   }
+
+   /**
+    * Loads the class using the ClassLoader corresponding to the caller object first, 
+    * if class not found we try with Thread's context ClassLoader (TCCL).
+    * If the TCCL doesn't exist or the class still cannot be found, we use the 
+    * System class loader.
+    *
+    * @param type FQN of class to load
+    * @param callerObject the object from which we want to load the class
+    * @return Loaded class
+    * @throws ClassNotFoundException
+    */
+   public static Class<?> loadClass(String type, Object callerObject) throws ClassNotFoundException
+   {
+      return loadClass(type, callerObject.getClass());
+   }
+   
+   /**
+    * Loads the class using the ClassLoader corresponding to the caller class first, 
+    * if class not found we try with Thread's context ClassLoader (TCCL).
+    * If the TCCL doesn't exist or the class still cannot be found, we use the 
+    * System class loader.
+    *
+    * @param type FQN of class to load
+    * @param callerClass the class from which we want to load the class
+    * @return Loaded class
+    * @throws ClassNotFoundException
+    */
+   public static Class<?> loadClass(String type, Class<?> callerClass) throws ClassNotFoundException
+   {
+      ClassLoader localCl = callerClass.getClassLoader();
+      try
+      {
+         return localCl.loadClass(type);
+      }
+      catch (ClassNotFoundException e)
+      {
+         if (LOG.isTraceEnabled())
+         {
+            LOG.trace("The class " + type + " could not be found in the Class loader of " + callerClass);
+         }
+         // Then we try with the Thread Context Class loader
+         ClassLoader cl = Thread.currentThread().getContextClassLoader();
+         try
+         {
+            if (cl != null)
+            {
+               return cl.loadClass(type);
+            }
+            else if (LOG.isTraceEnabled())
+            {
+               LOG.trace("No thread context Class loader could be found to load the class " + type);
+            }
+         }
+         catch (ClassNotFoundException e1)
+         {
+            // ignore me
+            if (LOG.isTraceEnabled())
+            {
+               LOG.trace("The class " + type + " could not be found in the thread context Class loader");
+            }
+            cl = null;
+         }
+         // Finally we test with the system class loader
+         try
+         {
+            cl = ClassLoader.getSystemClassLoader();
+         }
+         catch (Exception e1)
+         {
+            // ignore me
+            if (LOG.isTraceEnabled())
+            {
+               LOG.trace("The system Class loader could not be found to load the class " + type, e1);
+            }
+         }
+         if (cl != null)
+         {
+            return cl.loadClass(type);          
+         }
+         else if (LOG.isTraceEnabled())
+         {
+            LOG.trace("The system Class loader could not be found to load the class " + type);
+         }
+         throw e;        
+      }
+   }   
 }

Modified: kernel/branches/2.3.6-GA-JBAS7/exo.kernel.commons/src/main/java/org/exoplatform/services/log/impl/Log4JConfigurator.java
===================================================================
--- kernel/branches/2.3.6-GA-JBAS7/exo.kernel.commons/src/main/java/org/exoplatform/services/log/impl/Log4JConfigurator.java	2012-03-03 12:24:05 UTC (rev 5773)
+++ kernel/branches/2.3.6-GA-JBAS7/exo.kernel.commons/src/main/java/org/exoplatform/services/log/impl/Log4JConfigurator.java	2012-03-03 12:27:01 UTC (rev 5774)
@@ -19,6 +19,7 @@
 package org.exoplatform.services.log.impl;
 
 import org.exoplatform.commons.utils.SecurityHelper;
+import org.exoplatform.commons.utils.Tools;
 import org.exoplatform.services.log.AbstractLogConfigurator;
 
 import java.lang.reflect.Method;
@@ -43,7 +44,7 @@
          {
             try
             {
-               Class<?> propertyConfiguratorClass = Class.forName("org.apache.log4j.PropertyConfigurator");
+               Class<?> propertyConfiguratorClass = Tools.forName("org.apache.log4j.PropertyConfigurator", Log4JConfigurator.class);
                Method m = propertyConfiguratorClass.getMethod("configure", Properties.class);
                m.invoke(null, properties);
             }

Modified: kernel/branches/2.3.6-GA-JBAS7/exo.kernel.component.cache/src/main/java/org/exoplatform/services/cache/impl/CacheServiceImpl.java
===================================================================
--- kernel/branches/2.3.6-GA-JBAS7/exo.kernel.component.cache/src/main/java/org/exoplatform/services/cache/impl/CacheServiceImpl.java	2012-03-03 12:24:05 UTC (rev 5773)
+++ kernel/branches/2.3.6-GA-JBAS7/exo.kernel.component.cache/src/main/java/org/exoplatform/services/cache/impl/CacheServiceImpl.java	2012-03-03 12:27:01 UTC (rev 5774)
@@ -18,6 +18,7 @@
  */
 package org.exoplatform.services.cache.impl;
 
+import org.exoplatform.commons.utils.Tools;
 import org.exoplatform.container.component.ComponentPlugin;
 import org.exoplatform.container.xml.InitParams;
 import org.exoplatform.management.annotations.ManagedBy;
@@ -47,6 +48,7 @@
  * Created by The eXo Platform SAS. Author : Tuan Nguyen
  * tuan08 at users.sourceforge.net Sat, Sep 13, 2003 @ Time: 1:12:22 PM
  */
+ at SuppressWarnings("deprecation")
 @ManagedBy(CacheServiceManaged.class)
 public class CacheServiceImpl implements CacheService
 {
@@ -175,9 +177,8 @@
          // we assume that we expect to use the default cache factory
          try
          {
-            final ClassLoader cl = Thread.currentThread().getContextClassLoader();
             // We check if the given implementation is a known class
-            Class implClass = cl.loadClass(safeConfig.getImplementation());            
+            Class<?> implClass = Tools.loadClass(safeConfig.getImplementation(), this); 
             // Implementation is an existing class
             if (ExoCache.class.isAssignableFrom(implClass))
             {
@@ -259,6 +260,7 @@
       /**
        * {@inheritDoc}
        */
+      @SuppressWarnings({"rawtypes", "unchecked"})
       public ExoCache createCache(ExoCacheConfig config) throws ExoCacheInitException
       {
          final ExoCache simple = createCacheInstance(config);
@@ -266,11 +268,6 @@
          simple.setLabel(config.getLabel());
          simple.setMaxSize(config.getMaxSize());
          simple.setLiveTime(config.getLiveTime());
-         //       simple.setReplicated(config.isRepicated());
-         //       simple.setDistributed(config.isDistributed());
-         //       if (simple.isDistributed()) {
-         //         simple.addCacheListener(distrbutedListener_);
-         //       }
          simple.setLogEnabled(config.isLogEnabled());
          if (simple.isLogEnabled())
          {
@@ -285,7 +282,7 @@
        * @return a new instance of ExoCache
        * @throws ExoCacheInitException if any exception happens while initializing the cache
        */
-      @SuppressWarnings("unchecked")
+      @SuppressWarnings("rawtypes")
       private ExoCache createCacheInstance(ExoCacheConfig config) throws ExoCacheInitException
       {
          if (config.getImplementation() == null)
@@ -296,10 +293,9 @@
          else
          {
             // An implementation has been defined
-            final ClassLoader cl = Thread.currentThread().getContextClassLoader();
             try
             {
-               final Class clazz = cl.loadClass(config.getImplementation());
+               final Class<?> clazz = Tools.loadClass(config.getImplementation(), this);
                return (ExoCache)clazz.newInstance();
             }
             catch (ExceptionInInitializerError e)

Modified: kernel/branches/2.3.6-GA-JBAS7/exo.kernel.component.common/src/main/java/org/exoplatform/services/scheduler/CronJob.java
===================================================================
--- kernel/branches/2.3.6-GA-JBAS7/exo.kernel.component.common/src/main/java/org/exoplatform/services/scheduler/CronJob.java	2012-03-03 12:24:05 UTC (rev 5773)
+++ kernel/branches/2.3.6-GA-JBAS7/exo.kernel.component.common/src/main/java/org/exoplatform/services/scheduler/CronJob.java	2012-03-03 12:27:01 UTC (rev 5774)
@@ -19,6 +19,7 @@
 package org.exoplatform.services.scheduler;
 
 import org.exoplatform.commons.utils.ExoProperties;
+import org.exoplatform.commons.utils.Tools;
 import org.exoplatform.container.component.BaseComponentPlugin;
 import org.exoplatform.container.xml.InitParams;
 import org.quartz.JobDataMap;
@@ -42,7 +43,7 @@
       String jobName = props.getProperty("jobName");
       String jobGroup = props.getProperty("groupName");
       String jobClass = props.getProperty("job");
-      Class clazz = Class.forName(jobClass);
+      Class<?> clazz = Tools.forName(jobClass, this);
       jinfo_ = new JobInfo(jobName, jobGroup, clazz);
 
       expression_ = props.getProperty("expression");

Modified: kernel/branches/2.3.6-GA-JBAS7/exo.kernel.component.common/src/main/java/org/exoplatform/services/scheduler/PeriodJob.java
===================================================================
--- kernel/branches/2.3.6-GA-JBAS7/exo.kernel.component.common/src/main/java/org/exoplatform/services/scheduler/PeriodJob.java	2012-03-03 12:24:05 UTC (rev 5773)
+++ kernel/branches/2.3.6-GA-JBAS7/exo.kernel.component.common/src/main/java/org/exoplatform/services/scheduler/PeriodJob.java	2012-03-03 12:27:01 UTC (rev 5774)
@@ -19,6 +19,7 @@
 package org.exoplatform.services.scheduler;
 
 import org.exoplatform.commons.utils.ExoProperties;
+import org.exoplatform.commons.utils.Tools;
 import org.exoplatform.container.component.BaseComponentPlugin;
 import org.exoplatform.container.xml.InitParams;
 import org.quartz.JobDataMap;
@@ -47,7 +48,7 @@
       String jobName = props.getProperty("jobName");
       String jobGroup = props.getProperty("groupName");
       String jobClass = props.getProperty("job");
-      Class clazz = Class.forName(jobClass);
+      Class<?> clazz = Tools.forName(jobClass, this);
       jinfo_ = new JobInfo(jobName, jobGroup, clazz);
 
       Date startTime = getDate(props.getProperty("startTime"));

Modified: kernel/branches/2.3.6-GA-JBAS7/exo.kernel.container/src/main/java/org/exoplatform/container/ConcurrentPicoContainer.java
===================================================================
--- kernel/branches/2.3.6-GA-JBAS7/exo.kernel.container/src/main/java/org/exoplatform/container/ConcurrentPicoContainer.java	2012-03-03 12:24:05 UTC (rev 5773)
+++ kernel/branches/2.3.6-GA-JBAS7/exo.kernel.container/src/main/java/org/exoplatform/container/ConcurrentPicoContainer.java	2012-03-03 12:27:01 UTC (rev 5774)
@@ -413,7 +413,7 @@
       Map<Object, Object> map = depResolutionCtx.get();
       if (map != null)
       {
-         Object result = map.get(componentType);
+         Object result = map.get(componentAdapter.getComponentKey());
          if (result != null)
          {
             return result;

Modified: kernel/branches/2.3.6-GA-JBAS7/exo.kernel.container/src/main/java/org/exoplatform/container/jmx/MX4JComponentAdapter.java
===================================================================
--- kernel/branches/2.3.6-GA-JBAS7/exo.kernel.container/src/main/java/org/exoplatform/container/jmx/MX4JComponentAdapter.java	2012-03-03 12:24:05 UTC (rev 5773)
+++ kernel/branches/2.3.6-GA-JBAS7/exo.kernel.container/src/main/java/org/exoplatform/container/jmx/MX4JComponentAdapter.java	2012-03-03 12:27:01 UTC (rev 5774)
@@ -19,6 +19,7 @@
 package org.exoplatform.container.jmx;
 
 import org.exoplatform.commons.utils.SecurityHelper;
+import org.exoplatform.commons.utils.Tools;
 import org.exoplatform.container.ExoContainer;
 import org.exoplatform.container.component.ComponentLifecycle;
 import org.exoplatform.container.component.ComponentPlugin;
@@ -54,7 +55,7 @@
 
    private Log log = ExoLogger.getLogger("exo.kernel.container.MX4JComponentAdapter");
 
-   public MX4JComponentAdapter(Object key, Class implementation)
+   public MX4JComponentAdapter(Object key, Class<?> implementation)
    {
       super(key, implementation);
    }
@@ -83,7 +84,7 @@
             if (key instanceof String)
                componentKey = (String)key;
             else
-               componentKey = ((Class)key).getName();
+               componentKey = ((Class<?>)key).getName();
             manager = (ConfigurationManager)exocontainer.getComponentInstanceOfType(ConfigurationManager.class);
             component = manager.getComponent(componentKey);
             if (component != null)
@@ -150,11 +151,11 @@
 
          try
          {
-            Class pluginClass = Class.forName(plugin.getType());
+            Class<?> pluginClass = Tools.forName(plugin.getType(), this);
             ComponentPlugin cplugin = (ComponentPlugin)container.createComponent(pluginClass, plugin.getInitParams());
             cplugin.setName(plugin.getName());
             cplugin.setDescription(plugin.getDescription());
-            Class clazz = component.getClass();
+            Class<?> clazz = component.getClass();
 
             final Method m = getSetMethod(clazz, plugin.getSetMethod(), pluginClass);
             if (m == null)
@@ -195,7 +196,7 @@
     * @param pluginClass the {@link Class} of the plugin
     * @return the "set method" corresponding to the given context
     */
-   private Method getSetMethod(Class clazz, String name, Class pluginClass)
+   private Method getSetMethod(Class<?> clazz, String name, Class<?> pluginClass)
    {
       Method[] methods = clazz.getMethods();
       Method bestCandidate = null;
@@ -204,7 +205,7 @@
       {
          if (name.equals(m.getName()))
          {
-            Class[] types = m.getParameterTypes();
+            Class<?>[] types = m.getParameterTypes();
             if (types != null && types.length == 1 && ComponentPlugin.class.isAssignableFrom(types[0]))
             {
                int currentDepth = getClosestMatchDepth(pluginClass, types[0]);
@@ -230,7 +231,7 @@
     * @param type the class from which the plugin must be assignable
     * @return The total amount of times we had to up the hierarchy of the plugin
     */
-   private static int getClosestMatchDepth(Class pluginClass, Class type)
+   private static int getClosestMatchDepth(Class<?> pluginClass, Class<?> type)
    {
       return getClosestMatchDepth(pluginClass, type, 0);
    }
@@ -243,7 +244,7 @@
     * @param depth the current amount of times that we had to up the hierarchy of the plugin
     * @return The total amount of times we had to up the hierarchy of the plugin
     */
-   private static int getClosestMatchDepth(Class pluginClass, Class type, int depth)
+   private static int getClosestMatchDepth(Class<?> pluginClass, Class<?> type, int depth)
    {
       if (pluginClass == null || pluginClass.isAssignableFrom(type))
       {

Modified: kernel/branches/2.3.6-GA-JBAS7/exo.kernel.container/src/main/java/org/exoplatform/container/monitor/jvm/J2EEServerInfo.java
===================================================================
--- kernel/branches/2.3.6-GA-JBAS7/exo.kernel.container/src/main/java/org/exoplatform/container/monitor/jvm/J2EEServerInfo.java	2012-03-03 12:24:05 UTC (rev 5773)
+++ kernel/branches/2.3.6-GA-JBAS7/exo.kernel.container/src/main/java/org/exoplatform/container/monitor/jvm/J2EEServerInfo.java	2012-03-03 12:27:01 UTC (rev 5774)
@@ -18,7 +18,6 @@
  */
 package org.exoplatform.container.monitor.jvm;
 
-import org.exoplatform.commons.utils.PrivilegedSystemHelper;
 import org.exoplatform.commons.utils.SecurityHelper;
 import org.exoplatform.services.log.ExoLogger;
 import org.exoplatform.services.log.Log;
@@ -27,9 +26,7 @@
 import java.lang.management.ManagementFactory;
 import java.lang.reflect.Method;
 import java.net.URI;
-import java.net.URISyntaxException;
 import java.security.PrivilegedAction;
-import java.security.PrivilegedExceptionAction;
 
 import javax.management.MBeanServer;
 
@@ -71,142 +68,139 @@
 
    public J2EEServerInfo()
    {
-
-      String jonasHome = PrivilegedSystemHelper.getProperty("jonas.base");
-      String jbossHome = PrivilegedSystemHelper.getProperty("jboss.home.dir");
-      String jettyHome = PrivilegedSystemHelper.getProperty("jetty.home");
-      String websphereHome = PrivilegedSystemHelper.getProperty("was.install.root");
-      String weblogicHome = PrivilegedSystemHelper.getProperty("wls.home");
-      String glassfishHome = PrivilegedSystemHelper.getProperty("com.sun.aas.instanceRoot");
-      String catalinaHome = PrivilegedSystemHelper.getProperty("catalina.home");
-      String testHome = PrivilegedSystemHelper.getProperty("maven.exoplatform.dir");
-
-      // The name of the configuration directory
-      final String confDirName = PrivilegedSystemHelper.getProperty(EXO_CONF_DIR_NAME_PARAM, "exo-conf");
-      if (jonasHome != null)
+      SecurityHelper.doPrivilegedAction(new PrivilegedAction<Void>()
       {
-         serverName_ = "jonas";
-         serverHome_ = jonasHome;
-      }
-      else if (jbossHome != null)
-      {
-         serverName_ = "jboss";
-         serverHome_ = jbossHome;
-
-         // try find and use jboss.server.config.url
-         // based on http://www.jboss.org/community/docs/DOC-10730
-         String jbossConfigUrl = PrivilegedSystemHelper.getProperty("jboss.server.config.url");
-         if (jbossConfigUrl != null)
+         public Void run()
          {
-            try
+
+            String jonasHome = System.getProperty("jonas.base");
+            String jbossHome = System.getProperty("jboss.home.dir");
+            String jettyHome = System.getProperty("jetty.home");
+            String websphereHome = System.getProperty("was.install.root");
+            String weblogicHome = System.getProperty("wls.home");
+            String glassfishHome = System.getProperty("com.sun.aas.instanceRoot");
+            String catalinaHome = System.getProperty("catalina.home");
+            String testHome = System.getProperty("maven.exoplatform.dir");
+
+            // The name of the configuration directory
+            final String confDirName = System.getProperty(EXO_CONF_DIR_NAME_PARAM, "exo-conf");
+            if (jonasHome != null)
             {
-               exoConfDir_ = new File(new File(new URI(jbossConfigUrl)), confDirName).getAbsolutePath();
+               serverName_ = "jonas";
+               serverHome_ = jonasHome;
             }
-            catch (SecurityException e)
+            else if (jbossHome != null)
             {
-               if (LOG.isTraceEnabled())
+               serverName_ = "jboss";
+               serverHome_ = jbossHome;
+
+               // try find and use jboss.server.config.url
+               // based on http://www.jboss.org/community/docs/DOC-10730
+               String jbossConfigUrl = System.getProperty("jboss.server.config.url");
+               if (jbossConfigUrl != null)
                {
-                  LOG.trace("An exception occurred: " + e.getMessage());
+                  try
+                  {
+                     exoConfDir_ = new File(new File(new URI(jbossConfigUrl)), confDirName).getAbsolutePath();
+                  }
+                  catch (Throwable e)
+                  {
+                     // don't care about it
+                  }
                }
-            }
-            catch (URISyntaxException e)
-            {
-               if (LOG.isTraceEnabled())
+               else
                {
-                  LOG.trace("An exception occurred: " + e.getMessage());
+                  // New variable that exists only since JBoss AS 7
+                  String jbossConfigDir = System.getProperty("jboss.server.config.dir");
+                  if (jbossConfigDir != null)
+                  {
+                     try
+                     {
+                        exoConfDir_ = new File(jbossConfigDir, confDirName).getAbsolutePath();
+                     }
+                     catch (Throwable e)
+                     {
+                        // don't care about it
+                     }
+                  }
                }
-            }
-            catch (IllegalArgumentException e)
-            {
-               if (LOG.isTraceEnabled())
+               try
                {
-                  LOG.trace("An exception occurred: " + e.getMessage());
+                  Class<?> clazz =
+                     Thread.currentThread().getContextClassLoader().loadClass("org.jboss.mx.util.MBeanServerLocator");
+                  Method m = clazz.getMethod("locateJBoss");
+                  mbeanServer = (MBeanServer)m.invoke(null);
                }
-            }
-         }
-
-         //
-         try
-         {
-            Class clazz = SecurityHelper.doPrivilegedExceptionAction(new PrivilegedExceptionAction<Class>()
-            {
-               public Class run() throws Exception
+               catch (ClassNotFoundException ignore)
                {
-                  return Thread.currentThread().getContextClassLoader()
-                     .loadClass("org.jboss.mx.util.MBeanServerLocator");
+                  // We assume that JBoss AS 7 or higher is currently used
+                  // since this class has been removed starting from this version
+                  // of JBoss AS
+                  LOG.debug(ignore.getLocalizedMessage(), ignore);
                }
-            });
+               catch (Exception ignore)
+               {
+                  LOG.error(ignore.getLocalizedMessage(), ignore);
+               }
+            }
+            else if (jettyHome != null)
+            {
+               serverName_ = "jetty";
+               serverHome_ = jettyHome;
+            }
+            else if (websphereHome != null)
+            {
+               serverName_ = "websphere";
+               serverHome_ = websphereHome;
+            }
+            else if (weblogicHome != null)
+            {
+               serverName_ = "weblogic";
+               serverHome_ = weblogicHome;
+            }
+            else if (glassfishHome != null)
+            {
+               serverName_ = "glassfish";
+               serverHome_ = glassfishHome;
+            }
+            else if (catalinaHome != null)
+            {
+               // Catalina has to be processed at the end as other servers may embed it
+               serverName_ = "tomcat";
+               serverHome_ = catalinaHome;
+            }
+            else if (testHome != null)
+            {
+               serverName_ = "test";
+               serverHome_ = testHome;
+            }
+            else
+            {
+               // throw new UnsupportedOperationException("unknown server platform") ;
+               serverName_ = "standalone";
+               serverHome_ = System.getProperty("user.dir");
+            }
+            if (exoConfDir_ == null)
+            {
+               exoConfDir_ = serverHome_ + "/" + confDirName;
+            }
+            if (mbeanServer == null)
+            {
+               mbeanServer = ManagementFactory.getPlatformMBeanServer();
+            }
 
-            Method m = clazz.getMethod("locateJBoss");
-            mbeanServer = (MBeanServer)m.invoke(null);
-         }
-         catch (Exception ignore)
-         {
-            LOG.error(ignore.getLocalizedMessage(), ignore);
-         }
-      }
-      else if (jettyHome != null)
-      {
-         serverName_ = "jetty";
-         serverHome_ = jettyHome;
-      }
-      else if (websphereHome != null)
-      {
-         serverName_ = "websphere";
-         serverHome_ = websphereHome;
-      }
-      else if (weblogicHome != null)
-      {
-         serverName_ = "weblogic";
-         serverHome_ = weblogicHome;
-      }
-      else if (glassfishHome != null)
-      {
-         serverName_ = "glassfish";
-         serverHome_ = glassfishHome;
-      }
-      else if (catalinaHome != null)
-      {
-         // Catalina has to be processed at the end as other servers may embed it
-         serverName_ = "tomcat";
-         serverHome_ = catalinaHome;
-      }
-      else if (testHome != null)
-      {
-         serverName_ = "test";
-         serverHome_ = testHome;
-      }
-      else
-      {
-         // throw new UnsupportedOperationException("unknown server platform") ;
-         serverName_ = "standalone";
-         serverHome_ = PrivilegedSystemHelper.getProperty("user.dir");
-      }
-      if (exoConfDir_ == null)
-      {
-         exoConfDir_ = serverHome_ + "/" + confDirName;
-      }
-      if (mbeanServer == null)
-      {
-         mbeanServer = SecurityHelper.doPrivilegedAction(new PrivilegedAction<MBeanServer>()
-         {
-            public MBeanServer run()
+            String exoConfHome = System.getProperty(EXO_CONF_PARAM);
+            if (exoConfHome != null && exoConfHome.length() > 0)
             {
-               return ManagementFactory.getPlatformMBeanServer();
+               LOG.info("Override exo-conf directory '" + exoConfDir_ + "' with location '" + exoConfHome + "'");
+               exoConfDir_ = exoConfHome;
             }
-         });
-      }
 
-      String exoConfHome = PrivilegedSystemHelper.getProperty(EXO_CONF_PARAM);
-      if (exoConfHome != null && exoConfHome.length() > 0)
-      {
-         LOG.info("Override exo-conf directory '" + exoConfDir_ + "' with location '" + exoConfHome
-            + "'");
-         exoConfDir_ = exoConfHome;
-      }
-
-      serverHome_ = serverHome_.replace('\\', '/');
-      exoConfDir_ = exoConfDir_.replace('\\', '/');
+            serverHome_ = serverHome_.replace('\\', '/');
+            exoConfDir_ = exoConfDir_.replace('\\', '/');
+            return null;
+         }
+      });
    }
 
    /**

Modified: kernel/branches/2.3.6-GA-JBAS7/exo.kernel.container/src/main/java/org/exoplatform/container/util/ContainerUtil.java
===================================================================
--- kernel/branches/2.3.6-GA-JBAS7/exo.kernel.container/src/main/java/org/exoplatform/container/util/ContainerUtil.java	2012-03-03 12:24:05 UTC (rev 5773)
+++ kernel/branches/2.3.6-GA-JBAS7/exo.kernel.container/src/main/java/org/exoplatform/container/util/ContainerUtil.java	2012-03-03 12:27:01 UTC (rev 5774)
@@ -132,7 +132,7 @@
    {
       try
       {
-         Class clazz = Class.forName(plugin.getType());
+         Class<?> clazz = Tools.forName(plugin.getType(), ContainerUtil.class);
          org.exoplatform.container.ContainerLifecyclePlugin cplugin =
             (org.exoplatform.container.ContainerLifecyclePlugin)container
                .createComponent(clazz, plugin.getInitParams());
@@ -146,17 +146,16 @@
       }
    }
 
-   static public void addComponentLifecyclePlugin(ExoContainer container, ConfigurationManager conf)
+   public static void addComponentLifecyclePlugin(ExoContainer container, ConfigurationManager conf)
    {
       Collection plugins = conf.getConfiguration().getComponentLifecyclePlugins();
       Iterator i = plugins.iterator();
-      ClassLoader loader = Thread.currentThread().getContextClassLoader();
       while (i.hasNext())
       {
          ComponentLifecyclePlugin plugin = (ComponentLifecyclePlugin)i.next();
          try
          {
-            Class classType = loader.loadClass(plugin.getType());
+            Class<?> classType = Tools.loadClass(plugin.getType(), ContainerUtil.class);
             org.exoplatform.container.component.ComponentLifecyclePlugin instance =
                (org.exoplatform.container.component.ComponentLifecyclePlugin)classType.newInstance();
             container.addComponentLifecylePlugin(instance);
@@ -168,13 +167,12 @@
       }
    }
 
-   static public void addComponents(ExoContainer container, ConfigurationManager conf)
+   public static void addComponents(ExoContainer container, ConfigurationManager conf)
    {
       Collection components = conf.getComponents();
       if (components == null)
          return;
       Iterator i = components.iterator();
-      ClassLoader loader = Thread.currentThread().getContextClassLoader();
       while (i.hasNext())
       {
          Component component = (Component)i.next();
@@ -182,7 +180,7 @@
          String key = component.getKey();
          try
          {
-            Class classType = loader.loadClass(type);
+            Class<?> classType = Tools.loadClass(type, ContainerUtil.class);
             if (key == null)
             {
                if (component.isMultiInstance())
@@ -199,7 +197,7 @@
             {
                try
                {
-                  Class keyType = loader.loadClass(key);
+                  Class<?> keyType = Tools.loadClass(key, ContainerUtil.class);
                   if (component.isMultiInstance())
                   {
                      container.registerComponent(new ConstructorInjectionComponentAdapter(keyType, classType));
@@ -314,5 +312,5 @@
          }
       }
       return props;
-   }
+   }   
 }

Modified: kernel/branches/2.3.6-GA-JBAS7/exo.kernel.container/src/main/java/org/exoplatform/container/xml/ObjectParam.java
===================================================================
--- kernel/branches/2.3.6-GA-JBAS7/exo.kernel.container/src/main/java/org/exoplatform/container/xml/ObjectParam.java	2012-03-03 12:24:05 UTC (rev 5773)
+++ kernel/branches/2.3.6-GA-JBAS7/exo.kernel.container/src/main/java/org/exoplatform/container/xml/ObjectParam.java	2012-03-03 12:27:01 UTC (rev 5774)
@@ -19,6 +19,7 @@
 package org.exoplatform.container.xml;
 
 import org.apache.commons.beanutils.PropertyUtils;
+import org.exoplatform.commons.utils.Tools;
 import org.exoplatform.services.log.ExoLogger;
 import org.exoplatform.services.log.Log;
 
@@ -83,7 +84,7 @@
       Property prop = null;
       try
       {
-         Class clazz = Class.forName(type);
+         Class<?> clazz = Tools.forName(type, this);
          object_ = clazz.newInstance();
          for (int i = 0; i < properties_.size(); i++)
          {
@@ -157,7 +158,7 @@
             fullName.append(".");
             fullName.append(className);
 
-            Class clazz = Class.forName(fullName.toString());
+            Class clazz = Tools.forName(fullName.toString(), this);
             return clazz.newInstance();
          }
       }

Modified: kernel/branches/2.3.6-GA-JBAS7/exo.kernel.container/src/main/java/org/exoplatform/services/log/LogConfigurationInitializer.java
===================================================================
--- kernel/branches/2.3.6-GA-JBAS7/exo.kernel.container/src/main/java/org/exoplatform/services/log/LogConfigurationInitializer.java	2012-03-03 12:24:05 UTC (rev 5773)
+++ kernel/branches/2.3.6-GA-JBAS7/exo.kernel.container/src/main/java/org/exoplatform/services/log/LogConfigurationInitializer.java	2012-03-03 12:27:01 UTC (rev 5774)
@@ -18,6 +18,7 @@
  */
 package org.exoplatform.services.log;
 
+import org.exoplatform.commons.utils.Tools;
 import org.exoplatform.container.xml.InitParams;
 import org.exoplatform.container.xml.PropertiesParam;
 import org.exoplatform.container.xml.ValueParam;
@@ -167,7 +168,7 @@
       Properties props;
       if (configurer != null && properties != null)
       {
-         LogConfigurator conf = (LogConfigurator)Class.forName(configurer).newInstance();
+         LogConfigurator conf = (LogConfigurator)Tools.forName(configurer, this).newInstance();
          props = new Properties();
          props.putAll(properties);
          conf.configure(props);

Modified: kernel/branches/2.3.6-GA-JBAS7/exo.kernel.container/src/main/java/org/exoplatform/xml/object/XMLCollection.java
===================================================================
--- kernel/branches/2.3.6-GA-JBAS7/exo.kernel.container/src/main/java/org/exoplatform/xml/object/XMLCollection.java	2012-03-03 12:24:05 UTC (rev 5773)
+++ kernel/branches/2.3.6-GA-JBAS7/exo.kernel.container/src/main/java/org/exoplatform/xml/object/XMLCollection.java	2012-03-03 12:27:01 UTC (rev 5774)
@@ -18,6 +18,7 @@
  */
 package org.exoplatform.xml.object;
 
+import org.exoplatform.commons.utils.Tools;
 import org.jibx.runtime.IBindingFactory;
 import org.jibx.runtime.IMarshallingContext;
 import org.jibx.runtime.IUnmarshallingContext;
@@ -70,7 +71,7 @@
 
    public Collection getCollection() throws Exception
    {
-      Class clazz = Class.forName(type_);
+      Class<?> clazz = Tools.forName(type_, this);
       Collection collection = (Collection)clazz.newInstance();
       for (int i = 0; i < list_.size(); i++)
       {

Modified: kernel/branches/2.3.6-GA-JBAS7/exo.kernel.container/src/main/java/org/exoplatform/xml/object/XMLMap.java
===================================================================
--- kernel/branches/2.3.6-GA-JBAS7/exo.kernel.container/src/main/java/org/exoplatform/xml/object/XMLMap.java	2012-03-03 12:24:05 UTC (rev 5773)
+++ kernel/branches/2.3.6-GA-JBAS7/exo.kernel.container/src/main/java/org/exoplatform/xml/object/XMLMap.java	2012-03-03 12:27:01 UTC (rev 5774)
@@ -18,6 +18,8 @@
  */
 package org.exoplatform.xml.object;
 
+import org.exoplatform.commons.utils.Tools;
+
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.Map;
@@ -73,7 +75,7 @@
 
    public Map getMap() throws Exception
    {
-      Class clazz = Class.forName(type_);
+      Class<?> clazz = Tools.forName(type_, this);
       Map map = (Map)clazz.newInstance();
       for (int i = 0; i < listmap.size(); i++)
       {

Modified: kernel/branches/2.3.6-GA-JBAS7/exo.kernel.container/src/main/java/org/exoplatform/xml/object/XMLObject.java
===================================================================
--- kernel/branches/2.3.6-GA-JBAS7/exo.kernel.container/src/main/java/org/exoplatform/xml/object/XMLObject.java	2012-03-03 12:24:05 UTC (rev 5773)
+++ kernel/branches/2.3.6-GA-JBAS7/exo.kernel.container/src/main/java/org/exoplatform/xml/object/XMLObject.java	2012-03-03 12:27:01 UTC (rev 5774)
@@ -19,6 +19,7 @@
 package org.exoplatform.xml.object;
 
 import org.exoplatform.commons.utils.SecurityHelper;
+import org.exoplatform.commons.utils.Tools;
 import org.exoplatform.services.log.ExoLogger;
 import org.exoplatform.services.log.Log;
 import org.jibx.runtime.BindingDirectory;
@@ -172,7 +173,7 @@
 
    public Object toObject() throws Exception
    {
-      Class clazz = Class.forName(type);
+      Class<?> clazz = Tools.forName(type, this);
       Map fields = getFields(clazz);
       Object instance = clazz.newInstance();
       Iterator i = fields_.values().iterator();

Modified: kernel/branches/2.3.6-GA-JBAS7/exo.kernel.container/src/test/java/org/exoplatform/container/TestExoContainer.java
===================================================================
--- kernel/branches/2.3.6-GA-JBAS7/exo.kernel.container/src/test/java/org/exoplatform/container/TestExoContainer.java	2012-03-03 12:24:05 UTC (rev 5773)
+++ kernel/branches/2.3.6-GA-JBAS7/exo.kernel.container/src/test/java/org/exoplatform/container/TestExoContainer.java	2012-03-03 12:27:01 UTC (rev 5774)
@@ -18,6 +18,7 @@
 
 import org.exoplatform.commons.utils.PropertyManager;
 import org.exoplatform.container.component.BaseComponentPlugin;
+import org.exoplatform.container.component.ComponentPlugin;
 import org.exoplatform.container.configuration.ConfigurationManager;
 import org.exoplatform.container.jmx.AbstractTestContainer;
 import org.exoplatform.container.support.ContainerBuilder;
@@ -185,6 +186,19 @@
       assertEquals(container.getComponentInstanceOfType(SOE1.class), soe2.soe1);
    }
 
+   public void testStackOverFlow4()
+   {
+      final RootContainer container = createRootContainer("test-exo-container.xml", "testStackOverflowError");
+      MyService ms = (MyService)container.getComponentInstanceOfType(MyService.class);
+      assertNotNull(ms);
+      assertTrue(ms instanceof MyServiceImpl);
+      MyServiceImpl msi = (MyServiceImpl)ms;
+      assertNotNull(msi.componentPlugin);
+      assertTrue(msi.componentPlugin instanceof MyPlugin);
+      MyPlugin mp = (MyPlugin) msi.componentPlugin;
+      assertTrue(mp.svc == ms);
+   }
+   
    public void testCyclicRef()
    {
       final RootContainer container = createRootContainer("test-exo-container.xml", "testCyclicRef");
@@ -1005,4 +1019,44 @@
          this.soe1 = (SOE1)ExoContainerContext.getCurrentContainer().getComponentInstanceOfType(SOE1.class);
       }
    }
+   
+   public static class MyPlugin extends BaseComponentPlugin
+   {
+      MySpecialService svc;
+      
+      public MyPlugin(MySpecialService svc)
+      {
+         this.svc = svc;
+      }
+   }
+   
+   public static interface MyService
+   {
+      public void addPlugin(ComponentPlugin componentPlugin);
+   }
+   
+   public static interface MySpecialService extends MyService
+   {
+   }
+   
+   public static class MyServiceImpl implements MySpecialService, Startable
+   {
+      ComponentPlugin componentPlugin;
+      public MyServiceImpl()
+      {
+      }
+
+      public void addPlugin(ComponentPlugin componentPlugin)
+      {
+         this.componentPlugin = componentPlugin;
+      }
+
+      public void stop()
+      {
+      }
+
+      public void start()
+      {
+      }
+   }
 }

Modified: kernel/branches/2.3.6-GA-JBAS7/exo.kernel.container/src/test/resources/org/exoplatform/container/test-exo-container.xml
===================================================================
--- kernel/branches/2.3.6-GA-JBAS7/exo.kernel.container/src/test/resources/org/exoplatform/container/test-exo-container.xml	2012-03-03 12:24:05 UTC (rev 5773)
+++ kernel/branches/2.3.6-GA-JBAS7/exo.kernel.container/src/test/resources/org/exoplatform/container/test-exo-container.xml	2012-03-03 12:27:01 UTC (rev 5774)
@@ -87,4 +87,18 @@
 	<component profiles="testStartOrder">
 		<type>org.exoplatform.container.TestExoContainer$C2</type>
 	</component>
+   <component profiles="testStackOverflowError">
+      <key>org.exoplatform.container.TestExoContainer$MyService</key>
+      <type>org.exoplatform.container.TestExoContainer$MyServiceImpl</type>
+   </component>
+
+   <external-component-plugins profiles="testStackOverflowError">
+      <target-component>org.exoplatform.container.TestExoContainer$MyService</target-component>
+      <component-plugin>
+         <name>test.plugin</name>
+         <set-method>addPlugin</set-method>
+         <type>org.exoplatform.container.TestExoContainer$MyPlugin</type>
+         <description>User - Ticket Authenticator</description>
+      </component-plugin>
+   </external-component-plugins>   
 </configuration>
\ No newline at end of file



More information about the exo-jcr-commits mailing list