Groovy Documentation

org.codehaus.groovy.grails.commons
[Java] Class DefaultGrailsApplication

java.lang.Object
  groovy.lang.GroovyObjectSupport
      org.codehaus.groovy.grails.commons.DefaultGrailsApplication
All Implemented Interfaces:
GrailsApplication, org.springframework.beans.factory.BeanClassLoaderAware

public class DefaultGrailsApplication
extends groovy.lang.GroovyObjectSupport

Default implementation of the GrailsApplication interface that manages application loading, state, and artefact instances.

Upon loading this GrailsApplication will inspect each class using its registered ArtefactHandler instances. Each ArtefactHandler provides knowledge about the conventions used to establish its artefact type. For example controllers use the ControllerArtefactHandler to establish this knowledge.

New ArtefactHandler instances can be registered with the GrailsApplication thus allowing application extensibility.

Authors:
Marc Palmer
Steven Devijver
Graeme Rocher
See Also:
GrailsPluginManager
DefaultGrailsPluginManager
ArtefactHandler
ArtefactInfo
Since:
0.1


Field Summary
protected static java.util.regex.Pattern GETCLASSESMETH_PATTERN

protected static java.util.regex.Pattern GETCLASSESPROP_PATTERN

protected static java.util.regex.Pattern GETCLASS_PATTERN

protected static java.util.regex.Pattern ISCLASS_PATTERN

protected java.util.List allArtefactClasses

protected java.lang.Class[] allArtefactClassesArray

protected java.lang.Class[] allClasses

protected Metadata applicationMeta

protected ArtefactHandler[] artefactHandlers

protected java.util.Map artefactHandlersByName

protected java.util.Map artefactInfo

protected java.lang.ClassLoader cl

protected groovy.util.ConfigObject config

protected java.util.Map flatConfig

protected boolean initialised

protected java.util.List loadedClasses

protected static org.apache.commons.logging.Log log

protected org.springframework.context.ApplicationContext mainContext

protected org.springframework.context.ApplicationContext parentContext

protected org.springframework.core.io.Resource[] resources

 
Constructor Summary
DefaultGrailsApplication()

Creates a new empty Grails application.

DefaultGrailsApplication(java.lang.Class[] classes, java.lang.ClassLoader classLoader)

Creates a new GrailsApplication instance using the given classes and GroovyClassLoader.

DefaultGrailsApplication(org.springframework.core.io.Resource[] resources)

Loads a GrailsApplication using the given ResourceLocator instance which will search for appropriate class names

DefaultGrailsApplication(Resource[] resources)

Loads a GrailsApplication using the given ResourceLocator instance which will search for appropriate class names

 
Method Summary
GrailsClass addArtefact(java.lang.String artefactType, java.lang.Class artefactClass)

GrailsClass addArtefact(java.lang.String artefactType, GrailsClass artefactGrailsClass)

void addArtefact(java.lang.Class artefact)

protected GrailsClass addArtefact(java.lang.String artefactType, java.lang.Class artefactClass, boolean overrideable)

void addOverridableArtefact(java.lang.Class artefact)

GrailsClass addOverridableArtefact(java.lang.String artefactType, java.lang.Class artefactClass)

protected void addToLoaded(java.lang.Class clazz)

void clear()

void configChanged()

protected void configureLoadedClasses(java.lang.Class[] classes)

Configures the loaded classes within the GrailsApplication instance using the registered ArtefactHandler instances.

java.lang.Class[] getAllArtefacts()

Returns all the classes identified as artefacts by ArtefactHandler instances.

java.lang.Class[] getAllClasses()

GrailsClass getArtefact(java.lang.String artefactType, java.lang.String name)

GrailsClass getArtefactByLogicalPropertyName(java.lang.String type, java.lang.String logicalName)

protected int getArtefactCount(java.lang.String artefactType)

GrailsClass getArtefactForFeature(java.lang.String artefactType, java.lang.Object featureID)

ArtefactHandler getArtefactHandler(java.lang.String type)

ArtefactHandler[] getArtefactHandlers()

protected DefaultArtefactInfo getArtefactInfo(java.lang.String artefactType, boolean create)

Get or create the cache of classes for the specified artefact type.

ArtefactInfo getArtefactInfo(java.lang.String artefactType)

ArtefactHandler getArtefactType(java.lang.Class theClass)

GrailsClass[] getArtefacts(java.lang.String artefactType)

java.lang.Class getClassForName(java.lang.String className)

java.lang.ClassLoader getClassLoader()

groovy.util.ConfigObject getConfig()

protected GrailsClass getFirstArtefact(java.lang.String artefactType)

java.util.Map getFlatConfig()

org.springframework.context.ApplicationContext getMainContext()

Metadata getMetadata()

org.springframework.context.ApplicationContext getParentContext()

java.lang.Object getProperty(java.lang.String propertyName)

Override property access and hit on xxxxClasses to return class arrays of artefacts.

org.springframework.core.io.Resource getResourceForClass(java.lang.Class theClazz)

Retrieves the Spring Resource that was used to load the given Class.

boolean hasArtefactHandler(java.lang.String type)

protected void initArtefactHandlers()

Initialises the default set of ArtefactHandler instances.

void initialise()

protected void initializeArtefacts(java.lang.String artefactType)

Clears the application returning it to an empty state.

protected void initializeArtefacts(ArtefactHandler handler)

java.lang.Object invokeMethod(java.lang.String methodName, java.lang.Object args)

boolean isArtefact(java.lang.Class theClazz)

boolean isArtefactOfType(java.lang.String artefactType, java.lang.Class theClazz)

Returns true if the specified class is of the given artefact type as defined by the ArtefactHandler.

boolean isArtefactOfType(java.lang.String artefactType, java.lang.String className)

Returns true if the specified class name is of the given artefact type as defined by the ArtefactHandler.

boolean isInitialised()

boolean isWarDeployed()

protected java.lang.Class[] populateAllClasses()

void rebuild()

void refresh()

Refreshes this GrailsApplication, rebuilding all of the artefact definitions as defined by the registered ArtefactHandler instances.

protected void refreshArtefactGrailsClassCaches()

Tell all our artefact info objects to update their internal state after we've added a bunch of classes.

void refreshConstraints()

Refreshes constraints defined by the DomainClassArtefactHandler.

void registerArtefactHandler(ArtefactHandler handler)

Registers a new ArtefactHandler that is responsible for identifying and managing a particular artefact type that is defined by some convention.

void setApplicationContext(org.springframework.context.ApplicationContext applicationContext)

void setBeanClassLoader(java.lang.ClassLoader classLoader)

void setConfig(groovy.util.ConfigObject config)

void setMainContext(org.springframework.context.ApplicationContext context)

 
Methods inherited from class groovy.lang.GroovyObjectSupport
groovy.lang.GroovyObjectSupport#getMetaClass(), groovy.lang.GroovyObjectSupport#setMetaClass(groovy.lang.MetaClass), groovy.lang.GroovyObjectSupport#setProperty(java.lang.String, java.lang.Object), groovy.lang.GroovyObjectSupport#getProperty(java.lang.String), groovy.lang.GroovyObjectSupport#invokeMethod(java.lang.String, java.lang.Object), groovy.lang.GroovyObjectSupport#wait(), groovy.lang.GroovyObjectSupport#wait(long, int), groovy.lang.GroovyObjectSupport#wait(long), groovy.lang.GroovyObjectSupport#equals(java.lang.Object), groovy.lang.GroovyObjectSupport#toString(), groovy.lang.GroovyObjectSupport#hashCode(), groovy.lang.GroovyObjectSupport#getClass(), groovy.lang.GroovyObjectSupport#notify(), groovy.lang.GroovyObjectSupport#notifyAll()
 
Methods inherited from class java.lang.Object
java.lang.Object#wait(), java.lang.Object#wait(long, int), java.lang.Object#wait(long), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll()
 

Field Detail

GETCLASSESMETH_PATTERN

protected static final java.util.regex.Pattern GETCLASSESMETH_PATTERN


GETCLASSESPROP_PATTERN

protected static final java.util.regex.Pattern GETCLASSESPROP_PATTERN


GETCLASS_PATTERN

protected static final java.util.regex.Pattern GETCLASS_PATTERN


ISCLASS_PATTERN

protected static final java.util.regex.Pattern ISCLASS_PATTERN


allArtefactClasses

protected java.util.List allArtefactClasses


allArtefactClassesArray

protected java.lang.Class[] allArtefactClassesArray


allClasses

protected java.lang.Class[] allClasses


applicationMeta

protected Metadata applicationMeta


artefactHandlers

protected ArtefactHandler[] artefactHandlers


artefactHandlersByName

protected java.util.Map artefactHandlersByName


artefactInfo

protected java.util.Map artefactInfo


cl

protected java.lang.ClassLoader cl


config

protected groovy.util.ConfigObject config


flatConfig

@SuppressWarnings("rawtypes")
protected java.util.Map flatConfig


initialised

protected boolean initialised


loadedClasses

protected java.util.List loadedClasses


log

protected static org.apache.commons.logging.Log log


mainContext

protected org.springframework.context.ApplicationContext mainContext


parentContext

protected org.springframework.context.ApplicationContext parentContext


resources

protected org.springframework.core.io.Resource[] resources


 
Constructor Detail

DefaultGrailsApplication

public DefaultGrailsApplication()
Creates a new empty Grails application.


DefaultGrailsApplication

public DefaultGrailsApplication(java.lang.Class[] classes, java.lang.ClassLoader classLoader)
Creates a new GrailsApplication instance using the given classes and GroovyClassLoader.
Parameters:
classes - The classes that make up the GrailsApplication
classLoader - The GroovyClassLoader to use


DefaultGrailsApplication

public DefaultGrailsApplication(org.springframework.core.io.Resource[] resources)
Loads a GrailsApplication using the given ResourceLocator instance which will search for appropriate class names


DefaultGrailsApplication

public DefaultGrailsApplication(Resource[] resources)
Loads a GrailsApplication using the given ResourceLocator instance which will search for appropriate class names


 
Method Detail

addArtefact

public GrailsClass addArtefact(java.lang.String artefactType, fied GrailsClass is not the sa java.lang.Class artefactClass)


addArtefact

public GrailsClass addArtefact(java.lang.String artefactType, GrailsClass artefactGrailsClass)


addArtefact

public void addArtefact( java.lang.Class artefact)


addArtefact

protected GrailsClass addArtefact(java.lang.String artefactType, java.lang.Class artefactClass, boolean overrideable)


addOverridableArtefact

public void addOverridableArtefact(the artefact as defined by a java.lang.Class artefact)


addOverridableArtefact

public GrailsClass addOverridableArtefact(java.lang.String artefactType,  java.lang.Class artefactClass)


addToLoaded

protected void addToLoaded(java.lang.Class clazz)


clear

public void clear()


configChanged

public void configChanged()


configureLoadedClasses

protected void configureLoadedClasses(java.lang.Class[] classes)
Configures the loaded classes within the GrailsApplication instance using the registered ArtefactHandler instances.
Parameters:
classes - The classes to configure


getAllArtefacts

public java.lang.Class[] getAllArtefacts()
Returns all the classes identified as artefacts by ArtefactHandler instances.
Returns:
An array of classes


getAllClasses

public java.lang.Class[] getAllClasses()


getArtefact

public GrailsClass getArtefact(java.lang.String artefactType, java.lang.String name)


getArtefactByLogicalPropertyName

public GrailsClass getArtefactByLogicalPropertyName(java.lang.String type, java.lang.String logicalName)


getArtefactCount

protected int getArtefactCount(java.lang.String artefactType)


getArtefactForFeature

public GrailsClass getArtefactForFeature(java.lang.String artefactType, java.lang.Object featureID)


getArtefactHandler

public ArtefactHandler getArtefactHandler(java.lang.String type)


getArtefactHandlers

public ArtefactHandler[] getArtefactHandlers()


getArtefactInfo

protected DefaultArtefactInfo getArtefactInfo(java.lang.String artefactType, boolean create)
Get or create the cache of classes for the specified artefact type.
Parameters:
artefactType - The name of an artefact type
create - Set to true if you want non-existent caches to be created
Returns:
The cache of classes for the type, or null if no cache exists and create is false


getArtefactInfo

public ArtefactInfo getArtefactInfo(java.lang.String artefactType)

Overrides method invocation to return dynamic artefact methods.

We will support getXXXXClasses() and isXXXXClass(class)

Parameters:
methodName - The name of the method
args - The arguments to the method
Returns:
The return value of the method TODO Need to add matches for addClass(java.lang.Class) and addClass(GrailsClass)


getArtefactType

public ArtefactHandler getArtefactType( java.lang.Class theClass)


getArtefacts

public GrailsClass[] getArtefacts(java.lang.String artefactType)


getClassForName

public java.lang.Class getClassForName(java.lang.String className)


getClassLoader

public java.lang.ClassLoader getClassLoader()


getConfig

public groovy.util.ConfigObject getConfig()


getFirstArtefact

protected GrailsClass getFirstArtefact(java.lang.String artefactType)


getFlatConfig

*
public java.util.Map getFlatConfig()


getMainContext

public org.springframework.context.ApplicationContext getMainContext()


getMetadata

public Metadata getMetadata()


getParentContext

public org.springframework.context.ApplicationContext getParentContext()


getProperty

}
public java.lang.Object getProperty(java.lang.String propertyName)
Override property access and hit on xxxxClasses to return class arrays of artefacts.
Parameters:
propertyName - The name of the property, if it ends in *Classes then match and invoke internal ArtefactHandler
Returns:
All the artifacts or delegate to super.getProperty


getResourceForClass

public org.springframework.core.io.Resource getResourceForClass(s an artefact identified by on java.lang.Class theClazz)
Retrieves the Spring Resource that was used to load the given Class.
Parameters:
theClazz - The class
Returns:
Either a Spring Resource or null if no Resource was found for the given class


hasArtefactHandler

public boolean hasArtefactHandler(java.lang.String type)


initArtefactHandlers

protected void initArtefactHandlers()
Initialises the default set of ArtefactHandler instances.
See Also:
ArtefactHandler


initialise

public void initialise()


initializeArtefacts

protected void initializeArtefacts(java.lang.String artefactType)
Clears the application returning it to an empty state. Very dangerous method, use with caution.


initializeArtefacts

protected void initializeArtefacts(ArtefactHandler handler)


invokeMethod

"Dynamic method getClass(artefactName) requires a single String parameter");
public java.lang.Object invokeMethod(java.lang.String methodName, java.lang.Object args)


isArtefact

public boolean isArtefact( java.lang.Class theClazz)


isArtefactOfType

public boolean isArtefactOfType(java.lang.String artefactType,  java.lang.Class theClazz)
Returns true if the specified class is of the given artefact type as defined by the ArtefactHandler.
Parameters:
artefactType - The type of the artefact
theClazz - The class
Returns:
true if it is of the specified artefactType
See Also:
ArtefactHandler


isArtefactOfType

public boolean isArtefactOfType(java.lang.String artefactType, java.lang.String className)
Returns true if the specified class name is of the given artefact type as defined by the ArtefactHandler.
Parameters:
artefactType - The type of the artefact
className - The class name
Returns:
true if it is of the specified artefactType
See Also:
ArtefactHandler


isInitialised

public boolean isInitialised()


isWarDeployed

public boolean isWarDeployed()


populateAllClasses

protected java.lang.Class[] populateAllClasses()


rebuild

public void rebuild()


refresh

public void refresh()
Refreshes this GrailsApplication, rebuilding all of the artefact definitions as defined by the registered ArtefactHandler instances.


refreshArtefactGrailsClassCaches

protected void refreshArtefactGrailsClassCaches()
Tell all our artefact info objects to update their internal state after we've added a bunch of classes.


refreshConstraints

public void refreshConstraints()
Refreshes constraints defined by the DomainClassArtefactHandler. TODO: Move this out of GrailsApplication


registerArtefactHandler

public void registerArtefactHandler(ArtefactHandler handler)
Registers a new ArtefactHandler that is responsible for identifying and managing a particular artefact type that is defined by some convention.
Parameters:
handler - The ArtefactHandler to regster


setApplicationContext

public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext)


setBeanClassLoader

public void setBeanClassLoader(java.lang.ClassLoader classLoader)


setConfig

public void setConfig(groovy.util.ConfigObject config)


setMainContext

public void setMainContext(org.springframework.context.ApplicationContext context)


 

Groovy Documentation