Constructor<?>[] constructors = functionClass.getConstructors();
if (constructors.length == 0) {
try {
return (Function)functionClass.newInstance();
} catch (InstantiationException e) {
throw new FeatureException("The function '"+functionClass.getName()+"' cannot be initialized. ", e);
} catch (IllegalAccessException e) {
throw new FeatureException("The function '"+functionClass.getName()+"' cannot be initialized. ", e);
}
}
Class<?>[] params = constructors[0].getParameterTypes();
if (params.length == 0) {
try {
return (Function)functionClass.newInstance();
} catch (InstantiationException e) {
throw new FeatureException("The function '"+functionClass.getName()+"' cannot be initialized. ", e);
} catch (IllegalAccessException e) {
throw new FeatureException("The function '"+functionClass.getName()+"' cannot be initialized. ", e);
}
}
Object[] arguments = new Object[params.length];
for (int i = 0; i < params.length; i++) {
if (hasSubfunctions && params[i] == java.lang.String.class) {
arguments[i] = name;
} else {
arguments[i] = registry.get(params[i]);
if (arguments[i] == null) {
return null;
}
}
}
try {
return (Function)constructors[0].newInstance(arguments);
} catch (InstantiationException e) {
throw new FeatureException("The function '"+functionClass.getName()+"' cannot be initialized. ", e);
} catch (IllegalAccessException e) {
throw new FeatureException("The function '"+functionClass.getName()+"' cannot be initialized. ", e);
} catch (InvocationTargetException e) {
throw new FeatureException("The function '"+functionClass.getName()+"' cannot be initialized. ", e);
}
}