Each component is registered with the name of the root XML tag that represents the serialized form of the component and a static factory method. Subsequently when the #createComponent method is invoked it will instantiate a component by invoking the corresponding static factory method for the root XML tag.
The ComponentFactory
both constructs new instances of a component
(for example from a menu), and restores instances that have previously been saved.
If there is a problem when the ComponentFactory
attempts to create
a component, such as the XML defining an unregistered Component type,
then the ComponentFactory
creates a caplin.component.ErrorComponent
instead. The application uses this caplin.component.ErrorComponent
in place of the
required component.
Attributes | Name and Description |
---|---|
|
caplin.component.ComponentFactory()
This constructor is private and must never be invoked. |
Attributes | Name and Description |
---|---|
|
caplin.component.Component
createComponent(Object vXml)
Invoked when a component needs to be constructed. |
|
void
registerComponent(String sComponentType, Function fComponentCreatorMethod)
Maintains a list of components and the method required to construct the component. |
|
void
returnErrorComponentOnError( boolean)
Determine the behaviour of #createComponent when it encounters an error. |
►
caplin.component.ComponentFactory()
This constructor is private and must never be invoked.
►
caplin.component.Component
createComponent(Object vXml)
Invoked when a component needs to be constructed.
If anything goes wrong, such as a component of an unregistered type being created, or an exception being thrown by the fComponentCreatorMethod, then this method will return an caplin.component.ErrorComponent.
Object | vXml | The XML representation of the component to be constructed. May be a String or an XMLNode. |
►
void
registerComponent(String sComponentType, Function fComponentCreatorMethod)
Maintains a list of components and the method required to construct the component. The method takes a xml configuration.
If another Component has already been registered then it is ignored for that type and a warning message is reported
to the caplin.core.Logger.log()
.
Examples: To register a news component: caplin.component.ComponentFactory.registerComponent('news', mybank.news.NewsComponentGenerator.createFromSerializedState); To create a component: var sXml = "<news> rest of config here... "</news>"; caplin.component.ComponentFactory.createComponent(sXml);
String | sComponentType | The component type used as registry key. |
Function | fComponentCreatorMethod | The function used to create the component object. This function requires a xml string that supplies the parameters required to create the object. The root node of the configuration xml must match the type of the component registered with the factory. |
►
void
returnErrorComponentOnError( boolean)
Determine the behaviour of #createComponent when it encounters an error.
When this method is called with true
, #createComponent will return
a caplin.component.ErrorComponent on errors (default behaviour), and when
called with false
a caplin.core.Error is raised on errors.
boolean | bReturnErrorComponentOnError True if an error component should be returned on error, false otherwise. |