protected <T, V extends T> T instanceOf(Class<T> type, Class<V> ofClass) { try { return ofClass.newInstance(); } catch (Exception e) { annotationMonitor.elementCreationFailed(ofClass, e); throw new InstantiationFailed(ofClass, type, e); } }
protected Object injectEmbedder(Embedder embedder, Class<?> annotatedClass) { try { Object instance = annotatedClass.newInstance(); if (instance instanceof Embeddable) { Embeddable embeddable = (Embeddable) instance; embeddable.useEmbedder(embedder); } if (instance instanceof ConfigurableEmbedder) { ConfigurableEmbedder configurableEmbedder = (ConfigurableEmbedder) instance; configurableEmbedder.useConfiguration(embedder.configuration()); configurableEmbedder.addSteps(embedder.candidateSteps()); } return instance; } catch (Exception e) { annotationMonitor.elementCreationFailed(annotatedClass, e); throw new InstantiationFailed(annotatedClass, e); } }
/** * Builds CandidateSteps using annotation {@link UsingSteps} found in the annotated object * instance and the configuration provided * * @param configuration the Configuration * @return A List of CandidateSteps instances */ public List<CandidateSteps> buildCandidateSteps(Configuration configuration) { List<Object> stepsInstances = new ArrayList<Object>(); InjectableStepsFactory factory = null; if (finder.isAnnotationPresent(UsingSteps.class)) { List<Class<Object>> stepsClasses = finder.getAnnotatedClasses(UsingSteps.class, Object.class, "instances"); for (Class<Object> stepsClass : stepsClasses) { stepsInstances.add(instanceOf(Object.class, stepsClass)); } factory = new InstanceStepsFactory(configuration, stepsInstances); } else { annotationMonitor.annotationNotFound(UsingSteps.class, annotatedClass); } if (factory == null) { factory = new InstanceStepsFactory(configuration); } return factory.createCandidateSteps(); }