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.builder.ExpressionBuilder; 026import org.apache.camel.model.language.ExpressionDefinition; 027import org.apache.camel.spi.Metadata; 028 029/** 030 * Sets a named property on the message exchange 031 */ 032@Metadata(label = "eip,transformation") 033@XmlRootElement(name = "setProperty") 034@XmlAccessorType(XmlAccessType.FIELD) 035public class SetPropertyDefinition extends NoOutputExpressionNode { 036 @XmlAttribute(required = true) 037 private String propertyName; 038 039 public SetPropertyDefinition() { 040 } 041 042 public SetPropertyDefinition(String propertyName, ExpressionDefinition expression) { 043 super(expression); 044 setPropertyName(propertyName); 045 } 046 047 public SetPropertyDefinition(String propertyName, Expression expression) { 048 super(expression); 049 setPropertyName(propertyName); 050 } 051 052 public SetPropertyDefinition(String propertyName, String value) { 053 super(ExpressionBuilder.constantExpression(value)); 054 setPropertyName(propertyName); 055 } 056 057 @Override 058 public String toString() { 059 return "SetProperty[" + getPropertyName() + ", " + getExpression() + "]"; 060 } 061 062 @Override 063 public String getShortName() { 064 return "setProperty"; 065 } 066 067 @Override 068 public String getLabel() { 069 return "setProperty[" + getPropertyName() + "]"; 070 } 071 072 /** 073 * Expression to return the value of the message exchange property 074 */ 075 @Override 076 public void setExpression(ExpressionDefinition expression) { 077 // override to include javadoc what the expression is used for 078 super.setExpression(expression); 079 } 080 081 /** 082 * Name of exchange property to set a new value. 083 * <p/> 084 * The <tt>simple</tt> language can be used to define a dynamic evaluated exchange property name to be used. 085 * Otherwise a constant name will be used. 086 */ 087 public void setPropertyName(String propertyName) { 088 this.propertyName = propertyName; 089 } 090 091 public String getPropertyName() { 092 return propertyName; 093 } 094 095}