Package grails.core

Class ArtefactHandlerAdapter

    • Constructor Summary

      Constructors 
      Constructor Description
      ArtefactHandlerAdapter​(java.lang.String type, java.lang.Class<? extends GrailsClass> grailsClassType, java.lang.Class<?> grailsClassImpl, java.lang.String artefactSuffix)  
      ArtefactHandlerAdapter​(java.lang.String type, java.lang.Class<? extends GrailsClass> grailsClassType, java.lang.Class<?> grailsClassImpl, java.lang.String artefactSuffix, boolean allowAbstract)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      GrailsClass getArtefactForFeature​(java.lang.Object feature)
      Called to retrieve an artefact relating to some other key for example a URI or tag name
      java.lang.String getPluginName()
      Obtains the plugin name that deals with this artefact.
      java.lang.String getType()
      Implementations must return a name such as "Domain" to indicate the type of artefact they represent.
      void initialize​(ArtefactInfo artefacts)
      Sets up the relationships between the domain classes, this has to be done after the intial creation to avoid looping.
      boolean isArtefact​(java.lang.Class aClass)
      Called by the GrailsApplication whenever it needs to know if a given class is considered to be the kind of artefact represented by this handler.
      boolean isArtefact​(org.codehaus.groovy.ast.ClassNode classNode)
      Default implementation of ArtefactHandler.isArtefact(org.codehaus.groovy.ast.ClassNode) which returns true if the ClassNode passes the isArtefactResource(org.grails.io.support.Resource) method and the name of the ClassNode ends with the artefactSuffix
      boolean isArtefactClass​(java.lang.Class clazz)
      Checks that class's name ends in the suffix specified for this handler.
      boolean isArtefactGrailsClass​(GrailsClass artefactGrailsClass)
      Called to check if the specified GrailsClass is one managed by this artefact handler
      protected boolean isArtefactResource​(org.grails.io.support.Resource resource)
      Subclasses can override to narrow down whether the given resource is an artefact of this type.
      protected boolean isValidArtefactClassNode​(org.codehaus.groovy.ast.ClassNode classNode, int modifiers)  
      GrailsClass newArtefactClass​(java.lang.Class artefactClass)
      Creates new GrailsClass derived object using the type supplied in constructor.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • type

        protected java.lang.String type
      • grailsClassType

        protected java.lang.Class<?> grailsClassType
      • grailsClassImpl

        protected java.lang.Class<?> grailsClassImpl
      • allowAbstract

        protected boolean allowAbstract
      • artefactSuffix

        protected java.lang.String artefactSuffix
    • Constructor Detail

      • ArtefactHandlerAdapter

        public ArtefactHandlerAdapter​(java.lang.String type,
                                      java.lang.Class<? extends GrailsClass> grailsClassType,
                                      java.lang.Class<?> grailsClassImpl,
                                      java.lang.String artefactSuffix)
      • ArtefactHandlerAdapter

        public ArtefactHandlerAdapter​(java.lang.String type,
                                      java.lang.Class<? extends GrailsClass> grailsClassType,
                                      java.lang.Class<?> grailsClassImpl,
                                      java.lang.String artefactSuffix,
                                      boolean allowAbstract)
    • Method Detail

      • getPluginName

        public java.lang.String getPluginName()
        Description copied from interface: ArtefactHandler
        Obtains the plugin name that deals with this artefact.
        Specified by:
        getPluginName in interface ArtefactHandler
        Returns:
        The plugin name or null if there isn't one
      • getType

        public java.lang.String getType()
        Description copied from interface: ArtefactHandler
        Implementations must return a name such as "Domain" to indicate the type of artefact they represent.
        Specified by:
        getType in interface ArtefactHandler
        Returns:
        The aretfact type, as a String
      • isValidArtefactClassNode

        protected boolean isValidArtefactClassNode​(org.codehaus.groovy.ast.ClassNode classNode,
                                                   int modifiers)
      • isArtefactResource

        protected boolean isArtefactResource​(org.grails.io.support.Resource resource)
                                      throws java.io.IOException
        Subclasses can override to narrow down whether the given resource is an artefact of this type. The default is to consider all files under "grails-app" to be a resource
        Parameters:
        resource - The resource
        Returns:
        True if it is a Grails artefact
        Throws:
        java.io.IOException
      • isArtefact

        public final boolean isArtefact​(java.lang.Class aClass)
        Description copied from interface: ArtefactHandler

        Called by the GrailsApplication whenever it needs to know if a given class is considered to be the kind of artefact represented by this handler.

        Typically you will check the name of the class and some other properties to see if it is of the correct artefact type

        Specified by:
        isArtefact in interface ArtefactHandler
        Parameters:
        aClass - A class to test
        Returns:
        true if the class looks like one of your artefacts
      • isArtefactClass

        public boolean isArtefactClass​(java.lang.Class clazz)

        Checks that class's name ends in the suffix specified for this handler.

        Override for more complex criteria

        Parameters:
        clazz - The class to check
        Returns:
        true if it is an artefact of this type
      • newArtefactClass

        public GrailsClass newArtefactClass​(java.lang.Class artefactClass)

        Creates new GrailsClass derived object using the type supplied in constructor. May not perform optimally but is a convenience.

        Specified by:
        newArtefactClass in interface ArtefactHandler
        Parameters:
        artefactClass - Creates a new artefact for the given class
        Returns:
        An instance of the GrailsClass interface representing the artefact
      • initialize

        public void initialize​(ArtefactInfo artefacts)
        Sets up the relationships between the domain classes, this has to be done after the intial creation to avoid looping.
        Specified by:
        initialize in interface ArtefactHandler
        Parameters:
        artefacts - The collection of artefact classes for this handler
      • getArtefactForFeature

        public GrailsClass getArtefactForFeature​(java.lang.Object feature)
        Description copied from interface: ArtefactHandler

        Called to retrieve an artefact relating to some other key for example a URI or tag name

        Handlers are responsible for caching the appropriate information using the data passed to them in calls to initialize()

        Specified by:
        getArtefactForFeature in interface ArtefactHandler
        Parameters:
        feature - Any object that acts as a key
        Returns:
        A matching artefact GrailsClass or null if there is no match for this feature ID
      • isArtefactGrailsClass

        public boolean isArtefactGrailsClass​(GrailsClass artefactGrailsClass)
        Description copied from interface: ArtefactHandler

        Called to check if the specified GrailsClass is one managed by this artefact handler

        Specified by:
        isArtefactGrailsClass in interface ArtefactHandler
        Parameters:
        artefactGrailsClass - A GrailsClass instance
        Returns:
        true if this handler manages the specified GrailsClass