Browse Source

Improve public API of Extention* classes (#175)

pull/176/head
Sergey Tyurin 7 years ago committed by Decebal Suiu
parent
commit
5529c4dd08
  1. 9
      pf4j/src/main/java/org/pf4j/AbstractExtensionFinder.java
  2. 19
      pf4j/src/main/java/org/pf4j/ExtensionDescriptor.java
  3. 17
      pf4j/src/main/java/org/pf4j/ExtensionWrapper.java

9
pf4j/src/main/java/org/pf4j/AbstractExtensionFinder.java

@ -219,18 +219,13 @@ public abstract class AbstractExtensionFinder implements ExtensionFinder, Plugin
}
private ExtensionWrapper createExtensionWrapper(Class<?> extensionClass) {
ExtensionDescriptor descriptor = new ExtensionDescriptor();
int ordinal = 0;
if (extensionClass.isAnnotationPresent(Extension.class)) {
ordinal = extensionClass.getAnnotation(Extension.class).ordinal();
}
descriptor.setOrdinal(ordinal);
descriptor.setExtensionClass(extensionClass);
ExtensionDescriptor descriptor = new ExtensionDescriptor(ordinal, extensionClass);
ExtensionWrapper extensionWrapper = new ExtensionWrapper<>(descriptor);
extensionWrapper.setExtensionFactory(pluginManager.getExtensionFactory());
return extensionWrapper;
return new ExtensionWrapper<>(descriptor, pluginManager.getExtensionFactory());
}
private void checkDifferentClassLoaders(Class<?> type, Class<?> extensionClass) {

19
pf4j/src/main/java/org/pf4j/ExtensionDescriptor.java

@ -20,23 +20,12 @@ package org.pf4j;
*/
public class ExtensionDescriptor {
private int ordinal;
private Class<?> extensionClass;
public final int ordinal;
public final Class<?> extensionClass;
public Class<?> getExtensionClass() {
return extensionClass;
}
public int getOrdinal() {
return ordinal;
}
void setExtensionClass(Class<?> extensionClass) {
this.extensionClass = extensionClass;
}
void setOrdinal(int ordinal) {
public ExtensionDescriptor(int ordinal, Class<?> extensionClass) {
this.ordinal = ordinal;
this.extensionClass = extensionClass;
}
}

17
pf4j/src/main/java/org/pf4j/ExtensionWrapper.java

@ -22,18 +22,19 @@ package org.pf4j;
*/
public class ExtensionWrapper<T> implements Comparable<ExtensionWrapper<T>> {
ExtensionDescriptor descriptor;
ExtensionFactory extensionFactory;
T extension; // cache
private final ExtensionDescriptor descriptor;
private final ExtensionFactory extensionFactory;
private T extension; // cache
public ExtensionWrapper(ExtensionDescriptor descriptor) {
public ExtensionWrapper(ExtensionDescriptor descriptor, ExtensionFactory extensionFactory) {
this.descriptor = descriptor;
this.extensionFactory = extensionFactory;
}
@SuppressWarnings("unchecked")
public T getExtension() {
if (extension == null) {
extension = (T) extensionFactory.create(descriptor.getExtensionClass());
extension = (T) extensionFactory.create(descriptor.extensionClass);
}
return extension;
@ -44,7 +45,7 @@ public class ExtensionWrapper<T> implements Comparable<ExtensionWrapper<T>> {
}
public int getOrdinal() {
return descriptor.getOrdinal();
return descriptor.ordinal;
}
@Override
@ -52,8 +53,4 @@ public class ExtensionWrapper<T> implements Comparable<ExtensionWrapper<T>> {
return (getOrdinal() - o.getOrdinal());
}
void setExtensionFactory(ExtensionFactory extensionFactory) {
this.extensionFactory = extensionFactory;
}
}

Loading…
Cancel
Save