Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (C) 2008 EsperTech, Inc. All rights reserved. * http://esper.codehaus.org * http://www.espertech.com * ---------------------------------------------------------------------------------- * The software in this package is published under the terms of the GPL license * a copy of which has been included with this distribution in the license.txt file. * /
  
  package com.espertech.esperio.socket.config;
 
 
 import java.io.*;
 import java.net.URL;
 import java.util.Map;
 
 public class ConfigurationSocketAdapter {
     private static Log log = LogFactory.getLog(ConfigurationSocketAdapter.class);
 
     private Map<StringSocketConfigsockets;
 
     public ConfigurationSocketAdapter() {
          = new HashMap<StringSocketConfig>();
     }
 
     public Map<StringSocketConfiggetSockets() {
         return ;
     }
 
     public void setSockets(Map<StringSocketConfigsockets) {
         this. = sockets;
     }

    
Use the configuration specified in an application resource named esper.cfg.xml.

Returns:
Configuration initialized from the resource
Throws:
java.lang.RuntimeException thrown to indicate error reading configuration
 
     {
 		configure('/' + "esperio.socket.cfg.xml");
 		return this;
 	}

    
Use the ConfigurationSocketAdapter specified in the given application resource. The format of the resource is defined in esper-configuration-2.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:
ConfigurationSocketAdapter initialized from the resource
Throws:
java.lang.RuntimeException thrown to indicate error reading configuration
 
     public ConfigurationSocketAdapter configure(String resourcethrows RuntimeException
     {
         if (.isInfoEnabled())
         {
             .info"Configuring from resource: " + resource );
         }
         InputStream stream = getConfigurationInputStream(resource );
         ConfigurationSocketAdapterParser.doConfigure(thisstreamresource );
         return this;
     }

    
Get the ConfigurationSocketAdapter file as an InputStream. Might be overridden by subclasses to allow the ConfigurationSocketAdapter 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:
java.lang.RuntimeException thrown to indicate error reading configuration
 
     protected static InputStream getConfigurationInputStream(String resourcethrows RuntimeException
     {
         return getResourceAsStream(resource);
     }

    
Use the ConfigurationSocketAdapter specified by the given XML String. The format of the document obtained from the URL is defined in esper-configuration-2.0.xsd.

Parameters:
xml XML string
Returns:
A ConfigurationSocketAdapter configured via the file
Throws:
java.lang.RuntimeException is thrown when the URL could not be access
    {
        if (.isInfoEnabled())
        {
            .info"Configuring from string");
        }
        try {
            InputSource source = new InputSource(new StringReader(xml));
            DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
            builderFactory.setNamespaceAware(true);
            Document doc = builderFactory.newDocumentBuilder().parse(source);
            ConfigurationSocketAdapterParser.doConfigure(thisdoc);
            return this;
        }
        catch (IOException ioe) {
            throw new RuntimeException("could not configure from String: " + ioe.getMessage(), ioe );
        } catch (SAXException e) {
            throw new RuntimeException("could not configure from String: " + e.getMessage(), e );
        } catch (ParserConfigurationException e) {
            throw new RuntimeException("could not configure from String: " + e.getMessage(), e );
        }
    }

Use the ConfigurationSocketAdapter specified by the given URL. The format of the document obtained from the URL is defined in esper-configuration-2.0.xsd.

Parameters:
url URL from which you wish to load the configuration
Returns:
A ConfigurationSocketAdapter configured via the file
Throws:
java.lang.RuntimeException is thrown when the URL could not be access
    {
        if (.isInfoEnabled())
        {
            .info"Configuring from url: " + url.toString() );
        }
        try {
            ConfigurationSocketAdapterParser.doConfigure(thisurl.openStream(), url.toString());
            return this;
		}
		catch (IOException ioe) {
			throw new RuntimeException("could not configure from URL: " + urlioe );
		}
	}

    
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
    protected static InputStream getResourceAsStream(String resource)
    {
        String stripped = resource.startsWith("/") ?
                resource.substring(1) : resource;
        InputStream stream = null;
        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
        if (classLoader!=null) {
            stream = classLoader.getResourceAsStreamstripped );
        }
        if ( stream == null ) {
            stream = ConfigurationSocketAdapter.class.getResourceAsStreamresource );
        }
        if ( stream == null ) {
            stream = ConfigurationSocketAdapter.class.getClassLoader().getResourceAsStreamstripped );
        }
        if ( stream == null ) {
            throw new RuntimeExceptionresource + " not found" );
        }
        return stream;
    }

Use the ConfigurationSocketAdapter specified in the given application file. The format of the file is defined in esper-configuration-2.0.xsd.

Parameters:
configFile File from which you wish to load the configuration
Returns:
A ConfigurationSocketAdapter configured via the file
Throws:
java.lang.RuntimeException when the file could not be found
    {
        if (.isDebugEnabled())
        {
            .debug"configuring from file: " + configFile.getName() );
        }
        FileInputStream inputStream = null;
        try {
            inputStream = new FileInputStream(configFile);
            ConfigurationSocketAdapterParser.doConfigure(thisinputStreamconfigFile.toString());
		}
		catch (FileNotFoundException fnfe) {
			throw new RuntimeException"could not find file: " + configFilefnfe );
		}
        finally {
            if (inputStream != null) {
                try {
                    inputStream.close();
                } catch (IOException e) {
                    .debug("Error closing input stream"e);
                }
            }
        }        
        return this;
    }
New to GrepCode? Check out our FAQ X