forked from itrickzhang/service-flow
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0bfdbb4
commit 8ed87aa
Showing
7 changed files
with
178 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,4 +18,6 @@ | |
String name(); | ||
|
||
FlowTypeEnum type() default FlowTypeEnum.METHOD; | ||
|
||
String desc() default ""; | ||
} |
28 changes: 28 additions & 0 deletions
28
service-flow-sdk/src/main/java/com/service/flow/index/ReflectionsScan.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.service.flow.index; | ||
|
||
import org.reflections.Reflections; | ||
import org.reflections.scanners.FieldAnnotationsScanner; | ||
import org.reflections.scanners.MethodAnnotationsScanner; | ||
import org.reflections.scanners.MethodParameterScanner; | ||
import org.reflections.scanners.SubTypesScanner; | ||
import org.reflections.util.ConfigurationBuilder; | ||
|
||
/** | ||
* @author zhangcb | ||
* @ClassName ReflectionsScan.java | ||
* @Description TODO | ||
* @createTime 2020年06月29日 21:25:00 | ||
*/ | ||
public class ReflectionsScan { | ||
public static Reflections scan(String scanName){ | ||
// 扫包 | ||
Reflections reflections = new Reflections(new ConfigurationBuilder() | ||
.forPackages(scanName) // 指定路径URL | ||
.addScanners(new SubTypesScanner()) // 添加子类扫描工具 | ||
.addScanners(new FieldAnnotationsScanner()) // 添加 属性注解扫描工具 | ||
.addScanners(new MethodAnnotationsScanner() ) // 添加 方法注解扫描工具 | ||
.addScanners(new MethodParameterScanner() ) // 添加方法参数扫描工具 | ||
); | ||
return reflections; | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
...ice-flow-sdk/src/main/java/com/service/flow/index/component/BaseComponentClassLoader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package com.service.flow.index.component; | ||
|
||
import com.service.flow.api.DTO; | ||
import com.service.flow.api.Flow; | ||
import com.service.flow.api.FlowTypeEnum; | ||
import com.service.flow.index.ReflectionsScan; | ||
import com.service.flow.index.dto.DTODefinition; | ||
import org.reflections.Reflections; | ||
import org.reflections.scanners.*; | ||
import org.reflections.util.ConfigurationBuilder; | ||
|
||
import java.lang.reflect.Method; | ||
import java.util.HashMap; | ||
import java.util.Iterator; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
/** | ||
* @author zhangcb | ||
* @ClassName BaseComponentClassLoader.java | ||
* @Description TODO | ||
* @createTime 2020年06月29日 20:29:00 | ||
*/ | ||
public class BaseComponentClassLoader { | ||
|
||
private Map<String, ComponentDefinition> componentDefinitionMap; | ||
|
||
public BaseComponentClassLoader(){ | ||
this.componentDefinitionMap = new HashMap<>(); | ||
} | ||
|
||
public void load(String scanName) { | ||
// 扫包 | ||
Reflections reflections = ReflectionsScan.scan(scanName); | ||
// 获取带有特定注解对应的方法 | ||
Set<Method> methods = reflections.getMethodsAnnotatedWith(Flow.class ) ; | ||
Iterator<Method> iterator = methods.iterator(); | ||
while (iterator.hasNext()){ | ||
Method method = iterator.next(); | ||
Flow annotation = method.getAnnotation(Flow.class); | ||
String name = annotation.name(); | ||
FlowTypeEnum type = annotation.type(); | ||
String desc = annotation.desc(); | ||
String methodName = method.getName(); | ||
String className = method.getDeclaringClass().getName(); | ||
ComponentDefinition componentDefinition = new ComponentDefinition(); | ||
componentDefinition.setValue(name); | ||
componentDefinition.setClassName(className); | ||
componentDefinition.setMethodName(methodName); | ||
componentDefinition.setDesc(desc); | ||
this.componentDefinitionMap.put(name,componentDefinition); | ||
} | ||
} | ||
|
||
public Map<String,ComponentDefinition> getComponentDefinitionMap(){ | ||
return this.componentDefinitionMap; | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
service-flow-sdk/src/main/java/com/service/flow/index/component/ComponentDefinition.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package com.service.flow.index.component; | ||
|
||
|
||
import com.service.flow.index.dto.DTODefinition; | ||
|
||
/** | ||
* @author zhangcb | ||
* @ClassName ComponentDefinition.java | ||
* @Description TODO | ||
* @createTime 2020年06月29日 07:15:00 | ||
*/ | ||
public class ComponentDefinition { | ||
|
||
private String value; | ||
|
||
private String desc; | ||
|
||
private String className; | ||
|
||
private String methodName; | ||
|
||
private DTODefinition dtoDefinition; | ||
|
||
public String getValue() { | ||
return value; | ||
} | ||
|
||
public void setValue(String value) { | ||
this.value = value; | ||
} | ||
|
||
public String getDesc() { | ||
return desc; | ||
} | ||
|
||
public void setDesc(String desc) { | ||
this.desc = desc; | ||
} | ||
|
||
public String getClassName() { | ||
return className; | ||
} | ||
|
||
public void setClassName(String className) { | ||
this.className = className; | ||
} | ||
|
||
public String getMethodName() { | ||
return methodName; | ||
} | ||
|
||
public void setMethodName(String methodName) { | ||
this.methodName = methodName; | ||
} | ||
|
||
public DTODefinition getDtoDefinition() { | ||
return dtoDefinition; | ||
} | ||
|
||
public void setDtoDefinition(DTODefinition dtoDefinition) { | ||
this.dtoDefinition = dtoDefinition; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "ComponentDefinition{" + | ||
"value='" + value + '\'' + | ||
", desc='" + desc + '\'' + | ||
", className='" + className + '\'' + | ||
", methodName='" + methodName + '\'' + | ||
", dtoDefinition=" + dtoDefinition + | ||
'}'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters