org.codehaus.groovy.grails.plugins
Class DefaultGrailsPlugin

java.lang.Object
  extended by groovy.lang.GroovyObjectSupport
      extended by org.codehaus.groovy.grails.plugins.AbstractGrailsPlugin
          extended by org.codehaus.groovy.grails.plugins.DefaultGrailsPlugin
All Implemented Interfaces:
groovy.lang.GroovyObject, GrailsPlugin, ParentApplicationContextAware, ApplicationContextAware

public class DefaultGrailsPlugin
extends AbstractGrailsPlugin
implements GrailsPlugin, ParentApplicationContextAware

Implementation of the GrailsPlugin interface that wraps a Groovy plugin class and provides the magic to invoke its various methods from Java

Since:
0.4
Author:
Graeme Rocher

Nested Class Summary
 
Nested classes/interfaces inherited from class org.codehaus.groovy.grails.plugins.AbstractGrailsPlugin
AbstractGrailsPlugin.GrailsPluginClass
 
Field Summary
protected  BeanWrapper pluginBean
           
 
Fields inherited from class org.codehaus.groovy.grails.plugins.AbstractGrailsPlugin
application, applicationContext, dependencies, dependencyNames, evictionList, manager, pluginClass, version
 
Fields inherited from interface org.codehaus.groovy.grails.plugins.GrailsPlugin
ARTEFACTS, DEPENDS_ON, DO_WITH_APPLICATION_CONTEXT, DO_WITH_DYNAMIC_METHODS, DO_WITH_SPRING, DO_WITH_WEB_DESCRIPTOR, EVENT_ON_CHANGE, EVENT_ON_CONFIG_CHANGE, EVICT, INFLUENCES, ON_CHANGE, ON_CONFIG_CHANGE, PROVIDED_ARTEFACTS, STATUS, STATUS_DISABLED, STATUS_ENABLED, TRAILING_NAME, VERSION, WATCHED_RESOURCES
 
Constructor Summary
DefaultGrailsPlugin(Class pluginClass, GrailsApplication application)
           
DefaultGrailsPlugin(Class pluginClass, Resource resource, GrailsApplication application)
           
 
Method Summary
 BeanBuilder beans(groovy.lang.Closure closure)
           
 boolean checkForChanges()
          Monitors the plugin resources defined in the watchResources property for changes and fires onChange events by calling an onChange closure defined in the plugin (if it exists)
 void doArtefactConfiguration()
          Called prior to the initialisation of the GrailsApplication instance to allow the registration of additonal ArtefactHandlers
 void doWithApplicationContext(ApplicationContext applicationContext)
          This method is called to allow the plugin to add BeanDefinitions to the BeanDefinitionRegistry.
 void doWithDynamicMethods(ApplicationContext applicationContext)
          Calls a "doWithDynamicMethods" closure that allows a plugin to register dynamic methods at runtime
 void doWithRuntimeConfiguration(RuntimeSpringConfiguration springConfig)
          Executes the plugin code that performs runtime configuration as defined in the doWithSpring closure
 void doWithWebDescriptor(groovy.util.slurpersupport.GPathResult webXml)
          Handles processing of web.xml.
protected  void fireModifiedEvent(Resource resource, GrailsPlugin plugin)
           
 String[] getDependencyNames()
           
 String getDependentVersion(String name)
          The version of the specified dependency
 groovy.lang.GroovyObject getInstance()
          Retrieves the wrapped plugin instance for this plugin
 String[] getLoadAfterNames()
          Retrieves the names of plugins that this plugin should be loaded after.
 org.apache.commons.logging.Log getLog()
           
 String getName()
           
 String[] getObservedPluginNames()
          Retrieve the plugin names that this plugin is observing for changes
 ApplicationContext getParentCtx()
           
 GrailsPlugin getPlugin()
           
 Class[] getProvidedArtefacts()
          Retrieves an array of provided Artefacts that are pre-compiled additions to the GrailsApplication object but are overridable by the end-user
 PathMatchingResourcePatternResolver getResolver()
           
 String getVersion()
           
 Resource[] getWatchedResources()
           
 boolean isEnabled()
           
 Map notifyOfEvent(int eventKind, Object source)
          Notifies the plugin of a specific event for the given event id, which is one of ON_CHANGE, ON_CONFIG_CHANGE
 void notifyOfEvent(Map event)
          Notifies this plugin of the specified Event calling the onChange listener
 void refresh()
          Refreshes this Grails plugin reloading any watched resources as necessary
 void refresh(boolean fireEvent)
           
 void restartContainer()
           
 void setParentApplicationContext(ApplicationContext parent)
           
 void setWatchedResources(Resource[] watchedResources)
           
 String toString()
           
 
Methods inherited from class org.codehaus.groovy.grails.plugins.AbstractGrailsPlugin
getEvictionNames, getManager, setApplication, setApplicationContext, setManager
 
Methods inherited from class groovy.lang.GroovyObjectSupport
getMetaClass, getProperty, invokeMethod, setMetaClass, setProperty
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.codehaus.groovy.grails.plugins.GrailsPlugin
getEvictionNames, getManager, setApplication, setManager
 
Methods inherited from interface org.springframework.context.ApplicationContextAware
setApplicationContext
 

Field Detail

pluginBean

protected BeanWrapper pluginBean
Constructor Detail

DefaultGrailsPlugin

public DefaultGrailsPlugin(Class pluginClass,
                           Resource resource,
                           GrailsApplication application)

DefaultGrailsPlugin

public DefaultGrailsPlugin(Class pluginClass,
                           GrailsApplication application)
Method Detail

getLoadAfterNames

public String[] getLoadAfterNames()
Description copied from interface: GrailsPlugin
Retrieves the names of plugins that this plugin should be loaded after. This differs from dependencies in that if that plugin doesn't exist this plugin will still be loaded. It is a way of enforcing plugins are loaded before, but not necessarily needed

Specified by:
getLoadAfterNames in interface GrailsPlugin
Overrides:
getLoadAfterNames in class AbstractGrailsPlugin
Returns:
The names of the plugins that this plugin should be loaded after

getResolver

public PathMatchingResourcePatternResolver getResolver()
Returns:
the resolver

getParentCtx

public ApplicationContext getParentCtx()

beans

public BeanBuilder beans(groovy.lang.Closure closure)

doWithApplicationContext

public void doWithApplicationContext(ApplicationContext applicationContext)
Description copied from interface: GrailsPlugin

This method is called to allow the plugin to add BeanDefinitions to the BeanDefinitionRegistry.

Specified by:
doWithApplicationContext in interface GrailsPlugin
Specified by:
doWithApplicationContext in class AbstractGrailsPlugin
Parameters:
applicationContext - The Spring ApplicationContext instance

doWithRuntimeConfiguration

public void doWithRuntimeConfiguration(RuntimeSpringConfiguration springConfig)
Description copied from interface: GrailsPlugin
Executes the plugin code that performs runtime configuration as defined in the doWithSpring closure

Specified by:
doWithRuntimeConfiguration in interface GrailsPlugin
Specified by:
doWithRuntimeConfiguration in class AbstractGrailsPlugin
Parameters:
springConfig - The RuntimeSpringConfiguration instance

getName

public String getName()
Specified by:
getName in interface GrailsPlugin
Overrides:
getName in class AbstractGrailsPlugin
Returns:
The name of the plug-in

getVersion

public String getVersion()
Specified by:
getVersion in interface GrailsPlugin
Overrides:
getVersion in class AbstractGrailsPlugin
Returns:
The version of the plug-in

getDependencyNames

public String[] getDependencyNames()
Specified by:
getDependencyNames in interface GrailsPlugin
Overrides:
getDependencyNames in class AbstractGrailsPlugin
Returns:
The names of the plugins this plugin is dependant on

getWatchedResources

public Resource[] getWatchedResources()
Returns:
the watchedResources

getDependentVersion

public String getDependentVersion(String name)
Description copied from interface: GrailsPlugin
The version of the specified dependency

Specified by:
getDependentVersion in interface GrailsPlugin
Overrides:
getDependentVersion in class AbstractGrailsPlugin
Parameters:
name - the name of the dependency
Returns:
The version

toString

public String toString()
Overrides:
toString in class Object

doWithWebDescriptor

public void doWithWebDescriptor(groovy.util.slurpersupport.GPathResult webXml)
Description copied from interface: GrailsPlugin
Handles processing of web.xml. The method is passed a GPathResult which is parsed by groovy.util.XmlSlurper. A plug-in can then manipulate the in-memory XML however it chooses Once all plug-ins have been processed the web.xml is then written to disk based on its in-memory form

Specified by:
doWithWebDescriptor in interface GrailsPlugin
Overrides:
doWithWebDescriptor in class AbstractGrailsPlugin
Parameters:
webXml - The GPathResult representing web.xml

checkForChanges

public boolean checkForChanges()
Monitors the plugin resources defined in the watchResources property for changes and fires onChange events by calling an onChange closure defined in the plugin (if it exists)

Specified by:
checkForChanges in interface GrailsPlugin
Overrides:
checkForChanges in class AbstractGrailsPlugin
Returns:
Returns true when the plug-in itself changes in some way, as oppose to plug-in resources

fireModifiedEvent

protected void fireModifiedEvent(Resource resource,
                                 GrailsPlugin plugin)

restartContainer

public void restartContainer()

setWatchedResources

public void setWatchedResources(Resource[] watchedResources)
                         throws IOException
Throws:
IOException

getLog

public org.apache.commons.logging.Log getLog()

getPlugin

public GrailsPlugin getPlugin()

setParentApplicationContext

public void setParentApplicationContext(ApplicationContext parent)
Specified by:
setParentApplicationContext in interface ParentApplicationContextAware

refresh

public void refresh()
Description copied from interface: GrailsPlugin
Refreshes this Grails plugin reloading any watched resources as necessary

Specified by:
refresh in interface GrailsPlugin
Overrides:
refresh in class AbstractGrailsPlugin

refresh

public void refresh(boolean fireEvent)

getInstance

public groovy.lang.GroovyObject getInstance()
Description copied from interface: GrailsPlugin
Retrieves the wrapped plugin instance for this plugin

Specified by:
getInstance in interface GrailsPlugin
Returns:
The plugin instance

doWithDynamicMethods

public void doWithDynamicMethods(ApplicationContext applicationContext)
Description copied from interface: GrailsPlugin
Calls a "doWithDynamicMethods" closure that allows a plugin to register dynamic methods at runtime

Specified by:
doWithDynamicMethods in interface GrailsPlugin
Parameters:
applicationContext - The Spring ApplicationContext instance

isEnabled

public boolean isEnabled()
Specified by:
isEnabled in interface GrailsPlugin
Returns:
Whether the plugin is enabled or not

getObservedPluginNames

public String[] getObservedPluginNames()
Description copied from interface: GrailsPlugin
Retrieve the plugin names that this plugin is observing for changes

Specified by:
getObservedPluginNames in interface GrailsPlugin
Returns:
The names of the observed plugins

notifyOfEvent

public void notifyOfEvent(Map event)
Description copied from interface: GrailsPlugin
Notifies this plugin of the specified Event calling the onChange listener

Specified by:
notifyOfEvent in interface GrailsPlugin
Parameters:
event - The event to listen for

notifyOfEvent

public Map notifyOfEvent(int eventKind,
                         Object source)
Description copied from interface: GrailsPlugin
Notifies the plugin of a specific event for the given event id, which is one of ON_CHANGE, ON_CONFIG_CHANGE

Specified by:
notifyOfEvent in interface GrailsPlugin
Parameters:
eventKind - The event kind
source - The source of the event
Returns:
a Map that represents the event

doArtefactConfiguration

public void doArtefactConfiguration()
Description copied from interface: GrailsPlugin
Called prior to the initialisation of the GrailsApplication instance to allow the registration of additonal ArtefactHandlers

Specified by:
doArtefactConfiguration in interface GrailsPlugin
Specified by:
doArtefactConfiguration in class AbstractGrailsPlugin
See Also:
ArtefactHandler

getProvidedArtefacts

public Class[] getProvidedArtefacts()
Description copied from interface: GrailsPlugin
Retrieves an array of provided Artefacts that are pre-compiled additions to the GrailsApplication object but are overridable by the end-user

Specified by:
getProvidedArtefacts in interface GrailsPlugin
Returns:
A list of provided artefacts


Copyright (c) 2005-2006 The Grails project