]> source.dussan.org Git - pf4j.git/commitdiff
Improve public API of Extention* classes (#175)
authorSergey Tyurin <sergey.v.tyurin@gmail.com>
Thu, 12 Oct 2017 11:48:25 +0000 (04:48 -0700)
committerDecebal Suiu <decebal.suiu@gmail.com>
Thu, 12 Oct 2017 11:48:25 +0000 (14:48 +0300)
pf4j/src/main/java/org/pf4j/AbstractExtensionFinder.java
pf4j/src/main/java/org/pf4j/ExtensionDescriptor.java
pf4j/src/main/java/org/pf4j/ExtensionWrapper.java

index 49be73bc84d3c9d37b19eb8ab58a61a01c336b95..7aa64ca07a3898335be2fa337b64da4526c58372 100644 (file)
@@ -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) {
index cb0ebc1f346ddbb56c8df453f470a61081ae47e7..489404615e88ddcd4ca5e72844fc55fde28047dd 100644 (file)
@@ -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;
     }
 
 }
index 50c9612d05dc97c5d9733fd4d0be7fd8b133607b..22a2c53a95f2621d3ad004191ff33fc8d7fa3ebb 100644 (file)
@@ -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;
-    }
-
 }