Class MutableComponentModelImpl
- java.lang.Object
-
- org.apache.tapestry5.internal.model.MutableComponentModelImpl
-
- All Implemented Interfaces:
ComponentModel
,MutableComponentModel
public final class MutableComponentModelImpl extends Object implements MutableComponentModel
Internal implementation ofMutableComponentModel
.
-
-
Constructor Summary
Constructors Constructor Description MutableComponentModelImpl(String componentClassName, org.slf4j.Logger logger, Resource baseResource, ComponentModel parentModel, boolean pageClass, String libraryName)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description MutableEmbeddedComponentModel
addEmbeddedComponent(String id, String type, String componentClassName, boolean inheritInformalParameters, Location location)
Defines a new embedded component.void
addEventHandler(String eventType)
Identifies that the component includes an event handler for the indicated event type.void
addMixinClassName(String mixinClassName, String... order)
Adds a mixin to the component's implementation, optionally specifying ordering constraints, as per OrderedConfiguration.void
addParameter(String name, boolean required, boolean allowNull, String defaultBindingPrefix)
Adds a new formal parameter to the model.void
addParameter(String name, boolean required, boolean allowNull, String defaultBindingPrefix, boolean cached)
Adds a new formal parameter to the model.void
addRenderPhase(Class renderPhase)
Identifies that the component does handle the render phase.void
doHandleActivationEventContext()
Relevant for pages only, identifies that the component handleEventConstants.ACTIVATE
events supporting one of the three special case for catch all rules:Object
[]List
EventContext
void
enableSupportsInformalParameters()
Sets the internal flag to indicate that this model (and all models that extend from it) support informal parameters.Resource
getBaseResource()
Returns the resource corresponding to the class file for this component.String
getComponentClassName()
The fully qualified class name of the component.List<String>
getDeclaredParameterNames()
Returns an alphabetically sorted list of the names of all formal parameters defined by this specific class (parameters inherited from base classes are not identified).List<String>
getEmbeddedComponentIds()
Returns the ids of all embedded components defined within the component class (via theComponent
annotation), including those defined by any super-class.EmbeddedComponentModel
getEmbeddedComponentModel(String componentId)
Returns an embedded component defined by this component or by a super-class.String
getFieldPersistenceStrategy(String fieldName)
Returns the persistent strategy associated with the field.Set<Class>
getHandledRenderPhases()
Returns a set of all the render phases that this model (including parent models) that are handled.String
getLibraryName()
Returns the name of the library that defines this component; this may be the empty string for an application page or component, or will be a name of a library (possibly including "core" for built-in components).org.slf4j.Logger
getLogger()
Returns object that will be used to log warnings and errors related to this component.String
getMeta(String key)
Gets a meta value identified by the given key.List<String>
getMixinClassNames()
Returns a list of the class names of mixins that are part of the component's implementation.String[]
getOrderForMixin(String mixinClassName)
ParameterModel
getParameterModel(String parameterName)
Return a single parameter model by parameter name, or null if the parameter is not defined (is not a formal parameter).List<String>
getParameterNames()
Returns an alphabetically sorted list of the names of all formal parameters.ComponentModel
getParentModel()
Returns the component model for this component's super-class, if it exists.List<String>
getPersistentFieldNames()
Returns a list of the names of all persistent fields (within this class, or any super-class).boolean
getSupportsInformalParameters()
Returns true if the model indicates that informal parameters, additional parameters beyond the formal parameter defined for the component, are supported.boolean
handleActivationEventContext()
Relevant for pages only, indicates that the component handle theEventConstants.ACTIVATE
events with a catch all rulesboolean
handlesEvent(String eventType)
Determines if the component has an event handler for the indicated event name (case insensitive).boolean
isFormalParameter(String parameterName)
Returns true if the named parameter is formally defined (there's a ParameterModel).boolean
isMixinAfter()
Relevant for component mixins only.boolean
isPage()
Is this a model of a page (rather than a component, mixin, or base-class)?boolean
isRootClass()
Returns true if the modeled component is a root class, a component class whose parent class is not a component class.String
setFieldPersistenceStrategy(String fieldName, String strategy)
Used to define the field persistence strategy for a particular field name.void
setMeta(String key, String value)
Stores a meta data value under the indicated key.void
setMixinAfter(boolean mixinAfter)
Changes the value of the mixinAfter flag.String
toString()
-
-
-
Constructor Detail
-
MutableComponentModelImpl
public MutableComponentModelImpl(String componentClassName, org.slf4j.Logger logger, Resource baseResource, ComponentModel parentModel, boolean pageClass, String libraryName)
-
-
Method Detail
-
getLibraryName
public String getLibraryName()
Description copied from interface:ComponentModel
Returns the name of the library that defines this component; this may be the empty string for an application page or component, or will be a name of a library (possibly including "core" for built-in components). Library names are defined by theLibraryMapping
contributions to theComponentClassResolver
service.- Specified by:
getLibraryName
in interfaceComponentModel
- Returns:
- library name containing the component, or empty string for application components
-
getLogger
public org.slf4j.Logger getLogger()
Description copied from interface:ComponentModel
Returns object that will be used to log warnings and errors related to this component.- Specified by:
getLogger
in interfaceComponentModel
- See Also:
Log
-
getBaseResource
public Resource getBaseResource()
Description copied from interface:ComponentModel
Returns the resource corresponding to the class file for this component. This is used to find related resources, such as the component's template and message catalog.- Specified by:
getBaseResource
in interfaceComponentModel
-
getComponentClassName
public String getComponentClassName()
Description copied from interface:ComponentModel
The fully qualified class name of the component.- Specified by:
getComponentClassName
in interfaceComponentModel
-
addParameter
public void addParameter(String name, boolean required, boolean allowNull, String defaultBindingPrefix, boolean cached)
Description copied from interface:MutableComponentModel
Adds a new formal parameter to the model. Each parameter has a unique name (though access to parameters is case insensitive).- Specified by:
addParameter
in interfaceMutableComponentModel
- Parameters:
name
- new, unique name for the parameterrequired
- if true, the parameter must be boundallowNull
- if true, then parameter may be bound to null, if false a null check will be addeddefaultBindingPrefix
- the default binding prefix for this parameter @throws IllegalArgumentException if a parameter with the given name has already been defined for this modelcached
- if true, the parameter value should be cached within the component during rendering- See Also:
Parameter
-
addParameter
public void addParameter(String name, boolean required, boolean allowNull, String defaultBindingPrefix)
Description copied from interface:MutableComponentModel
Adds a new formal parameter to the model. Each parameter has a unique name (though access to parameters is case insensitive).- Specified by:
addParameter
in interfaceMutableComponentModel
- Parameters:
name
- new, unique name for the parameterrequired
- if true, the parameter must be boundallowNull
- if true, then parameter may be bound to null, if false a null check will be addeddefaultBindingPrefix
- the default binding prefix for this parameter @throws IllegalArgumentException if a parameter with the given name has already been defined for this model- See Also:
Parameter
-
getParameterModel
public ParameterModel getParameterModel(String parameterName)
Description copied from interface:ComponentModel
Return a single parameter model by parameter name, or null if the parameter is not defined (is not a formal parameter). This may be a parameter defined by this component, or from a base class.- Specified by:
getParameterModel
in interfaceComponentModel
- Parameters:
parameterName
- the name of the parameter (case is ignored)- Returns:
- the parameter model if found in this model or a parent model, or null if not found
-
isFormalParameter
public boolean isFormalParameter(String parameterName)
Description copied from interface:ComponentModel
Returns true if the named parameter is formally defined (there's a ParameterModel).- Specified by:
isFormalParameter
in interfaceComponentModel
- Parameters:
parameterName
- name of the parameter (case is ignored)
-
getParameterNames
public List<String> getParameterNames()
Description copied from interface:ComponentModel
Returns an alphabetically sorted list of the names of all formal parameters. This includes parameters defined by a base class.- Specified by:
getParameterNames
in interfaceComponentModel
-
getDeclaredParameterNames
public List<String> getDeclaredParameterNames()
Description copied from interface:ComponentModel
Returns an alphabetically sorted list of the names of all formal parameters defined by this specific class (parameters inherited from base classes are not identified).- Specified by:
getDeclaredParameterNames
in interfaceComponentModel
-
addEmbeddedComponent
public MutableEmbeddedComponentModel addEmbeddedComponent(String id, String type, String componentClassName, boolean inheritInformalParameters, Location location)
Description copied from interface:MutableComponentModel
Defines a new embedded component.- Specified by:
addEmbeddedComponent
in interfaceMutableComponentModel
- Parameters:
id
- the unique id for the embedded component, which must not already exist.type
- the type of the component (posslibly blank)componentClassName
- the fully qualified class name (derived from the field), used if the type is blankinheritInformalParameters
- if true, then the component will inherit informal parameters provided to its containerlocation
- where the component is defined @return a mutable model allowing parameters to be set
-
getEmbeddedComponentIds
public List<String> getEmbeddedComponentIds()
Description copied from interface:ComponentModel
Returns the ids of all embedded components defined within the component class (via theComponent
annotation), including those defined by any super-class.- Specified by:
getEmbeddedComponentIds
in interfaceComponentModel
-
getEmbeddedComponentModel
public EmbeddedComponentModel getEmbeddedComponentModel(String componentId)
Description copied from interface:ComponentModel
Returns an embedded component defined by this component or by a super-class.- Specified by:
getEmbeddedComponentModel
in interfaceComponentModel
- Parameters:
componentId
- the id of the embedded component- Returns:
- the embedded component model, or null if no component exists with that id
-
getFieldPersistenceStrategy
public String getFieldPersistenceStrategy(String fieldName)
Description copied from interface:ComponentModel
Returns the persistent strategy associated with the field.- Specified by:
getFieldPersistenceStrategy
in interfaceComponentModel
- Returns:
- the corresponding strategy, or the empty string
-
getPersistentFieldNames
public List<String> getPersistentFieldNames()
Description copied from interface:ComponentModel
Returns a list of the names of all persistent fields (within this class, or any super-class). The names are sorted alphabetically.- Specified by:
getPersistentFieldNames
in interfaceComponentModel
- See Also:
Persist
-
setFieldPersistenceStrategy
public String setFieldPersistenceStrategy(String fieldName, String strategy)
Description copied from interface:MutableComponentModel
Used to define the field persistence strategy for a particular field name. Returns a logical name for the field, which is guaranteed to be unique (this is necessary for handling the case where a subclass has a persistent field with the same name as a persistent field from a super-class).- Specified by:
setFieldPersistenceStrategy
in interfaceMutableComponentModel
- Parameters:
fieldName
- the name of the field which is to be made persistentstrategy
- the strategy for persisting the field, fromPersist.value()
. This value may be blank, in which case the stategy is inherited from the component, or the component's container.- Returns:
- a logical name for the field, to be used with
ComponentModel.getFieldPersistenceStrategy(String)
, and withInternalComponentResources.persistFieldChange(String, Object)
, etc.
-
isRootClass
public boolean isRootClass()
Description copied from interface:ComponentModel
Returns true if the modeled component is a root class, a component class whose parent class is not a component class. We may in the future require that components only extend from Object.- Specified by:
isRootClass
in interfaceComponentModel
- Returns:
- true if a root class, false if a subclass
-
addMixinClassName
public void addMixinClassName(String mixinClassName, String... order)
Description copied from interface:MutableComponentModel
Adds a mixin to the component's implementation, optionally specifying ordering constraints, as per OrderedConfiguration.- Specified by:
addMixinClassName
in interfaceMutableComponentModel
-
getMixinClassNames
public List<String> getMixinClassNames()
Description copied from interface:ComponentModel
Returns a list of the class names of mixins that are part of the component's implementation.- Specified by:
getMixinClassNames
in interfaceComponentModel
-
enableSupportsInformalParameters
public void enableSupportsInformalParameters()
Description copied from interface:MutableComponentModel
Sets the internal flag to indicate that this model (and all models that extend from it) support informal parameters.- Specified by:
enableSupportsInformalParameters
in interfaceMutableComponentModel
-
getSupportsInformalParameters
public boolean getSupportsInformalParameters()
Description copied from interface:ComponentModel
Returns true if the model indicates that informal parameters, additional parameters beyond the formal parameter defined for the component, are supported. This is false in most cases, but may be set to true for specific classes (when theSupportsInformalParameters
annotation is present, or inherited from a super-class).- Specified by:
getSupportsInformalParameters
in interfaceComponentModel
- Returns:
- true if this component model supports informal parameters
-
getParentModel
public ComponentModel getParentModel()
Description copied from interface:ComponentModel
Returns the component model for this component's super-class, if it exists. Remember that only classes in the correct packages, are considered component classes.- Specified by:
getParentModel
in interfaceComponentModel
- Returns:
- the parent class model, or null if this component's super class is not itself a component class
-
isMixinAfter
public boolean isMixinAfter()
Description copied from interface:ComponentModel
Relevant for component mixins only. Indicates that the mixin behavior should occur after (not before) the component. Normally, this flag is set by the presence of theMixinAfter
annotation.- Specified by:
isMixinAfter
in interfaceComponentModel
- Returns:
- true if the mixin should operate after, not before, the component
-
setMixinAfter
public void setMixinAfter(boolean mixinAfter)
Description copied from interface:MutableComponentModel
Changes the value of the mixinAfter flag. The default value is false.- Specified by:
setMixinAfter
in interfaceMutableComponentModel
-
setMeta
public void setMeta(String key, String value)
Description copied from interface:MutableComponentModel
Stores a meta data value under the indicated key.- Specified by:
setMeta
in interfaceMutableComponentModel
-
addRenderPhase
public void addRenderPhase(Class renderPhase)
Description copied from interface:MutableComponentModel
Identifies that the component does handle the render phase.- Specified by:
addRenderPhase
in interfaceMutableComponentModel
- Parameters:
renderPhase
- annotation class corresponding to the render phase- See Also:
ComponentModel.getHandledRenderPhases()
-
addEventHandler
public void addEventHandler(String eventType)
Description copied from interface:MutableComponentModel
Identifies that the component includes an event handler for the indicated event type.- Specified by:
addEventHandler
in interfaceMutableComponentModel
- Parameters:
eventType
- of handled event
-
getMeta
public String getMeta(String key)
Description copied from interface:ComponentModel
Gets a meta value identified by the given key. If the current model does not provide a value for the key, then the parent component model (if any) is searched.- Specified by:
getMeta
in interfaceComponentModel
- Parameters:
key
- identifies the value to be accessed- Returns:
- the value for the key (possibly inherited from a parent model), or null
-
getHandledRenderPhases
public Set<Class> getHandledRenderPhases()
Description copied from interface:ComponentModel
Returns a set of all the render phases that this model (including parent models) that are handled. Render phases are represented by the corresponding annotation (BeginRender
,AfterRender
, etc.).- Specified by:
getHandledRenderPhases
in interfaceComponentModel
- Returns:
- set of classes
-
handlesEvent
public boolean handlesEvent(String eventType)
Description copied from interface:ComponentModel
Determines if the component has an event handler for the indicated event name (case insensitive). This includes handlers in the component class itself, or its super-classes, but does not include event handlers supplied by implementation or instance mixins.- Specified by:
handlesEvent
in interfaceComponentModel
- Parameters:
eventType
- name of event to check (case insensitive)- Returns:
- true if event handler present
-
getOrderForMixin
public String[] getOrderForMixin(String mixinClassName)
- Specified by:
getOrderForMixin
in interfaceComponentModel
- Parameters:
mixinClassName
- class name of the mixin for which the ordering is desired- Returns:
- the ordering constraint(s) for the mixin, potentially null.
-
isPage
public boolean isPage()
Description copied from interface:ComponentModel
Is this a model of a page (rather than a component, mixin, or base-class)?- Specified by:
isPage
in interfaceComponentModel
- Returns:
- true if a page
-
doHandleActivationEventContext
public void doHandleActivationEventContext()
Description copied from interface:MutableComponentModel
Relevant for pages only, identifies that the component handleEventConstants.ACTIVATE
events supporting one of the three special case for catch all rules:- Specified by:
doHandleActivationEventContext
in interfaceMutableComponentModel
-
handleActivationEventContext
public boolean handleActivationEventContext()
Description copied from interface:ComponentModel
Relevant for pages only, indicates that the component handle theEventConstants.ACTIVATE
events with a catch all rules- Specified by:
handleActivationEventContext
in interfaceComponentModel
- Returns:
- true if the page implements catch all rules for the activate event context, or false otherwise
- See Also:
MutableComponentModel.doHandleActivationEventContext()
-
-