/**
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You 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.apache.camel.processor;

import org.apache.camel.AsyncProcessor;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.spi.RouteContext;
import org.apache.camel.spi.UnitOfWork;

/**
 * An {@link UnitOfWorkProcessor} that creates a child {@link UnitOfWork} that is
 * associated to a parent {@link UnitOfWork}.
 *
 * @see SubUnitOfWorkProcessor
 * @see org.apache.camel.spi.UnitOfWorkCallback
 */
public class ChildUnitOfWorkProcessor extends UnitOfWorkProcessor {

    private final UnitOfWork parent;

    public ChildUnitOfWorkProcessor(UnitOfWork parent, Processor processor) {
        super(processor);
        this.parent = parent;
    }

    public ChildUnitOfWorkProcessor(UnitOfWork parent, AsyncProcessor processor) {
        super(processor);
        this.parent = parent;
    }

    public ChildUnitOfWorkProcessor(UnitOfWork parent, RouteContext routeContext, Processor processor) {
        super(routeContext, processor);
        this.parent = parent;
    }

    public ChildUnitOfWorkProcessor(UnitOfWork parent, RouteContext routeContext, AsyncProcessor processor) {
        super(routeContext, processor);
        this.parent = parent;
    }

    @Override
    protected UnitOfWork createUnitOfWork(Exchange exchange) {
        // let the parent create a child unit of work to be used
        return parent.createChildUnitOfWork(exchange);
    }

}
