Package grails.core

Interface GrailsApplication

  • All Superinterfaces:
    org.springframework.context.ApplicationContextAware, org.springframework.beans.factory.Aware
    All Known Implementing Classes:
    AbstractGrailsApplication, DefaultGrailsApplication

    public interface GrailsApplication
    extends org.springframework.context.ApplicationContextAware

    The main interface representing a running Grails application. This interface's main purpose is to provide a mechanism for analysing the conventions within a Grails application as well as providing metadata and information about the execution environment.

    The GrailsApplication interface interfacts with ArtefactHandler instances which are capable of analysing different artefact types (controllers, domain classes etc.) and introspecting the artefact conventions

    Implementors of this inteface should be aware that a GrailsApplication is only initialised when the initialise() method is called. In other words GrailsApplication instances are lazily initialised by the Grails runtime.

    Since:
    0.1
    See Also:
    initialise(), ArtefactHandler
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      void addArtefact​(java.lang.Class artefact)
      Adds the given artefact, attempting to determine type from
      GrailsClass addArtefact​(java.lang.String artefactType, GrailsClass artefactGrailsClass)
      Registers a new artefact
      GrailsClass addArtefact​(java.lang.String artefactType, java.lang.Class artefactClass)
      Registers a new artefact
      void addOverridableArtefact​(java.lang.Class artefact)
      Adds an artefact that can be overriden by user defined classes
      void configChanged()
      Fired to inform the application when the Config.groovy file changes.
      java.lang.Class[] getAllArtefacts()
      Retrieves all java.lang.Class instances considered Artefacts loaded by the Grails class loader
      java.lang.Class[] getAllClasses()
      Retrieves all java.lang.Class instances loaded by the Grails class loader
      GrailsClass getArtefact​(java.lang.String artefactType, java.lang.String name)
      Gets the GrailsClass associated with the named artefact class
      GrailsClass getArtefactByLogicalPropertyName​(java.lang.String type, java.lang.String logicalName)
      Retrieves an artefact by its logical property name.
      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)
      Obtain all the class information about the artefactType specified
      GrailsClass[] getArtefacts​(java.lang.String artefactType)
      Get an array of all the GrailsClass instances relating to artefacts of the specified type.
      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 for the given name within the GrailsApplication or returns null
      java.lang.ClassLoader getClassLoader()
      Returns the class loader instance for the Grails application.
      grails.config.Config getConfig()
      Returns the ConfigObject instance.
      org.springframework.context.ApplicationContext getMainContext()
      Returns the Spring context for this application.
      org.grails.datastore.mapping.model.MappingContext getMappingContext()  
      grails.util.Metadata getMetadata()
      Get access to the project's metadata, specified in application.yml and grails.build.info if it is present
      org.springframework.context.ApplicationContext getParentContext()
      Returns the Spring application context that contains this application instance.
      org.springframework.core.io.Resource getResourceForClass​(java.lang.Class theClazz)
      Retrieves a Resource instance for the given Grails class or null it doesn't exist.
      boolean hasArtefactHandler​(java.lang.String type)
      Test whether an artefact handler exists for a given type
      void initialise()
      Initialise this GrailsApplication.
      boolean isArtefact​(java.lang.Class theClazz)
      Call this to find out if the class you have is an artefact loaded by grails.
      boolean isArtefactOfType​(java.lang.String artefactType, java.lang.Class theClazz)
      Check if the specified artefact Class has been loaded by Grails already AND is of the type expected
      boolean isArtefactOfType​(java.lang.String artefactType, java.lang.String className)
      Check if the artefact Class with the name specified is of the type expected
      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()
      This method will refresh the entire application
      void registerArtefactHandler​(ArtefactHandler handler)
      Register a new artefact handler
      void setMainContext​(org.springframework.context.ApplicationContext context)
      Sets the main Spring context for this application.
      void setMappingContext​(org.grails.datastore.mapping.model.MappingContext mappingContext)
      Configures the MappingContext for this application
      • Methods inherited from interface org.springframework.context.ApplicationContextAware

        setApplicationContext
    • Field Detail

      • APPLICATION_ID

        static final java.lang.String APPLICATION_ID
        The id of the grails application within a bean context
        See Also:
        Constant Field Values
      • CONFIG_CLASS

        @Deprecated
        static final java.lang.String CONFIG_CLASS
        Deprecated.
        The name of the class that provides configuration
        See Also:
        Constant Field Values
      • DATA_SOURCE_CLASS

        @Deprecated
        static final java.lang.String DATA_SOURCE_CLASS
        Deprecated.
        The name of the DataSource class
        See Also:
        Constant Field Values
      • PROJECT_META_FILE

        @Deprecated
        static final java.lang.String PROJECT_META_FILE
        Deprecated.
        The name of the project metadata file
        See Also:
        Constant Field Values
      • TRANSACTION_MANAGER_BEAN

        static final java.lang.String TRANSACTION_MANAGER_BEAN
        The name of the transaction manager bean
        See Also:
        Constant Field Values
      • SESSION_FACTORY_BEAN

        static final java.lang.String SESSION_FACTORY_BEAN
        See Also:
        Constant Field Values
      • MULTIPART_RESOLVER_BEAN

        static final java.lang.String MULTIPART_RESOLVER_BEAN
        See Also:
        Constant Field Values
      • EXCEPTION_HANDLER_BEAN

        static final java.lang.String EXCEPTION_HANDLER_BEAN
        See Also:
        Constant Field Values
      • DIALECT_DETECTOR_BEAN

        static final java.lang.String DIALECT_DETECTOR_BEAN
        See Also:
        Constant Field Values
      • OPEN_SESSION_IN_VIEW_INTERCEPTOR_BEAN

        static final java.lang.String OPEN_SESSION_IN_VIEW_INTERCEPTOR_BEAN
        See Also:
        Constant Field Values
    • Method Detail

      • getConfig

        grails.config.Config getConfig()
        Returns the ConfigObject instance.
        Returns:
        The ConfigObject instance
      • getClassLoader

        java.lang.ClassLoader getClassLoader()
        Returns the class loader instance for the Grails application.
        Returns:
        The ClassLoader instance
      • getAllClasses

        java.lang.Class[] getAllClasses()
        Retrieves all java.lang.Class instances loaded by the Grails class loader
        Returns:
        An array of classes
      • getAllArtefacts

        java.lang.Class[] getAllArtefacts()
        Retrieves all java.lang.Class instances considered Artefacts loaded by the Grails class loader
        Returns:
        An array of classes
      • getMainContext

        org.springframework.context.ApplicationContext getMainContext()
        Returns the Spring context for this application. Note that this will return null until the application is fully initialised. This context contains all the application artifacts, plugin beans, the works.
      • getMappingContext

        org.grails.datastore.mapping.model.MappingContext getMappingContext()
        Returns:
        The GORM MappingContext. Returns null if none present
      • setMainContext

        void setMainContext​(org.springframework.context.ApplicationContext context)
        Sets the main Spring context for this application.
      • setMappingContext

        void setMappingContext​(org.grails.datastore.mapping.model.MappingContext mappingContext)
        Configures the MappingContext for this application
        Parameters:
        mappingContext - The mapping context
      • getParentContext

        org.springframework.context.ApplicationContext getParentContext()
        Returns the Spring application context that contains this application instance. It is the parent of the context returned by getMainContext().
      • getClassForName

        java.lang.Class getClassForName​(java.lang.String className)
        Retrieves a class for the given name within the GrailsApplication or returns null
        Parameters:
        className - The name of the class
        Returns:
        The class or null
      • refresh

        void refresh()
        This method will refresh the entire application
      • rebuild

        void rebuild()
        Rebuilds this Application throwing away the class loader and re-constructing it from the loaded resources again. Can only be called in development mode and an error will be thrown if called in a different enivronment
      • getResourceForClass

        org.springframework.core.io.Resource getResourceForClass​(java.lang.Class theClazz)
        Retrieves a Resource instance for the given Grails class or null it doesn't exist.
        Parameters:
        theClazz - The Grails class
        Returns:
        A Resource or null
      • isArtefact

        boolean isArtefact​(java.lang.Class theClazz)

        Call this to find out if the class you have is an artefact loaded by grails.

        Parameters:
        theClazz - A class to test
        Returns:
        true if and only if the class was loaded from grails-app/
        Since:
        0.5
      • isArtefactOfType

        boolean isArtefactOfType​(java.lang.String artefactType,
                                 java.lang.Class theClazz)

        Check if the specified artefact Class has been loaded by Grails already AND is of the type expected

        Parameters:
        artefactType - A string identifying the artefact type to check for
        theClazz - The class to check
        Returns:
        true if Grails considers the class to be managed as an artefact of the type specified.
        Since:
        0.5
      • isArtefactOfType

        boolean isArtefactOfType​(java.lang.String artefactType,
                                 java.lang.String className)

        Check if the artefact Class with the name specified is of the type expected

        Parameters:
        artefactType - A string identifying the artefact type to check for
        className - The name of a class to check
        Returns:
        true if Grails considers the class to be managed as an artefact of the type specified.
        Since:
        0.5
      • getArtefact

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

        Gets the GrailsClass associated with the named artefact class

        i.e. to get the GrailsClass for controller called "BookController" you pass the name "BookController"

        Parameters:
        artefactType - The type of artefact to retrieve, i.e. "Controller"
        name - The name of an artefact such as "BookController"
        Returns:
        The associated GrailsClass or null
        Since:
        0.5
      • getArtefactType

        ArtefactHandler getArtefactType​(java.lang.Class theClass)
        Returns the ArtefactHandler for the given class or null
        Parameters:
        theClass - The class
        Returns:
        The ArtefactHandler
      • getArtefactInfo

        ArtefactInfo getArtefactInfo​(java.lang.String artefactType)

        Obtain all the class information about the artefactType specified

        Parameters:
        artefactType - An artefact type identifier i.e. "Domain"
        Returns:
        The artefact info or null if the artefactType is not recognized
        Since:
        0.5
      • getArtefacts

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

        Get an array of all the GrailsClass instances relating to artefacts of the specified type.

        Parameters:
        artefactType - The type of artefact to retrieve, i.e. "Controller"
        Returns:
        An array of GrailsClasses which may empty by not null
        Since:
        0.5
      • getArtefactForFeature

        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

        Parameters:
        artefactType - The type ID of the artefact, i.e. "TagLib"
        featureID - The "feature" ID, say a URL or tag name
        Returns:
        The grails class or null if none is found
        Since:
        0.5
      • addArtefact

        GrailsClass addArtefact​(java.lang.String artefactType,
                                java.lang.Class artefactClass)

        Registers a new artefact

        Parameters:
        artefactType - The type ID of the artefact, i.e. "TagLib"
        artefactClass - The class of the artefact. A new GrailsClass will be created automatically and added to internal structures, using the appropriate ArtefactHandler
        Returns:
        The new grails class for the artefact class
        Since:
        0.5
      • addArtefact

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

        Registers a new artefact

        Parameters:
        artefactType - The type ID of the artefact, i.e. "TagLib"
        artefactGrailsClass - The GrailsClass of the artefact.
        Returns:
        The supplied grails class for the artefact class
        Since:
        0.5
      • registerArtefactHandler

        void registerArtefactHandler​(ArtefactHandler handler)

        Register a new artefact handler

        Parameters:
        handler - The new handler to add
      • hasArtefactHandler

        boolean hasArtefactHandler​(java.lang.String type)

        Test whether an artefact handler exists for a given type

        Parameters:
        type - The type of the handler
        Returns:
        true if it does
      • getArtefactHandlers

        ArtefactHandler[] getArtefactHandlers()

        Obtain a list of all the artefact handlers

        Returns:
        The list, possible empty but not null, of all currently registered handlers
      • initialise

        void initialise()
        Initialise this GrailsApplication.
      • isInitialised

        boolean isInitialised()
        Returns whether this GrailsApplication has been initialised or not.
        Returns:
        true if it has been initialised
      • getMetadata

        grails.util.Metadata getMetadata()

        Get access to the project's metadata, specified in application.yml and grails.build.info if it is present

        This provides access to information like required grails version, application name, version etc but NOT general application settings.

        Returns:
        A read-only Map of data about the application, not environment specific
      • getArtefactByLogicalPropertyName

        GrailsClass getArtefactByLogicalPropertyName​(java.lang.String type,
                                                     java.lang.String logicalName)
        Retrieves an artefact by its logical property name. For example the logical property name of BookController would be book.
        Parameters:
        type - The artefact type
        logicalName - The logical name
        Returns:
        The GrailsClass or null if it doesn't exist
      • addArtefact

        void addArtefact​(java.lang.Class artefact)
        Adds the given artefact, attempting to determine type from
        Parameters:
        artefact - The artefact to add
      • isWarDeployed

        boolean isWarDeployed()
        Returns true if this application has been deployed as a WAR file
        Returns:
        true if the application is WAR deployed
      • addOverridableArtefact

        void addOverridableArtefact​(java.lang.Class artefact)
        Adds an artefact that can be overriden by user defined classes
        Parameters:
        artefact - An overridable artefact
      • configChanged

        void configChanged()
        Fired to inform the application when the Config.groovy file changes.
      • getArtefactHandler

        ArtefactHandler getArtefactHandler​(java.lang.String type)
        Returns the ArtefactHandler for the given type
        Parameters:
        type - The artefact handler type
        Returns:
        The artefact handler