ResourceAnnotationProvider改ResourceAnnotationLoader
This commit is contained in:
@@ -27,7 +27,6 @@ module org.redkale {
|
||||
exports org.redkale.convert.proto;
|
||||
exports org.redkale.convert.spi;
|
||||
exports org.redkale.inject;
|
||||
exports org.redkale.inject.spi;
|
||||
exports org.redkale.lock;
|
||||
exports org.redkale.lock.spi;
|
||||
exports org.redkale.mq;
|
||||
@@ -50,7 +49,6 @@ module org.redkale {
|
||||
uses org.redkale.cache.spi.CacheManagerProvider;
|
||||
uses org.redkale.cluster.spi.ClusterAgentProvider;
|
||||
uses org.redkale.convert.spi.ConvertProvider;
|
||||
uses org.redkale.inject.spi.ResourceAnnotationProvider;
|
||||
uses org.redkale.mq.spi.MessageAgentProvider;
|
||||
uses org.redkale.schedule.spi.ScheduleManagerProvider;
|
||||
uses org.redkale.source.spi.CacheSourceProvider;
|
||||
|
||||
@@ -1,26 +1,24 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package org.redkale.inject.spi;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Field;
|
||||
import org.redkale.inject.ResourceFactory;
|
||||
|
||||
/**
|
||||
* 自定义注入加载器
|
||||
*
|
||||
* <p>
|
||||
* 详情见: https://redkale.org
|
||||
*
|
||||
* @author zhangjx
|
||||
* @param <T> Annotation
|
||||
*/
|
||||
public interface ResourceAnnotationProvider<T extends Annotation> {
|
||||
|
||||
public void load(ResourceFactory factory, String srcResourceName, Object srcObj, T annotation, Field field, Object attachment);
|
||||
|
||||
public Class<T> annotationType();
|
||||
}
|
||||
/*
|
||||
*
|
||||
*/
|
||||
package org.redkale.inject;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
/**
|
||||
* 自定义注入加载器
|
||||
*
|
||||
* <p>
|
||||
* 详情见: https://redkale.org
|
||||
*
|
||||
* @since 2.8.0
|
||||
* @author zhangjx
|
||||
* @param <T> Annotation
|
||||
*/
|
||||
public interface ResourceAnnotationLoader<T extends Annotation> {
|
||||
|
||||
public void load(ResourceFactory factory, String srcResourceName, Object srcObj, T annotation, Field field, Object attachment);
|
||||
|
||||
public Class<T> annotationType();
|
||||
}
|
||||
@@ -18,7 +18,6 @@ import java.util.logging.*;
|
||||
import org.redkale.annotation.*;
|
||||
import org.redkale.convert.*;
|
||||
import org.redkale.convert.json.JsonConvert;
|
||||
import org.redkale.inject.spi.ResourceAnnotationProvider;
|
||||
import org.redkale.util.RedkaleClassLoader;
|
||||
import org.redkale.util.RedkaleException;
|
||||
import org.redkale.util.TypeToken;
|
||||
@@ -52,7 +51,7 @@ public final class ResourceFactory {
|
||||
|
||||
private final List<WeakReference<ResourceFactory>> chidren = new CopyOnWriteArrayList<>();
|
||||
|
||||
private final ConcurrentHashMap<Class<? extends Annotation>, ResourceAnnotationProvider> resAnnotationProviderMap = new ConcurrentHashMap();
|
||||
private final ConcurrentHashMap<Class<? extends Annotation>, ResourceAnnotationLoader> resAnnotationLoaderMap = new ConcurrentHashMap();
|
||||
|
||||
private final ConcurrentHashMap<Type, ResourceTypeLoader> resTypeLoaderMap = new ConcurrentHashMap();
|
||||
|
||||
@@ -60,16 +59,6 @@ public final class ResourceFactory {
|
||||
|
||||
private ResourceFactory(ResourceFactory parent) {
|
||||
this.parent = parent;
|
||||
if (parent == null) {
|
||||
ServiceLoader<ResourceAnnotationProvider> loaders = ServiceLoader.load(ResourceAnnotationProvider.class);
|
||||
RedkaleClassLoader.putServiceLoader(ResourceAnnotationProvider.class);
|
||||
Iterator<ResourceAnnotationProvider> it = loaders.iterator();
|
||||
while (it.hasNext()) {
|
||||
ResourceAnnotationProvider ril = it.next();
|
||||
RedkaleClassLoader.putReflectionPublicConstructors(ril.getClass(), ril.getClass().getName());
|
||||
this.resAnnotationProviderMap.put(ril.annotationType(), ril);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -857,7 +846,7 @@ public final class ResourceFactory {
|
||||
try {
|
||||
list.add(srcObj);
|
||||
Class clazz = srcObj.getClass();
|
||||
final boolean diyLoaderFlag = !parentRoot().resAnnotationProviderMap.isEmpty();
|
||||
final boolean diyLoaderFlag = !parentRoot().resAnnotationLoaderMap.isEmpty();
|
||||
do {
|
||||
if (java.lang.Enum.class.isAssignableFrom(clazz)) {
|
||||
break;
|
||||
@@ -897,7 +886,7 @@ public final class ResourceFactory {
|
||||
}
|
||||
}
|
||||
if (flag && diyLoaderFlag) {
|
||||
parentRoot().resAnnotationProviderMap.values().stream().forEach(iloader -> {
|
||||
parentRoot().resAnnotationLoaderMap.values().stream().forEach(iloader -> {
|
||||
Annotation ann = field.getAnnotation(iloader.annotationType());
|
||||
if (ann != null) {
|
||||
iloader.load(this, srcResourceName, srcObj, ann, field, attachment);
|
||||
@@ -1062,9 +1051,9 @@ public final class ResourceFactory {
|
||||
}
|
||||
}
|
||||
|
||||
public <T extends Annotation> void register(final ResourceAnnotationProvider<T> loader) {
|
||||
public <T extends Annotation> void register(final ResourceAnnotationLoader<T> loader) {
|
||||
Objects.requireNonNull(loader);
|
||||
parentRoot().resAnnotationProviderMap.put(loader.annotationType(), loader);
|
||||
parentRoot().resAnnotationLoaderMap.put(loader.annotationType(), loader);
|
||||
}
|
||||
|
||||
public void register(final ResourceTypeLoader rs, final Type... clazzs) {
|
||||
|
||||
@@ -23,10 +23,10 @@ import org.redkale.boot.ClassFilter;
|
||||
import org.redkale.boot.ModuleEngine;
|
||||
import org.redkale.boot.NodeServer;
|
||||
import org.redkale.convert.json.JsonConvert;
|
||||
import org.redkale.inject.ResourceAnnotationLoader;
|
||||
import org.redkale.inject.ResourceEvent;
|
||||
import org.redkale.inject.ResourceFactory;
|
||||
import org.redkale.inject.ResourceTypeLoader;
|
||||
import org.redkale.inject.spi.ResourceAnnotationProvider;
|
||||
import org.redkale.mq.MessageConsumer;
|
||||
import org.redkale.mq.MessageManager;
|
||||
import org.redkale.mq.MessageProducer;
|
||||
@@ -187,7 +187,7 @@ public class MessageModuleEngine extends ModuleEngine {
|
||||
}
|
||||
this.messageAgents = mqs;
|
||||
//------------------------------------ 注册 ResourceProducer MessageProducer ------------------------------------
|
||||
resourceFactory.register(new ResourceAnnotationProvider<ResourceProducer>() {
|
||||
resourceFactory.register(new ResourceAnnotationLoader<ResourceProducer>() {
|
||||
@Override
|
||||
public void load(ResourceFactory rf, String srcResourceName, Object srcObj, ResourceProducer annotation, Field field, Object attachment) {
|
||||
if (field.getType() != MessageProducer.class) {
|
||||
|
||||
@@ -12,8 +12,8 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
import java.lang.reflect.Field;
|
||||
import org.junit.jupiter.api.*;
|
||||
import org.redkale.convert.json.JsonConvert;
|
||||
import org.redkale.inject.ResourceAnnotationLoader;
|
||||
import org.redkale.inject.ResourceFactory;
|
||||
import org.redkale.inject.spi.ResourceAnnotationProvider;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -38,7 +38,7 @@ public class ResourceAnnotationTest {
|
||||
if (!main) Assertions.assertEquals(new File("conf/test.xml").toString(), bean.conf.toString());
|
||||
}
|
||||
|
||||
public static class CustomConfProvider implements ResourceAnnotationProvider<CustomConf> {
|
||||
public static class CustomConfProvider implements ResourceAnnotationLoader<CustomConf> {
|
||||
|
||||
@Override
|
||||
public void load(ResourceFactory factory, String srcResourceName, Object srcObj, CustomConf annotation, Field field, Object attachment) {
|
||||
|
||||
Reference in New Issue
Block a user