@Override
public <T> List<ExtensionWrapper<T>> find(Class<T> type) {
- log.debug("Find extensions for extension point {}", type.getName());
+ log.debug("Checking extension point '{}'", type.getName());
+ if (!isExtensionPoint(type)) {
+ log.warn("'{}' is not an extension point", type.getName());
+
+ return Collections.emptyList(); // or return null ?!
+ }
+
+ log.debug("Finding extensions for extension point '{}'", type.getName());
List<ExtensionWrapper<T>> result = new ArrayList<ExtensionWrapper<T>>();
if (entries == null) {
entries = readIndexFiles();
for (String entry : entries) {
try {
Class<?> extensionType = classLoader.loadClass(entry);
- log.debug("Checking extension type {}", extensionType.getName());
+ log.debug("Checking extension type '{}'", extensionType.getName());
if (type.isAssignableFrom(extensionType)) {
Object instance = extensionFactory.create(extensionType);
if (instance != null) {
Extension extension = extensionType.getAnnotation(Extension.class);
- log.debug("Added extension {} with ordinal {}", extensionType.getName(), extension.ordinal());
+ log.debug("Added extension '{}' with ordinal {}", extensionType.getName(), extension.ordinal());
result.add(new ExtensionWrapper<T>(type.cast(instance), extension.ordinal()));
}
} else {
- log.warn("{} is not an extension for extension point {}", extensionType.getName(), type.getName());
+ log.warn("'{}' is not an extension for extension point '{}'", extensionType.getName(), type.getName());
}
} catch (ClassNotFoundException e) {
log.error(e.getMessage(), e);
}
if (entries.isEmpty()) {
- log.debug("No extensions found for extension point {}", type.getName());
+ log.debug("No extensions found for extension point '{}'", type.getName());
} else {
- log.debug("Found {} extensions for extension point {}", entries.size(), type.getName());
+ log.debug("Found {} extensions for extension point '{}'", entries.size(), type.getName());
}
// sort by "ordinal" property
@Override
public Object create(Class<?> extensionType) {
- log.debug("Create instance for extension {}", extensionType.getName());
+ log.debug("Create instance for extension '{}'", extensionType.getName());
try {
return extensionType.newInstance();
}
return entries;
- }
+ }
+
+ private boolean isExtensionPoint(Class type) {
+ return ExtensionPoint.class.isAssignableFrom(type);
+ }
/**
* Creates an extension instance.