How to Create an Oracle CEP Event Type as a java.util.Map

Overview of Oracle CEP Events 2-21 java.util.Map map = new Map{name, java.lang.String}, {age, java.lang.Integer}, {address, java.lang.String}; rep.registerEventTypeAnotherEvent, map; For more information, see Section 2.7, Accessing the Event Type Repository . 3. Use the event type: ■ Reference the event types as standard JavaBeans in the Java code of the adapters and business logic POJO in your application. public void onEventList newEvents throws RejectEventException { for Object event : newEvents { java.util.Map anEvent = java.util.Map event; System.out.printlnAge: + anEvent.getAge; } } ■ Access the event types from Oracle CQL and EPL rules: The following Oracle CQL rule shows how you can reference the MarketEvent in a SELECT statement: query id=helloworldRule [CDATA[ select AnotherEvent.age from eventChannel [Now] ]] query

2.6 Using an Event Type Builder Factory

When you register an event type in the repository using the wlevs:event-type element, Oracle CEP creates instances of the event using the information in the event type class. Sometimes, however, you might want or need to have more control over how the event type instances are created. This is required if the POJO that represents the event does not expose the necessary getter and setter methods for the event properties. For example, assume the event type has a firstname property, but the EPL rule that executes on the event type assumes the property is called fname. Further assume that you cannot change either the event type class because you are using a shared event class from another bundle, for example or the EPL rule to make them compatible with each other. In this case you can use an event type builder factory to change the way the event type instance is created so that the property is named fname rather than firstname. When you program the event type builder factory, you must implement the EventBuilder.Factory inner interface of the com.bea.wlevs.ede.api.EventBuilder interface; see the Oracle Fusion Middleware Java API Reference for Oracle Complex Event Processing for details about the methods you must implement, such as createBuilder and createEvent. The following example of an event type builder factory class is taken from the FX sample: package com.bea.wlevs.example.fx; import java.util.HashMap; import java.util.Map; import com.bea.wlevs.ede.api.EventBuilder; import com.bea.wlevs.example.fx.OutputBean.ForeignExchangeEvent; public class ForeignExchangeBuilderFactory implements EventBuilder.Factory { public EventBuilder createBuilder { return new ForeignExchangeBuilder; 2-22 Oracle Complex Event Processing Developers Guide } static class ForeignExchangeBuilder implements EventBuilder { private MapString,Object values = new HashMapString,Object10; public Object createEvent { return new ForeignExchangeEvent String values.getsymbol, Double values.getprice, String values.getfromRate, String values.gettoRate; } public void putString property, Object value throws IllegalStateException { values.putproperty, value; } } } When you register the event type in the EPN assembly file, use the wlevs:property name=builderFactory child element of the wlevs:event-type element to specify the name of the factory class. The hard-coded builderFactory value of the name attribute alerts Oracle CEP that it should use the specified factory class, rather than its own default factory, when creating instances of this event. For example, in the FX example, the builder factory is registered as shown in bold: wlevs:event-type-repository wlevs:event-type type-name=ForeignExchangeEvent wlevs:classcom.bea.wlevs.example.fx.OutputBeanForeignExchangeEventwlevs:class wlevs:property name=builderFactory bean id=builderFactory class=com.bea.wlevs.example.fx.ForeignExchangeBuilderFactory wlevs:property wlevs:event-type wlevs:event-type-repository

2.7 Accessing the Event Type Repository

The EventTypeRepository is a singleton OSGi service. Because it is a singleton, you only need to specify its interface name to identify it. You can get a service from OSGi in any of the following ways: ■ Section 2.7.1, Using the EPN Assembly File ■ Section 2.7.2, Using the Spring-DM ServiceReference Annotation ■ Section 2.7.3, Using the Oracle CEP Service Annotation For more information, see Oracle Fusion Middleware Java API Reference for Oracle Complex Event Processing.

2.7.1 Using the EPN Assembly File

You can access the EventTypeRepository by specifying an osgi:reference in the EPN assembly file as Example 2–15 shows. Example 2–15 EPN Assembly File With OSGi Reference to EventTypeRepository osgi:reference id=etr interface=com.bea.wlevs.ede.api.EventTypeRepository bean id=outputBean class=com.acme.MyBean property name=eventTypeRepository ref=etr bean