Coverage Report - org.apache.camel.model.RoutesType
 
Classes in this File Line Coverage Branch Coverage Complexity
RoutesType
74% 
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;
 18  
 
 19  
 import java.util.ArrayList;
 20  
 import java.util.List;
 21  
 
 22  
 import javax.xml.bind.annotation.XmlAccessType;
 23  
 import javax.xml.bind.annotation.XmlAccessorType;
 24  
 import javax.xml.bind.annotation.XmlAttribute;
 25  
 import javax.xml.bind.annotation.XmlElementRef;
 26  
 import javax.xml.bind.annotation.XmlRootElement;
 27  
 import javax.xml.bind.annotation.XmlTransient;
 28  
 
 29  
 import org.apache.camel.CamelContext;
 30  
 import org.apache.camel.Endpoint;
 31  
 import org.apache.camel.Route;
 32  
 import org.apache.camel.Predicate;
 33  
 import org.apache.camel.processor.DelegateProcessor;
 34  
 
 35  
 /**
 36  
  * Represents a collection of routes
 37  
  *
 38  
  * @version $Revision: $
 39  
  */
 40  
 @XmlRootElement(name = "routes")
 41  
 @XmlAccessorType(XmlAccessType.FIELD)
 42  306
 public class RoutesType implements RouteContainer {
 43  
     
 44  
     // TODO: not sure how else to use an optional attribute in JAXB2
 45  
     @XmlAttribute
 46  306
     private Boolean inheritErrorHandlerFlag = Boolean.TRUE; 
 47  
     @XmlElementRef
 48  306
     private List<RouteType> routes = new ArrayList<RouteType>();
 49  
     @XmlTransient
 50  306
     private List<InterceptorType> interceptors = new ArrayList<InterceptorType>();
 51  
     @XmlTransient
 52  306
     private List<InterceptType> intercepts = new ArrayList<InterceptType>();
 53  
     @XmlTransient
 54  306
     private List<ExceptionType> exceptions = new ArrayList<ExceptionType>();
 55  
     @XmlTransient
 56  
     private CamelContext camelContext;
 57  
 
 58  
     @Override
 59  
     public String toString() {
 60  66
         return "Routes: " + routes;
 61  
     }
 62  
 
 63  
     public void populateRoutes(List<Route> answer) throws Exception {
 64  267
         for (RouteType route : routes) {
 65  267
             route.addRoutes(camelContext, answer);
 66  264
         }
 67  264
     }
 68  
 
 69  
     // Properties
 70  
     //-----------------------------------------------------------------------
 71  
     public List<RouteType> getRoutes() {
 72  306
         return routes;
 73  
     }
 74  
 
 75  
     public void setRoutes(List<RouteType> routes) {
 76  0
         this.routes = routes;
 77  0
     }
 78  
 
 79  
     public List<InterceptorType> getInterceptors() {
 80  273
         return interceptors;
 81  
     }
 82  
 
 83  
     public void setInterceptors(List<InterceptorType> interceptors) {
 84  0
         this.interceptors = interceptors;
 85  0
     }
 86  
 
 87  
     public List<InterceptType> getIntercepts() {
 88  297
         return intercepts;
 89  
     }
 90  
 
 91  
     public void setIntercepts(List<InterceptType> intercepts) {
 92  0
         this.intercepts = intercepts;
 93  0
     }
 94  
 
 95  
     public List<ExceptionType> getExceptions() {
 96  291
         return exceptions;
 97  
     }
 98  
 
 99  
     public void setExceptions(List<ExceptionType> exceptions) {
 100  0
         this.exceptions = exceptions;
 101  0
     }
 102  
 
 103  
     public CamelContext getCamelContext() {
 104  273
         return camelContext;
 105  
     }
 106  
 
 107  
     public void setCamelContext(CamelContext camelContext) {
 108  267
         this.camelContext = camelContext;
 109  267
     }
 110  
 
 111  
     public Boolean getInheritErrorHandlerFlag() {
 112  273
         return inheritErrorHandlerFlag;
 113  
     }
 114  
 
 115  
     public void setInheritErrorHandlerFlag(Boolean inheritErrorHandlerFlag) {
 116  0
         this.inheritErrorHandlerFlag = inheritErrorHandlerFlag;
 117  0
     }
 118  
 
 119  
     // Fluent API
 120  
     //-------------------------------------------------------------------------
 121  
 
 122  
     /**
 123  
      * Creates a new route
 124  
      */
 125  
     public RouteType route() {
 126  6
         RouteType route = new RouteType();
 127  6
         return route(route);
 128  
     }
 129  
 
 130  
     /**
 131  
      * Creates a new route from the given URI input
 132  
      */
 133  
     public RouteType from(String uri) {
 134  267
         RouteType route = new RouteType(uri);
 135  267
         return route(route);
 136  
     }
 137  
 
 138  
     /**
 139  
      * Creates a new route from the given endpoint
 140  
      */
 141  
     public RouteType from(Endpoint endpoint) {
 142  0
         RouteType route = new RouteType(endpoint);
 143  0
         return route(route);
 144  
     }
 145  
 
 146  
     public RouteType route(RouteType route) {
 147  
         // lets configure the route
 148  273
         route.setCamelContext(getCamelContext());
 149  273
         route.setInheritErrorHandlerFlag(getInheritErrorHandlerFlag());
 150  273
         route.getInterceptors().addAll(getInterceptors());
 151  273
         route.getOutputs().addAll(getIntercepts());
 152  273
         route.getOutputs().addAll(getExceptions());
 153  273
         getRoutes().add(route);
 154  273
         return route;
 155  
     }
 156  
 
 157  
     public RoutesType intercept(DelegateProcessor interceptor) {
 158  0
         getInterceptors().add(new InterceptorRef(interceptor));
 159  0
         return this;
 160  
     }
 161  
     
 162  
     public InterceptType intercept() {
 163  12
         InterceptType answer = new InterceptType();
 164  12
         getIntercepts().add(answer);
 165  12
         return answer;
 166  
     }
 167  
 
 168  
     public OtherwiseType intercept(Predicate predicate) {
 169  12
         InterceptType answer = new InterceptType();
 170  12
         getIntercepts().add(answer);
 171  12
         return answer.when(predicate);
 172  
     }
 173  
 
 174  
     public ExceptionType exception(Class exceptionType) {
 175  18
         ExceptionType answer = new ExceptionType(exceptionType);
 176  18
         getExceptions().add(answer);
 177  18
         return answer;
 178  
     }
 179  
 }