org.specrunner.plugins.core.factories
Class PluginFactoryImpl

java.lang.Object
  extended by org.specrunner.plugins.core.factories.PluginFactoryImpl
All Implemented Interfaces:
IPluginFactory
Direct Known Subclasses:
PluginFactoryAttribute, PluginFactoryCSS, PluginFactoryCustom, PluginFactoryElement

public abstract class PluginFactoryImpl
extends Object
implements IPluginFactory

Partial plugin factory implementation.

Author:
Thiago Santos.

Field Summary
protected  Map<String,String> aliasToTypeNames
          Map from alias to class name.
protected  Map<String,Class<? extends IPlugin>> aliasToTypes
          Map from alias to types.
protected  Map<String,IPlugin> templates
          Map from alias to templates.
protected  Map<String,String> typeNamesToAlias
          Map from alias to names.
 
Constructor Summary
protected PluginFactoryImpl(String file, PluginKind kind)
          Creates a factory loading the given file.
 
Method Summary
 IPluginFactory bind(PluginKind kind, String alias, IPlugin plugin)
          Bind a plugin instance to a given kind.
 boolean finalizePlugin(nu.xom.Node source, IContext context, IPlugin plugin)
          Finalize a plugin.
 String getAlias(Class<? extends IPlugin> type)
          Given a class, for example, return the corresponding alias for the plugin.
 Class<? extends IPlugin> getClass(String alias)
          Given a name, return the corresponding plugin class associated. i.e.
 PluginKind getKind()
          Get the kind to factory.
 void initialize()
          Initialize the factory.
protected  boolean test(PluginKind type)
          Test if the factory accept the plugin.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.specrunner.plugins.IPluginFactory
newPlugin
 

Field Detail

aliasToTypeNames

protected Map<String,String> aliasToTypeNames
Map from alias to class name.


aliasToTypes

protected Map<String,Class<? extends IPlugin>> aliasToTypes
Map from alias to types.


templates

protected Map<String,IPlugin> templates
Map from alias to templates.


typeNamesToAlias

protected Map<String,String> typeNamesToAlias
Map from alias to names.

Constructor Detail

PluginFactoryImpl

protected PluginFactoryImpl(String file,
                            PluginKind kind)
Creates a factory loading the given file.

Parameters:
file - The file to be loaded.
kind - The factory kind.
Method Detail

getKind

public PluginKind getKind()
Get the kind to factory.

Returns:
The factory kind.

initialize

public void initialize()
                throws PluginException
Initialize the factory.

Throws:
PluginException - On initialization errors.

getClass

public Class<? extends IPlugin> getClass(String alias)
                                  throws PluginException
Description copied from interface: IPluginFactory
Given a name, return the corresponding plugin class associated. i.e. For 'include' the class PluginInclude of core plugins package is returned or if 'bean' is requested the PluginBean is returned.

Specified by:
getClass in interface IPluginFactory
Parameters:
alias - The plugin alias.
Returns:
The class, if type is mapped, null, otherwise.
Throws:
PluginException - On reference lookup failure.

getAlias

public String getAlias(Class<? extends IPlugin> type)
                throws PluginException
Description copied from interface: IPluginFactory
Given a class, for example, return the corresponding alias for the plugin.

Specified by:
getAlias in interface IPluginFactory
Parameters:
type - The plugin type, i.e. 'PluginInclude.class', 'PluginConnection', etc.
Returns:
The alias, if type is mapped, null, otherwise. Null does not means a invalid plugin, but the plugin is either not mapped in the usual way, or the factory of plugins is not based on alias premises.
Throws:
PluginException - On alias lookup name failure.

bind

public IPluginFactory bind(PluginKind kind,
                           String alias,
                           IPlugin plugin)
                    throws PluginException
Description copied from interface: IPluginFactory
Bind a plugin instance to a given kind.

Specified by:
bind in interface IPluginFactory
Parameters:
kind - The plugin kind.
alias - The alias.
plugin - The plugin instance.
Returns:
The factory itself.
Throws:
PluginException - On bind errors.

test

protected boolean test(PluginKind type)
Test if the factory accept the plugin.

Parameters:
type - The plugin type.
Returns:
true, if accept the type, false, otherwise.

finalizePlugin

public boolean finalizePlugin(nu.xom.Node source,
                              IContext context,
                              IPlugin plugin)
                       throws PluginException
Description copied from interface: IPluginFactory
Finalize a plugin.

Specified by:
finalizePlugin in interface IPluginFactory
Parameters:
source - The source Node..
context - The context.
plugin - The previously created plugin for this node.
Returns:
true, if finalized, false, otherwise.
Throws:
PluginException - On finalization error.


Copyright © 2014. All rights reserved.