Package grails.core

Class ArtefactHandlerAdapter

java.lang.Object
grails.core.ArtefactHandlerAdapter
All Implemented Interfaces:
ArtefactHandler
Direct Known Subclasses:
ControllerArtefactHandler, DomainClassArtefactHandler, ServiceArtefactHandler, UrlMappingsArtefactHandler

public class ArtefactHandlerAdapter extends Object implements ArtefactHandler
Adapter for the ArtefactHandler interface
Since:
1.0
  • Field Details

    • type

      protected String type
    • grailsClassType

      protected Class<?> grailsClassType
    • grailsClassImpl

      protected Class<?> grailsClassImpl
    • allowAbstract

      protected boolean allowAbstract
    • artefactSuffix

      protected String artefactSuffix
  • Constructor Details

    • ArtefactHandlerAdapter

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

      public ArtefactHandlerAdapter(String type, Class<? extends GrailsClass> grailsClassType, Class<?> grailsClassImpl, String artefactSuffix, boolean allowAbstract)
  • Method Details

    • getPluginName

      public 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 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
    • isArtefact

      public 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
      Specified by:
      isArtefact in interface ArtefactHandler
      Parameters:
      classNode - The ClassNode instance
      Returns:
      True if the ClassNode is an artefact of this type
    • isValidArtefactClassNode

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

      protected boolean isArtefactResource(org.grails.io.support.Resource resource) throws 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:
      IOException
    • isArtefact

      public final boolean isArtefact(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(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(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(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