public Object newInstance(String cname,
String subpackages) {
if (subpackages != null && subpackages.length > 0)
throw new UnsupportedOperationException( "newInstance(classname, packages) not implemented" );
final Class< ? > clazz;
try {
clazz = ReflectHelper.classForName( cname );
}
catch ( ClassNotFoundException e ) {
throw new SearchException("Unable to find class " + cname, e);
}
try {
final Object instance = clazz.newInstance();
if (instance instanceof ResourceLoaderAware) {
( ( ResourceLoaderAware) instance ).inform( this );
}
return instance;
}
catch ( InstantiationException e ) {
throw new SearchException("Unable to instanciate class with no-arg constructor: " + cname, e);
}
catch ( IllegalAccessException e ) {
throw new SearchException("Unable to instanciate class with no-arg constructor: " + cname, e);
}
}
|