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