/*
 * Copyright 2009 the original author or authors.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *     
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.openehealth.ipf.platform.camel.core.model;

import java.util.ArrayList;
import java.util.List;

import org.apache.camel.Processor;
import org.apache.camel.model.OutputType;
import org.apache.camel.model.ProcessorType;
import org.apache.camel.processor.Pipeline;
import org.apache.camel.spi.RouteContext;

/**
 * @author Martin Krasser
 */
public abstract class DelegateType extends OutputType<ProcessorType> {

    @Override
    public Processor createProcessor(RouteContext routeContext) throws Exception {
        Processor delegate = doCreateDelegate(routeContext);
        Processor next = routeContext.createProcessor(this);
        
        List<Processor> processors = new ArrayList<Processor>();
        processors.add(delegate);
        if (next != null) {
            processors.add(next);
        }
        return Pipeline.newInstance(processors);
    }
    
    protected abstract Processor doCreateDelegate(RouteContext routeContext);
    
}

@@ -863,24 +863,78 @@
 essorType;%0D%0A
+import org.apache.camel.processor.DelegateProcessor;%0D%0A
 import org.a
@@ -1016,16 +1016,543 @@
 %0A%0D%0A/**%0D%0A
+ * An %7B@link OutputType%7D that combines the %7B@link Processor%7D created by%0D%0A * %7B@link #doCreateDelegate(RouteContext)%7D and the child processor created by%0D%0A * %7B@link RouteContext#createProcessor(ProcessorType)%7D into a %7B@link Pipeline%7D.%0D%0A * This base class supports the implementation of parameterizable DSL extensions%0D%0A * without forcing implementors to create %7B@link DelegateProcessor%7D instances.%0D%0A * Instead, plain %7B@link Processor%7D instances can be returned by%0D%0A * %7B@link #doCreateDelegate(RouteContext)%7D implementations.%0D%0A * %0D%0A
  * @auth
@@ -2115,20 +2115,247 @@
 %0A    %7D%0D%0A
+%0D%0A
     
+/**%0D%0A     * Creates a %7B@link Processor%7D for this DSL element.%0D%0A     * %0D%0A     * @param routeContext%0D%0A     *            the current route context.%0D%0A     * @return a %7B@link Processor%7D instance.%0D%0A     * @throws Exception%0D%0A     */
 %0D%0A    pr
@@ -2420,24 +2420,41 @@
 outeContext)
+ throws Exception
 ;%0D%0A    %0D%0A%7D%0D%0A

allow doCreateDelegate implementors to throw checked exceptions.