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