Overview | Package | Class | Deprecated | Index | Help
| Groovy Documentation
| FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.codehaus.groovy.grails.commons
[Java] Class DefaultGrailsApplication

    java.lang.Object
      groovy.lang.GroovyObjectSupport
          org.codehaus.groovy.grails.commons.DefaultGrailsApplication

All Implemented Interfaces:
  GrailsApplication

    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.

Authors:
  Marc Palmer
  Steven Devijver
  Graeme Rocher

See Also:
  GrailsPluginManager
  DefaultGrailsPluginManager
  ArtefactHandler
  ArtefactInfo

Since:
  0.1

Constructor Summary
`DefaultGrailsApplication()` Creates a new empty Grails application.
`DefaultGrailsApplication(Class[] classes, java.lang.ClassLoader classLoader)` Creates a new GrailsApplication instance using the given classes and GroovyClassLoader.
`DefaultGrailsApplication(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)`
`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.
`void` | `configChanged()`
`Class[]` | `getAllArtefacts()` Returns all the classes identified as artefacts by ArtefactHandler instances.
`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)`
`GrailsClass` | `getArtefactForFeature(java.lang.String artefactType, java.lang.Object featureID)`
`ArtefactHandler` | `getArtefactHandler(java.lang.String type)`
`ArtefactHandler[]` | `getArtefactHandlers()`
`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()`
`java.util.Map` | `getFlatConfig()`
`ApplicationContext` | `getMainContext()`
`java.util.Map` | `getMetadata()`
`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)`
`void` | `initialise()`
`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()`
`boolean` | `isWarDeployed()`
`void` | `rebuild()`
`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` | `setMainContext(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()

Constructor Detail

### DefaultGrailsApplication

    public DefaultGrailsApplication()

  Creates a new empty Grails application.

### DefaultGrailsApplication

    public DefaultGrailsApplication(Class[] classes, java.lang.ClassLoader classLoader)

  Creates a new GrailsApplication instance using the given classes and GroovyClassLoader.
  Parameters:
    `classes` - The classes that make up the GrailsApplication
    `classLoader` - The GroovyClassLoader to use

### DefaultGrailsApplication

    public DefaultGrailsApplication(Resource[] resources)

  Constructs a GrailsApplication with the given set of groovy sources specified as Spring Resource instances.
  Parameters:
    `resources` - An array or Groovy sources provides by Spring Resource instances

### DefaultGrailsApplication

    public DefaultGrailsApplication(GrailsResourceLoader resourceLoader)

Method Detail

### addArtefact

    public GrailsClass addArtefact(java.lang.String artefactType, @SuppressWarnings("rawtypes") java.lang.Class artefactClass)

  Adds an artefact of the given type for the given Class.
  throws:
    GrailsConfigurationException If the specified Class is not the same as the type defined by the ArtefactHandler
  Parameters:
    `artefactType` - The type of the artefact as defined by a ArtefactHandler instance
    `artefactClass` - A Class instance that matches the type defined by the ArtefactHandler
  Returns:
    The GrailsClass if successful or null if it couldn't be added
  See Also:
    ArtefactHandler

### addArtefact

    public GrailsClass addArtefact(java.lang.String artefactType, GrailsClass artefactGrailsClass)

  Adds an artefact of the given type for the given GrailsClass.
  throws:
    GrailsConfigurationException If the specified GrailsClass is not the same as the type defined by the ArtefactHandler
  Parameters:
    `artefactType` - The type of the artefact as defined by a ArtefactHandler instance
    `artefactGrailsClass` - A GrailsClass instance that matches the type defined by the ArtefactHandler
  Returns:
    The GrailsClass if successful or null if it couldn't be added
  See Also:
    ArtefactHandler

### addArtefact

    public void addArtefact(@SuppressWarnings("rawtypes") java.lang.Class artefact)

### addOverridableArtefact

    public void addOverridableArtefact(@SuppressWarnings("rawtypes") java.lang.Class artefact)

### addOverridableArtefact

    public GrailsClass addOverridableArtefact(java.lang.String artefactType, @SuppressWarnings("rawtypes") java.lang.Class artefactClass)

  Adds an artefact of the given type for the given Class.
  throws:
    GrailsConfigurationException If the specified Class is not the same as the type defined by the ArtefactHandler
  Parameters:
    `artefactType` - The type of the artefact as defined by a ArtefactHandler instance
    `artefactClass` - A Class instance that matches the type defined by the ArtefactHandler
  Returns:
    The GrailsClass if successful or null if it couldn't be added
  See Also:
    ArtefactHandler

### configChanged

    public void configChanged()

### getAllArtefacts

    public Class[] getAllArtefacts()

  Returns all the classes identified as artefacts by ArtefactHandler instances.
  Returns:
    An array of classes

### getAllClasses

    public Class[] getAllClasses()

  Retrieves all classes loaded by the GrailsApplication.
  Returns:
    All classes loaded by the GrailsApplication

### getArtefact

    public GrailsClass getArtefact(java.lang.String artefactType, java.lang.String name)

  Retrieves an artefact for the given type and name.
  Parameters:
    `artefactType` - The artefact type as defined by a registered ArtefactHandler
    `name` - The name of the class
  Returns:
    A GrailsClass instance or null if none could be found for the given artefactType and name

### getArtefactByLogicalPropertyName

    public GrailsClass getArtefactByLogicalPropertyName(java.lang.String type, java.lang.String logicalName)

### getArtefactForFeature

    public GrailsClass getArtefactForFeature(java.lang.String artefactType, java.lang.Object featureID)

### getArtefactHandler

    public ArtefactHandler getArtefactHandler(java.lang.String type)

### getArtefactHandlers

    public ArtefactHandler[] getArtefactHandlers()

### getArtefactInfo

    public ArtefactInfo getArtefactInfo(java.lang.String artefactType)

  Get the cache of classes for the specified artefact type.
  Parameters:
    `artefactType` - The name of an artefact type
  Returns:
    The cache of classes for the type, or null if no cache exists

### getArtefactType

    public ArtefactHandler getArtefactType(@SuppressWarnings("rawtypes") java.lang.Class theClass)

### getArtefacts

    public GrailsClass[] getArtefacts(java.lang.String artefactType)

  Returns all of the GrailsClass instances for the given artefactType as defined by the ArtefactHandler
  Parameters:
    `artefactType` - The type of the artefact defined by the ArtefactHandler
  Returns:
    An array of classes for the given artefact

### getClassForName

    public java.lang.Class getClassForName(java.lang.String className)

  Retrieves a class from the GrailsApplication for the given name.
  Parameters:
    `className` - The class name
  Returns:
    Either the Class instance or null if it doesn't exist

### getClassLoader

    public java.lang.ClassLoader getClassLoader()

### getConfig

    public groovy.util.ConfigObject getConfig()

### getFlatConfig

    @SuppressWarnings("rawtypes")
    public java.util.Map getFlatConfig()

### getMainContext

    public ApplicationContext getMainContext()

### getMetadata

    @SuppressWarnings("rawtypes")
    public java.util.Map getMetadata()

### getParentContext

    public ApplicationContext getParentContext()

  Retrieves the parent ApplicationContext for this GrailsApplication.
  Returns:
    The parent ApplicationContext

### getProperty

    @Override
    public java.lang.Object getProperty(java.lang.String propertyName)

  Override property access and hit on xxxxClasses to return class arrays of artefacts.
  Parameters:
    `propertyName` - The name of the property, if it ends in *Classes then match and invoke internal ArtefactHandler
  Returns:
    All the artifacts or delegate to super.getProperty

### getResourceForClass

    public Resource getResourceForClass(@SuppressWarnings("rawtypes") java.lang.Class theClazz)

  Retrieves the Spring Resource that was used to load the given Class.
  Parameters:
    `theClazz` - The class
  Returns:
    Either a Spring Resource or null if no Resource was found for the given class

### getResourceLoader

    public GrailsResourceLoader getResourceLoader()

### hasArtefactHandler

    public boolean hasArtefactHandler(java.lang.String type)

### initialise

    public void initialise()

### invokeMethod

    @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)

  todo:
    Need to add matches for addClass(java.lang.Class) and addClass(GrailsClass)
  Parameters:
    `methodName` - The name of the method
    `args` - The arguments to the method
  Returns:
    The return value of the method

### isArtefact

    public boolean isArtefact(@SuppressWarnings("rawtypes") java.lang.Class theClazz)

  Returns true if the given class is an artefact identified by one of the registered ArtefactHandler instances. Uses class name equality to handle class reloading
  Parameters:
    `theClazz` - The class to check
  Returns:
    True if it is an artefact

### isArtefactOfType

    public boolean isArtefactOfType(java.lang.String artefactType, @SuppressWarnings("rawtypes") java.lang.Class theClazz)

  Returns true if the specified class is of the given artefact type as defined by the ArtefactHandler.
  Parameters:
    `artefactType` - The type of the artefact
    `theClazz` - The class
  Returns:
    True if it is of the specified artefactType
  See Also:
    ArtefactHandler

### isArtefactOfType

    public 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.
  Parameters:
    `artefactType` - The type of the artefact
    `className` - The class name
  Returns:
    True if it is of the specified artefactType
  See Also:
    ArtefactHandler

### isInitialised

    public boolean isInitialised()

### isWarDeployed

    public boolean isWarDeployed()

### rebuild

    public void rebuild()

### refresh

    public void refresh()

  Refreshes this GrailsApplication, rebuilding all of the artefact definitions as defined by the registered ArtefactHandler instances.

### refreshConstraints

    public void refreshConstraints()

  Refreshes constraints defined by the DomainClassArtefactHandler.
  todo:
    Move this out of GrailsApplication

### registerArtefactHandler

    public 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.
  Parameters:
    `handler` - The ArtefactHandler to regster

### setApplicationContext

    public void setApplicationContext(ApplicationContext applicationContext)

  Sets the parent ApplicationContext for the GrailsApplication.
  throws:
    BeansException Thrown when an error occurs setting the ApplicationContext
  Parameters:
    `applicationContext` - The ApplicationContext

### setBeanClassLoader

    public void setBeanClassLoader(java.lang.ClassLoader classLoader)

### setMainContext

    public void setMainContext(ApplicationContext context)

Groovy Documentation