net.esper.event
Class EventTypeFactory

java.lang.Object
  extended by net.esper.event.EventTypeFactory

public final class EventTypeFactory
extends java.lang.Object

A singleton factory class for obtaining EventType instances. The singleton caches EventType instances for Java beans, and does not cache event types for Map-based events. It is recommended to cache references to Map type implementations and reuse them for memory efficiency.

Usage (JavaBean):

 Class employeeBeanClass = Class.forName("com.xyz.beans.Employee");
 EventType empolyeeType = EventTypeFactory.getInstance().createBeanType(employeeBeanClass);
 
Usage (Map):
 HashMap employeeProperties = new HashMap();
 employeeProperties.put("firstName", String.class);
 employeeProperties.put("SSN", Integer.class);
 EventType empolyeeType = EventTypeFactory.getInstance().createMapType(employeeProperties);
 


Method Summary
protected  void clear()
          Clear any cached types - for unit testing pruposes.
 EventType createBeanType(java.lang.Class clazz)
          Creates a new EventType object for a java bean of the specified class if this is the first time the class has been seen.
 EventType createMapType(java.util.Map<java.lang.String,java.lang.Class> propertyTypes)
          Creates a new EventType instance for an event type that contains a map of name value pairs.
 java.util.Set<EventType> getDeepSuperTypes(EventType eventType)
          Returns super types to event type, going up the hierarchy and including all super-interfaces and classes.
static EventTypeFactory getInstance()
          Returns singleton instance.
protected static void getSuper(java.lang.Class clazz, java.util.Set<java.lang.Class> result)
          Add the given class's implemented interfaces and superclasses to the result set of classes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static EventTypeFactory getInstance()
Returns singleton instance.

Returns:
singleton instance

clear

protected void clear()
Clear any cached types - for unit testing pruposes.


createMapType

public final EventType createMapType(java.util.Map<java.lang.String,java.lang.Class> propertyTypes)
Creates a new EventType instance for an event type that contains a map of name value pairs. The method accepts a Map that contains the property names as keys and Class objects as the values. The Class instances represent the property types.

New instances are created by this method on every invocation. Clients to this method need to cache the returned EventType instance to reuse EventType's for same-typed events.

Parameters:
propertyTypes - is a map of String to Class objects
Returns:
EventType implementation for map field names and value types

createBeanType

public final EventType createBeanType(java.lang.Class clazz)
Creates a new EventType object for a java bean of the specified class if this is the first time the class has been seen. Else uses a cached EventType instance, i.e. client classes do not need to cache.

Parameters:
clazz - is the class of the Java bean.
Returns:
EventType implementation for bean class

getDeepSuperTypes

public final java.util.Set<EventType> getDeepSuperTypes(EventType eventType)
Returns super types to event type, going up the hierarchy and including all super-interfaces and classes.

Parameters:
eventType - is the type to traverse up
Returns:
set of event types represeting all superclasses and implemented interfaces, all the way up to Object

getSuper

protected static void getSuper(java.lang.Class clazz,
                               java.util.Set<java.lang.Class> result)
Add the given class's implemented interfaces and superclasses to the result set of classes.

Parameters:
clazz - to introspect
result - to add classes to