Instantiate a new ADDFFunctionalGroupHandler given its class name @param theInterface @return @throws ClassNotFoundException @throws NoSuchMethodException @throws SecurityException @throws InvocationTargetException @throws IllegalArgumentException @throws IllegalAccessException @throws Inst
(Class<I> theInterface)
| 862 | * @throws InstantiationException |
| 863 | */ |
| 864 | @SuppressWarnings("unchecked") |
| 865 | protected <I> I newHandler(Class<I> theInterface) { |
| 866 | if (theInterface == null) return null; |
| 867 | |
| 868 | String className = null; |
| 869 | |
| 870 | try { |
| 871 | className = Config.getValueWithGlobalDefault(this.getEngine(), theInterface.getSimpleName()); |
| 872 | mLog.info(">>> className = " + className); |
| 873 | if (Strings.isNullOrEmpty(className)) { |
| 874 | mLog.error(String.format("Cannot determine classname for %s from configuration source [%s] %s", |
| 875 | theInterface.getSimpleName(), Config.getConfigHandler().getSource(), this.getEngine())); |
| 876 | return null; |
| 877 | } |
| 878 | |
| 879 | Class<?> clazz = Class.forName(className); |
| 880 | |
| 881 | if (Modifier.isAbstract(clazz.getModifiers())) { |
| 882 | throw new InstantiationError(String.format("Class %s is abstract and cannot be instantiated", className)); |
| 883 | } |
| 884 | |
| 885 | Constructor<ADDFFunctionalGroupHandler> cons = (Constructor<ADDFFunctionalGroupHandler>) clazz |
| 886 | .getDeclaredConstructor(new Class<?>[] { DDF.class }); |
| 887 | |
| 888 | if (cons != null) cons.setAccessible(true); |
| 889 | |
| 890 | return cons != null ? (I) cons.newInstance(this) : null; |
| 891 | |
| 892 | } catch (ClassNotFoundException cnfe) { |
| 893 | mLog.error(String.format("Cannot instantiate handler for [%s] %s/%s", this.getEngine(), |
| 894 | theInterface.getSimpleName(), className), cnfe); |
| 895 | } catch (NoSuchMethodException nsme) { |
| 896 | mLog.error(String.format("Cannot instantiate handler for [%s] %s/%s", this.getEngine(), |
| 897 | theInterface.getSimpleName(), className), nsme); |
| 898 | } catch (IllegalAccessException iae) { |
| 899 | mLog.error(String.format("Cannot instantiate handler for [%s] %s/%s", this.getEngine(), |
| 900 | theInterface.getSimpleName(), className), iae); |
| 901 | } catch (InstantiationException ie) { |
| 902 | mLog.error(String.format("Cannot instantiate handler for [%s] %s/%s", this.getEngine(), |
| 903 | theInterface.getSimpleName(), className), ie); |
| 904 | } catch (InvocationTargetException ite) { |
| 905 | mLog.error(String.format("Cannot instantiate handler for [%s] %s/%s", this.getEngine(), |
| 906 | theInterface.getSimpleName(), className), ite); |
| 907 | } |
| 908 | return null; |
| 909 | } |
| 910 | |
| 911 | |
| 912 | @Override |
no test coverage detected