com.daiyc.extension.core.ExtensionPointRegistry Maven / Gradle / Ivy
package com.daiyc.extension.core;
import java.util.function.Supplier;
/**
* @author daiyc
* @since 2024/7/20
*/
@SuppressWarnings({"unchecked", "rawtypes"})
public interface ExtensionPointRegistry {
void register(Class clazz);
void register(Class clazz, T ext);
void register(Class clazz, Supplier supplier);
/**
* ExtensionPoint -> ExtensionLoader
*/
// protected final Map, ExtensionLoader>> registry = new ConcurrentHashMap<>();
//
// public void register(Class clazz) {
// assert !clazz.isInterface();
// assert !Modifier.isAbstract(clazz.getModifiers());
//
// Extension ext = clazz.getAnnotation(Extension.class);
// if (ext == null) {
// return;
// }
//
// List> points = new ArrayList<>();
//
// Class> p = clazz;
// while (!p.equals(Object.class)) {
// List> eps = Arrays.stream(p.getInterfaces())
// .filter(type -> type.isAnnotationPresent(ExtensionPoint.class))
// .collect(Collectors.toList());
// points.addAll(eps);
// p = p.getSuperclass();
// }
//
// for (Class> point : points) {
// DefaultExtensionLoader> extensionLoader = (DefaultExtensionLoader>) registry.computeIfAbsent(point, DefaultExtensionLoader::new);
// extensionLoader.register((Class) clazz);
// }
// }
//
// public ExtensionLoader getExtensionLoader(Class clazz) {
// return (ExtensionLoader) registry.get(clazz);
// }
//
// public boolean register(Class clazz, T instance) {
// // todo
// return false;
// }
//
// public T getExtension(Class clazz) {
// return getExtension(clazz, null);
// }
//
// public T getExtension(Class clazz, ExtensionMatcher matcher) {
// return null;
// }
}