public interface GrailsApplication extends org.springframework.context.ApplicationContextAware
The main interface representing a running Grails application. This interface's main purpose is to provide a mechanism for analysing the conventions within a Grails application as well as providing metadata and information about the execution environment.
The GrailsApplication interface interfacts with ArtefactHandler instances which are capable of analysing different artefact types (controllers, domain classes etc.) and introspecting the artefact conventions
Implementors of this inteface should be aware that a GrailsApplication is only initialised when the initialise() method is called. In other words GrailsApplication instances are lazily initialised by the Grails runtime.
Modifiers | Name | Description |
---|---|---|
java.lang.String |
APPLICATION_ID |
The id of the grails application within a bean context |
java.lang.String |
CLASS_LOADER_BEAN |
|
java.lang.String |
CONFIG_CLASS |
The name of the class that provides configuration |
java.lang.String |
DATA_SOURCE_BEAN |
|
java.lang.String |
DATA_SOURCE_CLASS |
The name of the DataSource class |
java.lang.String |
DIALECT_DETECTOR_BEAN |
|
java.lang.String |
EXCEPTION_HANDLER_BEAN |
|
java.lang.String |
MESSAGE_SOURCE_BEAN |
|
java.lang.String |
MULTIPART_RESOLVER_BEAN |
|
java.lang.String |
OPEN_SESSION_IN_VIEW_INTERCEPTOR_BEAN |
|
java.lang.String |
PROJECT_META_FILE |
The name of the project metadata file |
java.lang.String |
SESSION_FACTORY_BEAN |
|
java.lang.String |
TRANSACTION_MANAGER_BEAN |
The name of the transaction manager bean |
Type Params | Return Type | Name and description |
---|---|---|
|
public GrailsClass |
addArtefact(java.lang.String artefactType, java.lang.Class artefactClass) |
|
public GrailsClass |
addArtefact(java.lang.String artefactType, GrailsClass artefactGrailsClass) |
|
public void |
addArtefact(java.lang.Class artefact) Adds the given artefact, attempting to determine type from |
|
public void |
addOverridableArtefact(java.lang.Class artefact) Adds an artefact that can be overriden by user defined classes |
|
public void |
configChanged() Fired to inform the application when the Config.groovy file changes. |
|
public java.lang.Class[] |
getAllArtefacts() Retrieves all java.lang.Class instances considered Artefacts loaded by the Grails class loader |
|
public java.lang.Class[] |
getAllClasses() Retrieves all java.lang.Class instances loaded by the Grails class loader |
|
public GrailsClass |
getArtefact(java.lang.String artefactType, java.lang.String name) |
|
public GrailsClass |
getArtefactByLogicalPropertyName(java.lang.String type, java.lang.String logicalName) Retrieves an artefact by its logical property name. |
|
public GrailsClass |
getArtefactForFeature(java.lang.String artefactType, java.lang.Object featureID) |
|
public ArtefactHandler |
getArtefactHandler(java.lang.String type) Returns the ArtefactHandler for the given type |
|
public ArtefactHandler[] |
getArtefactHandlers() |
|
public ArtefactInfo |
getArtefactInfo(java.lang.String artefactType) |
|
public ArtefactHandler |
getArtefactType(java.lang.Class theClass) Returns the ArtefactHandler for the given class or null |
|
public GrailsClass[] |
getArtefacts(java.lang.String artefactType) |
|
public java.lang.Class |
getClassForName(java.lang.String className) Retrieves a class for the given name within the GrailsApplication or returns null |
|
public java.lang.ClassLoader |
getClassLoader() Returns the class loader instance for the Grails application. |
|
public Config |
getConfig() Returns the ConfigObject instance. |
|
public org.springframework.context.ApplicationContext |
getMainContext() Returns the Spring context for this application. |
|
public org.grails.datastore.mapping.model.MappingContext |
getMappingContext()
|
|
public Metadata |
getMetadata() |
|
public org.springframework.context.ApplicationContext |
getParentContext() Returns the Spring application context that contains this application instance. |
|
public org.springframework.core.io.Resource |
getResourceForClass(java.lang.Class theClazz) Retrieves a Resource instance for the given Grails class or null it doesn't exist. |
|
public boolean |
hasArtefactHandler(java.lang.String type) |
|
public void |
initialise() Initialise this GrailsApplication. |
|
public boolean |
isArtefact(java.lang.Class theClazz) |
|
public boolean |
isArtefactOfType(java.lang.String artefactType, java.lang.Class theClazz) |
|
public boolean |
isArtefactOfType(java.lang.String artefactType, java.lang.String className) |
|
public boolean |
isInitialised() Returns whether this GrailsApplication has been initialised or not. |
|
public boolean |
isWarDeployed() Returns true if this application has been deployed as a WAR file |
|
public void |
rebuild() Rebuilds this Application throwing away the class loader and re-constructing it from the loaded resources again. |
|
public void |
refresh() This method will refresh the entire application |
|
public void |
registerArtefactHandler(ArtefactHandler handler) |
|
public void |
setMainContext(org.springframework.context.ApplicationContext context) Sets the main Spring context for this application. |
|
public void |
setMappingContext(org.grails.datastore.mapping.model.MappingContext mappingContext) Configures the org.grails.datastore.mapping.model.MappingContext for this application |
Methods inherited from class | Name |
---|---|
interface org.springframework.context.ApplicationContextAware |
org.springframework.context.ApplicationContextAware#setApplicationContext(org.springframework.context.ApplicationContext) |
The id of the grails application within a bean context
The name of the class that provides configuration
The name of the DataSource class
The name of the project metadata file
The name of the transaction manager bean
Registers a new artefact
artefactType
- The type ID of the artefact, i.e. "TagLib"artefactClass
- The class of the artefact. A new GrailsClass will be created automatically and added
to internal structures, using the appropriate ArtefactHandler
Registers a new artefact
artefactType
- The type ID of the artefact, i.e. "TagLib"artefactGrailsClass
- The GrailsClass of the artefact.Adds the given artefact, attempting to determine type from
artefact
- The artefact to addAdds an artefact that can be overriden by user defined classes
artefact
- An overridable artefactFired to inform the application when the Config.groovy file changes.
Retrieves all java.lang.Class instances considered Artefacts loaded by the Grails class loader
Retrieves all java.lang.Class instances loaded by the Grails class loader
Gets the GrailsClass associated with the named artefact class
i.e. to get the GrailsClass for controller called "BookController" you pass the name "BookController"
artefactType
- The type of artefact to retrieve, i.e. "Controller"name
- The name of an artefact such as "BookController"Retrieves an artefact by its logical property name. For example the logical property name of BookController would be book.
type
- The artefact typelogicalName
- The logical name
Get an artefact GrailsClass by a "feature" which depending on the artefact may be a URI or tag name for example
artefactType
- The type ID of the artefact, i.e. "TagLib"featureID
- The "feature" ID, say a URL or tag nameReturns the ArtefactHandler for the given type
type
- The artefact handler type
Obtain a list of all the artefact handlers
Obtain all the class information about the artefactType specified
artefactType
- An artefact type identifier i.e. "Domain"Returns the ArtefactHandler for the given class or null
theClass
- The class
Get an array of all the GrailsClass instances relating to artefacts of the specified type.
artefactType
- The type of artefact to retrieve, i.e. "Controller"Retrieves a class for the given name within the GrailsApplication or returns null
className
- The name of the classReturns the class loader instance for the Grails application.
Returns the ConfigObject instance.
Returns the Spring context for this application. Note that this
will return null
until the application is fully
initialised. This context contains all the application artifacts,
plugin beans, the works.
Get access to the project's metadata, specified in application.yml and grails.build.info if it is present
This provides access to information like required grails version, application name, version etc but NOT general application settings.
Returns the Spring application context that contains this application instance. It is the parent of the context returned by getMainContext().
Retrieves a Resource instance for the given Grails class or null it doesn't exist.
theClazz
- The Grails class
Test whether an artefact handler exists for a given type
type
- The type of the handlerInitialise this GrailsApplication.
Call this to find out if the class you have is an artefact loaded by grails.
theClazz
- A class to test
Check if the specified artefact Class has been loaded by Grails already AND is of the type expected
artefactType
- A string identifying the artefact type to check fortheClazz
- The class to check
Check if the artefact Class with the name specified is of the type expected
artefactType
- A string identifying the artefact type to check forclassName
- The name of a class to checkReturns whether this GrailsApplication has been initialised or not.
Returns true if this application has been deployed as a WAR file
Rebuilds this Application throwing away the class loader and re-constructing it from the loaded resources again. Can only be called in development mode and an error will be thrown if called in a different enivronment
This method will refresh the entire application
Register a new artefact handler
handler
- The new handler to addSets the main Spring context for this application.
Configures the org.grails.datastore.mapping.model.MappingContext for this application
mappingContext
- The mapping context