Class ArtefactHandlerAdapter
- java.lang.Object
-
- grails.core.ArtefactHandlerAdapter
-
- All Implemented Interfaces:
ArtefactHandler
- Direct Known Subclasses:
ControllerArtefactHandler,DomainClassArtefactHandler,ServiceArtefactHandler,UrlMappingsArtefactHandler
public class ArtefactHandlerAdapter extends java.lang.Object implements ArtefactHandler
Adapter for theArtefactHandlerinterface- Since:
- 1.0
-
-
Field Summary
Fields Modifier and Type Field Description protected booleanallowAbstractprotected java.lang.StringartefactSuffixprotected java.lang.Class<?>grailsClassImplprotected java.lang.Class<?>grailsClassTypeprotected java.lang.Stringtype
-
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 GrailsClassgetArtefactForFeature(java.lang.Object feature)Called to retrieve an artefact relating to some other key for example a URI or tag namejava.lang.StringgetPluginName()Obtains the plugin name that deals with this artefact.java.lang.StringgetType()Implementations must return a name such as "Domain" to indicate the type of artefact they represent.voidinitialize(ArtefactInfo artefacts)Sets up the relationships between the domain classes, this has to be done after the intial creation to avoid looping.booleanisArtefact(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.booleanisArtefact(org.codehaus.groovy.ast.ClassNode classNode)Default implementation ofArtefactHandler.isArtefact(org.codehaus.groovy.ast.ClassNode)which returns true if the ClassNode passes theisArtefactResource(org.grails.io.support.Resource)method and the name of the ClassNode ends with theartefactSuffixbooleanisArtefactClass(java.lang.Class clazz)Checks that class's name ends in the suffix specified for this handler.booleanisArtefactGrailsClass(GrailsClass artefactGrailsClass)Called to check if the specified GrailsClass is one managed by this artefact handlerprotected booleanisArtefactResource(org.grails.io.support.Resource resource)Subclasses can override to narrow down whether the given resource is an artefact of this type.protected booleanisValidArtefactClassNode(org.codehaus.groovy.ast.ClassNode classNode, int modifiers)GrailsClassnewArtefactClass(java.lang.Class artefactClass)Creates new GrailsClass derived object using the type supplied in constructor.
-
-
-
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:ArtefactHandlerObtains the plugin name that deals with this artefact.- Specified by:
getPluginNamein interfaceArtefactHandler- Returns:
- The plugin name or null if there isn't one
-
getType
public java.lang.String getType()
Description copied from interface:ArtefactHandlerImplementations must return a name such as "Domain" to indicate the type of artefact they represent.- Specified by:
getTypein interfaceArtefactHandler- Returns:
- The aretfact type, as a String
-
isArtefact
public boolean isArtefact(org.codehaus.groovy.ast.ClassNode classNode)
Default implementation ofArtefactHandler.isArtefact(org.codehaus.groovy.ast.ClassNode)which returns true if the ClassNode passes theisArtefactResource(org.grails.io.support.Resource)method and the name of the ClassNode ends with theartefactSuffix- Specified by:
isArtefactin interfaceArtefactHandler- 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 java.io.IOExceptionSubclasses 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:ArtefactHandlerCalled 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:
isArtefactin interfaceArtefactHandler- 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:
newArtefactClassin interfaceArtefactHandler- 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:
initializein interfaceArtefactHandler- Parameters:
artefacts- The collection of artefact classes for this handler
-
getArtefactForFeature
public GrailsClass getArtefactForFeature(java.lang.Object feature)
Description copied from interface:ArtefactHandlerCalled 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:
getArtefactForFeaturein interfaceArtefactHandler- 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:ArtefactHandlerCalled to check if the specified GrailsClass is one managed by this artefact handler
- Specified by:
isArtefactGrailsClassin interfaceArtefactHandler- Parameters:
artefactGrailsClass- A GrailsClass instance- Returns:
- true if this handler manages the specified GrailsClass
-
-