001 /**
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017 package org.apache.camel.spi;
018
019 import org.apache.camel.Processor;
020 import org.apache.camel.model.ProcessorDefinition;
021
022 /**
023 * A factory to create {@link Processor} based on the {@link org.apache.camel.model.ProcessorDefinition definition}.
024 * <p/>
025 * This allows you to implement a custom factory in which you can control the creation of the processors.
026 * It also allows you to manipulate the {@link org.apache.camel.model.ProcessorDefinition definition}s for example to
027 * configure or change options. Its also possible to add new steps in the route by adding outputs to
028 * {@link org.apache.camel.model.ProcessorDefinition definition}s.
029 * <p/>
030 * <b>Important:</b> By returning <tt>null</tt> from the create methods you fallback to let the default implementation in Camel create
031 * the {@link Processor}. You want to do this if you <i>only</i> want to manipulate the
032 * {@link org.apache.camel.model.ProcessorDefinition definition}s.
033 *
034 * @version
035 */
036 public interface ProcessorFactory {
037
038 /**
039 * Creates the child processor.
040 * <p/>
041 * The child processor is an output from the given definition, for example the sub route in a splitter EIP.
042 *
043 * @param routeContext the route context
044 * @param definition the definition which represents the processor
045 * @param mandatory whether or not the child is mandatory
046 * @return the created processor, or <tt>null</tt> to let the default implementation in Camel create the processor.
047 * @throws Exception can be thrown if error creating the processor
048 */
049 Processor createChildProcessor(RouteContext routeContext, ProcessorDefinition<?> definition, boolean mandatory) throws Exception;
050
051 /**
052 * Creates the processor.
053 *
054 * @param routeContext the route context
055 * @param definition the definition which represents the processor
056 * @return the created processor, or <tt>null</tt> to let the default implementation in Camel create the processor.
057 * @throws Exception can be thrown if error creating the processor
058 */
059 Processor createProcessor(RouteContext routeContext, ProcessorDefinition<?> definition) throws Exception;
060
061 }