net.esper.client
Class Configuration

java.lang.Object
  extended by net.esper.client.Configuration

public class Configuration
extends Object

An instance of Configuration allows the application to specify properties to be used when creating a EPServiceProvider. Usually an application will create a single Configuration, then get one or more instances of EPServiceProvider via EPServiceProviderManager. The Configuration is meant only as an initialization-time object. EPServiceProviders are immutable and do not retain any association back to the Configuration.
The format of an Esper XML configuration file is defined in esper-configuration-1.0.xsd.


Field Summary
protected static String ESPER_DEFAULT_CONFIG
          Default name of the configuration file.
protected  Map<String,String> eventClasses
          Map of event name and fully-qualified Java class name.
protected  Map<String,ConfigurationEventTypeLegacy> eventTypesLegacy
          Map of event type alias and Legacy-type event configuration.
protected  Map<String,ConfigurationEventTypeXMLDOM> eventTypesXMLDOM
          Map of event type alias and XML DOM configuration.
protected  List<String> imports
          The java-style class and package name imports that will be used to resolve partial class names.
protected  Map<String,Properties> mapAliases
          The type aliases for events that result when maps are sent into the engine.
 
Constructor Summary
Configuration()
          Constructs an empty configuration.
 
Method Summary
 void addEventTypeAlias(String eventTypeAlias, Class javaEventClass)
          Add an alias for an event type represented by Java-bean plain-old Java object events.
 void addEventTypeAlias(String eventTypeAlias, ConfigurationEventTypeXMLDOM xmlDOMEventTypeDesc)
          Add an alias for an event type that represents org.w3c.dom.Node events.
 void addEventTypeAlias(String eventTypeAlias, Properties typeMap)
          Add an alias for an event type that represents java.util.Map events.
 void addEventTypeAlias(String eventTypeAlias, String javaEventClassName)
          Add an alias for an event type represented by Java-bean plain-old Java object events.
 void addEventTypeAlias(String eventTypeAlias, String javaEventClass, ConfigurationEventTypeLegacy legacyEventTypeDesc)
          Add an alias for an event type that represents legacy Java type (non-JavaBean style) events.
 void addImport(String autoImport)
          Add an import (a class or package).
 Configuration configure()
          Use the configuration specified in an application resource named esper.cfg.xml.
 Configuration configure(Document document)
          Use the mappings and properties specified in the given XML document.
 Configuration configure(File configFile)
          Use the configuration specified in the given application file.
 Configuration configure(String resource)
          Use the configuration specified in the given application resource.
 Configuration configure(URL url)
          Use the configuration specified by the given URL.
protected  InputStream getConfigurationInputStream(String resource)
          Get the configuration file as an InputStream.
 Map<String,String> getEventTypeAliases()
          Returns the mapping of event type alias to Java class name.
 Map<String,ConfigurationEventTypeLegacy> getEventTypesLegacy()
          Returns the mapping of event type alias to legacy java event type information.
 Map<String,Properties> getEventTypesMapEvents()
          Returns a map keyed by event type alias name, and values being the definition for the event type of the property names and types that make up the event.
 Map<String,ConfigurationEventTypeXMLDOM> getEventTypesXMLDOM()
          Returns the mapping of event type alias to XML DOM event type information.
 List<String> getImports()
          Returns the class and package imports.
protected static InputStream getResourceAsStream(String resource)
          Returns an input stream from an application resource in the classpath.
protected  void reset()
          Reset to an empty configuration.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ESPER_DEFAULT_CONFIG

protected static final String ESPER_DEFAULT_CONFIG
Default name of the configuration file.

See Also:
Constant Field Values

eventClasses

protected Map<String,String> eventClasses
Map of event name and fully-qualified Java class name.


eventTypesXMLDOM

protected Map<String,ConfigurationEventTypeXMLDOM> eventTypesXMLDOM
Map of event type alias and XML DOM configuration.


eventTypesLegacy

protected Map<String,ConfigurationEventTypeLegacy> eventTypesLegacy
Map of event type alias and Legacy-type event configuration.


mapAliases

protected Map<String,Properties> mapAliases
The type aliases for events that result when maps are sent into the engine.


imports

protected List<String> imports
The java-style class and package name imports that will be used to resolve partial class names.

Constructor Detail

Configuration

public Configuration()
Constructs an empty configuration. The auto import values are set by default to java.lang, java.math, java.text and java.util.

Method Detail

addEventTypeAlias

public void addEventTypeAlias(String eventTypeAlias,
                              String javaEventClassName)
Add an alias for an event type represented by Java-bean plain-old Java object events.

Parameters:
eventTypeAlias - is the alias for the event type
javaEventClassName - fully-qualified class name of the event type

addEventTypeAlias

public void addEventTypeAlias(String eventTypeAlias,
                              Class javaEventClass)
Add an alias for an event type represented by Java-bean plain-old Java object events.

Parameters:
eventTypeAlias - is the alias for the event type
javaEventClass - is the Java event class for which to create the alias

addEventTypeAlias

public void addEventTypeAlias(String eventTypeAlias,
                              Properties typeMap)
Add an alias for an event type that represents java.util.Map events.

Parameters:
eventTypeAlias - is the alias for the event type
typeMap - maps the name of each property in the Map event to the type (as a string) of its value in the Map object

addEventTypeAlias

public void addEventTypeAlias(String eventTypeAlias,
                              ConfigurationEventTypeXMLDOM xmlDOMEventTypeDesc)
Add an alias for an event type that represents org.w3c.dom.Node events.

Parameters:
eventTypeAlias - is the alias for the event type
xmlDOMEventTypeDesc - descriptor containing property and mapping information for XML-DOM events

addEventTypeAlias

public void addEventTypeAlias(String eventTypeAlias,
                              String javaEventClass,
                              ConfigurationEventTypeLegacy legacyEventTypeDesc)
Add an alias for an event type that represents legacy Java type (non-JavaBean style) events.

Parameters:
eventTypeAlias - is the alias for the event type
javaEventClass - fully-qualified class name of the event type
legacyEventTypeDesc - descriptor containing property and mapping information for Legacy Java type events

addImport

public void addImport(String autoImport)
Add an import (a class or package). Adding will suppress the use of the default imports.

Parameters:
autoImport - - the import to add

getEventTypeAliases

public Map<String,String> getEventTypeAliases()
Returns the mapping of event type alias to Java class name.

Returns:
event type aliases for Java class names

getEventTypesMapEvents

public Map<String,Properties> getEventTypesMapEvents()
Returns a map keyed by event type alias name, and values being the definition for the event type of the property names and types that make up the event.

Returns:
map of event type alias name and definition of event properties

getEventTypesXMLDOM

public Map<String,ConfigurationEventTypeXMLDOM> getEventTypesXMLDOM()
Returns the mapping of event type alias to XML DOM event type information.

Returns:
event type aliases mapping to XML DOM configs

getEventTypesLegacy

public Map<String,ConfigurationEventTypeLegacy> getEventTypesLegacy()
Returns the mapping of event type alias to legacy java event type information.

Returns:
event type aliases mapping to legacy java class configs

getImports

public List<String> getImports()
Returns the class and package imports.

Returns:
imported names

configure

public Configuration configure()
                        throws EPException
Use the configuration specified in an application resource named esper.cfg.xml.

Returns:
Configuration initialized from the resource
Throws:
EPException - thrown to indicate error reading configuration

configure

public Configuration configure(String resource)
                        throws EPException
Use the configuration specified in the given application resource. The format of the resource is defined in esper-configuration-1.0.xsd.

The resource is found via getConfigurationInputStream(resource). That method can be overridden to implement an arbitrary lookup strategy.

See getResourceAsStream for information on how the resource name is resolved.

Parameters:
resource - if the file name of the resource
Returns:
Configuration initialized from the resource
Throws:
EPException - thrown to indicate error reading configuration

getConfigurationInputStream

protected InputStream getConfigurationInputStream(String resource)
                                           throws EPException
Get the configuration file as an InputStream. Might be overridden by subclasses to allow the configuration to be located by some arbitrary mechanism.

See getResourceAsStream for information on how the resource name is resolved.

Parameters:
resource - is the resource name
Returns:
input stream for resource
Throws:
EPException - thrown to indicate error reading configuration

configure

public Configuration configure(URL url)
                        throws EPException
Use the configuration specified by the given URL. The format of the document obtained from the URL is defined in esper-configuration-1.0.xsd.

Parameters:
url - URL from which you wish to load the configuration
Returns:
A configuration configured via the file
Throws:
EPException

configure

public Configuration configure(File configFile)
                        throws EPException
Use the configuration specified in the given application file. The format of the file is defined in esper-configuration-1.0.xsd.

Parameters:
configFile - File from which you wish to load the configuration
Returns:
A configuration configured via the file
Throws:
EPException

configure

public Configuration configure(Document document)
                        throws EPException
Use the mappings and properties specified in the given XML document. The format of the file is defined in esper-configuration-1.0.xsd.

Parameters:
document - an XML document from which you wish to load the configuration
Returns:
A configuration configured via the Document
Throws:
EPException - if there is problem in accessing the document.

getResourceAsStream

protected static InputStream getResourceAsStream(String resource)
Returns an input stream from an application resource in the classpath.

The method first removes the '/' character from the resource name if the first character is '/'.

The lookup order is as follows:

If a thread context class loader exists, use Thread.currentThread().getResourceAsStream to obtain an InputStream.

If no input stream was returned, use the Configuration.class.getResourceAsStream. to obtain an InputStream.

If no input stream was returned, use the Configuration.class.getClassLoader().getResourceAsStream. to obtain an InputStream.

If no input stream was returned, throw an Exception.

Parameters:
resource - to get input stream for
Returns:
input stream for resource

reset

protected void reset()
Reset to an empty configuration.