diff --git a/cola-framework/cola-core/src/main/java/com/alibaba/cola/domain/DomainFactory.java b/cola-framework/cola-core/src/main/java/com/alibaba/cola/domain/DomainFactory.java deleted file mode 100644 index b838616c6..000000000 --- a/cola-framework/cola-core/src/main/java/com/alibaba/cola/domain/DomainFactory.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.alibaba.cola.domain; - -import com.alibaba.cola.common.ApplicationContextHelper; - -/** - * DomainFactory - * - * @author Frank Zhang - * @date 2019-01-03 2:41 PM - */ -public class DomainFactory { - - public static T create(Class entityClz){ - return ApplicationContextHelper.getBean(entityClz); - } - - public static T getBean(Class entityClz){ - return ApplicationContextHelper.getBean(entityClz); - } -} diff --git a/cola-framework/cola-core/src/main/java/com/alibaba/cola/domain/DomainFactoryHelper.java b/cola-framework/cola-core/src/main/java/com/alibaba/cola/domain/DomainFactoryHelper.java deleted file mode 100644 index 83fcbd719..000000000 --- a/cola-framework/cola-core/src/main/java/com/alibaba/cola/domain/DomainFactoryHelper.java +++ /dev/null @@ -1,51 +0,0 @@ -package com.alibaba.cola.domain; - - -import com.alibaba.cola.event.EventBus; -import com.alibaba.cola.repository.RepositoryBus; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -import java.lang.reflect.InvocationTargetException; -import java.util.ArrayList; -import java.util.List; - -/** - * @author lorne - * @date 2020/1/26 - * @description - */ -@Component -public class DomainFactoryHelper implements DomainObjectFactoryI { - - private EventBus eventBus; - - private RepositoryBus repositoryBus; - - public DomainFactoryHelper(@Autowired(required = false) EventBus eventBus, - @Autowired(required = false) RepositoryBus repositoryBus) { - this.eventBus = eventBus; - this.repositoryBus = repositoryBus; - } - - @Override - public T create(Class clazz,Object ... initargs) { - List> list =null; - if(initargs!=null){ - list = new ArrayList<>(); - for (Object obj:initargs){ - list.add(obj.getClass()); - } - } - Class[] parameterTypes = list!=null?list.toArray(new Class[]{}):null; - try { - DomainObject domain = clazz.getDeclaredConstructor(parameterTypes).newInstance(initargs); - domain.initEventBus(eventBus); - domain.initPresentationBus(repositoryBus); - return (T)domain; - } catch (InstantiationException | IllegalAccessException | - InvocationTargetException | NoSuchMethodException e) { - throw new RuntimeException(e); - } - } -} diff --git a/cola-framework/cola-core/src/main/java/com/alibaba/cola/domain/DomainObject.java b/cola-framework/cola-core/src/main/java/com/alibaba/cola/domain/DomainObject.java index 6eb6fb19c..efe98864a 100644 --- a/cola-framework/cola-core/src/main/java/com/alibaba/cola/domain/DomainObject.java +++ b/cola-framework/cola-core/src/main/java/com/alibaba/cola/domain/DomainObject.java @@ -1,12 +1,9 @@ package com.alibaba.cola.domain; +import com.alibaba.cola.common.ApplicationContextHelper; import com.alibaba.cola.event.EventBus; import com.alibaba.cola.repository.RepositoryBus; -import java.lang.reflect.InvocationTargetException; -import java.util.ArrayList; -import java.util.List; - /** * @author lorne * @date 2020/1/23 @@ -14,38 +11,15 @@ */ public abstract class DomainObject extends EntityObject { - protected EventBus eventBus; - - protected RepositoryBus repositoryBus; + protected static EventBus eventBus; - public final void initEventBus(EventBus eventBus){ - this.eventBus = eventBus; - } + protected static RepositoryBus repositoryBus; - public final void initPresentationBus(RepositoryBus repositoryBus){ - this.repositoryBus = repositoryBus; + static { + eventBus = ApplicationContextHelper.getBean(EventBus.class); + repositoryBus = ApplicationContextHelper.getBean(RepositoryBus.class); } public void execute(){} - public final T createDomain(Class clazz, Object ... initargs) { - List> list =null; - if(initargs!=null){ - list = new ArrayList<>(); - for (Object obj:initargs){ - list.add(obj.getClass()); - } - } - Class[] parameterTypes = list!=null?list.toArray(new Class[]{}):null; - try { - DomainObject domain = clazz.getDeclaredConstructor(parameterTypes).newInstance(initargs); - domain.initEventBus(eventBus); - domain.initPresentationBus(repositoryBus); - return (T)domain; - } catch (InstantiationException | IllegalAccessException | - InvocationTargetException | NoSuchMethodException e) { - throw new RuntimeException(e); - } - } - } diff --git a/cola-framework/cola-core/src/main/java/com/alibaba/cola/domain/DomainObjectFactoryI.java b/cola-framework/cola-core/src/main/java/com/alibaba/cola/domain/DomainObjectFactoryI.java deleted file mode 100644 index d9868936c..000000000 --- a/cola-framework/cola-core/src/main/java/com/alibaba/cola/domain/DomainObjectFactoryI.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.alibaba.cola.domain; - -/** - * @author lorne - * @date 2020/1/27 - * @description - */ -public interface DomainObjectFactoryI { - - T create(Class clazz,Object ... initargs); -} diff --git a/cola-framework/cola-core/src/main/java/com/alibaba/cola/executor/AbsDomainExecutor.java b/cola-framework/cola-core/src/main/java/com/alibaba/cola/executor/AbsDomainExecutor.java deleted file mode 100644 index 880e67d1d..000000000 --- a/cola-framework/cola-core/src/main/java/com/alibaba/cola/executor/AbsDomainExecutor.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.alibaba.cola.executor; - -import com.alibaba.cola.domain.DomainFactoryHelper; -import com.alibaba.cola.domain.DomainObject; -import com.alibaba.cola.dto.Executor; -import com.alibaba.cola.dto.Response; -import org.springframework.beans.factory.annotation.Autowired; - -/** - * @author lorne - * @date 2020/1/26 - * @description - */ -public abstract class AbsDomainExecutor implements ExecutorI { - - @Autowired - protected DomainFactoryHelper domainFactoryHelper; - - public T createDomain(Class clazz, Object ... initargs){ - return (T)domainFactoryHelper.create(clazz,initargs); - } - - - public T createDomainAndExecute(Class clazz, Object ... initargs){ - DomainObject domain = createDomain(clazz,initargs); - domain.execute(); - return (T)domain; - } - -}