Return-Path: Delivered-To: apmail-jackrabbit-commits-archive@www.apache.org Received: (qmail 1665 invoked from network); 4 Sep 2006 11:01:55 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 4 Sep 2006 11:01:55 -0000 Received: (qmail 74478 invoked by uid 500); 4 Sep 2006 11:01:55 -0000 Delivered-To: apmail-jackrabbit-commits-archive@jackrabbit.apache.org Received: (qmail 74386 invoked by uid 500); 4 Sep 2006 11:01:54 -0000 Mailing-List: contact commits-help@jackrabbit.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@jackrabbit.apache.org Delivered-To: mailing list commits@jackrabbit.apache.org Received: (qmail 74358 invoked by uid 99); 4 Sep 2006 11:01:53 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 04 Sep 2006 04:01:53 -0700 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: local policy) Received: from [140.211.166.113] (HELO eris.apache.org) (140.211.166.113) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 04 Sep 2006 04:01:52 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id B22E71A981A; Mon, 4 Sep 2006 04:01:30 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r440026 - /jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/config/BeanConfig.java Date: Mon, 04 Sep 2006 11:01:30 -0000 To: commits@jackrabbit.apache.org From: fmeschbe@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20060904110130.B22E71A981A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: fmeschbe Date: Mon Sep 4 04:01:27 2006 New Revision: 440026 URL: http://svn.apache.org/viewvc?view=rev&rev=440026 Log: JCR-561 Add support to provide custom classloader for class instantiation from configuration Modified: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/config/BeanConfig.java Modified: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/config/BeanConfig.java URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/config/BeanConfig.java?view=diff&rev=440026&r1=440025&r2=440026 ============================================================================== --- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/config/BeanConfig.java (original) +++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/config/BeanConfig.java Mon Sep 4 04:01:27 2006 @@ -28,6 +28,16 @@ */ public class BeanConfig { + /** The default class loader used by all instances of this class */ + private static ClassLoader DEFAULT_CLASS_LOADER = + BeanConfig.class.getClassLoader(); + + /** + * The current class loader used by this instance to create instances of + * configured classes. + */ + private ClassLoader classLoader = getDefaultClassLoader(); + /** * The class name of the configured bean. */ @@ -87,7 +97,9 @@ */ public Object newInstance() throws ConfigurationException { try { - Object object = Class.forName(getClassName()).newInstance(); + Class objectClass = + Class.forName(getClassName(), true, getClassLoader()); + Object object = objectClass.newInstance(); BeanMap map = new BeanMap(object); Iterator iterator = map.keyIterator(); while (iterator.hasNext()) { @@ -113,4 +125,66 @@ } } + //---------- Configurable class loader support ---------------------------- + + /** + * Returns the current ClassLoader used to instantiate objects + * in the {@link #newInstance()} method. + * + * @see #newInstance() + * @see #setClassLoader(ClassLoader) + * @see #getDefaultClassLoader() + * @see #setDefaultClassLoader(ClassLoader) + */ + public ClassLoader getClassLoader() { + return classLoader; + } + + /** + * Sets the ClassLoader used to instantiate objects in the + * {@link #newInstance()} method. + * + * @param classLoader The class loader to set on this instance. If this is + * null the system class loader will be used, which may + * lead to unexpected class loading failures. + * + * @see #newInstance() + * @see #getClassLoader() + * @see #getDefaultClassLoader() + * @see #setDefaultClassLoader(ClassLoader) + */ + public void setClassLoader(ClassLoader classLoader) { + this.classLoader = classLoader; + } + + /** + * Returns the current ClassLoader used for new instances of + * this class as the loader used to instantiate objects in the + * {@link #newInstance()} method. + * + * @see #newInstance() + * @see #getClassLoader() + * @see #setClassLoader(ClassLoader) + * @see #setDefaultClassLoader(ClassLoader) + */ + public static ClassLoader getDefaultClassLoader() { + return DEFAULT_CLASS_LOADER; + } + + /** + * Sets the ClassLoader used for new instances of this class as + * the loader to instantiate objects in the {@link #newInstance()} method. + * + * @param classLoader The class loader to set as the default class loader. + * If this is null the system class loader will be used, + * which may lead to unexpected class loading failures. + * + * @see #newInstance() + * @see #getClassLoader() + * @see #setClassLoader(ClassLoader) + * @see #getDefaultClassLoader() + */ + public static void setDefaultClassLoader(ClassLoader classLoader) { + DEFAULT_CLASS_LOADER = classLoader; + } }