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 */
017 package org.apache.camel.model.language;
018
019 import javax.xml.bind.annotation.XmlAccessType;
020 import javax.xml.bind.annotation.XmlAccessorType;
021 import javax.xml.bind.annotation.XmlAttribute;
022 import javax.xml.bind.annotation.XmlRootElement;
023
024 import org.apache.camel.Expression;
025 import org.apache.camel.Predicate;
026 import org.apache.camel.language.bean.BeanExpression;
027 import org.apache.camel.spi.RouteContext;
028
029 /**
030 * For expressions and predicates using the
031 * <a href="http://camel.apache.org/bean-language.html">bean language</a>
032 *
033 * @version $Revision: 751221 $
034 */
035 @XmlRootElement(name = "method")
036 @XmlAccessorType(XmlAccessType.FIELD)
037 public class MethodCallExpression extends ExpressionDefinition {
038 @XmlAttribute(required = false)
039 private String bean;
040 @XmlAttribute(required = false)
041 private String method;
042
043 public MethodCallExpression() {
044 }
045
046 public MethodCallExpression(String beanName) {
047 super(beanName);
048 }
049
050 public MethodCallExpression(String beanName, String method) {
051 super(beanName);
052 this.method = method;
053 }
054
055 public String getLanguage() {
056 return "bean";
057 }
058
059 public String getMethod() {
060 return method;
061 }
062
063 public void setMethod(String method) {
064 this.method = method;
065 }
066
067 @Override
068 public Expression createExpression(RouteContext routeContext) {
069 return new BeanExpression(beanName(), getMethod());
070 }
071
072 @Override
073 public Predicate createPredicate(RouteContext routeContext) {
074 return new BeanExpression(beanName(), getMethod());
075 }
076
077 protected String beanName() {
078 if (bean != null) {
079 return bean;
080 }
081 return getExpression();
082 }
083
084 @Override
085 public String toString() {
086 return "bean{" + beanName() + (method != null ? ", method=" + method : "") + "}";
087 }
088 }