org.apache.camel.impl
Class DefaultComponent<E extends Exchange>

java.lang.Object
  extended by org.apache.camel.impl.ServiceSupport
      extended by org.apache.camel.impl.DefaultComponent<E>
All Implemented Interfaces:
Component<E>, Service
Direct Known Subclasses:
BeanComponent, DataSetComponent, DirectComponent, FileComponent, JMXComponent, ListComponent, LogComponent, MockComponent, RefComponent, SedaComponent, TimerComponent

public abstract class DefaultComponent<E extends Exchange>
extends ServiceSupport
implements Component<E>

Default component to use for base for components implementations.

Version:
$Revision: 706013 $

Constructor Summary
DefaultComponent()
           
DefaultComponent(CamelContext context)
           
 
Method Summary
<T> T
convertTo(Class<T> type, Object value)
          Converts the given value to the requested type
 Endpoint<E> createEndpoint(String uri)
          Attempt to resolve an endpoint for the given URI if the component is capable of handling the URI
protected abstract  Endpoint<E> createEndpoint(String uri, String remaining, Map parameters)
          A factory method allowing derived components to create a new endpoint from the given URI, remaining path and optional parameters
protected  ScheduledExecutorService createExecutorService()
          A factory method to create a default thread pool and executor
protected  void doStart()
           
protected  void doStop()
           
<T> T
getAndRemoveParameter(Map parameters, String key, Class<T> type)
          Gets the parameter and remove it from the parameter map.
<T> T
getAndRemoveParameter(Map parameters, String key, Class<T> type, T defaultValue)
          Gets the parameter and remove it from the parameter map.
 CamelContext getCamelContext()
          Returns the context
 ScheduledExecutorService getExecutorService()
           
 Object lookup(String name)
          Look up the given named bean in the Registry on the CamelContext
<T> T
lookup(String name, Class<T> beanType)
          Look up the given named bean of the given type in the Registry on the CamelContext
<T> T
mandatoryConvertTo(Class<T> type, Object value)
          Converts the given value to the specified type throwing an IllegalArgumentException if the value could not be converted to a non null value
 Object mandatoryLookup(String name)
          Look up the given named bean in the Registry on the CamelContext or throws
<T> T
mandatoryLookup(String name, Class<T> beanType)
          Look up the given named bean of the given type in the Registry on the CamelContext
<T> T
newInstance(Class<T> beanType)
          Creates a new instance of the given type using the Injector on the given CamelContext
 void setCamelContext(CamelContext context)
          The CamelContext is injected into the component when it is added to it
 void setExecutorService(ScheduledExecutorService executorService)
           
protected  void setProperties(Object bean, Map parameters)
          Sets the bean properties on the given bean
protected  boolean useIntrospectionOnEndpoint()
          Derived classes may wish to overload this to prevent the default introspection of URI parameters on the created Endpoint instance
protected  void validateURI(String uri, String path, Map parameters)
          Strategy for validation of the uri when creating the endpoint.
 
Methods inherited from class org.apache.camel.impl.ServiceSupport
addChildService, getThreadName, getVersion, isRunAllowed, isStarted, isStarting, isStopped, isStopping, nextThreadCounter, removeChildService, start, stop
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultComponent

public DefaultComponent()

DefaultComponent

public DefaultComponent(CamelContext context)
Method Detail

createEndpoint

public Endpoint<E> createEndpoint(String uri)
                                            throws Exception
Description copied from interface: Component
Attempt to resolve an endpoint for the given URI if the component is capable of handling the URI

Specified by:
createEndpoint in interface Component<E extends Exchange>
Parameters:
uri - the URI to create
Returns:
a newly created endpoint or null if this component cannot create instances of the given uri
Throws:
Exception

validateURI

protected void validateURI(String uri,
                           String path,
                           Map parameters)
                    throws ResolveEndpointFailedException
Strategy for validation of the uri when creating the endpoint.

Parameters:
uri - the uri - the uri the end user provided untouched
path - the path - part after the scheme
parameters - the parameters, an empty map if no parameters given
Throws:
ResolveEndpointFailedException - should be thrown if the URI validation failed

getCamelContext

public CamelContext getCamelContext()
Description copied from interface: Component
Returns the context

Specified by:
getCamelContext in interface Component<E extends Exchange>
Returns:
the context of this component

setCamelContext

public void setCamelContext(CamelContext context)
Description copied from interface: Component
The CamelContext is injected into the component when it is added to it

Specified by:
setCamelContext in interface Component<E extends Exchange>

getExecutorService

public ScheduledExecutorService getExecutorService()

setExecutorService

public void setExecutorService(ScheduledExecutorService executorService)

createExecutorService

protected ScheduledExecutorService createExecutorService()
A factory method to create a default thread pool and executor


doStart

protected void doStart()
                throws Exception
Specified by:
doStart in class ServiceSupport
Throws:
Exception

doStop

protected void doStop()
               throws Exception
Specified by:
doStop in class ServiceSupport
Throws:
Exception

createEndpoint

protected abstract Endpoint<E> createEndpoint(String uri,
                                              String remaining,
                                              Map parameters)
                                                        throws Exception
A factory method allowing derived components to create a new endpoint from the given URI, remaining path and optional parameters

Parameters:
uri - the full URI of the endpoint
remaining - the remaining part of the URI without the query parameters or component prefix
parameters - the optional parameters passed in
Returns:
a newly created endpoint or null if the endpoint cannot be created based on the inputs
Throws:
Exception

setProperties

protected void setProperties(Object bean,
                             Map parameters)
                      throws Exception
Sets the bean properties on the given bean

Throws:
Exception

useIntrospectionOnEndpoint

protected boolean useIntrospectionOnEndpoint()
Derived classes may wish to overload this to prevent the default introspection of URI parameters on the created Endpoint instance


convertTo

public <T> T convertTo(Class<T> type,
                       Object value)
Converts the given value to the requested type


mandatoryConvertTo

public <T> T mandatoryConvertTo(Class<T> type,
                                Object value)
Converts the given value to the specified type throwing an IllegalArgumentException if the value could not be converted to a non null value


newInstance

public <T> T newInstance(Class<T> beanType)
Creates a new instance of the given type using the Injector on the given CamelContext


lookup

public Object lookup(String name)
Look up the given named bean in the Registry on the CamelContext


lookup

public <T> T lookup(String name,
                    Class<T> beanType)
Look up the given named bean of the given type in the Registry on the CamelContext


mandatoryLookup

public Object mandatoryLookup(String name)
Look up the given named bean in the Registry on the CamelContext or throws


mandatoryLookup

public <T> T mandatoryLookup(String name,
                             Class<T> beanType)
Look up the given named bean of the given type in the Registry on the CamelContext


getAndRemoveParameter

public <T> T getAndRemoveParameter(Map parameters,
                                   String key,
                                   Class<T> type)
Gets the parameter and remove it from the parameter map.

Parameters:
parameters - the parameters
key - the key
type - the requested type to convert the value from the parameter
Returns:
the converted value parameter, null if parameter does not exists.

getAndRemoveParameter

public <T> T getAndRemoveParameter(Map parameters,
                                   String key,
                                   Class<T> type,
                                   T defaultValue)
Gets the parameter and remove it from the parameter map.

Parameters:
parameters - the parameters
key - the key
type - the requested type to convert the value from the parameter
defaultValue - use this default value if the parameter does not contain the key
Returns:
the converted value parameter


Copyright © 2009 Apache Software Foundation. All Rights Reserved.