public class DefaultGrailsApplication extends groovy.lang.GroovyObjectSupport implements GrailsApplication, org.springframework.beans.factory.BeanClassLoaderAware
GrailsPluginManager,
DefaultGrailsPluginManager,
ArtefactHandler,
ArtefactInfo| Modifier and Type | Field and Description |
|---|---|
protected java.util.List<java.lang.Class<?>> |
allArtefactClasses |
protected java.lang.Class<?>[] |
allArtefactClassesArray |
protected java.lang.Class<?>[] |
allClasses |
protected grails.util.Metadata |
applicationMeta |
protected ArtefactHandler[] |
artefactHandlers |
protected java.util.Map<java.lang.String,ArtefactHandler> |
artefactHandlersByName |
protected java.util.Map<java.lang.String,ArtefactInfo> |
artefactInfo |
protected java.lang.ClassLoader |
classLoader |
protected groovy.util.ConfigObject |
config |
protected java.util.Map |
flatConfig |
protected static java.util.regex.Pattern |
GETCLASS_PATTERN |
protected static java.util.regex.Pattern |
GETCLASSESMETH_PATTERN |
protected static java.util.regex.Pattern |
GETCLASSESPROP_PATTERN |
protected boolean |
initialised |
protected static java.util.regex.Pattern |
ISCLASS_PATTERN |
protected java.util.Set<java.lang.Class<?>> |
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 |
APPLICATION_ID, CLASS_EDITOR_BEAN, CLASS_LOADER_BEAN, CONFIG_CLASS, CUSTOM_EDITORS_BEAN, DATA_SOURCE_BEAN, DATA_SOURCE_CLASS, DIALECT_DETECTOR_BEAN, ENV_APPLICATION, ENV_DEVELOPMENT, ENV_PRODUCTION, ENV_TEST, ENVIRONMENT, ENVIRONMENT_DEFAULT, EXCEPTION_HANDLER_BEAN, GLOBAL_PLUGINS_DIR, HIBERNATE_PROPERTIES_BEAN, MESSAGE_SOURCE_BEAN, MULTIPART_RESOLVER_BEAN, OPEN_SESSION_IN_VIEW_INTERCEPTOR_BEAN, PLUGINS_DIR, PROJECT_CLASSES_DIR, PROJECT_META_FILE, PROJECT_RESOURCES_DIR, PROJECT_TEST_CLASSES_DIR, PROJECT_WORK_DIR, SESSION_FACTORY_BEAN, TRANSACTION_MANAGER_BEAN, 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(java.lang.ClassLoader classLoader) |
DefaultGrailsApplication(org.springframework.core.io.Resource[] resources)
Loads a GrailsApplication using the given ResourceLocator instance which will search for appropriate class names
|
DefaultGrailsApplication(org.codehaus.groovy.grails.io.support.Resource[] resources)
Loads a GrailsApplication using the given ResourceLocator instance which will search for appropriate class names
|
| 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.
|
protected GrailsClass |
addArtefact(java.lang.String artefactType,
java.lang.Class<?> artefactClass,
boolean overrideable) |
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.
|
protected void |
addToLoaded(java.lang.Class<?> clazz) |
void |
clear()
Clears the application returning it to an empty state.
|
void |
configChanged()
Fired to inform the application when the Config.groovy file changes.
|
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)
Retrieves an artefact by its logical property name.
|
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)
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.
|
protected DefaultArtefactInfo |
getArtefactInfo(java.lang.String artefactType,
boolean create)
Get or create 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.
|
groovy.util.ConfigObject |
getConfig()
Returns the ConfigObject instance.
|
protected GrailsClass |
getFirstArtefact(java.lang.String artefactType) |
java.util.Map<java.lang.String,java.lang.Object> |
getFlatConfig()
Returns the flatten ConfigObject for use from Java classes.
|
org.springframework.context.ApplicationContext |
getMainContext()
Returns the Spring context for this application.
|
grails.util.Metadata |
getMetadata()
Get access to the project's metadata, specified in application.properties
|
org.springframework.context.ApplicationContext |
getParentContext()
Returns the Spring application context that contains this
application instance.
|
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)
Test whether an artefact handler exists for a given type
|
protected void |
initArtefactHandlers()
Initialises the default set of ArtefactHandler instances.
|
void |
initialise()
Initialise this GrailsApplication.
|
protected static void |
initialiseGroovyExtensionModules() |
protected void |
initializeArtefacts(ArtefactHandler handler)
Re-initialize the artefacts of the specified type.
|
protected void |
initializeArtefacts(java.lang.String artefactType)
Re-initialize the artefacts of the specified type.
|
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
|
protected java.lang.Class<?>[] |
populateAllClasses() |
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.
|
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)
Sets the main Spring context for this application.
|
void |
updateFlatConfig() |
getMetaClass, setMetaClass, setPropertyclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitconfigChanged, getClassLoader, getFlatConfig, getMainContext, getMetadata, getParentContext, isWarDeployed, setMainContextprotected static final java.util.regex.Pattern GETCLASSESPROP_PATTERN
protected static final java.util.regex.Pattern GETCLASSESMETH_PATTERN
protected static final java.util.regex.Pattern ISCLASS_PATTERN
protected static final java.util.regex.Pattern GETCLASS_PATTERN
protected java.lang.Class<?>[] allClasses
protected static org.apache.commons.logging.Log log
protected java.util.Set<java.lang.Class<?>> loadedClasses
protected ArtefactHandler[] artefactHandlers
protected java.util.Map<java.lang.String,ArtefactHandler> artefactHandlersByName
protected java.util.List<java.lang.Class<?>> allArtefactClasses
protected java.util.Map<java.lang.String,ArtefactInfo> artefactInfo
protected java.lang.Class<?>[] allArtefactClassesArray
protected org.springframework.core.io.Resource[] resources
protected boolean initialised
protected java.lang.ClassLoader classLoader
protected groovy.util.ConfigObject config
protected java.util.Map flatConfig
protected org.springframework.context.ApplicationContext parentContext
protected org.springframework.context.ApplicationContext mainContext
protected grails.util.Metadata applicationMeta
public DefaultGrailsApplication()
public DefaultGrailsApplication(java.lang.ClassLoader classLoader)
public DefaultGrailsApplication(java.lang.Class<?>[] classes,
java.lang.ClassLoader classLoader)
classes - The classes that make up the GrailsApplicationclassLoader - The GroovyClassLoader to usepublic DefaultGrailsApplication(org.springframework.core.io.Resource[] resources)
public DefaultGrailsApplication(org.codehaus.groovy.grails.io.support.Resource[] resources)
protected void initArtefactHandlers()
ArtefactHandlerpublic java.lang.Class<?>[] getAllArtefacts()
getAllArtefacts in interface GrailsApplicationprotected java.lang.Class<?>[] populateAllClasses()
protected void configureLoadedClasses(java.lang.Class<?>[] classes)
classes - The classes to configureprotected void refreshArtefactGrailsClassCaches()
protected void addToLoaded(java.lang.Class<?> clazz)
public groovy.util.ConfigObject getConfig()
GrailsApplicationgetConfig in interface GrailsApplicationprotected int getArtefactCount(java.lang.String artefactType)
artefactType - The type of the artefact as defined by the ArtefactHandlerpublic java.lang.Class<?>[] getAllClasses()
getAllClasses in interface GrailsApplicationpublic java.lang.Class<?> getClassForName(java.lang.String className)
getClassForName in interface GrailsApplicationclassName - The class namepublic void refreshConstraints()
refreshConstraints in interface GrailsApplicationpublic void refresh()
refresh in interface GrailsApplicationpublic void rebuild()
GrailsApplicationrebuild in interface GrailsApplicationpublic org.springframework.core.io.Resource getResourceForClass(java.lang.Class theClazz)
getResourceForClass in interface GrailsApplicationtheClazz - The classpublic boolean isArtefact(java.lang.Class theClazz)
isArtefact in interface GrailsApplicationtheClazz - The class to checkpublic boolean isArtefactOfType(java.lang.String artefactType,
java.lang.Class theClazz)
isArtefactOfType in interface GrailsApplicationartefactType - The type of the artefacttheClazz - The classArtefactHandlerpublic boolean isArtefactOfType(java.lang.String artefactType,
java.lang.String className)
isArtefactOfType in interface GrailsApplicationartefactType - The type of the artefactclassName - The class nameArtefactHandlerpublic GrailsClass getArtefact(java.lang.String artefactType, java.lang.String name)
getArtefact in interface GrailsApplicationartefactType - The artefact type as defined by a registered ArtefactHandlername - The name of the classpublic ArtefactHandler getArtefactType(java.lang.Class theClass)
GrailsApplicationgetArtefactType in interface GrailsApplicationtheClass - The classprotected GrailsClass getFirstArtefact(java.lang.String artefactType)
public GrailsClass[] getArtefacts(java.lang.String artefactType)
getArtefacts in interface GrailsApplicationartefactType - The type of the artefact defined by the ArtefactHandlerpublic GrailsClass getArtefactForFeature(java.lang.String artefactType, java.lang.Object featureID)
GrailsApplicationGet an artefact GrailsClass by a "feature" which depending on the artefact may be a URI or tag name for example
getArtefactForFeature in interface GrailsApplicationartefactType - 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 GrailsApplicationartefactType - 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 ArtefactHandlerArtefactHandlerpublic GrailsClass addArtefact(java.lang.String artefactType, GrailsClass artefactGrailsClass)
addArtefact in interface GrailsApplicationartefactType - 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 ArtefactHandlerArtefactHandlerpublic void registerArtefactHandler(ArtefactHandler handler)
registerArtefactHandler in interface GrailsApplicationhandler - The ArtefactHandler to regsterpublic boolean hasArtefactHandler(java.lang.String type)
GrailsApplicationTest whether an artefact handler exists for a given type
hasArtefactHandler in interface GrailsApplicationtype - The type of the handlerpublic ArtefactHandler[] getArtefactHandlers()
GrailsApplicationObtain a list of all the artefact handlers
getArtefactHandlers in interface GrailsApplicationpublic ArtefactHandler getArtefactHandler(java.lang.String type)
GrailsApplicationgetArtefactHandler in interface GrailsApplicationtype - The artefact handler typeprotected void initializeArtefacts(java.lang.String artefactType)
artefactType - The type of artefact to initpublic void clear()
protected void initializeArtefacts(ArtefactHandler handler)
handler - The handler to registerprotected DefaultArtefactInfo getArtefactInfo(java.lang.String artefactType, boolean create)
artefactType - The name of an artefact typecreate - Set to true if you want non-existent caches to be createdpublic ArtefactInfo getArtefactInfo(java.lang.String artefactType)
getArtefactInfo in interface GrailsApplicationartefactType - 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)
invokeMethod in interface groovy.lang.GroovyObjectinvokeMethod in class groovy.lang.GroovyObjectSupportmethodName - The name of the methodargs - The arguments to the methodpublic java.lang.Object getProperty(java.lang.String propertyName)
getProperty in interface groovy.lang.GroovyObjectgetProperty in class groovy.lang.GroovyObjectSupportpropertyName - The name of the property, if it ends in *Classes then match and invoke internal ArtefactHandlerpublic void initialise()
GrailsApplicationinitialise in interface GrailsApplicationprotected static void initialiseGroovyExtensionModules()
public boolean isInitialised()
GrailsApplicationisInitialised in interface GrailsApplicationpublic GrailsClass getArtefactByLogicalPropertyName(java.lang.String type, java.lang.String logicalName)
GrailsApplicationgetArtefactByLogicalPropertyName in interface GrailsApplicationtype - The artefact typelogicalName - The logical namepublic void addArtefact(java.lang.Class artefact)
GrailsApplicationaddArtefact in interface GrailsApplicationartefact - The artefact to addpublic void setBeanClassLoader(java.lang.ClassLoader classLoader)
setBeanClassLoader in interface org.springframework.beans.factory.BeanClassLoaderAwarepublic void addOverridableArtefact(java.lang.Class artefact)
GrailsApplicationaddOverridableArtefact in interface GrailsApplicationartefact - An overridable artefactpublic 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 ArtefactHandlerArtefactHandlerprotected GrailsClass addArtefact(java.lang.String artefactType, java.lang.Class<?> artefactClass, boolean overrideable)
public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext)
throws org.springframework.beans.BeansException
setApplicationContext in interface org.springframework.context.ApplicationContextAwareorg.springframework.beans.BeansExceptionpublic grails.util.Metadata getMetadata()
GrailsApplicationGet 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 GrailsApplicationpublic boolean isWarDeployed()
GrailsApplicationisWarDeployed in interface GrailsApplicationpublic void setConfig(groovy.util.ConfigObject config)
public void updateFlatConfig()
public java.util.Map<java.lang.String,java.lang.Object> getFlatConfig()
GrailsApplicationgetFlatConfig in interface GrailsApplicationpublic void configChanged()
GrailsApplicationconfigChanged in interface GrailsApplicationpublic java.lang.ClassLoader getClassLoader()
GrailsApplicationgetClassLoader in interface GrailsApplicationpublic org.springframework.context.ApplicationContext getMainContext()
GrailsApplicationnull until the application is fully
initialised. This context contains all the application artifacts,
plugin beans, the works.getMainContext in interface GrailsApplicationpublic void setMainContext(org.springframework.context.ApplicationContext context)
GrailsApplicationsetMainContext in interface GrailsApplicationpublic org.springframework.context.ApplicationContext getParentContext()
GrailsApplicationGrailsApplication.getMainContext().getParentContext in interface GrailsApplication