public class DefaultGrailsApplication extends GroovyObjectSupport implements GrailsApplication
GrailsPluginManager
,
DefaultGrailsPluginManager
,
ArtefactHandler
,
ArtefactInfo
APPLICATION_ID, CONFIG_CLASS, DATA_SOURCE_CLASS, ENV_APPLICATION, ENV_DEVELOPMENT, ENV_PRODUCTION, ENV_TEST, ENVIRONMENT, ENVIRONMENT_DEFAULT, GLOBAL_PLUGINS_DIR, PLUGINS_DIR, PROJECT_CLASSES_DIR, PROJECT_META_FILE, PROJECT_RESOURCES_DIR, PROJECT_TEST_CLASSES_DIR, PROJECT_WORK_DIR, WORK_DIR
Constructor and Description |
---|
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(GrailsResourceLoader resourceLoader) |
DefaultGrailsApplication(Resource[] resources)
Constructs a GrailsApplication with the given set of groovy sources specified as Spring Resource instances.
|
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)
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 |
addOverridableArtefact(java.lang.Class artefact)
Adds an artefact that can be overriden by user defined classes
|
GrailsClass |
addOverridableArtefact(java.lang.String artefactType,
java.lang.Class artefactClass)
Adds an artefact of the given type for the given Class.
|
void |
clear()
Clears the application returning it to an empty state.
|
void |
configChanged()
Fired to inform the application when the Config.groovy file changes.
|
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)
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)
Get the cache of classes for the specified artefact type.
|
GrailsClass[] |
getArtefacts(java.lang.String artefactType)
Returns all of the GrailsClass instances for the given artefactType as defined by the ArtefactHandler
|
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 from the GrailsApplication for the given name.
|
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()
Retrieves the parent ApplicationContext for this GrailsApplication.
|
java.lang.Object |
getProperty(java.lang.String propertyName)
Override property access and hit on xxxxClasses to return class arrays of artefacts.
|
Resource |
getResourceForClass(java.lang.Class theClazz)
Retrieves the Spring Resource that was used to load the given Class.
|
GrailsResourceLoader |
getResourceLoader() |
boolean |
hasArtefactHandler(java.lang.String type)
Test whether an artefact handler exists for a given type
|
void |
initialise()
Initialise this GrailsApplication.
|
java.lang.Object |
invokeMethod(java.lang.String methodName,
java.lang.Object args)
Overrides method invocation to return dynamic artefact methods.
|
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()
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()
Refreshes this GrailsApplication, rebuilding all of the artefact definitions as
defined by the registered ArtefactHandler instances.
|
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(ApplicationContext applicationContext)
Sets the parent ApplicationContext for the GrailsApplication.
|
void |
setBeanClassLoader(java.lang.ClassLoader classLoader) |
void |
setConfig(ConfigObject config) |
void |
setMainContext(ApplicationContext context)
Sets the main Spring context for this application.
|
public DefaultGrailsApplication()
public DefaultGrailsApplication(java.lang.Class<?>[] classes, java.lang.ClassLoader classLoader)
classes
- The classes that make up the GrailsApplicationclassLoader
- The GroovyClassLoader to usepublic DefaultGrailsApplication(Resource[] resources)
resources
- An array or Groovy sources provides by Spring Resource instancespublic DefaultGrailsApplication(GrailsResourceLoader resourceLoader)
public java.lang.Class<?>[] getAllArtefacts()
getAllArtefacts
in interface GrailsApplication
public GrailsResourceLoader getResourceLoader()
public java.lang.ClassLoader getClassLoader()
GrailsApplication
getClassLoader
in interface GrailsApplication
public ConfigObject getConfig()
GrailsApplication
getConfig
in interface GrailsApplication
public void setConfig(ConfigObject config)
public java.util.Map<java.lang.String,java.lang.Object> getFlatConfig()
GrailsApplication
getFlatConfig
in interface GrailsApplication
public java.lang.Class<?>[] getAllClasses()
getAllClasses
in interface GrailsApplication
public ApplicationContext getMainContext()
GrailsApplication
null
until the application is fully
initialised. This context contains all the application artifacts,
plugin beans, the works.getMainContext
in interface GrailsApplication
public void setMainContext(ApplicationContext context)
GrailsApplication
setMainContext
in interface GrailsApplication
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException
applicationContext
- The ApplicationContextBeansException
- Thrown when an error occurs setting the ApplicationContextpublic ApplicationContext getParentContext()
getParentContext
in interface GrailsApplication
public java.lang.Class<?> getClassForName(java.lang.String className)
getClassForName
in interface GrailsApplication
className
- The class namepublic void refreshConstraints()
refreshConstraints
in interface GrailsApplication
public void refresh()
refresh
in interface GrailsApplication
public void rebuild()
GrailsApplication
rebuild
in interface GrailsApplication
public Resource getResourceForClass(java.lang.Class theClazz)
getResourceForClass
in interface GrailsApplication
theClazz
- The classpublic boolean isArtefact(java.lang.Class theClazz)
isArtefact
in interface GrailsApplication
theClazz
- The class to checkpublic boolean isArtefactOfType(java.lang.String artefactType, java.lang.Class theClazz)
isArtefactOfType
in interface GrailsApplication
artefactType
- The type of the artefacttheClazz
- The classArtefactHandler
public boolean isArtefactOfType(java.lang.String artefactType, java.lang.String className)
isArtefactOfType
in interface GrailsApplication
artefactType
- The type of the artefactclassName
- The class nameArtefactHandler
public GrailsClass getArtefact(java.lang.String artefactType, java.lang.String name)
getArtefact
in interface GrailsApplication
artefactType
- The artefact type as defined by a registered ArtefactHandlername
- The name of the classpublic ArtefactHandler getArtefactType(java.lang.Class theClass)
GrailsApplication
getArtefactType
in interface GrailsApplication
theClass
- The classpublic GrailsClass[] getArtefacts(java.lang.String artefactType)
getArtefacts
in interface GrailsApplication
artefactType
- The type of the artefact defined by the ArtefactHandlerpublic GrailsClass getArtefactForFeature(java.lang.String artefactType, java.lang.Object featureID)
GrailsApplication
Get an artefact GrailsClass by a "feature" which depending on the artefact may be a URI or tag name for example
getArtefactForFeature
in interface GrailsApplication
artefactType
- The type ID of the artefact, i.e. "TagLib"featureID
- The "feature" ID, say a URL or tag namepublic GrailsClass addArtefact(java.lang.String artefactType, java.lang.Class artefactClass)
addArtefact
in interface GrailsApplication
artefactType
- The type of the artefact as defined by a ArtefactHandler instanceartefactClass
- A Class instance that matches the type defined by the ArtefactHandlerGrailsConfigurationException
- If the specified Class is not the same as the type defined by the ArtefactHandlerArtefactHandler
public GrailsClass addArtefact(java.lang.String artefactType, GrailsClass artefactGrailsClass)
addArtefact
in interface GrailsApplication
artefactType
- The type of the artefact as defined by a ArtefactHandler instanceartefactGrailsClass
- A GrailsClass instance that matches the type defined by the ArtefactHandlerGrailsConfigurationException
- If the specified GrailsClass is not the same as the type defined by the ArtefactHandlerArtefactHandler
public void registerArtefactHandler(ArtefactHandler handler)
registerArtefactHandler
in interface GrailsApplication
handler
- The ArtefactHandler to regsterpublic boolean hasArtefactHandler(java.lang.String type)
GrailsApplication
Test whether an artefact handler exists for a given type
hasArtefactHandler
in interface GrailsApplication
type
- The type of the handlerpublic ArtefactHandler[] getArtefactHandlers()
GrailsApplication
Obtain a list of all the artefact handlers
getArtefactHandlers
in interface GrailsApplication
public ArtefactHandler getArtefactHandler(java.lang.String type)
GrailsApplication
getArtefactHandler
in interface GrailsApplication
type
- The artefact handler typepublic void clear()
public ArtefactInfo getArtefactInfo(java.lang.String artefactType)
getArtefactInfo
in interface GrailsApplication
artefactType
- The name of an artefact typepublic java.lang.Object invokeMethod(java.lang.String methodName, java.lang.Object args)
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 methodpublic java.lang.Object getProperty(java.lang.String propertyName)
propertyName
- The name of the property, if it ends in *Classes then match and invoke internal ArtefactHandlerpublic void initialise()
GrailsApplication
initialise
in interface GrailsApplication
public boolean isInitialised()
GrailsApplication
isInitialised
in interface GrailsApplication
public Metadata getMetadata()
GrailsApplication
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.
getMetadata
in interface GrailsApplication
public GrailsClass getArtefactByLogicalPropertyName(java.lang.String type, java.lang.String logicalName)
GrailsApplication
getArtefactByLogicalPropertyName
in interface GrailsApplication
type
- The artefact typelogicalName
- The logical namepublic void addArtefact(java.lang.Class artefact)
GrailsApplication
addArtefact
in interface GrailsApplication
artefact
- The artefact to addpublic boolean isWarDeployed()
GrailsApplication
isWarDeployed
in interface GrailsApplication
public void setBeanClassLoader(java.lang.ClassLoader classLoader)
public void addOverridableArtefact(java.lang.Class artefact)
GrailsApplication
addOverridableArtefact
in interface GrailsApplication
artefact
- An overridable artefactpublic void configChanged()
GrailsApplication
configChanged
in interface GrailsApplication
public GrailsClass addOverridableArtefact(java.lang.String artefactType, java.lang.Class artefactClass)
artefactType
- The type of the artefact as defined by a ArtefactHandler instanceartefactClass
- A Class instance that matches the type defined by the ArtefactHandlerGrailsConfigurationException
- If the specified Class is not the same as the type defined by the ArtefactHandlerArtefactHandler