Java Code Examples for org.apache.camel.CamelContextAware#trySetCamelContext()

The following examples show how to use org.apache.camel.CamelContextAware#trySetCamelContext() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CamelMainSupport.java    From camel-kafka-connector with Apache License 2.0 5 votes vote down vote up
private DataFormat lookupAndInstantiateDataformat(String dataformatName) {
    DataFormat df = camel.resolveDataFormat(dataformatName);

    if (df == null) {
        df = camel.createDataFormat(dataformatName);

        final String prefix = CAMEL_DATAFORMAT_PROPERTIES_PREFIX + dataformatName + ".";
        final Properties props = camel.getPropertiesComponent().loadProperties(k -> k.startsWith(prefix));

        CamelContextAware.trySetCamelContext(df, camel);

        if (!props.isEmpty()) {
            PropertyBindingSupport.build()
                    .withCamelContext(camel)
                    .withOptionPrefix(prefix)
                    .withRemoveParameters(false)
                    .withProperties((Map) props)
                    .withTarget(df)
                    .bind();
        }
    }

    //TODO: move it to the caller?
    if (df == null) {
        throw new UnsupportedOperationException("No DataFormat found with name " + dataformatName);
    }
    return df;
}
 
Example 2
Source File: HandlerCustomizer.java    From syndesis with Apache License 2.0 5 votes vote down vote up
public static void customizeComponent(final CamelContext context, final Connector connector, final ConnectorDescriptor descriptor, final Component component,
    final Map<String, Object> properties) {
    final List<String> customizers = CollectionsUtils.aggregate(ArrayList::new, connector.getConnectorCustomizers(), descriptor.getConnectorCustomizers());

    // Set input/output data shape if the component proxy implements
    // Input/OutputDataShapeAware
    descriptor.getInputDataShape().ifPresent(ds -> trySetInputDataShape(component, ds));
    descriptor.getOutputDataShape().ifPresent(ds -> trySetOutputDataShape(component, ds));

    for (final String customizerType : customizers) {
        final ComponentCustomizer<Component> customizer = resolveCustomizer(context, customizerType);

        // Set the camel context if the customizer implements
        // the CamelContextAware interface.
        CamelContextAware.trySetCamelContext(customizer, context);

        // Set input/output data shape if the customizer implements
        // Input/OutputDataShapeAware
        descriptor.getInputDataShape().ifPresent(ds -> trySetInputDataShape(customizer, ds));
        descriptor.getOutputDataShape().ifPresent(ds -> trySetOutputDataShape(customizer, ds));

        // Try to set properties to the component
        setProperties(context, customizer, properties);

        // Invoke the customizer
        customizer.customize(component, properties);
    }
}