org.apache.camel.impl
Class DefaultComponent

java.lang.Object
  extended by org.apache.camel.support.ServiceSupport
      extended by org.apache.camel.impl.DefaultComponent
All Implemented Interfaces:
CamelContextAware, Component, Service, ShutdownableService, StatefulService, SuspendableService
Direct Known Subclasses:
BindingComponent, BindingNameComponent, HeaderFilterStrategyComponent, PropertiesComponent, RefComponent, UriEndpointComponent, ValidatorComponent

public abstract class DefaultComponent
extends ServiceSupport
implements Component

Default component to use for base for components implementations.

Version:

Field Summary
 
Fields inherited from class org.apache.camel.support.ServiceSupport
shutdown, shuttingdown, started, starting, stopped, stopping, suspended, suspending
 
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.
 ComponentConfiguration createComponentConfiguration()
          Creates a configuration helper object for a component that lets you configure the various URI and parameter values; then create the full URI for it, create a new Endpoint from it or configure an existing Endpoint from the values.
 EndpointConfiguration createConfiguration(String uri)
          Attempt to create a configuration object from the given uri
 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  void doStart()
          Implementations override this method to support customized start/stop.
protected  void doStop()
          Implementations override this method to support customized start/stop.
<T> T
getAndRemoveOrResolveReferenceParameter(Map<String,Object> parameters, String key, Class<T> type)
          Gets the parameter and remove it from the parameter map.
<T> T
getAndRemoveOrResolveReferenceParameter(Map<String,Object> parameters, String key, Class<T> type, T defaultValue)
          Gets the parameter and remove it from the parameter map.
<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()
          Get the CamelContext
protected  String ifStartsWithReturnRemainder(String prefix, String text)
          Returns the reminder of the text if it starts with the prefix.
protected  String preProcessUri(String uri)
          Deprecated. 
<T> List<T>
resolveAndRemoveReferenceListParameter(Map<String,Object> parameters, String key, Class<T> elementType)
          Resolves a reference list parameter in the registry and removes it from the map.
<T> List<T>
resolveAndRemoveReferenceListParameter(Map<String,Object> parameters, String key, Class<T> elementType, List<T> defaultValue)
          Resolves a reference list parameter in the registry and removes it from the map.
<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)
          Injects the CamelContext
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
 boolean useRawUri()
          Whether to use raw or encoded uri, when creating endpoints.
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.support.ServiceSupport
doResume, doShutdown, doSuspend, getStatus, getVersion, isRunAllowed, isStarted, isStarting, isStopped, isStopping, isStoppingOrStopped, isSuspended, isSuspending, resume, shutdown, start, stop, suspend
 
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

preProcessUri

@Deprecated
protected String preProcessUri(String uri)
Deprecated. 


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.

See Component.useRawUri() for controlling whether the passed in uri should be as-is (raw), or encoded (default).

Specified by:
createEndpoint in interface Component
Parameters:
uri - the URI to create; either raw or encoded (default)
Returns:
a newly created Endpoint or null if this component cannot create Endpoint instances using the given uri
Throws:
Exception - is thrown if error creating the endpoint
See Also:
Component.useRawUri()

createComponentConfiguration

public ComponentConfiguration createComponentConfiguration()
Description copied from interface: Component
Creates a configuration helper object for a component that lets you configure the various URI and parameter values; then create the full URI for it, create a new Endpoint from it or configure an existing Endpoint from the values. This method is intended to be used in cases where there is not yet a full URI to configure an endpoint yet; but rather there are a number of parameters to configure to then build up a new URI or directly create an Endpoint from the parameter values.

Specified by:
createComponentConfiguration in interface Component

createConfiguration

public EndpointConfiguration createConfiguration(String uri)
                                          throws Exception
Description copied from interface: Component
Attempt to create a configuration object from the given uri

Specified by:
createConfiguration in interface Component
Parameters:
uri - the configuration URI
Returns:
a newly created EndpointConfiguration
Throws:
Exception - is thrown if the configuration URI is invalid

useRawUri

public boolean useRawUri()
Description copied from interface: Component
Whether to use raw or encoded uri, when creating endpoints.

Notice: When using raw uris, then the parameter values is raw as well.

Specified by:
useRawUri in interface Component
Returns:
true to use raw uris, false to use encoded uris (default).

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:
uri - the uri
remaining - the remaining part of the URI without the query parameters or component prefix
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
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
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: CamelContextAware
Get the CamelContext

Specified by:
getCamelContext in interface CamelContextAware
Returns:
camelContext the Camel context

setCamelContext

public void setCamelContext(CamelContext context)
Description copied from interface: CamelContextAware
Injects the CamelContext

Specified by:
setCamelContext in interface CamelContextAware
Parameters:
context - the Camel context

doStart

protected void doStart()
                throws Exception
Description copied from class: ServiceSupport
Implementations override this method to support customized start/stop.

Important: See ServiceSupport.doStop() for more details.

Specified by:
doStart in class ServiceSupport
Throws:
Exception
See Also:
ServiceSupport.doStop()

doStop

protected void doStop()
               throws Exception
Description copied from class: ServiceSupport
Implementations override this method to support customized start/stop.

Important: Camel will invoke this ServiceSupport.doStop() method when the service is being stopped. This method will also be invoked if the service is still in uninitialized state (eg has not been started). The method is always called to allow the service to do custom logic when the service is being stopped, such as when CamelContext is shutting down.

Specified by:
doStop in class ServiceSupport
Throws:
Exception
See Also:
ServiceSupport.doStart()

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 - is thrown if error creating the endpoint

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


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)

getAndRemoveOrResolveReferenceParameter

public <T> T getAndRemoveOrResolveReferenceParameter(Map<String,Object> parameters,
                                                     String key,
                                                     Class<T> type)
Gets the parameter and remove it from the parameter map. This method resolves reference parameters in the registry as well.

Parameters:
parameters - the parameters
key - the key
type - the requested type to convert the value from the parameter
Returns:
the converted value parameter

getAndRemoveOrResolveReferenceParameter

public <T> T getAndRemoveOrResolveReferenceParameter(Map<String,Object> parameters,
                                                     String key,
                                                     Class<T> type,
                                                     T defaultValue)
Gets the parameter and remove it from the parameter map. This method resolves reference parameters in the registry as well.

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

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 the registry.
Parameters:
parameters - parameter map.
key - parameter map key.
type - type of object to lookup in the registry.
Returns:
the referenced object or null if the parameter map doesn't contain the key.
Throws:
IllegalArgumentException - if a non-null reference was not found in registry.

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 the registry.
Parameters:
parameters - parameter map.
key - parameter map key.
type - type of object to lookup in the registry.
defaultValue - default value to use if the parameter map doesn't contain the key.
Returns:
the referenced object or the default value.
Throws:
IllegalArgumentException - if referenced object was not found in registry.

resolveAndRemoveReferenceListParameter

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

Parameters:
parameters - parameter map.
key - parameter map key.
elementType - result list element type.
Returns:
the list of referenced objects or an empty list if the parameter map doesn't contain the key.
Throws:
IllegalArgumentException - if any of the referenced objects was not found in registry.
See Also:
EndpointHelper.resolveReferenceListParameter(CamelContext, String, Class)

resolveAndRemoveReferenceListParameter

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

Parameters:
parameters - parameter map.
key - parameter map key.
elementType - result list element type.
defaultValue - default value to use if the parameter map doesn't contain the key.
Returns:
the list of referenced objects or the default value.
Throws:
IllegalArgumentException - if any of the referenced objects was not found in registry.
See Also:
EndpointHelper.resolveReferenceListParameter(CamelContext, String, Class)

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


Apache Camel