net.esper.client
Class Configuration

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

public class Configuration
extends java.lang.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 java.lang.String ESPER_DEFAULT_CONFIG
          Default name of the configuration file.
protected  java.util.Map<java.lang.String,java.lang.String> eventClasses
          Map of event name and fully-qualified Java class name.
 
Constructor Summary
Configuration()
          Constructs an empty configuration.
 
Method Summary
 void addEventTypeAlias(java.lang.String eventTypeAlias, java.lang.String javaEventClass)
          Add an alias for an event type.
 Configuration configure()
          Use the configuration specified in an application resource named esper.cfg.xml.
 Configuration configure(org.w3c.dom.Document document)
          Use the mappings and properties specified in the given XML document.
 Configuration configure(java.io.File configFile)
          Use the configuration specified in the given application file.
 Configuration configure(java.lang.String resource)
          Use the configuration specified in the given application resource.
 Configuration configure(java.net.URL url)
          Use the configuration specified by the given URL.
protected  Configuration doConfigure(org.w3c.dom.Document doc)
          Parse the W3C DOM document.
protected  Configuration doConfigure(java.io.InputStream stream, java.lang.String resourceName)
          Use the configuration specified in the given input stream.
protected  java.io.InputStream getConfigurationInputStream(java.lang.String resource)
          Get the configuration file as an InputStream.
 java.util.Map<java.lang.String,java.lang.String> getEventTypeAliases()
          Returns the mapping of event type alias to event types.
protected static java.io.InputStream getResourceAsStream(java.lang.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 java.lang.String ESPER_DEFAULT_CONFIG
Default name of the configuration file.

See Also:
Constant Field Values

eventClasses

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

Constructor Detail

Configuration

public Configuration()
Constructs an empty configuration.

Method Detail

addEventTypeAlias

public void addEventTypeAlias(java.lang.String eventTypeAlias,
                              java.lang.String javaEventClass)
Add an alias for an event type.

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

getEventTypeAliases

public java.util.Map<java.lang.String,java.lang.String> getEventTypeAliases()
Returns the mapping of event type alias to event types.

Returns:
event type aliases

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(java.lang.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).

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 java.io.InputStream getConfigurationInputStream(java.lang.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.

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

configure

public Configuration configure(java.net.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(java.io.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(org.w3c.dom.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.

doConfigure

protected Configuration doConfigure(java.io.InputStream stream,
                                    java.lang.String resourceName)
                             throws EPException
Use the configuration specified in the given input stream.

Parameters:
stream - Inputstream to be read from
resourceName - The name to use in warning/error messages
Returns:
A configuration configured via the stream
Throws:
EPException

doConfigure

protected Configuration doConfigure(org.w3c.dom.Document doc)
                             throws EPException
Parse the W3C DOM document.

Parameters:
doc - to parse
Returns:
configuration
Throws:
EPException

getResourceAsStream

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

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

reset

protected void reset()
Reset to an empty configuration.