[exo-jcr-commits] exo-jcr SVN: r5417 - in kernel/branches/2.4.x: exo.kernel.commons/src/main/java/org/exoplatform/services/log/impl and 8 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Wed Jan 4 06:37:07 EST 2012


Author: tolusha
Date: 2012-01-04 06:37:05 -0500 (Wed, 04 Jan 2012)
New Revision: 5417

Added:
   kernel/branches/2.4.x/exo.kernel.commons/src/main/java/org/exoplatform/commons/utils/ClassLoading.java
Modified:
   kernel/branches/2.4.x/exo.kernel.commons/src/main/java/org/exoplatform/services/log/impl/Log4JConfigurator.java
   kernel/branches/2.4.x/exo.kernel.component.cache/src/main/java/org/exoplatform/services/cache/impl/CacheServiceImpl.java
   kernel/branches/2.4.x/exo.kernel.component.common/src/main/java/org/exoplatform/services/scheduler/CronJob.java
   kernel/branches/2.4.x/exo.kernel.component.common/src/main/java/org/exoplatform/services/scheduler/PeriodJob.java
   kernel/branches/2.4.x/exo.kernel.container/src/main/java/org/exoplatform/container/jmx/MX4JComponentAdapter.java
   kernel/branches/2.4.x/exo.kernel.container/src/main/java/org/exoplatform/container/monitor/jvm/J2EEServerInfo.java
   kernel/branches/2.4.x/exo.kernel.container/src/main/java/org/exoplatform/container/util/ContainerUtil.java
   kernel/branches/2.4.x/exo.kernel.container/src/main/java/org/exoplatform/container/xml/ObjectParam.java
   kernel/branches/2.4.x/exo.kernel.container/src/main/java/org/exoplatform/services/log/LogConfigurationInitializer.java
   kernel/branches/2.4.x/exo.kernel.container/src/main/java/org/exoplatform/xml/object/XMLCollection.java
   kernel/branches/2.4.x/exo.kernel.container/src/main/java/org/exoplatform/xml/object/XMLMap.java
   kernel/branches/2.4.x/exo.kernel.container/src/main/java/org/exoplatform/xml/object/XMLObject.java
Log:
EXOJCR-1580: Make eXo JCR supports JBoss AS7

Added: kernel/branches/2.4.x/exo.kernel.commons/src/main/java/org/exoplatform/commons/utils/ClassLoading.java
===================================================================
--- kernel/branches/2.4.x/exo.kernel.commons/src/main/java/org/exoplatform/commons/utils/ClassLoading.java	                        (rev 0)
+++ kernel/branches/2.4.x/exo.kernel.commons/src/main/java/org/exoplatform/commons/utils/ClassLoading.java	2012-01-04 11:37:05 UTC (rev 5417)
@@ -0,0 +1,209 @@
+/*
+ * Copyright (C) 2012 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.exoplatform.commons.utils;
+
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+
+/**
+ * @author <a href="abazko at exoplatform.com">Anatoliy Bazko</a>
+ * @version $Id: ClassLoading.java 34360 2009-07-22 23:58:59Z tolusha $
+ */
+public class ClassLoading
+{
+   /**
+    * The logger
+    */
+   private static final Log LOG = ExoLogger.getLogger("org.exoplatform.commons.utils.ClassLoader");
+
+   /**
+    * 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.4.x/exo.kernel.commons/src/main/java/org/exoplatform/services/log/impl/Log4JConfigurator.java
===================================================================
--- kernel/branches/2.4.x/exo.kernel.commons/src/main/java/org/exoplatform/services/log/impl/Log4JConfigurator.java	2012-01-03 14:51:49 UTC (rev 5416)
+++ kernel/branches/2.4.x/exo.kernel.commons/src/main/java/org/exoplatform/services/log/impl/Log4JConfigurator.java	2012-01-04 11:37:05 UTC (rev 5417)
@@ -18,6 +18,7 @@
  */
 package org.exoplatform.services.log.impl;
 
+import org.exoplatform.commons.utils.ClassLoading;
 import org.exoplatform.commons.utils.SecurityHelper;
 import org.exoplatform.services.log.AbstractLogConfigurator;
 
@@ -43,7 +44,7 @@
          {
             try
             {
-               Class<?> propertyConfiguratorClass = Class.forName("org.apache.log4j.PropertyConfigurator");
+               Class<?> propertyConfiguratorClass = ClassLoading.forName("org.apache.log4j.PropertyConfigurator", Log4JConfigurator.class);
                Method m = propertyConfiguratorClass.getMethod("configure", Properties.class);
                m.invoke(null, properties);
             }

Modified: kernel/branches/2.4.x/exo.kernel.component.cache/src/main/java/org/exoplatform/services/cache/impl/CacheServiceImpl.java
===================================================================
--- kernel/branches/2.4.x/exo.kernel.component.cache/src/main/java/org/exoplatform/services/cache/impl/CacheServiceImpl.java	2012-01-03 14:51:49 UTC (rev 5416)
+++ kernel/branches/2.4.x/exo.kernel.component.cache/src/main/java/org/exoplatform/services/cache/impl/CacheServiceImpl.java	2012-01-04 11:37:05 UTC (rev 5417)
@@ -18,6 +18,7 @@
  */
 package org.exoplatform.services.cache.impl;
 
+import org.exoplatform.commons.utils.ClassLoading;
 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 = ClassLoading.loadClass(safeConfig.getImplementation(), this); 
             // Implementation is an existing class
             if (ExoCache.class.isAssignableFrom(implClass))
             {
@@ -239,6 +240,7 @@
       /**
        * {@inheritDoc}
        */
+      @SuppressWarnings({"rawtypes", "unchecked"})
       public ExoCache createCache(ExoCacheConfig config) throws ExoCacheInitException
       {
          final ExoCache simple = createCacheInstance(config);
@@ -246,11 +248,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())
          {
@@ -265,7 +262,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)
@@ -276,10 +273,9 @@
          else
          {
             // An implementation has been defined
-            final ClassLoader cl = Thread.currentThread().getContextClassLoader();
             try
             {
-               final Class clazz = cl.loadClass(config.getImplementation());
+               final Class<?> clazz = ClassLoading.loadClass(config.getImplementation(), this);
                return (ExoCache)clazz.newInstance();
             }
             catch (Exception e)

Modified: kernel/branches/2.4.x/exo.kernel.component.common/src/main/java/org/exoplatform/services/scheduler/CronJob.java
===================================================================
--- kernel/branches/2.4.x/exo.kernel.component.common/src/main/java/org/exoplatform/services/scheduler/CronJob.java	2012-01-03 14:51:49 UTC (rev 5416)
+++ kernel/branches/2.4.x/exo.kernel.component.common/src/main/java/org/exoplatform/services/scheduler/CronJob.java	2012-01-04 11:37:05 UTC (rev 5417)
@@ -18,6 +18,7 @@
  */
 package org.exoplatform.services.scheduler;
 
+import org.exoplatform.commons.utils.ClassLoading;
 import org.exoplatform.commons.utils.ExoProperties;
 import org.exoplatform.container.component.BaseComponentPlugin;
 import org.exoplatform.container.xml.InitParams;
@@ -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 = ClassLoading.forName(jobClass, this);
       jinfo_ = new JobInfo(jobName, jobGroup, clazz);
 
       expression_ = props.getProperty("expression");

Modified: kernel/branches/2.4.x/exo.kernel.component.common/src/main/java/org/exoplatform/services/scheduler/PeriodJob.java
===================================================================
--- kernel/branches/2.4.x/exo.kernel.component.common/src/main/java/org/exoplatform/services/scheduler/PeriodJob.java	2012-01-03 14:51:49 UTC (rev 5416)
+++ kernel/branches/2.4.x/exo.kernel.component.common/src/main/java/org/exoplatform/services/scheduler/PeriodJob.java	2012-01-04 11:37:05 UTC (rev 5417)
@@ -18,6 +18,7 @@
  */
 package org.exoplatform.services.scheduler;
 
+import org.exoplatform.commons.utils.ClassLoading;
 import org.exoplatform.commons.utils.ExoProperties;
 import org.exoplatform.container.component.BaseComponentPlugin;
 import org.exoplatform.container.xml.InitParams;
@@ -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 = ClassLoading.forName(jobClass, this);
       jinfo_ = new JobInfo(jobName, jobGroup, clazz);
 
       Date startTime = getDate(props.getProperty("startTime"));

Modified: kernel/branches/2.4.x/exo.kernel.container/src/main/java/org/exoplatform/container/jmx/MX4JComponentAdapter.java
===================================================================
--- kernel/branches/2.4.x/exo.kernel.container/src/main/java/org/exoplatform/container/jmx/MX4JComponentAdapter.java	2012-01-03 14:51:49 UTC (rev 5416)
+++ kernel/branches/2.4.x/exo.kernel.container/src/main/java/org/exoplatform/container/jmx/MX4JComponentAdapter.java	2012-01-04 11:37:05 UTC (rev 5417)
@@ -18,6 +18,7 @@
  */
 package org.exoplatform.container.jmx;
 
+import org.exoplatform.commons.utils.ClassLoading;
 import org.exoplatform.commons.utils.SecurityHelper;
 import org.exoplatform.container.ExoContainer;
 import org.exoplatform.container.component.ComponentLifecycle;
@@ -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 = ClassLoading.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.4.x/exo.kernel.container/src/main/java/org/exoplatform/container/monitor/jvm/J2EEServerInfo.java
===================================================================
--- kernel/branches/2.4.x/exo.kernel.container/src/main/java/org/exoplatform/container/monitor/jvm/J2EEServerInfo.java	2012-01-03 14:51:49 UTC (rev 5416)
+++ kernel/branches/2.4.x/exo.kernel.container/src/main/java/org/exoplatform/container/monitor/jvm/J2EEServerInfo.java	2012-01-04 11:37:05 UTC (rev 5417)
@@ -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;
@@ -28,7 +27,6 @@
 import java.lang.reflect.Method;
 import java.net.URI;
 import java.security.PrivilegedAction;
-import java.security.PrivilegedExceptionAction;
 
 import javax.management.MBeanServer;
 
@@ -70,125 +68,140 @@
 
    public J2EEServerInfo()
    {
+      SecurityHelper.doPrivilegedAction(new PrivilegedAction<Void>()
+      {
+         public Void run()
+         {
 
-      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");
+            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 = PrivilegedSystemHelper.getProperty(EXO_CONF_DIR_NAME_PARAM, "exo-conf");
-      if (jonasHome != null)
-      {
-         serverName_ = "jonas";
-         serverHome_ = jonasHome;
-      }
-      else if (jbossHome != null)
-      {
-         serverName_ = "jboss";
-         serverHome_ = jbossHome;
+            // The name of the configuration directory
+            final String confDirName = System.getProperty(EXO_CONF_DIR_NAME_PARAM, "exo-conf");
+            if (jonasHome != null)
+            {
+               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)
-         {
-            try
+               // 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)
+               {
+                  try
+                  {
+                     exoConfDir_ = new File(new File(new URI(jbossConfigUrl)), confDirName).getAbsolutePath();
+                  }
+                  catch (Throwable e)
+                  {
+                     // don't care about it
+                  }
+               }
+               else
+               {
+                  // 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
+                     }
+                  }
+               }
+               try
+               {
+                  Class<?> clazz = Thread.currentThread().getContextClassLoader()
+                           .loadClass("org.jboss.mx.util.MBeanServerLocator");
+                  Method m = clazz.getMethod("locateJBoss");
+                  mbeanServer = (MBeanServer)m.invoke(null);
+               }
+               catch (ClassNotFoundException ignore)
+               {
+                  // 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)
             {
-               exoConfDir_ = new File(new File(new URI(jbossConfigUrl)), confDirName).getAbsolutePath();
+               serverName_ = "jetty";
+               serverHome_ = jettyHome;
             }
-            catch (Throwable e)
+            else if (websphereHome != null)
             {
-               // don't care about it
+               serverName_ = "websphere";
+               serverHome_ = websphereHome;
             }
-         }
-
-         //
-         try
-         {
-            Class clazz = SecurityHelper.doPrivilegedExceptionAction(new PrivilegedExceptionAction<Class>()
+            else if (weblogicHome != null)
             {
-               public Class run() throws Exception
-               {
-                  return Thread.currentThread().getContextClassLoader()
-                     .loadClass("org.jboss.mx.util.MBeanServerLocator");
-               }
-            });
+               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.4.x/exo.kernel.container/src/main/java/org/exoplatform/container/util/ContainerUtil.java
===================================================================
--- kernel/branches/2.4.x/exo.kernel.container/src/main/java/org/exoplatform/container/util/ContainerUtil.java	2012-01-03 14:51:49 UTC (rev 5416)
+++ kernel/branches/2.4.x/exo.kernel.container/src/main/java/org/exoplatform/container/util/ContainerUtil.java	2012-01-04 11:37:05 UTC (rev 5417)
@@ -18,6 +18,7 @@
  */
 package org.exoplatform.container.util;
 
+import org.exoplatform.commons.utils.ClassLoading;
 import org.exoplatform.commons.utils.PropertiesLoader;
 import org.exoplatform.commons.utils.SecurityHelper;
 import org.exoplatform.commons.utils.Tools;
@@ -132,7 +133,7 @@
    {
       try
       {
-         Class clazz = Class.forName(plugin.getType());
+         Class<?> clazz = ClassLoading.forName(plugin.getType(), ContainerUtil.class);
          org.exoplatform.container.ContainerLifecyclePlugin cplugin =
             (org.exoplatform.container.ContainerLifecyclePlugin)container
                .createComponent(clazz, plugin.getInitParams());
@@ -146,17 +147,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 = ClassLoading.loadClass(plugin.getType(), ContainerUtil.class);
             org.exoplatform.container.component.ComponentLifecyclePlugin instance =
                (org.exoplatform.container.component.ComponentLifecyclePlugin)classType.newInstance();
             container.addComponentLifecylePlugin(instance);
@@ -168,13 +168,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 +181,7 @@
          String key = component.getKey();
          try
          {
-            Class classType = loader.loadClass(type);
+            Class<?> classType = ClassLoading.loadClass(type, ContainerUtil.class);
             if (key == null)
             {
                if (component.isMultiInstance())
@@ -199,7 +198,7 @@
             {
                try
                {
-                  Class keyType = loader.loadClass(key);
+                  Class<?> keyType = ClassLoading.loadClass(key, ContainerUtil.class);
                   if (component.isMultiInstance())
                   {
                      container.registerComponent(new ConstructorInjectionComponentAdapter(keyType, classType));
@@ -310,5 +309,5 @@
          }
       }
       return props;
-   }
+   }   
 }

Modified: kernel/branches/2.4.x/exo.kernel.container/src/main/java/org/exoplatform/container/xml/ObjectParam.java
===================================================================
--- kernel/branches/2.4.x/exo.kernel.container/src/main/java/org/exoplatform/container/xml/ObjectParam.java	2012-01-03 14:51:49 UTC (rev 5416)
+++ kernel/branches/2.4.x/exo.kernel.container/src/main/java/org/exoplatform/container/xml/ObjectParam.java	2012-01-04 11:37:05 UTC (rev 5417)
@@ -19,6 +19,7 @@
 package org.exoplatform.container.xml;
 
 import org.apache.commons.beanutils.PropertyUtils;
+import org.exoplatform.commons.utils.ClassLoading;
 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 = ClassLoading.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 = ClassLoading.forName(fullName.toString(), this);
             return clazz.newInstance();
          }
       }

Modified: kernel/branches/2.4.x/exo.kernel.container/src/main/java/org/exoplatform/services/log/LogConfigurationInitializer.java
===================================================================
--- kernel/branches/2.4.x/exo.kernel.container/src/main/java/org/exoplatform/services/log/LogConfigurationInitializer.java	2012-01-03 14:51:49 UTC (rev 5416)
+++ kernel/branches/2.4.x/exo.kernel.container/src/main/java/org/exoplatform/services/log/LogConfigurationInitializer.java	2012-01-04 11:37:05 UTC (rev 5417)
@@ -18,6 +18,7 @@
  */
 package org.exoplatform.services.log;
 
+import org.exoplatform.commons.utils.ClassLoading;
 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)ClassLoading.forName(configurer, this).newInstance();
          props = new Properties();
          props.putAll(properties);
          conf.configure(props);

Modified: kernel/branches/2.4.x/exo.kernel.container/src/main/java/org/exoplatform/xml/object/XMLCollection.java
===================================================================
--- kernel/branches/2.4.x/exo.kernel.container/src/main/java/org/exoplatform/xml/object/XMLCollection.java	2012-01-03 14:51:49 UTC (rev 5416)
+++ kernel/branches/2.4.x/exo.kernel.container/src/main/java/org/exoplatform/xml/object/XMLCollection.java	2012-01-04 11:37:05 UTC (rev 5417)
@@ -18,6 +18,7 @@
  */
 package org.exoplatform.xml.object;
 
+import org.exoplatform.commons.utils.ClassLoading;
 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 = ClassLoading.forName(type_, this);
       Collection collection = (Collection)clazz.newInstance();
       for (int i = 0; i < list_.size(); i++)
       {

Modified: kernel/branches/2.4.x/exo.kernel.container/src/main/java/org/exoplatform/xml/object/XMLMap.java
===================================================================
--- kernel/branches/2.4.x/exo.kernel.container/src/main/java/org/exoplatform/xml/object/XMLMap.java	2012-01-03 14:51:49 UTC (rev 5416)
+++ kernel/branches/2.4.x/exo.kernel.container/src/main/java/org/exoplatform/xml/object/XMLMap.java	2012-01-04 11:37:05 UTC (rev 5417)
@@ -18,6 +18,8 @@
  */
 package org.exoplatform.xml.object;
 
+import org.exoplatform.commons.utils.ClassLoading;
+
 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 = ClassLoading.forName(type_, this);
       Map map = (Map)clazz.newInstance();
       for (int i = 0; i < listmap.size(); i++)
       {

Modified: kernel/branches/2.4.x/exo.kernel.container/src/main/java/org/exoplatform/xml/object/XMLObject.java
===================================================================
--- kernel/branches/2.4.x/exo.kernel.container/src/main/java/org/exoplatform/xml/object/XMLObject.java	2012-01-03 14:51:49 UTC (rev 5416)
+++ kernel/branches/2.4.x/exo.kernel.container/src/main/java/org/exoplatform/xml/object/XMLObject.java	2012-01-04 11:37:05 UTC (rev 5417)
@@ -18,6 +18,7 @@
  */
 package org.exoplatform.xml.object;
 
+import org.exoplatform.commons.utils.ClassLoading;
 import org.exoplatform.commons.utils.SecurityHelper;
 import org.exoplatform.services.log.ExoLogger;
 import org.exoplatform.services.log.Log;
@@ -172,7 +173,7 @@
 
    public Object toObject() throws Exception
    {
-      Class clazz = Class.forName(type);
+      Class<?> clazz = ClassLoading.forName(type, this);
       Map fields = getFields(clazz);
       Object instance = clazz.newInstance();
       Iterator i = fields_.values().iterator();



More information about the exo-jcr-commits mailing list