org.apache.camel.impl
Class DefaultComponent

java.lang.Object
  extended by org.apache.camel.impl.ServiceSupport
      extended by org.apache.camel.impl.DefaultComponent
All Implemented Interfaces:
Component, Service
Direct Known Subclasses:
BeanComponent, BrowseComponent, DataSetComponent, DirectComponent, GenericFileComponent, HeaderFilterStrategyComponent, LogComponent, MockComponent, RefComponent, SedaComponent, TimerComponent

public abstract class DefaultComponent
extends ServiceSupport
implements Component

Default component to use for base for components implementations.

Version:
$Revision: 835186 $

Constructor Summary
DefaultComponent()
           
DefaultComponent(CamelContext context)
           
 
Method Summary
protected  void afterConfiguration(String uri, String remaining, Endpoint endpoint, Map<String,Object> parameters)
          Strategy to do post configuration logic.
<T> T
convertTo(Class<T> type, Object value)
          Deprecated. will be removed in Camel 2.2
 Endpoint createEndpoint(String uri)
          Attempt to resolve an endpoint for the given URI if the component is capable of handling the URI
protected abstract  Endpoint createEndpoint(String uri, String remaining, Map<String,Object> parameters)
          A factory method allowing derived components to create a new endpoint from the given URI, remaining path and optional parameters
protected  ScheduledExecutorService createScheduledExecutorService()
          A factory method to create a default thread pool and executor
protected  void doStart()
           
protected  void doStop()
           
<T> T
getAndRemoveParameter(Map<String,Object> parameters, String key, Class<T> type)
          Gets the parameter and remove it from the parameter map.
<T> T
getAndRemoveParameter(Map<String,Object> parameters, String key, Class<T> type, T defaultValue)
          Gets the parameter and remove it from the parameter map.
 CamelContext getCamelContext()
          Returns the context
 ExecutorService getExecutorService()
           
 ScheduledExecutorService getScheduledExecutorService()
           
protected  String ifStartsWithReturnRemainder(String prefix, String text)
          Returns the reminder of the text if it starts with the prefix.
 Object lookup(String name)
          Deprecated. will be removed in Camel 2.2
<T> T
lookup(String name, Class<T> beanType)
          Deprecated. will be removed in Camel 2.2
<T> T
mandatoryConvertTo(Class<T> type, Object value)
          Deprecated. will be removed in Camel 2.2
 Object mandatoryLookup(String name)
          Deprecated. will be removed in Camel 2.2
<T> T
mandatoryLookup(String name, Class<T> beanType)
          Deprecated. will be removed in Camel 2.2
<T> T
newInstance(Class<T> beanType)
          Deprecated. will be removed in Camel 2.2
<T> T
resolveAndRemoveReferenceParameter(Map<String,Object> parameters, String key, Class<T> type)
          Resolves a reference parameter in the registry and removes it from the map.
<T> T
resolveAndRemoveReferenceParameter(Map<String,Object> parameters, String key, Class<T> type, T defaultValue)
          Resolves a reference parameter in the registry and removes it from the map.
 void setCamelContext(CamelContext context)
          The CamelContext is injected into the component when it is added to it
 void setExecutorService(ExecutorService executorService)
           
protected  void setProperties(Object bean, Map<String,Object> 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 validateParameters(String uri, Map<String,Object> parameters, String optionPrefix)
          Strategy for validation of parameters, that was not able to be resolved to any endpoint options.
protected  void validateURI(String uri, String path, Map<String,Object> parameters)
          Strategy for validation of the uri when creating the endpoint.
 
Methods inherited from class org.apache.camel.impl.ServiceSupport
addChildService, getStatus, getVersion, isRunAllowed, isStarted, isStarting, isStopped, isStopping, 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 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
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

afterConfiguration

protected void afterConfiguration(String uri,
                                  String remaining,
                                  Endpoint endpoint,
                                  Map<String,Object> parameters)
                           throws Exception
Strategy to do post configuration logic.

Can be used to construct an URI based on the remaining parameters. For example the parameters that configures the endpoint have been removed from the parameters which leaves only the additional parameters left.

Parameters:
endpoint - the created endpoint
parameters - the remaining parameters after the endpoint has been created and parsed the parameters
Throws:
Exception - can be thrown to indicate error creating the endpoint

validateParameters

protected void validateParameters(String uri,
                                  Map<String,Object> parameters,
                                  String optionPrefix)
Strategy for validation of parameters, that was not able to be resolved to any endpoint options.

Parameters:
uri - the uri - the uri the end user provided untouched
parameters - the parameters, an empty map if no parameters given
optionPrefix - optional prefix to filter the parameters for validation. Use null for validate all.
Throws:
ResolveEndpointFailedException - should be thrown if the URI validation failed

validateURI

protected void validateURI(String uri,
                           String path,
                           Map<String,Object> parameters)
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
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

getExecutorService

public ExecutorService getExecutorService()

setExecutorService

public void setExecutorService(ExecutorService executorService)

getScheduledExecutorService

public ScheduledExecutorService getScheduledExecutorService()

createScheduledExecutorService

protected ScheduledExecutorService createScheduledExecutorService()
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 createEndpoint(String uri,
                                           String remaining,
                                           Map<String,Object> 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<String,Object> parameters)
                      throws Exception
Sets the bean properties on the given bean

Parameters:
bean - the bean
parameters - properties to set
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

@Deprecated
public <T> T convertTo(Class<T> type,
                                  Object value)
Deprecated. will be removed in Camel 2.2

Converts the given value to the requested type


mandatoryConvertTo

@Deprecated
public <T> T mandatoryConvertTo(Class<T> type,
                                           Object value)
Deprecated. will be removed in Camel 2.2

Converts the given value to the specified type throwing an IllegalArgumentException if the value could not be converted to a non null value


newInstance

@Deprecated
public <T> T newInstance(Class<T> beanType)
Deprecated. will be removed in Camel 2.2

Creates a new instance of the given type using the Injector on the given CamelContext


lookup

@Deprecated
public Object lookup(String name)
Deprecated. will be removed in Camel 2.2

Look up the given named bean in the Registry on the CamelContext


lookup

@Deprecated
public <T> T lookup(String name,
                               Class<T> beanType)
Deprecated. will be removed in Camel 2.2

Look up the given named bean of the given type in the Registry on the CamelContext


mandatoryLookup

@Deprecated
public Object mandatoryLookup(String name)
Deprecated. will be removed in Camel 2.2

Look up the given named bean in the Registry on the CamelContext or throws exception if not found.


mandatoryLookup

@Deprecated
public <T> T mandatoryLookup(String name,
                                        Class<T> beanType)
Deprecated. will be removed in Camel 2.2

Look up the given named bean of the given type in the Registry on the CamelContext or throws exception if not found.


getAndRemoveParameter

public <T> T getAndRemoveParameter(Map<String,Object> parameters,
                                   String key,
                                   Class<T> type)
Gets the parameter and remove it from the parameter map. This method doesn't resolve reference parameters in the registry.

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.
See Also:
resolveAndRemoveReferenceParameter(Map, String, Class)

getAndRemoveParameter

public <T> T getAndRemoveParameter(Map<String,Object> parameters,
                                   String key,
                                   Class<T> type,
                                   T defaultValue)
Gets the parameter and remove it from the parameter map. This method doesn't resolve reference parameters in the registry.

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
See Also:
resolveAndRemoveReferenceParameter(Map, String, Class, Object)

resolveAndRemoveReferenceParameter

public <T> T resolveAndRemoveReferenceParameter(Map<String,Object> parameters,
                                                String key,
                                                Class<T> type)
Resolves a reference parameter in the registry and removes it from the map.

Type Parameters:
T - type of object to lookup in th registry.
Parameters:
parameters - parameter map.
key - parameter map key.
type - type of object to lookup in th registry.
Returns:
the referenced object or null.

resolveAndRemoveReferenceParameter

public <T> T resolveAndRemoveReferenceParameter(Map<String,Object> parameters,
                                                String key,
                                                Class<T> type,
                                                T defaultValue)
Resolves a reference parameter in the registry and removes it from the map.

Type Parameters:
T - type of object to lookup in th registry.
Parameters:
parameters - parameter map.
key - parameter map key.
type - type of object to lookup in th registry.
defaultValue - default value to use if neither the parameter map contains the key nor the registry contains an object of requested type.
Returns:
the referenced object, the default value or null.

ifStartsWithReturnRemainder

protected String ifStartsWithReturnRemainder(String prefix,
                                             String text)
Returns the reminder of the text if it starts with the prefix.

Is useable for string parameters that contains commands.

Parameters:
prefix - the prefix
text - the text
Returns:
the reminder, or null if no reminder


Copyright © 2007-2009 The Apache Software Foundation. All Rights Reserved.