Caplin Trader 5.1.0

Class: module:ct-component/ComponentFactory


new module:ct-component/ComponentFactory()

This constructor is private and must never be invoked.

A singleton that registers each defined module:ct-component/Component in a registry by calling the module:ct-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:ct-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:ct-component/ErrorComponent instead. The application uses this ErrorComponent in place of the required component.


createComponent(vXml) → {module:ct-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:ct-component/ErrorComponent.

Name Type Description
vXml Object

The XML representation of the component to be constructed. May be a String or an XMLNode.


An instance of the component defined within the specified XML string or XML node.


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: ComponentFactory.registerComponent('news', NewsComponentGenerator.createFromSerializedState);

	To create a component:
	var sXml = '<news> rest of config here... '</news>';
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.

  • Aliases remove the need to register a creation method with the ComponentFactory.


Determine the behaviour of module:ct-component/ComponentFactory#createComponent when it encounters an error.

When this method is called with true, module:ct-component/ComponentFactory#createComponent will return a module:ct-component/ErrorComponent on errors (default behaviour), and when called with false a module:ct-core/Error is raised on errors.

Name Type Description

bReturnErrorComponentOnError True if an error component should be returned on error, false otherwise.