Class ExtensionSupport
java.lang.Object
ca.phon.extensions.ExtensionSupport
- All Implemented Interfaces:
IExtendable
Class which provides extension support for objects
that implement the IExtendable interface.
This class can also perform automatic installation
of extensions declared in the
META-INF/services/ca.phon.extensions.ExtensionProvider.
file.
Example:
The IExtendable object:
public class MyExtendableObject implements IExtendable {
private final ExtensionSupport = new ExtensionSupport(MyExtendableObject.class, this);
...
}
Custom extension (note the requirement of the Extension annotation:)
@MyExtension(MyExtendableObject.class)
public class MyExtension {
}
Extension provider (note the requirement of the Extension annotation:)
@Extension(MyExtendableObject.class)
public class MyExtensionProvider implements ExtensionProvider {
@Overrides
public void installExtension(IExtendable obj) {
obj.putExtension(MyExtension.class, new MyExtension());
}
}
In the META-INF/services/ca.phon.extensions.ExtensionProvider file:
my.class.path.MyExtensionProviderNow, every time a new instance of
MyExtendableObject is created
a new MyExtension object will also be created and attached to
our IExtendable object.
-
Constructor Summary
ConstructorsModifierConstructorDescription<T extends IExtendable>ExtensionSupport(Class<? extends T> declaredType, T obj) Create a new extension support object for the given object. -
Method Summary
Modifier and TypeMethodDescription<T> TgetExtension(Class<T> cap) Get the requested extension if available.Return all extension types supportedstatic <T> Optional<T> getOptionalExtension(IExtendable extendable, Class<T> cap) Static utility method for returning an extension wrapped in aOptionalvoidLoad automatic extensions as defined in the classpath META-INF/services files<T> TputExtension(Class<T> cap, T impl) Add a new extension.<T> TremoveExtension(Class<T> cap) Remove a capability.
-
Constructor Details
-
ExtensionSupport
Create a new extension support object for the given object. This class will automatically load any extensions- Parameters:
declaredType-obj-
-
-
Method Details
-
initExtensions
public void initExtensions()Load automatic extensions as defined in the classpath META-INF/services files -
getExtensions
Description copied from interface:IExtendableReturn all extension types supported- Specified by:
getExtensionsin interfaceIExtendable
-
getExtension
Description copied from interface:IExtendableGet the requested extension if available.- Specified by:
getExtensionin interfaceIExtendable- Returns:
- the capability object or
nullif the cability is not available
-
putExtension
Description copied from interface:IExtendableAdd a new extension.- Specified by:
putExtensionin interfaceIExtendable- Parameters:
cap- the extension to add- Returns:
- the added extension implementation
-
removeExtension
Description copied from interface:IExtendableRemove a capability.- Specified by:
removeExtensionin interfaceIExtendable- Parameters:
cap- the capability to remove
-
getOptionalExtension
Static utility method for returning an extension wrapped in aOptional- Parameters:
extendable-cap-- Returns:
- optional of requested extension
-