Runtime components : Core components : ElementFactory : Tasks : Customizing ElementFactory
  
Customizing ElementFactory
There are four ways to customize ElementFactory, namely, by using tag provider, by adding ElementProcessor, by changing default, and by implementing class table.
Tag provider
In previous sections, BasicElementFactory is created using the constructor public BasicElementFactory(String fileName);. The BasicElementFactory created from this constructor reads the element definition from the file specified by fileName. The XML file can import some other XML files, for example:
<test.xml>
  <import file="abc.xml"/>
</test.xml>
There is also another constructor for BasicElementFactory: public BasicElementFactory(TagProvider provider). This constructor accepts an argument in type of TagProvider. You can implement your own TagProvider to find your definition in your own way or even define the Tag in your own style (other than XML). Following is the interface definition of TagProvider:
public interface TagProvider {
  public Tag getTag(String id) throws ConfigException;
}
Add ElementProcessor
There is a call back interface com.ibm.btt.element.ElementProcessor. If you want to perform some tasks before or after the factory creates or initializes an element, you can implement this interface, and add your implementation to BasicElementFactory.
Following is the sample code, you must define it in your TagProvide and use elementProcessors as the ID.
<list id="elementProcessors">
  <yourPackage.YourElementProcessor1 />
  <yourPackage.YourElementProcessor2 />
</list>
Following is the ElementProcessor interface:
public interface ElementProcessor {
public Tag beforeCreateElement(Tag tag) throws ElementException;
public Object beforeInitializeElement(Tag tag, Object element) throws ElementException;
public Object afterInitializeElement(Tag tag, Object element) throws ElementException;
}
Change default scope
It is not required to define attribute Scope in every element definition. If the Scope is not defined, ElementFactory then uses a default value: singleton. You can use the following code to change the default Scope value:
<string id="defaultScope" value="prototype" />
Note You must define it in your TagProvider, together with your element definition. And you must use defaultScope as the ID.
Class table
Class name together with package name might be a long string. You can define short cut for a class name.
To define the short cut for a class name, you must define a Map containing the mapping between the short cut and the real class name. The Map must be defined in your TagProvider, together with your element definition. You must use classTable as the ID. See Tag naming rulesfor more details.
Go up to
Tasks