From 5f6bf879d6cb2fe841c20306b12f67b38e343437 Mon Sep 17 00:00:00 2001 From: Oliver Drotbohm Date: Mon, 4 Mar 2019 16:14:10 +0100 Subject: [PATCH] #40 - Fixed docs on general usage of PluginFactory API. --- README.markdown | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/README.markdown b/README.markdown index f0e1e95..bf82c0d 100644 --- a/README.markdown +++ b/README.markdown @@ -47,7 +47,7 @@ public interface MyPluginInterface { /** - * A host application class working with instances of the plugin + * A host application class working with instances of the plugin * interface. */ public class HostImpl implements Host { @@ -70,7 +70,7 @@ public class HostImpl implements Host { } ``` -This is the way you would typically construct a host component in general. Leveraging dependency injection via setters allows flexible usage in a variety of environments. Thus you could easily provide a factory class that is able to lookup `MyPluginInterface` +This is the way you would typically construct a host component in general. Leveraging dependency injection via setters allows flexible usage in a variety of environments. Thus you could easily provide a factory class that is able to lookup `MyPluginInterface` implementations from the classpath, instantiate them and inject them into `HostImpl`. Using Spring as component container you could configure something like this: @@ -201,15 +201,14 @@ cases Spring Plugin provides a `PluginRegistry, S>` interfac **Example 1.7. Usage of the PluginRegistry** ```java -PluginRegistry registry = SimplePluginRegistry.create(); -// Add plugin instances -registry.add(new FooImplementation()); -// Returns the first plugin supporting SOFTWARE -registry.getPluginFor(ProductType.SOFTWARE); +PluginRegistry registry = SimplePluginRegistry.of(new FooImplementation()); + +// Returns the first plugin supporting SOFTWARE if available +Optional plugin = registry.getPluginFor(ProductType.SOFTWARE); // Returns the first plugin supporting SOFTWARE, or DefaultPlugin if none found -registry.getPluginFor(ProductType.SOFTWARE, new DefaultPlugin()); +ProductProcessor plugin = registry.getPluginOrDefaultFor(ProductType.SOFTWARE, () -> new DefaultPlugin()); // Returns all plugins supporting HARDWARE, throwing the given exception if none found -registry.getPluginsFor(ProductType.HARDWARE, new MyException("Damn!"); +List plugin = registry.getPluginsFor(ProductType.HARDWARE, () -> new MyException("Damn!"); ``` #### Configuration, XML namespace and @EnablePluginRegistries @@ -276,15 +275,15 @@ The `MetadataProvider` interface is to be used in application plugin interfaces ### O OSGi - + * Open Services Gateway Initiative - a fully fledged plugin runtime environment on top of the Java VM - [http://en.wikipedia.org/wiki/OSGi](http://en.wikipedia.org/wiki/OSGi). ### X XML - + * eXtensible Markup Language XSD - + * Xml Schema Definition