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