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