summaryrefslogtreecommitdiffstats
path: root/pf4j/src
diff options
context:
space:
mode:
authorSergey Tyurin <sergey.v.tyurin@gmail.com>2017-10-12 04:48:25 -0700
committerDecebal Suiu <decebal.suiu@gmail.com>2017-10-12 14:48:25 +0300
commit5529c4dd08b1db8c6748cb622476b1a446636c35 (patch)
tree439d64e8cb069547cca87bdfa4bd3f765a08029e /pf4j/src
parent2b1b2f88929b92ae9a29724a9542bf76a4e51a0a (diff)
downloadpf4j-5529c4dd08b1db8c6748cb622476b1a446636c35.tar.gz
pf4j-5529c4dd08b1db8c6748cb622476b1a446636c35.zip
Improve public API of Extention* classes (#175)
Diffstat (limited to 'pf4j/src')
-rw-r--r--pf4j/src/main/java/org/pf4j/AbstractExtensionFinder.java9
-rw-r--r--pf4j/src/main/java/org/pf4j/ExtensionDescriptor.java19
-rw-r--r--pf4j/src/main/java/org/pf4j/ExtensionWrapper.java19
3 files changed, 14 insertions, 33 deletions
diff --git a/pf4j/src/main/java/org/pf4j/AbstractExtensionFinder.java b/pf4j/src/main/java/org/pf4j/AbstractExtensionFinder.java
index 49be73b..7aa64ca 100644
--- a/pf4j/src/main/java/org/pf4j/AbstractExtensionFinder.java
+++ b/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) {
diff --git a/pf4j/src/main/java/org/pf4j/ExtensionDescriptor.java b/pf4j/src/main/java/org/pf4j/ExtensionDescriptor.java
index cb0ebc1..4894046 100644
--- a/pf4j/src/main/java/org/pf4j/ExtensionDescriptor.java
+++ b/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;
}
}
diff --git a/pf4j/src/main/java/org/pf4j/ExtensionWrapper.java b/pf4j/src/main/java/org/pf4j/ExtensionWrapper.java
index 50c9612..22a2c53 100644
--- a/pf4j/src/main/java/org/pf4j/ExtensionWrapper.java
+++ b/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;
- }
-
}