|
||||||||||
PREV CLASS NEXT CLASS | 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
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.
GrailsPluginManager
,
DefaultGrailsPluginManager
,
ArtefactHandler
,
ArtefactInfo
Field Summary |
---|
Fields inherited from interface org.codehaus.groovy.grails.commons.GrailsApplication |
---|
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 Summary | |
---|---|
DefaultGrailsApplication()
Creates a new empty Grails application |
|
DefaultGrailsApplication(Class[] classes,
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 |
Method Summary | |
---|---|
void |
addArtefact(Class artefact)
Adds the given artefact, attempting to determine type from |
GrailsClass |
addArtefact(String artefactType,
Class artefactClass)
Adds an artefact of the given type for the given Class. |
GrailsClass |
addArtefact(String artefactType,
GrailsClass artefactGrailsClass)
Adds an artefact of the given type for the given GrailsClass. |
void |
addOverridableArtefact(Class artefact)
Adds an artefact that can be overriden by user defined classes |
GrailsClass |
addOverridableArtefact(String artefactType,
Class artefactClass)
Adds an artefact of the given type for the given Class. |
void |
configChanged()
Fired to inform the application when the Config.groovy file changes |
Class[] |
getAllArtefacts()
Returns all the classes identified as artefacts by ArtefactHandler instances |
Class[] |
getAllClasses()
Retrieves all classes loaded by the GrailsApplication |
GrailsClass |
getArtefact(String artefactType,
String name)
Retrieves an artefact for the given type and nam |
GrailsClass |
getArtefactByLogicalPropertyName(String type,
String logicalName)
Retrieves an artefact by its logical property name. |
GrailsClass |
getArtefactForFeature(String artefactType,
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(String type)
Returns the ArtefactHandler for the given type |
ArtefactHandler[] |
getArtefactHandlers()
Obtain a list of all the artefact handlers |
ArtefactInfo |
getArtefactInfo(String artefactType)
Get the cache of classes for the specified artefact type |
GrailsClass[] |
getArtefacts(String artefactType)
Returns all of the GrailsClass instances for the given artefactType as defined by the ArtefactHandler |
ArtefactHandler |
getArtefactType(Class theClass)
Returns the ArtefactHandler for the given class or null |
Class |
getClassForName(String className)
Retrieves a class from the GrailsApplication for the given name |
ClassLoader |
getClassLoader()
Returns the class loader instance for the Grails application |
groovy.util.ConfigObject |
getConfig()
Returns the ConfigObject instance |
Map |
getFlatConfig()
Returns the flatten ConfigObject for use from Java classes |
ApplicationContext |
getMainContext()
Returns the Spring context for this application. |
Map |
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. |
ApplicationContext |
getParentContext()
Retrieves the parent ApplicationContext for this GrailsApplication |
Object |
getProperty(String propertyName)
Override property access and hit on xxxxClasses to return class arrays of artefacts |
Resource |
getResourceForClass(Class theClazz)
Retrieves the Spring Resource that was used to load the given Class |
GrailsResourceLoader |
getResourceLoader()
|
boolean |
hasArtefactHandler(String type)
Test whether an artefact handler exists for a given type |
void |
initialise()
Initialise this GrailsApplication |
Object |
invokeMethod(String methodName,
Object args)
Overrides method invocation to return dynamic artefact methods We will support getXXXXClasses() and isXXXXClass(class) |
boolean |
isArtefact(Class theClazz)
Returns true if the given class is an artefact identified by one of the registered ArtefactHandler instances. |
boolean |
isArtefactOfType(String artefactType,
Class theClazz)
Returns true if the specified class is of the given artefact type as defined by the ArtefactHandler |
boolean |
isArtefactOfType(String artefactType,
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 an particular artefact type that is defined by some convention |
void |
setApplicationContext(ApplicationContext applicationContext)
Sets the parent ApplicationContext for the GrailsApplication |
void |
setBeanClassLoader(ClassLoader classLoader)
|
void |
setMainContext(ApplicationContext context)
Sets the main Spring context for this application. |
Methods inherited from class groovy.lang.GroovyObjectSupport |
---|
getMetaClass, setMetaClass, setProperty |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public DefaultGrailsApplication()
public DefaultGrailsApplication(Class[] classes, ClassLoader classLoader)
classes
- The classes that make up the GrailsApplicationclassLoader
- The GroovyClassLoader to usepublic DefaultGrailsApplication(Resource[] resources) throws IOException
resources
- An array or Groovy sources provides by Spring Resource instances
IOException
- Thrown when an error occurs reading a Groovy sourcepublic DefaultGrailsApplication(GrailsResourceLoader resourceLoader)
Method Detail |
---|
public Class[] getAllArtefacts()
getAllArtefacts
in interface GrailsApplication
public GrailsResourceLoader getResourceLoader()
public ClassLoader getClassLoader()
GrailsApplication
Returns the class loader instance for the Grails application
getClassLoader
in interface GrailsApplication
public groovy.util.ConfigObject getConfig()
GrailsApplication
getConfig
in interface GrailsApplication
public Map getFlatConfig()
GrailsApplication
getFlatConfig
in interface GrailsApplication
public 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
setApplicationContext
in interface ApplicationContextAware
applicationContext
- The ApplicationContext
BeansException
- Thrown when an error occurs setting the ApplicationContextpublic ApplicationContext getParentContext()
getParentContext
in interface GrailsApplication
public Class getClassForName(String className)
getClassForName
in interface GrailsApplication
className
- The class name
public void refreshConstraints()
refreshConstraints
in interface GrailsApplication
public void refresh()
refresh
in interface GrailsApplication
public void rebuild()
GrailsApplication
rebuild
in interface GrailsApplication
public Resource getResourceForClass(Class theClazz)
getResourceForClass
in interface GrailsApplication
theClazz
- The class
public boolean isArtefact(Class theClazz)
isArtefact
in interface GrailsApplication
theClazz
- The class to check
public boolean isArtefactOfType(String artefactType, Class theClazz)
isArtefactOfType
in interface GrailsApplication
artefactType
- The type of the artefacttheClazz
- The class
ArtefactHandler
public boolean isArtefactOfType(String artefactType, String className)
isArtefactOfType
in interface GrailsApplication
artefactType
- The type of the artefactclassName
- The class name
ArtefactHandler
public GrailsClass getArtefact(String artefactType, String name)
getArtefact
in interface GrailsApplication
artefactType
- The artefact type as defined by a registered ArtefactHandlername
- The name of the class
public ArtefactHandler getArtefactType(Class theClass)
GrailsApplication
getArtefactType
in interface GrailsApplication
theClass
- The class
public GrailsClass[] getArtefacts(String artefactType)
getArtefacts
in interface GrailsApplication
artefactType
- The type of the artefact defined by the ArtefactHandler
public GrailsClass getArtefactForFeature(String artefactType, 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 name
public GrailsClass addArtefact(String artefactType, 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 ArtefactHandler
GrailsConfigurationException
- If the specified Class is not the same as the type defined by the ArtefactHandlerArtefactHandler
public GrailsClass addArtefact(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 ArtefactHandler
GrailsConfigurationException
- 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(String type)
GrailsApplication
Test whether an artefact handler exists for a given type
hasArtefactHandler
in interface GrailsApplication
type
- The type of the handler
public ArtefactHandler[] getArtefactHandlers()
GrailsApplication
Obtain a list of all the artefact handlers
getArtefactHandlers
in interface GrailsApplication
public ArtefactHandler getArtefactHandler(String type)
GrailsApplication
getArtefactHandler
in interface GrailsApplication
type
- The artefact handler type
public ArtefactInfo getArtefactInfo(String artefactType)
Get the cache of classes for the specified artefact type
getArtefactInfo
in interface GrailsApplication
artefactType
- The name of an artefact type
public Object invokeMethod(String methodName, Object args)
Overrides method invocation to return dynamic artefact methods
We will support getXXXXClasses() and isXXXXClass(class)
invokeMethod
in interface groovy.lang.GroovyObject
invokeMethod
in class groovy.lang.GroovyObjectSupport
methodName
- The name of the methodargs
- The arguments to the method
public Object getProperty(String propertyName)
Override property access and hit on xxxxClasses to return class arrays of artefacts
getProperty
in interface groovy.lang.GroovyObject
getProperty
in class groovy.lang.GroovyObjectSupport
propertyName
- The name of the property, if it ends in *Classes then match and invoke internal ArtefactHandler
public void initialise()
GrailsApplication
initialise
in interface GrailsApplication
public boolean isInitialised()
GrailsApplication
isInitialised
in interface GrailsApplication
public Map 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(String type, String logicalName)
GrailsApplication
getArtefactByLogicalPropertyName
in interface GrailsApplication
type
- The artefact typelogicalName
- The logical name
public void addArtefact(Class artefact)
GrailsApplication
addArtefact
in interface GrailsApplication
artefact
- The artefact to addpublic boolean isWarDeployed()
GrailsApplication
isWarDeployed
in interface GrailsApplication
public void setBeanClassLoader(ClassLoader classLoader)
setBeanClassLoader
in interface BeanClassLoaderAware
public void addOverridableArtefact(Class artefact)
GrailsApplication
addOverridableArtefact
in interface GrailsApplication
artefact
- An overridable artefactpublic void configChanged()
GrailsApplication
configChanged
in interface GrailsApplication
public GrailsClass addOverridableArtefact(String artefactType, 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
GrailsConfigurationException
- If the specified Class is not the same as the type defined by the ArtefactHandlerArtefactHandler
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |