Coverage Report - org.apache.camel.builder.BuilderSupport
 
Classes in this File Line Coverage Branch Coverage Complexity
BuilderSupport
34% 
29% 
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.builder;
 18  
 
 19  
 import java.util.ArrayList;
 20  
 import java.util.List;
 21  
 
 22  
 import org.apache.camel.CamelContext;
 23  
 import org.apache.camel.Endpoint;
 24  
 import org.apache.camel.NoSuchEndpointException;
 25  
 import org.apache.camel.processor.LoggingLevel;
 26  
 import org.apache.camel.processor.SendProcessor;
 27  
 import org.apache.commons.logging.Log;
 28  
 import org.apache.commons.logging.LogFactory;
 29  
 
 30  
 /**
 31  
  * Base class for implementation inheritance for different clauses in the <a
 32  
  * href="http://activemq.apache.org/camel/dsl.html">Java DSL</a>
 33  
  * 
 34  
  * @version $Revision: $
 35  
  */
 36  
 public abstract class BuilderSupport {
 37  
     private CamelContext context;
 38  
     private ErrorHandlerBuilder errorHandlerBuilder;
 39  267
     private boolean inheritErrorHandler = true;
 40  
 
 41  267
     protected BuilderSupport(CamelContext context) {
 42  267
         this.context = context;
 43  267
     }
 44  
 
 45  0
     protected BuilderSupport(BuilderSupport parent) {
 46  0
         this.context = parent.getContext();
 47  0
         this.inheritErrorHandler = parent.inheritErrorHandler;
 48  0
         if (inheritErrorHandler && parent.errorHandlerBuilder != null) {
 49  0
             this.errorHandlerBuilder = parent.errorHandlerBuilder.copy();
 50  
         }
 51  0
     }
 52  
 
 53  
     // Builder methods
 54  
     // -------------------------------------------------------------------------
 55  
 
 56  
     /**
 57  
      * Returns a value builder for the given header
 58  
      */
 59  
     public ValueBuilder header(String name) {
 60  90
         return Builder.header(name);
 61  
     }
 62  
 
 63  
     /**
 64  
      * Returns a predicate and value builder for the inbound body on an exchange
 65  
      */
 66  
     public ValueBuilder body() {
 67  12
         return Builder.body();
 68  
     }
 69  
 
 70  
     /**
 71  
      * Returns a predicate and value builder for the inbound message body as a
 72  
      * specific type
 73  
      */
 74  
     public <T> ValueBuilder bodyAs(Class<T> type) {
 75  3
         return Builder.bodyAs(type);
 76  
     }
 77  
 
 78  
     /**
 79  
      * Returns a predicate and value builder for the outbound body on an
 80  
      * exchange
 81  
      */
 82  
     public ValueBuilder outBody() {
 83  0
         return Builder.outBody();
 84  
     }
 85  
 
 86  
     /**
 87  
      * Returns a predicate and value builder for the outbound message body as a
 88  
      * specific type
 89  
      */
 90  
     public <T> ValueBuilder outBody(Class<T> type) {
 91  0
         return Builder.outBody(type);
 92  
     }
 93  
 
 94  
     /**
 95  
      * Returns a value builder for the given system property
 96  
      */
 97  
     public ValueBuilder systemProperty(String name) {
 98  0
         return Builder.systemProperty(name);
 99  
     }
 100  
 
 101  
     /**
 102  
      * Returns a value builder for the given system property
 103  
      */
 104  
     public ValueBuilder systemProperty(String name, String defaultValue) {
 105  0
         return Builder.systemProperty(name, defaultValue);
 106  
     }
 107  
 
 108  
     /**
 109  
      * Resolves the given URI to an endpoint
 110  
      * 
 111  
      * @throws NoSuchEndpointException if the endpoint URI could not be resolved
 112  
      */
 113  
     public Endpoint endpoint(String uri) throws NoSuchEndpointException {
 114  6
         if (uri == null) {
 115  0
             throw new IllegalArgumentException("uri parameter cannot be null");
 116  
         }
 117  6
         Endpoint endpoint = getContext().getEndpoint(uri);
 118  6
         if (endpoint == null) {
 119  0
             throw new NoSuchEndpointException(uri);
 120  
         }
 121  6
         return endpoint;
 122  
     }
 123  
 
 124  
     /**
 125  
      * Resolves the list of URIs into a list of {@link Endpoint} instances
 126  
      * 
 127  
      * @throws NoSuchEndpointException if an endpoint URI could not be resolved
 128  
      */
 129  
     public List<Endpoint> endpoints(String... uris) throws NoSuchEndpointException {
 130  0
         List<Endpoint> endpoints = new ArrayList<Endpoint>();
 131  0
         for (String uri : uris) {
 132  0
             endpoints.add(endpoint(uri));
 133  
         }
 134  0
         return endpoints;
 135  
     }
 136  
 
 137  
     /**
 138  
      * Helper method to create a list of {@link Endpoint} instances
 139  
      */
 140  
     public List<Endpoint> endpoints(Endpoint... endpoints) {
 141  0
         List<Endpoint> answer = new ArrayList<Endpoint>();
 142  0
         for (Endpoint endpoint : endpoints) {
 143  0
             answer.add(endpoint);
 144  
         }
 145  0
         return answer;
 146  
     }
 147  
 
 148  
     /**
 149  
      * Creates a disabled error handler for removing the default error handler
 150  
      */
 151  
     public NoErrorHandlerBuilder noErrorHandler() {
 152  0
         return new NoErrorHandlerBuilder();
 153  
     }
 154  
 
 155  
     /**
 156  
      * Creates an error handler which just logs errors
 157  
      */
 158  
     public LoggingErrorHandlerBuilder loggingErrorHandler() {
 159  0
         return new LoggingErrorHandlerBuilder();
 160  
     }
 161  
 
 162  
     /**
 163  
      * Creates an error handler which just logs errors
 164  
      */
 165  
     public LoggingErrorHandlerBuilder loggingErrorHandler(String log) {
 166  3
         return loggingErrorHandler(LogFactory.getLog(log));
 167  
     }
 168  
 
 169  
     /**
 170  
      * Creates an error handler which just logs errors
 171  
      */
 172  
     public LoggingErrorHandlerBuilder loggingErrorHandler(Log log) {
 173  3
         return new LoggingErrorHandlerBuilder(log);
 174  
     }
 175  
 
 176  
     /**
 177  
      * Creates an error handler which just logs errors
 178  
      */
 179  
     public LoggingErrorHandlerBuilder loggingErrorHandler(Log log, LoggingLevel level) {
 180  0
         return new LoggingErrorHandlerBuilder(log, level);
 181  
     }
 182  
 
 183  
     public DeadLetterChannelBuilder deadLetterChannel() {
 184  0
         return new DeadLetterChannelBuilder();
 185  
     }
 186  
 
 187  
     public DeadLetterChannelBuilder deadLetterChannel(String deadLetterUri) {
 188  6
         return deadLetterChannel(endpoint(deadLetterUri));
 189  
     }
 190  
 
 191  
     public DeadLetterChannelBuilder deadLetterChannel(Endpoint deadLetterEndpoint) {
 192  6
         return new DeadLetterChannelBuilder(new SendProcessor(deadLetterEndpoint));
 193  
     }
 194  
 
 195  
     // Properties
 196  
     // -------------------------------------------------------------------------
 197  
     public CamelContext getContext() {
 198  273
         return context;
 199  
     }
 200  
 
 201  
     public void setContext(CamelContext context) {
 202  267
         this.context = context;
 203  267
     }
 204  
 
 205  
     public ErrorHandlerBuilder getErrorHandlerBuilder() {
 206  0
         if (errorHandlerBuilder == null) {
 207  0
             errorHandlerBuilder = createErrorHandlerBuilder();
 208  
         }
 209  0
         return errorHandlerBuilder;
 210  
     }
 211  
 
 212  
     protected ErrorHandlerBuilder createErrorHandlerBuilder() {
 213  0
         if (isInheritErrorHandler()) {
 214  0
             return new DeadLetterChannelBuilder();
 215  
         } else {
 216  0
             return new NoErrorHandlerBuilder();
 217  
         }
 218  
     }
 219  
 
 220  
     /**
 221  
      * Sets the error handler to use with processors created by this builder
 222  
      */
 223  
     public void setErrorHandlerBuilder(ErrorHandlerBuilder errorHandlerBuilder) {
 224  0
         this.errorHandlerBuilder = errorHandlerBuilder;
 225  0
     }
 226  
 
 227  
     public boolean isInheritErrorHandler() {
 228  0
         return inheritErrorHandler;
 229  
     }
 230  
 
 231  
     public void setInheritErrorHandler(boolean inheritErrorHandler) {
 232  0
         this.inheritErrorHandler = inheritErrorHandler;
 233  0
     }
 234  
 }