Coverage Report - org.apache.camel.model.language.ExpressionType
 
Classes in this File Line Coverage Branch Coverage Complexity
ExpressionType
66% 
100% 
0
 
 1  
 /**
 2  
  * Licensed to the Apache Software Foundation (ASF) under one or more
 3  
  * contributor license agreements.  See the NOTICE file distributed with
 4  
  * this work for additional information regarding copyright ownership.
 5  
  * The ASF licenses this file to You under the Apache License, Version 2.0
 6  
  * (the "License"); you may not use this file except in compliance with
 7  
  * the License.  You may obtain a copy of the License at
 8  
  *
 9  
  *      http://www.apache.org/licenses/LICENSE-2.0
 10  
  *
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 package org.apache.camel.model.language;
 18  
 
 19  
 import javax.xml.bind.annotation.XmlAccessType;
 20  
 import javax.xml.bind.annotation.XmlAccessorType;
 21  
 import javax.xml.bind.annotation.XmlAttribute;
 22  
 import javax.xml.bind.annotation.XmlID;
 23  
 import javax.xml.bind.annotation.XmlTransient;
 24  
 import javax.xml.bind.annotation.XmlType;
 25  
 import javax.xml.bind.annotation.XmlValue;
 26  
 import javax.xml.bind.annotation.adapters.CollapsedStringAdapter;
 27  
 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
 28  
 
 29  
 import org.apache.camel.CamelContext;
 30  
 import org.apache.camel.Exchange;
 31  
 import org.apache.camel.Expression;
 32  
 import org.apache.camel.Predicate;
 33  
 import org.apache.camel.impl.RouteContext;
 34  
 import org.apache.camel.spi.Language;
 35  
 
 36  
 /**
 37  
  * A useful base class for an expression
 38  
  *
 39  
  * @version $Revision: 1.1 $
 40  
  */
 41  
 @XmlType(name = "expressionType")
 42  
 @XmlAccessorType(XmlAccessType.FIELD)
 43  
 public class ExpressionType {
 44  
     @XmlAttribute
 45  
     @XmlJavaTypeAdapter(CollapsedStringAdapter.class)
 46  
     @XmlID
 47  
     private String id;
 48  
     @XmlValue
 49  
     private String expression;
 50  
     @XmlTransient
 51  
     private Predicate predicate;
 52  
     @XmlTransient
 53  
     private Expression expressionValue;
 54  
 
 55  27
     public ExpressionType() {
 56  27
     }
 57  
 
 58  3
     public ExpressionType(String expression) {
 59  3
         this.expression = expression;
 60  3
     }
 61  
 
 62  93
     public ExpressionType(Predicate predicate) {
 63  93
         this.predicate = predicate;
 64  93
     }
 65  
 
 66  24
     public ExpressionType(Expression expression) {
 67  24
         this.expressionValue = expression;
 68  24
     }
 69  
 
 70  
     @Override
 71  
     public String toString() {
 72  129
         return getLanguage() + "Expression[" + getExpression() + "]";
 73  
     }
 74  
 
 75  
     public String getLanguage() {
 76  0
         return "";
 77  
     }
 78  
 
 79  
     public Predicate<Exchange> createPredicate(RouteContext route) {
 80  93
         if (predicate == null) {
 81  0
             CamelContext camelContext = route.getCamelContext();
 82  0
             Language language = camelContext.resolveLanguage(getLanguage());
 83  0
             predicate = language.createPredicate(getExpression());
 84  
         }
 85  93
         return predicate;
 86  
     }
 87  
 
 88  
     public Expression createExpression(RouteContext routeContext) {
 89  24
         if (expressionValue == null) {
 90  0
             CamelContext camelContext = routeContext.getCamelContext();
 91  0
             Language language = camelContext.resolveLanguage(getLanguage());
 92  0
             expressionValue = language.createExpression(getExpression());
 93  
         }
 94  24
         return expressionValue;
 95  
     }
 96  
 
 97  
     public String getExpression() {
 98  147
         return expression;
 99  
     }
 100  
 
 101  
     public void setExpression(String expression) {
 102  3
         this.expression = expression;
 103  3
     }
 104  
 
 105  
     /**
 106  
      * Gets the value of the id property.
 107  
      *
 108  
      * @return possible object is
 109  
      *         {@link String }
 110  
      */
 111  
     public String getId() {
 112  0
         return id;
 113  
     }
 114  
 
 115  
     /**
 116  
      * Sets the value of the id property.
 117  
      *
 118  
      * @param value allowed object is
 119  
      *              {@link String }
 120  
      */
 121  
     public void setId(String value) {
 122  0
         this.id = value;
 123  0
     }
 124  
 }