public class DefaultGrailsApplication extends AbstractGrailsApplication
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.Modifiers | Name | Description |
---|---|---|
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<java.lang.Class<?>> |
allArtefactClasses |
|
protected java.lang.Class<?>[] |
allArtefactClassesArray |
|
protected java.lang.Class<?>[] |
allClasses |
|
protected ArtefactHandler[] |
artefactHandlers |
|
protected java.util.Map<java.lang.String, ArtefactHandler> |
artefactHandlersByName |
|
protected java.util.Map<java.lang.String, ArtefactInfo> |
artefactInfo |
|
protected boolean |
initialised |
|
protected java.util.Set<java.lang.Class<?>> |
loadedClasses |
|
protected static org.apache.commons.logging.Log |
log |
|
protected org.springframework.core.io.Resource[] |
resources |
Fields inherited from class | Fields |
---|---|
class AbstractGrailsApplication |
applicationMeta, classLoader, config, flatConfig, mainContext, parentContext |
Constructor and description |
---|
DefaultGrailsApplication
() Creates a new empty Grails application. |
DefaultGrailsApplication
(java.lang.ClassLoader classLoader) |
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 |
Type | Name and description |
---|---|
GrailsClass |
addArtefact(java.lang.String artefactType, java.lang.Class artefactClass) Adds an artefact of the given type for the given Class. |
GrailsClass |
addArtefact(java.lang.String artefactType, GrailsClass artefactGrailsClass) Adds an artefact of the given type for the given GrailsClass. |
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) Adds an artefact of the given type for the given Class. |
protected void |
addToLoaded(java.lang.Class<?> clazz) |
void |
clear() Clears the application returning it to an empty state. |
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() Retrieves all classes loaded by the GrailsApplication. |
GrailsClass |
getArtefact(java.lang.String artefactType, java.lang.String name) Retrieves an artefact for the given type and name. |
GrailsClass |
getArtefactByLogicalPropertyName(java.lang.String type, java.lang.String logicalName) |
protected int |
getArtefactCount(java.lang.String artefactType) Retrieves the number of artefacts registered for the given artefactType as defined by the ArtefactHandler. |
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) Get the cache of classes for the specified artefact type. |
ArtefactHandler |
getArtefactType(java.lang.Class theClass) |
GrailsClass[] |
getArtefacts(java.lang.String artefactType) Returns all of the GrailsClass instances for the given artefactType as defined by the ArtefactHandler |
java.lang.Class<?> |
getClassForName(java.lang.String className) Retrieves a class from the GrailsApplication for the given name. |
groovy.util.ConfigObject |
getConfig() |
protected GrailsClass |
getFirstArtefact(java.lang.String artefactType) |
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 static void |
initialiseGroovyExtensionModules() |
protected void |
initializeArtefacts(java.lang.String artefactType) Re-initialize the artefacts of the specified type. |
protected void |
initializeArtefacts(ArtefactHandler handler) Re-initialize the artefacts of the specified type. |
java.lang.Object |
invokeMethod(java.lang.String methodName, java.lang.Object args) |
boolean |
isArtefact(java.lang.Class theClazz) Returns true if the given class is an artefact identified by one of the registered ArtefactHandler instances. |
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() |
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 |
setBeanClassLoader(java.lang.ClassLoader classLoader) |
Methods inherited from class | Name |
---|---|
class AbstractGrailsApplication |
configChanged, getClassForName, getClassLoader, getConfig, getFlatConfig, getMainContext, getMetadata, getParentContext, isWarDeployed, setApplicationContext, setBeanClassLoader, setConfig, setMainContext, updateFlatConfig |
class groovy.lang.GroovyObjectSupport |
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#getMetaClass(), groovy.lang.GroovyObjectSupport#setMetaClass(groovy.lang.MetaClass), groovy.lang.GroovyObjectSupport#wait(long, int), groovy.lang.GroovyObjectSupport#wait(long), groovy.lang.GroovyObjectSupport#wait(), 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() |
Creates a new empty Grails application.
Creates a new GrailsApplication instance using the given classes and GroovyClassLoader.
classes
- The classes that make up the GrailsApplicationclassLoader
- The GroovyClassLoader to useLoads a GrailsApplication using the given ResourceLocator instance which will search for appropriate class names
Loads a GrailsApplication using the given ResourceLocator instance which will search for appropriate class names
Adds an artefact of the given type for the given Class.
artefactType
- The type of the artefact as defined by a ArtefactHandler instanceartefactClass
- A Class instance that matches the type defined by the ArtefactHandlerAdds an artefact of the given type for the given GrailsClass.
artefactType
- The type of the artefact as defined by a ArtefactHandler instanceartefactGrailsClass
- A GrailsClass instance that matches the type defined by the ArtefactHandlerAdds an artefact of the given type for the given Class.
artefactType
- The type of the artefact as defined by a ArtefactHandler instanceartefactClass
- A Class instance that matches the type defined by the ArtefactHandlerClears the application returning it to an empty state. Very dangerous method, use with caution.
Configures the loaded classes within the GrailsApplication instance using the registered ArtefactHandler instances.
classes
- The classes to configureReturns all the classes identified as artefacts by ArtefactHandler instances.
Retrieves all classes loaded by the GrailsApplication.
Retrieves an artefact for the given type and name.
artefactType
- The artefact type as defined by a registered ArtefactHandlername
- The name of the classRetrieves the number of artefacts registered for the given artefactType as defined by the ArtefactHandler.
artefactType
- The type of the artefact as defined by the ArtefactHandlerGet or create the cache of classes for the specified artefact type.
artefactType
- The name of an artefact typecreate
- Set to true if you want non-existent caches to be createdGet the cache of classes for the specified artefact type.
artefactType
- The name of an artefact typeReturns all of the GrailsClass instances for the given artefactType as defined by the ArtefactHandler
artefactType
- The type of the artefact defined by the ArtefactHandlerRetrieves a class from the GrailsApplication for the given name.
className
- The class nameOverride property access and hit on xxxxClasses to return class arrays of artefacts.
propertyName
- The name of the property, if it ends in *Classes then match and invoke internal ArtefactHandlerRetrieves the Spring Resource that was used to load the given Class.
theClazz
- The classInitialises the default set of ArtefactHandler instances.
Re-initialize the artefacts of the specified type. This gives handlers a chance to update caches etc.
artefactType
- The type of artefact to initRe-initialize the artefacts of the specified type. This gives handlers a chance to update caches etc.
handler
- The handler to register
Overrides method invocation to return dynamic artefact methods.
We will support getXXXXClasses() and isXXXXClass(class)
methodName
- The name of the methodargs
- The arguments to the methodReturns true if the given class is an artefact identified by one of the registered ArtefactHandler instances. Uses class name equality to handle class reloading
theClazz
- The class to checkReturns true if the specified class is of the given artefact type as defined by the ArtefactHandler.
artefactType
- The type of the artefacttheClazz
- The classReturns true if the specified class name is of the given artefact type as defined by the ArtefactHandler.
artefactType
- The type of the artefactclassName
- The class nameRefreshes this GrailsApplication, rebuilding all of the artefact definitions as defined by the registered ArtefactHandler instances.
Tell all our artefact info objects to update their internal state after we've added a bunch of classes.
Refreshes constraints defined by the DomainClassArtefactHandler. TODO: Move this out of GrailsApplication
Registers a new ArtefactHandler that is responsible for identifying and managing a particular artefact type that is defined by some convention.
handler
- The ArtefactHandler to regster