|
||||||||||
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, ENV_APPLICATION, ENV_DEVELOPMENT, ENV_PRODUCTION, ENV_TEST, ENVIRONMENT, PROJECT_CLASSES_DIR, PROJECT_RESOURCES_DIR, PROJECT_TEST_CLASSES_DIR, WORK_DIR |
Constructor Summary | |
---|---|
DefaultGrailsApplication()
Creates a new empty Grails application |
|
DefaultGrailsApplication(Class[] classes,
groovy.lang.GroovyClassLoader 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. |
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[] |
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 |
Class |
getClassForName(String className)
Retrieves a class from the GrailsApplication for the given name |
groovy.lang.GroovyClassLoader |
getClassLoader()
Returns the class loader instance for the Grails application |
groovy.util.ConfigObject |
getConfig()
Returns the ConfigObject instance |
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()
|
GrailsControllerClass |
getScaffoldingController(GrailsDomainClass domainClass)
Retrieves the controller that is scaffolding the specified domain class |
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 |
protected Map |
loadMetadata()
|
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)
|
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, groovy.lang.GroovyClassLoader 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 |
---|
protected Map loadMetadata()
public Class[] getAllArtefacts()
getAllArtefacts
in interface GrailsApplication
public GrailsControllerClass getScaffoldingController(GrailsDomainClass domainClass)
GrailsApplication
getScaffoldingController
in interface GrailsApplication
domainClass
- The domain class to check
public GrailsResourceLoader getResourceLoader()
public groovy.lang.GroovyClassLoader 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 Class[] getAllClasses()
getAllClasses
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 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 ArtefactHandler[] getArtefactHandlers()
GrailsApplication
Obtain a list of all the artefact handlers
getArtefactHandlers
in interface GrailsApplication
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
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |