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 */
017package org.apache.camel.model;
018
019import javax.xml.bind.annotation.XmlAccessType;
020import javax.xml.bind.annotation.XmlAccessorType;
021import javax.xml.bind.annotation.XmlAttribute;
022import javax.xml.bind.annotation.XmlRootElement;
023
024import org.apache.camel.Expression;
025import org.apache.camel.Processor;
026import org.apache.camel.builder.ProcessorBuilder;
027import org.apache.camel.model.language.ExpressionDefinition;
028import org.apache.camel.spi.Metadata;
029import org.apache.camel.spi.RouteContext;
030import org.apache.camel.util.ObjectHelper;
031
032/**
033 * Sets the value of a header on the outbound message
034 *
035 * @deprecated not really needed, will be removed in the future
036 */
037@Metadata(label = "eip,transformation")
038@XmlRootElement(name = "setOutHeader")
039@XmlAccessorType(XmlAccessType.FIELD)
040@Deprecated
041public class SetOutHeaderDefinition extends NoOutputExpressionNode {
042    @XmlAttribute(required = true)
043    private String headerName;
044    
045    public SetOutHeaderDefinition() {
046    }
047
048    public SetOutHeaderDefinition(String headerName, ExpressionDefinition expression) {
049        super(expression);
050        setHeaderName(headerName);
051    }
052
053    public SetOutHeaderDefinition(String headerName, Expression expression) {
054        super(expression);
055        setHeaderName(headerName);        
056    }
057
058    @Override
059    public String toString() {
060        return "SetOutHeader[" + getHeaderName() + ", " + getExpression() + "]";
061    }
062    
063    @Override
064    public String getLabel() {
065        return "setOutHeader[" + getHeaderName() + "]";
066    }
067
068    @Override
069    public Processor createProcessor(RouteContext routeContext) throws Exception {
070        ObjectHelper.notNull(getHeaderName(), "headerName", this);
071        Expression expr = getExpression().createExpression(routeContext);
072        return ProcessorBuilder.setOutHeader(getHeaderName(), expr);
073    }
074
075    /**
076     * Expression to return the value of the header
077     */
078    @Override
079    public void setExpression(ExpressionDefinition expression) {
080        // override to include javadoc what the expression is used for
081        super.setExpression(expression);
082    }
083
084    /**
085     * Name of message header to set a new value
086     */
087    public void setHeaderName(String headerName) {
088        this.headerName = headerName;
089    }
090
091    public String getHeaderName() {
092        return headerName;
093    }
094    
095}