Author: vbaranov
Date: 2008-03-25 06:18:03 -0400 (Tue, 25 Mar 2008)
New Revision: 7156
Modified:
trunk/framework/api/src/main/java/org/richfaces/skin/SkinFactory.java
Log:
http://jira.jboss.com/jira/browse/RF-995
Modified: trunk/framework/api/src/main/java/org/richfaces/skin/SkinFactory.java
===================================================================
--- trunk/framework/api/src/main/java/org/richfaces/skin/SkinFactory.java 2008-03-25
09:39:03 UTC (rev 7155)
+++ trunk/framework/api/src/main/java/org/richfaces/skin/SkinFactory.java 2008-03-25
10:18:03 UTC (rev 7156)
@@ -26,10 +26,12 @@
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
+import javax.faces.FacesException;
import javax.faces.context.FacesContext;
import org.ajax4jsf.Messages;
@@ -89,17 +91,7 @@
Messages.SET_SKIN_FACTORY_INFO,
factoryClassName));
}
- Class<?> clazz = Class.forName(factoryClassName, false, loader);
- try {
- // try construct factory chain.
- Constructor<?> factoryConstructor = clazz
- .getConstructor(new Class[] { SkinFactory.class });
- instance = (SkinFactory) factoryConstructor
- .newInstance(new Object[] { instance });
- } catch (NoSuchMethodException e) {
- // no chain constructor - attempt default.
- instance = (SkinFactory) clazz.newInstance();
- }
+ instance = instantiateSkinFactory(factoryClassName, loader);
} catch (Exception e) {
log
.warn(
@@ -115,27 +107,58 @@
}
}
- if (instance == null) {
- try{
- // instantiate default implementation of SkinFactory -
org.richfaces.skin.SkinFactoryImpl,
- // placed in the richfaces-impl.jar
- instance = (SkinFactory)
Class.forName(DEFAULT_SKIN_FACTORY_IMPL_CLASS).newInstance();
- } catch (InstantiationException ie) {
- log.error(Messages.getMessage(Messages.CREATING_SKIN_FACTORY_ERROR), ie);
- } catch (IllegalAccessException iae) {
- log.error(Messages.getMessage(Messages.CREATING_SKIN_FACTORY_ERROR), iae);
- } catch (ClassNotFoundException cnfe) {
- log.error(Messages.getMessage(Messages.CREATING_SKIN_FACTORY_ERROR), cnfe);
- }
+ if (instance == null) {
+ // instantiate default implementation of SkinFactory -
org.richfaces.skin.SkinFactoryImpl,
+ // placed in the richfaces-impl.jar
+ instance = instantiateSkinFactory(DEFAULT_SKIN_FACTORY_IMPL_CLASS, loader);
}
instances.put(loader, instance);
}
return instance;
}
+
+ /**
+ * Create new instance of class with given name with the help of given
<code>ClassLoader</code>.
+ * Instantiated class should extend <code>SkinFactory</code> base class.
+ * @param factoryClassName - class name of SkinFactory
+ * @param classLoader - class loader
+ * @return - instantiated <code>SkinFactory</code>
+ * @throws FacesException - FacesException is thrown when instantiation fails;
+ * causing exception is wrapped into
<code>FacesException</code>
+ */
+ private static SkinFactory instantiateSkinFactory(String factoryClassName, ClassLoader
classLoader) throws FacesException {
+ SkinFactory instance = null;
+ try {
+ Class<?> clazz = Class.forName(factoryClassName, false, classLoader);
+ try {
+ // try construct factory chain.
+ Constructor<?> factoryConstructor = clazz.getConstructor(new Class[] {
SkinFactory.class });
+ instance = (SkinFactory) factoryConstructor.newInstance(new Object[] { instance
});
+ } catch (NoSuchMethodException e) {
+ // no chain constructor - attempt default.
+ instance = (SkinFactory) clazz.newInstance();
+ }
+ } catch (InvocationTargetException ite) {
+ log.error(Messages.getMessage(Messages.CREATING_SKIN_FACTORY_ERROR), ite);
+ throw new FacesException("Exception when creating instance of [" +
SkinFactory.class.getName() + "]", ite);
+ } catch (InstantiationException ie) {
+ log.error(Messages.getMessage(Messages.CREATING_SKIN_FACTORY_ERROR), ie);
+ throw new FacesException("Exception when creating instance of [" +
SkinFactory.class.getName() + "]", ie);
+ } catch (IllegalAccessException iae) {
+ log.error(Messages.getMessage(Messages.CREATING_SKIN_FACTORY_ERROR), iae);
+ throw new FacesException("Exception when creating instance of [" +
SkinFactory.class.getName() + "]", iae);
+ } catch (ClassNotFoundException cnfe) {
+ log.error(Messages.getMessage(Messages.CREATING_SKIN_FACTORY_ERROR), cnfe);
+ throw new FacesException("Exception when creating instance of [" +
SkinFactory.class.getName() + "]", cnfe);
+ }
+ return instance;
+ }
+
/**
* Get default {@link Skin} implementation.
+ *
* @param context
* @return
*/