/** * Register a Blueprint from Class * * @param clazz Blueprint class * @throws RegisterBlueprintException failed to register blueprint */ public void registerBlueprint(Class clazz) throws RegisterBlueprintException { Object blueprint = null; try { blueprint = clazz.newInstance(); } catch (InstantiationException e) { throw new RegisterBlueprintException(e); } catch (IllegalAccessException e) { throw new RegisterBlueprintException(e); } registerBlueprint(blueprint); }
/** * Register a Blueprint from a String Class name * * @param className String */ public void registerBlueprint(String className) throws RegisterBlueprintException { try { registerBlueprint(Class.forName(className)); } catch (ClassNotFoundException e) { throw new RegisterBlueprintException(e); } }
/** * Register all Blueprint in package. * * @param _package String package to scan * @throws RegisterBlueprintException failed to register blueprint */ public void setRegisterBlueprintsByPackage(String _package) throws RegisterBlueprintException { Set<Class<?>> annotated = null; try { annotated = new ClassesInPackageScanner().findAnnotatedClasses(_package, Blueprint.class); } catch (IOException e) { throw new RegisterBlueprintException(e); } logger.info("Scanned {} and found {}", _package, annotated); this.setRegisterBlueprints(annotated); }
/** * Register a List of Blueprint, Class, or String * class names of Blueprint * * @param blueprints List * @throws RegisterBlueprintException failed to register blueprint */ public void setRegisterBlueprints(Collection blueprints) throws RegisterBlueprintException { for (Object blueprint : blueprints) { if (blueprint instanceof Class) { registerBlueprint((Class) blueprint); } else if (blueprint instanceof String) { registerBlueprint((String) blueprint); } else if (blueprint instanceof String) { registerBlueprint(blueprint); } else { throw new RegisterBlueprintException("Only supports List comprised of Class<Blueprint>, Blueprint, or String className"); } } }
throw new RegisterBlueprintException("Blueprint class not annotated by @Blueprint: " + blueprint); fieldVal = field.get(blueprint); } catch (IllegalArgumentException e) { throw new RegisterBlueprintException(e); } catch (IllegalAccessException e) { throw new RegisterBlueprintException(e); newInstance = (Constructable) fieldVal; } else { throw new RegisterBlueprintException("Blueprint " + blueprint.getClass().getSimpleName() + " Field class for " + field.getName() + " is invalid ConstructorCallback"); fieldVal = field.get(blueprint); } catch (IllegalArgumentException e) { throw new RegisterBlueprintException(e); } catch (IllegalAccessException e) { throw new RegisterBlueprintException(e); afterCreateCallbacks.add((AfterCreateCallback)fieldVal); } else { throw new RegisterBlueprintException("Blueprint " + blueprint.getClass().getSimpleName() + " Field class for " + field.getName() + " is invalid AfterCreateCallback"); defaultField.setValue(field.get(blueprint)); } catch (IllegalArgumentException e) { throw new RegisterBlueprintException(e); } catch (IllegalAccessException e) { throw new RegisterBlueprintException(e); throw new RegisterBlueprintException("@MappedList targetList must implement List for field " + field.getName());