instance = ctor.newInstance();
}
else
{
String msg = "Cannot create " + type + " with class " + className + " because it does not implement the expected interface " + expectedClass.getName();
throw new PortletInitializationException(msg);
}
}
catch (InvocationTargetException e)
{
String msg = "Cannot create " + type + " with class " + className + " because the class contructor threw an exception";
throw new PortletInitializationException(msg, e.getCause());
}
catch (IllegalAccessException e)
{
String msg = "Cannot create " + type + " with class " + className + " because the class is not accessible";
throw new PortletInitializationException(msg, e);
}
catch (NoSuchMethodException e)
{
String msg = "Cannot create " + type + " with class " + className + " because it does not have an no argument constructor";
throw new PortletInitializationException(msg, e);
}
catch (ClassNotFoundException e)
{
String msg = "Cannot create " + type + " with class " + className + " because the class cannot be loaded";
throw new PortletInitializationException(msg, e);
}
catch (InstantiationException e)
{
String msg = "Cannot create " + type + " with class " + className + " because it cannot be instantiated";
throw new PortletInitializationException(msg, e);
}
catch (Error e)
{
String msg = "Cannot create " + type + " with class " + className + " because of an error";
throw new PortletInitializationException(msg, e);
}
//
final ClassLoader previousLoader = Thread.currentThread().getContextClassLoader();
try
{
Thread.currentThread().setContextClassLoader(classLoader);
//
start(instance);
}
catch (Exception e)
{
String msg = "The " + type + " threw an exception during init";
throw new PortletInitializationException(msg, e);
}
finally
{
Thread.currentThread().setContextClassLoader(previousLoader);
}