Use custom Common Base Event factory homes to control configuration and implementation of unique event factories.
Event factory homes create and provide homes for Event Factory instances. Each event factory home has a content handler. This content handler is assigned to every event factory the event factory home creates. In turn, when a Common Base Event is created, the content handler from the event factory is assigned to it. Event factory instances are maintained by the associated event factory home, based on their unique name. For example, when application code requests a named event factory, the newly created event factory instance is returned and persisted for future requests for that named event factory.
The following classes were added to facilitate the use of event eactory homes for logging Common Base Events:
Class Name | Description |
WsEventFactoryHomeImpl | This class extends the org.eclipse.hyades.logging.events.cbe.impl.AbstractEventFactoryHome class. This event factory home returns event factory instances associated with the WsContentHandlerImpl content handler. The WsContentHandlerImpl is the content handler used by the WebSphere Application Server by default when no event factory template is in use. |
WsTemplateEventFactory
| This class extends the org.eclipse.hyades.logging.events.cbe.impl.EventXMLFileEventFactoryHomeImpl class. This event factory home returns event factory instances associated with the WsTemplateContentHandlerImpl Content Handler. The WsTemplateContentHandlerImpl is the content handler used by the WebSphere Application Server when an Event Factory template is required. |
public class CustomEventFactoryHome extends AbstractEventFactoryHome { public CustomEventFactoryHome() { super(); // TODO Custom intialization code goes here } public ContentHandler createContentHandler(String arg0) { // Always use custom content handler return resolveContentHandler(); } public ContentHandler resolveContentHandler() { // Always use custom content handler return new CustomContentHandler(); } }
// get the event factory EventFactory eventFactory=(new CustomEventFactoryHome()).getEventFactory("XYZ"); // create an event - call appropriate method eventFactory.createCommonBaseEvent(); // log event ...
public class CustomTemplateEventFactoryHome extends EventXMLFileEventFactoryHomeImpl { public CustomTemplateEventFactoryHome() { super(); // TODO Custom intialization code goes here } public ContentHandler createContentHandler(String arg0) { // Always use custom content handler return resolveContentHandler(); } public ContentHandler resolveContentHandler() { // Always use custom content handler return new CustomTemplateContentHandler(); } }
// get the event factory EventFactory eventFactory=(new CustomTemplateEventFactoryHome()).getEventFactory("XYZ"); // create an event - call appropriate method eventFactory.createCommonBaseEvent(); // log event ...
public class CustomTemplateEventFactoryHome extends EventXMLFileEventFactoryHomeImpl { public CustomTemplateEventFactoryHome() { super(); // TODO Custom intialization code goes here } public ContentHandler createContentHandler(String arg0) { // Always use custom content handler return resolveContentHandler(); } public ContentHandler resolveContentHandler() { // Always use custom content handler return new CustomTemplateContentHandler(); } } Figure 4 CustomTemplateEventFactoryHome class public class CustomEventFactoryHelper { // name of the event factory to use public static final String FACTORY_NAME="XYZ"; public static EventFactory getEventFactory(String param1, String param2) { EventFactory factory=null; switch (resolveFactory(param1,param2)) { case 1: factory=(new CustomEventFactoryHome()).getEventFactory(FACTORY_NAME); break; case 2: factory=(new CustomTemplateEventFactoryHome()).getEventFactory(FACTORY_NAME); break; default: // Add default for event factory break; } return factory; } private static int resolveFactory(String param1, String param2) { int factory=0; // Add code here to resolve which factory to use return factory; } }
// get the event factory EventFactory eventFactory= CustomEventFactoryHelper.getEventFactory("param1","param2","param3"); // create an event - call appropriate method eventFactory.createCommonBaseEvent(); // log event ...