From 91f2e742c47d31e1e82ded5de12ddaf974dfa9f1 Mon Sep 17 00:00:00 2001 From: Avinash Date: Mon, 10 Jun 2019 20:58:18 +0530 Subject: [PATCH] Fix - Receiving the Implentationm --- src/main/java/com/firefly/dp/FactoryProducer.java | 12 +++++++----- .../com/firefly/dp/helper/FactoryMemberHelper.java | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/firefly/dp/FactoryProducer.java b/src/main/java/com/firefly/dp/FactoryProducer.java index 9a540d5..f223fbe 100644 --- a/src/main/java/com/firefly/dp/FactoryProducer.java +++ b/src/main/java/com/firefly/dp/FactoryProducer.java @@ -2,28 +2,30 @@ import com.firefly.dp.annotations.FactoryMember; import com.firefly.dp.helper.FactoryMemberHelper; +import lombok.Setter; import java.lang.annotation.Annotation; import java.util.List; import java.util.Optional; import java.util.stream.Stream; +@Setter public class FactoryProducer { private List factoryMembers; - public T getImplemention(Class clazz, String value) { + public T getImplemention(Class clazz, String value) throws IllegalAccessException, InstantiationException { - List implementedClazz = new FactoryMemberHelper(this.factoryMembers, clazz).accumulateByParent(); - for (Object o : implementedClazz) { - Annotation[] annotations = o.getClass().getAnnotations(); + List implementedClazz = new FactoryMemberHelper(this.factoryMembers, clazz).accumulateByParent(); + for (Class o : implementedClazz) { + Annotation[] annotations = o.getAnnotations(); Optional first = Stream.of(annotations) .filter(annotation -> annotation.annotationType().equals(FactoryMember.class)) .findFirst(); if (first.isPresent()) { FactoryMember annotation = (FactoryMember) first.get(); if (annotation.key().equalsIgnoreCase(value)) - return (T) o; + return (T) o.newInstance(); } } diff --git a/src/main/java/com/firefly/dp/helper/FactoryMemberHelper.java b/src/main/java/com/firefly/dp/helper/FactoryMemberHelper.java index f719318..d45bac8 100644 --- a/src/main/java/com/firefly/dp/helper/FactoryMemberHelper.java +++ b/src/main/java/com/firefly/dp/helper/FactoryMemberHelper.java @@ -12,7 +12,7 @@ public class FactoryMemberHelper { private Class parentClass; - public List accumulateByParent() { + public List accumulateByParent() { return this.fireFlyClazz.stream() .filter(clazz -> parentClass.isAssignableFrom(clazz)) .collect(Collectors.toList());