public interface ComponentInterface<C extends ComponentInterface<?>>
ComponentContainerInterface
). The
name must be unique inside the container and can be considered as key or ID
of a component. Components are usually members in one container only.
Components contain attributes implementing the interface AttributeInterface
. In this sense a component plays the role of a composite
in the composite design pattern for attributes. The attributes are usually
private members of a concrete component. Attributes can be added to the
components attribute list. This is usually done in the constructor of the
component class implementing this interface, where the attributes are
instantiated. This list is used by the methods visitAttribute(String,Visitor)
and visitAttributes(Visitor)
to
forward the visitor to one or all attributes of the component. Attributes
are uniquely identified by their keyword inside the component.
Components can be registered and created by the component factory (see class
ComponentFactory
). A component plays the product role in the abstract
factory design pattern. The factory uses the prototype design pattern to
create components. Components play the prototype role. They must implement
the method cloneComponent(String,String,ComponentInterface)
if they
are intended to be created by the component factory. The component type is
used by the factory as key to find and clone the prototype.
Components may have container attributes as an attribute, which contain again components. This subcomponents are also called child components. The component containing the subcomponents is denoted as parent component to the subcomponents. A component has a reference to it's parent component. The root component is the component without a parent.
Components play the element role in the visitor design pattern. Components
accept visitor objects implementing the interface Visitor
.
Components, which accepted the visitor call back the visitor method Visitor.visitComponent(ComponentInterface)
.
Components play the invoker role in the command design pattern. They maintain a command list. Concrete components may play the client and the receiver of this pattern. The client is responsible to create concrete command objects and set the receiver. The receiver executes the action.
Components maintain a usage and a reference counter. The concrete use of
these counters is defined by the concrete components. Generally a usage count
greater than zero should prohibit an attribute change. A reference count
greater than zero should prohibit the destruction of the component. The
interface defines also the method isDeletable()
and isModifiable()
, which can be used by a client to determine if the component
can be deleted or attributes of the component can be modified by the user or
not. The concrete implementation is determined by the class implementing this
interface. These methods are called by framework classes, which are related
to user interfaces, like GUI packages or the command line parsers in the
visitors package.
A context can be assigned/retrieved to components in form of an anonymous
object by the methods setAnonymousObject(Object)
and getAnonymousObject()
. This methods can be used by derived frameworks to add
a context to the components. These methods/anonymous object are not intended
to be used by the application, which uses the framework. This feature can
only be used by one framework so it has to be well documented how it is used!
Modifier and Type | Method and Description |
---|---|
void |
acceptVisitor(Visitor visitor)
This method accepts a visitor object.
|
C |
cloneComponent(java.lang.String componentName,
java.lang.String componentType,
ComponentInterface<?> parentComponent)
This method applies to the prototype design pattern and returns a new
component of the same type as the concrete class implementing this method
This method is used by the component factory to create new components
(see class
ComponentFactory ). |
void |
copyComponent(ComponentInterface<?> sourceComponent)
This method copies the attribute values from the passed source component
to this component.
|
C |
createCopy()
This method copies this component and returns the copied
component.
|
C |
createCopy(ComponentInterface<?> parentComponent)
This method copies this component and returns the copied
component.
|
long |
decrementReferenceCount()
The method decrements the reference counter if it is not zero.
|
long |
decrementUsageCount()
The method decrements the usage counter if it is not zero.
|
void |
executeCommand(java.lang.String commandName)
This method retrieves the command object with the specified name and
calls the method
CommandInterface.execute() of the object. |
java.lang.Object |
getAnonymousObject()
This method can be used to retrieve the anonymous object of the
component.
|
java.lang.String |
getDisplayType()
This method returns the component display type.
|
java.lang.String |
getDisplayType(java.util.Locale locale)
This method returns the component display type in the passed locale.
|
java.lang.String |
getName()
This method returns the component name.
|
ComponentInterface<?> |
getParent()
This method returns the parent component.
|
long |
getReferenceCount()
The method returns the reference counter.
|
java.lang.String |
getType()
This method returns the component type.
|
long |
getUsageCount()
The method returns the usage counter.
|
long |
incrementReferenceCount()
The method increments the reference counter.
|
long |
incrementUsageCount()
The method increments the usage counter.
|
void |
initializeComponent()
This method is called by the framework to initialize the component after
it has been created by the method
cloneComponent(String,String,ComponentInterface) and the attributes has
been initialized as far as possible. |
boolean |
isComponentEqual(ComponentInterface<?> otherComponent)
This method compares the passed component with this component and
returns true if the components are equal.
|
boolean |
isDeletable()
This method returns true if a user is allowed to delete the
component, otherwise false.
|
boolean |
isModifiable()
This method returns true if the component is modifiable, otherwise
false.
|
void |
registerCommand(CommandInterface command)
This method registers a command in the command dictionary of the
component.
|
void |
setAnonymousObject(java.lang.Object object)
This method can be used to assign an anonymous object to the component.
|
void |
setParent(ComponentInterface<?> parentComponent)
This method may be used to set the parent component of this
component if not already done at construction time.
|
java.lang.String |
toString()
This method returns the string representation of the component.
|
java.lang.String |
toString(java.util.Locale locale)
This method returns the string representation of the component for the
passed locale.
|
void |
unregisterCommand(java.lang.String commandName)
This method removes the specified command form the component if it
exists.
|
void |
visitAttribute(java.lang.String keyword,
Visitor visitor)
This method applies to the visitor design pattern and forwards the
visitor to the attribute with the passed keyword.
|
void |
visitAttributes(Visitor visitor)
This method applies to the visitor design pattern and forwards the
visitor to all attributes of the component.
|
void acceptVisitor(Visitor visitor) throws AcafException
Visitor.visitComponent(ComponentInterface)
is called.visitor
- The visitor to be accepted by the component.AcafException
- May be thrown by implementing classes or the visitor.C cloneComponent(java.lang.String componentName, java.lang.String componentType, ComponentInterface<?> parentComponent)
ComponentFactory
). The passed component name must not
be null.
The parent component may be null, when the component to be created
has no parent (root component) of if the parent is currently unknown. In
this case the created component is not initialized with the parent
component at construction time and the method initializeComponent()
cannot access the parent component. The method
setParent(ComponentInterface)
may be used afterwards to set the
parent component.
componentName
- The name of the created component.componentType
- The component type, which identifies the component
class in an application and in the component factory.parentComponent
- The parent component of the created component.void copyComponent(ComponentInterface<?> sourceComponent) throws AcafException
AttributeInterface.copyValue(AttributeInterface,ComponentInterface)
is
called for this purpose.
The source component must not necessarily have the same type as this component. The source component may be a template to be copied, which is an instance of a different class.
sourceComponent
- The source component to be copied.AcafException
- Thrown, when copying the component fails.C createCopy() throws AcafException
cloneComponent(String, String,ComponentInterface)
and copyComponent(ComponentInterface)
are called to create the copy.
The copy is not initialized by the method initializeComponent()
.AcafException
- Thrown, when copying the component fails.C createCopy(ComponentInterface<?> parentComponent) throws AcafException
cloneComponent(String,String,ComponentInterface)
and copyComponent(ComponentInterface)
are called to create the copy. The
copy is not initialized by the method initializeComponent()
.parentComponent
- The parent component of the copy.AcafException
- Thrown, when copying the component fails.long decrementReferenceCount()
long decrementUsageCount()
void executeCommand(java.lang.String commandName) throws ComponentNoSuchCommand
CommandInterface.execute()
of the object.commandName
- The name of the command to be executed.ComponentNoSuchCommand
- Thrown, if the command object with the
passed name is not found.java.lang.Object getAnonymousObject()
setAnonymousObject(Object)
.
This methods can be used by derived frameworks to add a context to the components. These methods/anonymous object are not intended to be used by the application which uses the framework.
java.lang.String getDisplayType()
java.lang.String getDisplayType(java.util.Locale locale)
locale
- The locale of the display type.java.lang.String getName()
ComponentInterface<?> getParent()
long getReferenceCount()
java.lang.String getType()
long getUsageCount()
long incrementReferenceCount()
long incrementUsageCount()
void initializeComponent() throws AcafException
cloneComponent(String,String,ComponentInterface)
and the attributes has
been initialized as far as possible. Initializing the attributes includes
also the container attributes, which are populated with the child
components. The child components are initialized by this method before
this (parent-)component! After calling this method the framework inserts
the component in a container if required.
The parent component is usually already accessible when it is passed to
the method cloneComponent(String,String,ComponentInterface)
.
Also the component name and type are accessible. The parent component
however may be not yet fully initialized! The component name and type of
the parent component are accessible.
This method may be used by classes implementing the interface to perform initialization tasks usually implemented in the constructor. Note, that the constructor cannot be used for all tasks, because prototype components for example cannot always be fully initialized. The initialization may already use the attribute values and the initialized client components.
The component is exposed to other components when it is inserted into a component container after this method is called.
AcafException
- May be thrown, when initialization fails.boolean isComponentEqual(ComponentInterface<?> otherComponent) throws AcafException
Object.equals(Object)
.otherComponent
- The component to be compared with this
component.AcafException
- Thrown, when comparing the components fails.AttributeInterface.isValueEqual(AttributeInterface)
boolean isDeletable()
boolean isModifiable()
void registerCommand(CommandInterface command)
command
- The command to be registered for the component.void setAnonymousObject(java.lang.Object object)
getAnonymousObject()
.
This methods can be used by derived frameworks to add a context to the components. These methods/anonymous object are not intended to be used by the application, which uses the framework.
object
- The anonymous object to be assigned to the component.void setParent(ComponentInterface<?> parentComponent)
parentComponent
- The parent component of this component.java.lang.String toString()
toString
in class java.lang.Object
java.lang.String toString(java.util.Locale locale)
locale
- The locale of the string representation.void unregisterCommand(java.lang.String commandName)
commandName
- The name of the command to be removed.void visitAttribute(java.lang.String keyword, Visitor visitor) throws AcafException
keyword
- The keyword of the attribute to be visited.visitor
- The visitor to be sent to the attribute.AcafException
- May be thrown by implementing classes or the visitor.void visitAttributes(Visitor visitor) throws AcafException
visitor
- The visitor to be sent to the attributes.AcafException
- May be thrown by implementing classes or the visitor.