Caplin Trader 4.8.0

Class: module:caplin/component/ComponentFactory

module:caplin/component/ComponentFactory

Constructor

new module:caplin/component/ComponentFactory()

This constructor is private and must never be invoked. A singleton that registers each defined module:caplin/component/Component in a registry by calling the module:caplin/component/ComponentFactory#registerComponent method.

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 module:caplin/component/ComponentFactory#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 module:caplin/component/ErrorComponent instead. The application uses this ErrorComponent in place of the required component.

Methods

createComponent(vXml) → {module:caplin/component/Component}

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 module:caplin/component/ErrorComponent.

Parameters:
Name Type Description
vXml Object The XML representation of the component to be constructed. May be a String or an XMLNode.
Returns:
An instance of the component defined within the specified XML string or XML node.
Type
module:caplin/component/Component

registerComponent(sComponentType, 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 require('fell').error().

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);

Parameters:
Name Type Description
sComponentType String The component type used as registry key.
fComponentCreatorMethod function 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.
Deprecated:
  • Aliases remove the need to register a creation method with the ComponentFactory.

    returnErrorComponentOnError(boolean)

    Determine the behaviour of module:caplin/component/ComponentFactory#createComponent when it encounters an error. When this method is called with true, module:caplin/component/ComponentFactory#createComponent will return a module:caplin/component/ErrorComponent on errors (default behaviour), and when called with false a module:caplin/core/Error is raised on errors.
    Parameters:
    Name Type Description
    boolean bReturnErrorComponentOnError True if an error component should be returned on error, false otherwise.