public interface GrailsApplication
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.
initialise()
,
ArtefactHandler
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
APPLICATION_ID
The id of the grails application within a bean context
|
static java.lang.String |
CONFIG_CLASS
The name of the class that provides configuration
|
static java.lang.String |
DATA_SOURCE_CLASS |
static java.lang.String |
ENV_APPLICATION
Deprecated.
Use
grails.util.Environment#APPLICATION instead. |
static java.lang.String |
ENV_DEVELOPMENT
Deprecated.
Use
grails.util.Environment#DEVELOPMENT instead. |
static java.lang.String |
ENV_PRODUCTION
Deprecated.
Use
grails.util.Environment#PRODUCTION instead. |
static java.lang.String |
ENV_TEST
Deprecated.
Use
grails.util.Environment#TEST instead. |
static java.lang.String |
ENVIRONMENT
Deprecated.
Use
grails.util.Environment#KEY instead. |
static java.lang.String |
ENVIRONMENT_DEFAULT
Deprecated.
Use
grails.util.Environment#DEFAULT instead. |
static java.lang.String |
GLOBAL_PLUGINS_DIR
Deprecated.
Use
grails.util.BuildSettings#GLOBAL_PLUGINS_DIR instead. |
static java.lang.String |
PLUGINS_DIR
Deprecated.
Use
grails.util.BuildSettings#PLUGINS_DIR instead. |
static java.lang.String |
PROJECT_CLASSES_DIR
Deprecated.
Use
grails.util.BuildSettings#PROJECT_CLASSES_DIR instead. |
static java.lang.String |
PROJECT_META_FILE |
static java.lang.String |
PROJECT_RESOURCES_DIR
Deprecated.
Use
grails.util.BuildSettings#PROJECT_RESOURCES_DIR instead. |
static java.lang.String |
PROJECT_TEST_CLASSES_DIR
Deprecated.
Use
grails.util.BuildSettings#PROJECT_TEST_CLASSES_DIR instead. |
static java.lang.String |
PROJECT_WORK_DIR
Deprecated.
Use
grails.util.BuildSettings#PROJECT_WORK_DIR instead. |
static java.lang.String |
WORK_DIR
Deprecated.
Use
grails.util.BuildSettings#WORK_DIR instead. |
Modifier and Type | Method and Description |
---|---|
void |
addArtefact(java.lang.Class artefact)
Adds the given artefact, attempting to determine type from
|
GrailsClass |
addArtefact(java.lang.String artefactType,
java.lang.Class artefactClass)
Registers a new artefact
|
GrailsClass |
addArtefact(java.lang.String artefactType,
GrailsClass artefactGrailsClass)
Registers a new artefact
|
void |
addOverridableArtefact(java.lang.Class artefact)
Adds an artefact that can be overriden by user defined classes
|
void |
configChanged()
Fired to inform the application when the Config.groovy file changes.
|
java.lang.Class[] |
getAllArtefacts()
Retrieves all java.lang.Class instances considered Artefacts loaded by the Grails class loader
|
java.lang.Class[] |
getAllClasses()
Retrieves all java.lang.Class instances loaded by the Grails class loader
|
GrailsClass |
getArtefact(java.lang.String artefactType,
java.lang.String name)
Gets the GrailsClass associated with the named artefact class
|
GrailsClass |
getArtefactByLogicalPropertyName(java.lang.String type,
java.lang.String logicalName)
Retrieves an artefact by its logical property name.
|
GrailsClass |
getArtefactForFeature(java.lang.String artefactType,
java.lang.Object featureID)
Get an artefact GrailsClass by a "feature" which depending on the artefact may be a URI or tag name
for example
|
ArtefactHandler |
getArtefactHandler(java.lang.String type)
Returns the ArtefactHandler for the given type
|
ArtefactHandler[] |
getArtefactHandlers()
Obtain a list of all the artefact handlers
|
ArtefactInfo |
getArtefactInfo(java.lang.String artefactType)
Obtain all the class information about the artefactType specified
|
GrailsClass[] |
getArtefacts(java.lang.String artefactType)
Get an array of all the GrailsClass instances relating to artefacts of the specified type.
|
ArtefactHandler |
getArtefactType(java.lang.Class theClass)
Returns the ArtefactHandler for the given class or null
|
java.lang.Class |
getClassForName(java.lang.String className)
Retrieves a class for the given name within the GrailsApplication or returns null
|
java.lang.ClassLoader |
getClassLoader()
Returns the class loader instance for the Grails application.
|
ConfigObject |
getConfig()
Returns the ConfigObject instance.
|
java.util.Map<java.lang.String,java.lang.Object> |
getFlatConfig()
Returns the flatten ConfigObject for use from Java classes.
|
ApplicationContext |
getMainContext()
Returns the Spring context for this application.
|
Metadata |
getMetadata()
Get access to the project's metadata, specified in application.properties
|
ApplicationContext |
getParentContext()
Returns the Spring application context that contains this
application instance.
|
Resource |
getResourceForClass(java.lang.Class theClazz)
Retrieves a Resource instance for the given Grails class or null it doesn't exist.
|
boolean |
hasArtefactHandler(java.lang.String type)
Test whether an artefact handler exists for a given type
|
void |
initialise()
Initialise this GrailsApplication.
|
boolean |
isArtefact(java.lang.Class theClazz)
Call this to find out if the class you have is an artefact loaded by grails.
|
boolean |
isArtefactOfType(java.lang.String artefactType,
java.lang.Class theClazz)
Check if the specified artefact Class has been loaded by Grails already AND is
of the type expected
|
boolean |
isArtefactOfType(java.lang.String artefactType,
java.lang.String className)
Check if the artefact Class with the name specified is of the type expected
|
boolean |
isInitialised()
Returns whether this GrailsApplication has been initialised or not.
|
boolean |
isWarDeployed()
Returns true if this application has been deployed as a WAR file
|
void |
rebuild()
Rebuilds this Application throwing away the class loader and re-constructing it from the loaded
resources again.
|
void |
refresh()
This method will refresh the entire application
|
void |
refreshConstraints()
Rebuilds the constraint definitions.
|
void |
registerArtefactHandler(ArtefactHandler handler)
Register a new artefact handler
|
void |
setMainContext(ApplicationContext context)
Sets the main Spring context for this application.
|
@Deprecated static final java.lang.String WORK_DIR
grails.util.BuildSettings#WORK_DIR
instead.@Deprecated static final java.lang.String PROJECT_WORK_DIR
grails.util.BuildSettings#PROJECT_WORK_DIR
instead.@Deprecated static final java.lang.String PLUGINS_DIR
grails.util.BuildSettings#PLUGINS_DIR
instead.@Deprecated static final java.lang.String GLOBAL_PLUGINS_DIR
grails.util.BuildSettings#GLOBAL_PLUGINS_DIR
instead.@Deprecated static final java.lang.String PROJECT_RESOURCES_DIR
grails.util.BuildSettings#PROJECT_RESOURCES_DIR
instead.@Deprecated static final java.lang.String PROJECT_CLASSES_DIR
grails.util.BuildSettings#PROJECT_CLASSES_DIR
instead.@Deprecated static final java.lang.String PROJECT_TEST_CLASSES_DIR
grails.util.BuildSettings#PROJECT_TEST_CLASSES_DIR
instead.static final java.lang.String APPLICATION_ID
@Deprecated static final java.lang.String ENVIRONMENT
grails.util.Environment#KEY
instead.@Deprecated static final java.lang.String ENVIRONMENT_DEFAULT
grails.util.Environment#DEFAULT
instead.@Deprecated static final java.lang.String ENV_DEVELOPMENT
grails.util.Environment#DEVELOPMENT
instead.@Deprecated static final java.lang.String ENV_APPLICATION
grails.util.Environment#APPLICATION
instead.@Deprecated static final java.lang.String ENV_PRODUCTION
grails.util.Environment#PRODUCTION
instead.@Deprecated static final java.lang.String ENV_TEST
grails.util.Environment#TEST
instead.static final java.lang.String CONFIG_CLASS
static final java.lang.String DATA_SOURCE_CLASS
static final java.lang.String PROJECT_META_FILE
ConfigObject getConfig()
java.util.Map<java.lang.String,java.lang.Object> getFlatConfig()
java.lang.ClassLoader getClassLoader()
java.lang.Class[] getAllClasses()
java.lang.Class[] getAllArtefacts()
ApplicationContext getMainContext()
null
until the application is fully
initialised. This context contains all the application artifacts,
plugin beans, the works.void setMainContext(ApplicationContext context)
ApplicationContext getParentContext()
getMainContext()
.java.lang.Class getClassForName(java.lang.String className)
className
- The name of the classvoid refreshConstraints()
void refresh()
void rebuild()
Resource getResourceForClass(java.lang.Class theClazz)
theClazz
- The Grails classboolean isArtefact(java.lang.Class theClazz)
Call this to find out if the class you have is an artefact loaded by grails.
theClazz
- A class to testboolean isArtefactOfType(java.lang.String artefactType, java.lang.Class theClazz)
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 checkboolean isArtefactOfType(java.lang.String artefactType, java.lang.String className)
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 checkGrailsClass getArtefact(java.lang.String artefactType, java.lang.String name)
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"ArtefactHandler getArtefactType(java.lang.Class theClass)
theClass
- The classArtefactInfo getArtefactInfo(java.lang.String artefactType)
Obtain all the class information about the artefactType specified
artefactType
- An artefact type identifier i.e. "Domain"GrailsClass[] getArtefacts(java.lang.String artefactType)
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"GrailsClass getArtefactForFeature(java.lang.String artefactType, java.lang.Object featureID)
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 nameGrailsClass addArtefact(java.lang.String artefactType, java.lang.Class artefactClass)
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 ArtefactHandlerGrailsClass addArtefact(java.lang.String artefactType, GrailsClass artefactGrailsClass)
Registers a new artefact
artefactType
- The type ID of the artefact, i.e. "TagLib"artefactGrailsClass
- The GrailsClass of the artefact.void registerArtefactHandler(ArtefactHandler handler)
Register a new artefact handler
handler
- The new handler to addboolean hasArtefactHandler(java.lang.String type)
Test whether an artefact handler exists for a given type
type
- The type of the handlerArtefactHandler[] getArtefactHandlers()
Obtain a list of all the artefact handlers
void initialise()
boolean isInitialised()
Metadata getMetadata()
Get access to the project's metadata, specified in application.properties
This provides access to information like required grails version, application name, version etc but NOT general application settings.
GrailsClass getArtefactByLogicalPropertyName(java.lang.String type, java.lang.String logicalName)
type
- The artefact typelogicalName
- The logical namevoid addArtefact(java.lang.Class artefact)
artefact
- The artefact to addboolean isWarDeployed()
void addOverridableArtefact(java.lang.Class artefact)
artefact
- An overridable artefactvoid configChanged()
ArtefactHandler getArtefactHandler(java.lang.String type)
type
- The artefact handler type