1 /* 2 * $Id: AbstractMessageProcessorChainBuilder.java 20320 2010-11-24 15:03:31Z dfeist $ 3 * -------------------------------------------------------------------------------------- 4 * Copyright (c) MuleSoft, Inc. All rights reserved. http://www.mulesoft.com 5 * 6 * The software in this package is published under the terms of the CPAL v1.0 7 * license, a copy of which has been included with this distribution in the 8 * LICENSE.txt file. 9 */ 10 11 package org.mule.processor.chain; 12 13 import org.mule.api.MuleException; 14 import org.mule.api.construct.FlowConstruct; 15 import org.mule.api.processor.MessageProcessor; 16 import org.mule.api.processor.MessageProcessorBuilder; 17 import org.mule.api.processor.MessageProcessorChainBuilder; 18 19 import java.util.ArrayList; 20 import java.util.List; 21 22 /** 23 * <p> 24 * Constructs a chain of {@link MessageProcessor}s and wraps the invocation of the chain in a composite 25 * MessageProcessor. Both MessageProcessors and InterceptingMessageProcessor's can be chained together 26 * arbitrarily in a single chain. InterceptingMessageProcessors simply intercept the next MessageProcessor in 27 * the chain. When other non-intercepting MessageProcessors are used an adapter is used internally to chain 28 * the MessageProcessor with the next in the chain. 29 * </p> 30 * <p> 31 * The MessageProcessor instance that this builder builds can be nested in other chains as required. 32 * </p> 33 */ 34 public abstract class AbstractMessageProcessorChainBuilder implements MessageProcessorChainBuilder 35 { 36 37 protected List processors = new ArrayList(); 38 protected String name; 39 protected FlowConstruct flowConstruct; 40 41 public AbstractMessageProcessorChainBuilder() 42 { 43 // empty 44 } 45 46 public AbstractMessageProcessorChainBuilder(FlowConstruct flowConstruct) 47 { 48 this.flowConstruct = flowConstruct; 49 } 50 51 // Argument is of type Object because it could be a MessageProcessor or a MessageProcessorBuilder 52 protected MessageProcessor initializeMessageProcessor(Object processor) throws MuleException 53 { 54 // TODO DF: FlowConstuct should be injected here but there is an issue with spring not have reference 55 // to it. For now we inject it once the MessageProcessor is built and this works, but 56 // MessageProcessorBuilders should have FlowConstuct available when building really. 57 58 if (processor instanceof MessageProcessorBuilder) 59 { 60 return ((MessageProcessorBuilder) processor).build(); 61 } 62 else 63 { 64 return (MessageProcessor) processor; 65 } 66 } 67 68 public void setName(String name) 69 { 70 this.name = name; 71 } 72 73 }