|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface Configurable
Defines the interface that must be implemented by any configurable component in Sphinx-4. The life cycle of a component is as follows:
public static final String
fields which are annotated with one of the following
annoations: newProperties
method is
called. This method is called with a PropertySheet
containing the properties (usually taken from an
external configuration file). The component should extract the properties from the property sheet. If some properties
defined for a component does not fullfill the property definition given by the annotation (type, range, etc.) a
PropertyException
is thrown. Typically, once a component gets its configuration data via the
newData
method, the component will initialize itself.
Note: In most cases newProperties
is called only once as a result of system configuration during
startup. But nevertheless it is possible (and sometimes necessary) to reconfigure a component while it's running.
Therefore, a well behaved component should react properly to multiple newProperties
calls. Connecting to other components
Components often need to interact with other components in the system. One of the design goals of Sphinx-4 is that it allows for very flexible hookup of components in the system. Therefore, it is *not* considered good S4 style to hardcode which subcomponents a particular subcomponent is interacting with. Instead, the component should use the configuration manager to provide the hookup to another component.
For example, if a component needs to interact with a Linguist. Instead of explicitly setting which linguist is to be used via a constructor or via asetLinguist
call, the component should instead define a configuration
property for the linguist. This would be done like so:
\@S4Component(type=Linguist.class)
public static String PROP_LINGUIST = "linguist";
The linguist is made available in the newProperties
method, like so:
public void newProperties(PropertySheet propertySheet) {
linguist = (Linguist) propertySheet.getComponent(PROP_LINGUIST);
}
getComponent
call will find the proper linguist based upon the configuration data. Thus, if the
configuration for this component had the 'linguist' defined to be 'dynamicLexTreeLinguist', then the configuration
manager will look up and return a linguist with that name, creating and configuring it as necessary. Of course, the
dynamicLexTreeLinguist itself may have a number of sub-components that will be created and configured as a result. If
the component doesn't exist (but was defined to mandatory) and no configuration information is found in the config
file for it, or if it is of the wrong type, a PropertyException
will be thrown.
Method Summary | |
---|---|
void |
newProperties(PropertySheet ps)
This method is called when this configurable component needs to be reconfigured. |
Method Detail |
---|
void newProperties(PropertySheet ps) throws PropertyException
ps
- a property sheet holding the new data
PropertyException
- if there is a problem with the properties.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |