Interface RouteTemplateContext

All Superinterfaces:
HasCamelContext

public interface RouteTemplateContext extends HasCamelContext
Contextual environment provided to a route template while it is being instantiated into a concrete Route.

A route template is a parameterized route blueprint registered in the CamelContext. When the template is instantiated (for example by a Kamelet), the framework creates a RouteTemplateContext that carries the parameter bindings and a local bean repository. Template beans (RouteTemplateContext.BeanSupplier) declared inside the template are resolved through this context rather than the global registry, so each instantiation gets its own private set of beans.

Implementors provide this context to the template engine; application developers typically interact with it only when writing custom RouteTemplateParameterSource or Kamelet binding code.

Since:
3.10
See Also:
  • Method Details

    • bind

      default void bind(String id, Object bean)
      Binds the bean to the repository (if possible). If the bean is CamelContextAware then the registry will automatically inject the context if possible.
      Parameters:
      id - the id of the bean
      bean - the bean
    • bind

      void bind(String id, Class<?> type, Object bean)
      Binds the bean to the repository (if possible).

      Binding by id and type allows to bind multiple entries with the same id but with different type. If the bean is CamelContextAware then the registry will automatically inject the context if possible.

      Parameters:
      id - the id of the bean
      type - the type of the bean to associate the binding
      bean - the bean
    • bind

      void bind(String id, Class<?> type, Supplier<Object> bean)
      Binds the bean (via a supplier) to the repository (if possible).

      Camel will cache the result from the supplier from first lookup (singleton scope). If you do not need cached then use bindAsPrototype(String, Class, Supplier) instead.

      Binding by id and type allows to bind multiple entries with the same id but with different type. If the bean is CamelContextAware then the registry will automatically inject the context if possible.

      Parameters:
      id - the id of the bean
      type - the type of the bean to associate the binding
      bean - a supplier for the bean
    • bindAsPrototype

      void bindAsPrototype(String id, Class<?> type, Supplier<Object> bean)
      Binds the bean (via a supplier) to the repository (if possible).

      Notice that the supplier will be called each time the bean is being looked up (not cached).

      Binding by id and type allows to bind multiple entries with the same id but with different type. If the bean is CamelContextAware then the registry will automatically inject the context if possible.

      Parameters:
      id - the id of the bean
      type - the type of the bean to associate the binding
      bean - a supplier for the bean
    • registerDestroyMethod

      void registerDestroyMethod(String id, String method)
      Registers an optional destroy method to invoke on the bean when stopping Camel.
      Parameters:
      id - the id of the bean
      method - the destroy method name
    • getProperty

      @Nullable Object getProperty(String name)
      Gets the property with the given name
      Parameters:
      name - name of property
      Returns:
      the property value or null if no property exists
    • getEnvironmentVariable

      @Nullable Object getEnvironmentVariable(String name)
      Gets the environment variable parameter that matches the given property name. The match is performed by normalizing the given property name as an OS environment variable name. The environment variable name may use pure uppercase or camelCase converted to underscore property names. As an example bucketNameOrArn property matches BUCKETNAMEORARN and BUCKET_NAME_OR_ARN environment variables.
      Parameters:
      name - name of property
      Returns:
      the property value or null if no property exists
    • getProperty

      <T> @Nullable T getProperty(String name, Class<?> type)
      Gets the property with the given name
      Parameters:
      name - name of property
      type - the type of the property
      Returns:
      the property value or null if no property exists
      Throws:
      TypeConversionException - is thrown if error during type conversion
    • setParameter

      void setParameter(String name, Object value)
      Sets a parameter
      Parameters:
      name - the parameter name
      value - the parameter value
    • getParameters

      Map<String,Object> getParameters()
      The parameters to use for the route template when creating the new route
    • hasParameter

      boolean hasParameter(String name)
      Whether the route template has a parameter with the given name
      Parameters:
      name - the parameter name
      Returns:
      true if exists
    • hasEnvironmentVariable

      boolean hasEnvironmentVariable(String name)
      Whether the route template has an environment variable parameter that matches the given parameter name. The match is performed by normalizing the given name as an OS environment variable name. The environment variable name may use pure uppercase or camelCase converted to underscore property names. As an example bucketNameOrArn property matches BUCKETNAMEORARN and BUCKET_NAME_OR_ARN environment variables.
      Parameters:
      name - the parameter name
      Returns:
      true if exists
    • getLocalBeanRepository

      BeanRepository getLocalBeanRepository()
      Gets the local bean repository for the route template when creating the new route
    • setConfigurer

      void setConfigurer(@Nullable Consumer<RouteTemplateContext> configurer)
      Sets a custom configurer which allows to do configuration while the route template is being used to create a route. This gives control over the creating process, such as binding local beans and doing other kind of customization.
      Parameters:
      configurer - the configurer with callback to invoke with the given route template context
    • getConfigurer

      @Nullable Consumer<RouteTemplateContext> getConfigurer()
      Gets the custom configurer.