|
Groovy Documentation | |||||||
FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object groovy.lang.GroovyObjectSupport org.codehaus.groovy.grails.commons.DefaultGrailsApplication
public class DefaultGrailsApplication extends groovy.lang.GroovyObjectSupport
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.Field Summary | |
---|---|
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 |
allArtefactClasses
|
protected java.lang.Class[] |
allArtefactClassesArray
|
protected java.lang.Class[] |
allClasses
|
protected Metadata |
applicationMeta
|
protected ArtefactHandler[] |
artefactHandlers
|
protected java.util.Map |
artefactHandlersByName
|
protected java.util.Map |
artefactInfo
|
protected java.lang.ClassLoader |
cl
|
protected groovy.util.ConfigObject |
config
|
protected java.util.Map |
flatConfig
|
protected boolean |
initialised
|
protected java.util.List |
loadedClasses
|
protected static org.apache.commons.logging.Log |
log
|
protected org.springframework.context.ApplicationContext |
mainContext
|
protected org.springframework.context.ApplicationContext |
parentContext
|
protected GrailsResourceLoader |
resourceLoader
|
protected org.springframework.core.io.Resource[] |
resources
|
Constructor Summary | |
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(org.springframework.core.io.Resource[] resources)
Constructs a GrailsApplication with the given set of groovy sources specified as Spring Resource instances. |
|
DefaultGrailsApplication(GrailsResourceLoader resourceLoader)
|
Method Summary | |
---|---|
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. |
void
|
configChanged()
|
protected groovy.lang.GroovyClassLoader
|
configureClassLoader()
Configures a GroovyClassLoader for the given GrailsInjectionOperation and GrailsResourceLoader. |
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. |
java.lang.ClassLoader
|
getClassLoader()
|
groovy.util.ConfigObject
|
getConfig()
|
protected GrailsClass
|
getFirstArtefact(java.lang.String artefactType)
|
java.util.Map
|
getFlatConfig()
|
org.springframework.context.ApplicationContext
|
getMainContext()
|
Metadata
|
getMetadata()
|
org.springframework.context.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. |
org.springframework.core.io.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)
|
protected void
|
initArtefactHandlers()
Initialises the default set of ArtefactHandler instances. |
void
|
initialise()
|
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()
|
boolean
|
isWarDeployed()
|
protected void
|
loadGrailsApplicationFromResources(org.springframework.core.io.Resource[] resources)
|
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
|
setApplicationContext(org.springframework.context.ApplicationContext applicationContext)
Sets the parent ApplicationContext for the GrailsApplication. |
void
|
setBeanClassLoader(java.lang.ClassLoader classLoader)
|
void
|
setConfig(groovy.util.ConfigObject config)
|
void
|
setMainContext(org.springframework.context.ApplicationContext context)
|
Methods inherited from class groovy.lang.GroovyObjectSupport | |
---|---|
groovy.lang.GroovyObjectSupport#setProperty(java.lang.String, java.lang.Object), groovy.lang.GroovyObjectSupport#getProperty(java.lang.String), groovy.lang.GroovyObjectSupport#getMetaClass(), groovy.lang.GroovyObjectSupport#setMetaClass(groovy.lang.MetaClass), groovy.lang.GroovyObjectSupport#invokeMethod(java.lang.String, java.lang.Object), groovy.lang.GroovyObjectSupport#wait(), groovy.lang.GroovyObjectSupport#wait(long), groovy.lang.GroovyObjectSupport#wait(long, int), 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() |
Methods inherited from class java.lang.Object | |
---|---|
java.lang.Object#wait(), java.lang.Object#wait(long), java.lang.Object#wait(long, int), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll() |
Field Detail |
---|
protected static final java.util.regex.Pattern GETCLASSESMETH_PATTERN
protected static final java.util.regex.Pattern GETCLASSESPROP_PATTERN
protected static final java.util.regex.Pattern GETCLASS_PATTERN
protected static final java.util.regex.Pattern ISCLASS_PATTERN
protected java.util.List allArtefactClasses
protected java.lang.Class[] allArtefactClassesArray
protected java.lang.Class[] allClasses
protected Metadata applicationMeta
protected ArtefactHandler[] artefactHandlers
protected java.util.Map artefactHandlersByName
protected java.util.Map artefactInfo
protected java.lang.ClassLoader cl
protected groovy.util.ConfigObject config
@SuppressWarnings("rawtypes") protected java.util.Map flatConfig
protected boolean initialised
protected java.util.List loadedClasses
protected static org.apache.commons.logging.Log log
protected org.springframework.context.ApplicationContext mainContext
protected org.springframework.context.ApplicationContext parentContext
protected GrailsResourceLoader resourceLoader
protected org.springframework.core.io.Resource[] resources
Constructor Detail |
---|
public DefaultGrailsApplication()
public DefaultGrailsApplication(java.lang.Class[] classes, java.lang.ClassLoader classLoader)
classes
- The classes that make up the GrailsApplicationclassLoader
- The GroovyClassLoader to use
public DefaultGrailsApplication(org.springframework.core.io.Resource[] resources)
resources
- An array or Groovy sources provides by Spring Resource instances
public DefaultGrailsApplication(GrailsResourceLoader resourceLoader)
Method Detail |
---|
public GrailsClass addArtefact(java.lang.String artefactType, @SuppressWarnings("rawtypes") 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 ArtefactHandler
public GrailsClass addArtefact(java.lang.String artefactType, GrailsClass artefactGrailsClass)
artefactType
- The type of the artefact as defined by a ArtefactHandler instanceartefactGrailsClass
- A GrailsClass instance that matches the type defined by the ArtefactHandler
public void addArtefact(@SuppressWarnings("rawtypes") java.lang.Class artefact)
protected GrailsClass addArtefact(java.lang.String artefactType, java.lang.Class artefactClass, boolean overrideable)
public void addOverridableArtefact(@SuppressWarnings("rawtypes") java.lang.Class artefact)
public GrailsClass addOverridableArtefact(java.lang.String artefactType, @SuppressWarnings("rawtypes") 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 ArtefactHandler
protected void addToLoaded(java.lang.Class clazz)
public void clear()
public void configChanged()
protected groovy.lang.GroovyClassLoader configureClassLoader()
protected void configureLoadedClasses(java.lang.Class[] classes)
classes
- The classes to configure
public java.lang.Class[] getAllArtefacts()
public java.lang.Class[] getAllClasses()
public GrailsClass getArtefact(java.lang.String artefactType, java.lang.String name)
artefactType
- The artefact type as defined by a registered ArtefactHandlername
- The name of the class
public GrailsClass getArtefactByLogicalPropertyName(java.lang.String type, java.lang.String logicalName)
protected int getArtefactCount(java.lang.String artefactType)
artefactType
- The type of the artefact as defined by the ArtefactHandler
public GrailsClass getArtefactForFeature(java.lang.String artefactType, java.lang.Object featureID)
public ArtefactHandler getArtefactHandler(java.lang.String type)
public ArtefactHandler[] getArtefactHandlers()
protected 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 created
public ArtefactInfo getArtefactInfo(java.lang.String artefactType)
artefactType
- The name of an artefact type
public ArtefactHandler getArtefactType(@SuppressWarnings("rawtypes") java.lang.Class theClass)
public GrailsClass[] getArtefacts(java.lang.String artefactType)
artefactType
- The type of the artefact defined by the ArtefactHandler
public java.lang.Class getClassForName(java.lang.String className)
className
- The class name
public java.lang.ClassLoader getClassLoader()
public groovy.util.ConfigObject getConfig()
protected GrailsClass getFirstArtefact(java.lang.String artefactType)
@SuppressWarnings("unchecked") public java.util.Map getFlatConfig()
public org.springframework.context.ApplicationContext getMainContext()
public Metadata getMetadata()
public org.springframework.context.ApplicationContext getParentContext()
@Override public java.lang.Object getProperty(java.lang.String propertyName)
propertyName
- The name of the property, if it ends in *Classes then match and invoke internal ArtefactHandler
public org.springframework.core.io.Resource getResourceForClass(@SuppressWarnings("rawtypes") java.lang.Class theClazz)
theClazz
- The class
public GrailsResourceLoader getResourceLoader()
public boolean hasArtefactHandler(java.lang.String type)
protected void initArtefactHandlers()
public void initialise()
protected void initializeArtefacts(java.lang.String artefactType)
artefactType
- The type of artefact to init
protected void initializeArtefacts(ArtefactHandler handler)
handler
- The handler to register
@Override public 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 method
public boolean isArtefact(@SuppressWarnings("rawtypes") java.lang.Class theClazz)
theClazz
- The class to check
public boolean isArtefactOfType(java.lang.String artefactType, @SuppressWarnings("rawtypes") java.lang.Class theClazz)
artefactType
- The type of the artefacttheClazz
- The class
public boolean isArtefactOfType(java.lang.String artefactType, java.lang.String className)
artefactType
- The type of the artefactclassName
- The class name
public boolean isInitialised()
public boolean isWarDeployed()
@SuppressWarnings("rawtypes") protected void loadGrailsApplicationFromResources(@SuppressWarnings("hiding") org.springframework.core.io.Resource[] resources)
protected java.lang.Class[] populateAllClasses()
public void rebuild()
public void refresh()
protected void refreshArtefactGrailsClassCaches()
public void refreshConstraints()
public void registerArtefactHandler(ArtefactHandler handler)
handler
- The ArtefactHandler to regster
public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext)
applicationContext
- The ApplicationContext
public void setBeanClassLoader(java.lang.ClassLoader classLoader)
public void setConfig(groovy.util.ConfigObject config)
public void setMainContext(org.springframework.context.ApplicationContext context)
Groovy Documentation