Coverage Report - org.apache.camel.bam.ActivityBuilder
 
Classes in this File Line Coverage Branch Coverage Complexity
ActivityBuilder
92% 
100% 
1.154
 
 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.bam;
 18  
 
 19  
 import java.util.Date;
 20  
 
 21  
 import org.apache.camel.Endpoint;
 22  
 import org.apache.camel.Expression;
 23  
 import org.apache.camel.Processor;
 24  
 import org.apache.camel.Route;
 25  
 import org.apache.camel.bam.model.ActivityState;
 26  
 import org.apache.camel.bam.model.ProcessInstance;
 27  
 import org.apache.camel.bam.rules.ActivityRules;
 28  
 import org.apache.camel.builder.ProcessorFactory;
 29  
 import org.apache.camel.impl.EventDrivenConsumerRoute;
 30  
 
 31  
 /**
 32  
  * @version $Revision: $
 33  
  */
 34  
 public class ActivityBuilder implements ProcessorFactory {
 35  
     private ProcessBuilder processBuilder;
 36  
     private Endpoint endpoint;
 37  
     private ActivityRules activityRules;
 38  
     private Expression correlationExpression;
 39  
 
 40  4
     public ActivityBuilder(ProcessBuilder processBuilder, Endpoint endpoint) {
 41  4
         this.processBuilder = processBuilder;
 42  4
         this.endpoint = endpoint;
 43  4
         this.activityRules = new ActivityRules(processBuilder);
 44  4
         this.activityRules.setActivityName(endpoint.getEndpointUri());
 45  4
     }
 46  
 
 47  
     public Endpoint getEndpoint() {
 48  4
         return endpoint;
 49  
     }
 50  
 
 51  
     public Processor createProcessor() throws Exception {
 52  4
         return processBuilder.createActivityProcessor(this);
 53  
     }
 54  
 
 55  
     public Route createRoute() throws Exception {
 56  4
         Processor processor = createProcessor();
 57  4
         if (processor == null) {
 58  0
             throw new IllegalArgumentException("No processor created for ActivityBuilder: " + this);
 59  
         }
 60  4
         return new EventDrivenConsumerRoute(getEndpoint(), processor);
 61  
     }
 62  
 
 63  
     // Builder methods
 64  
     //-----------------------------------------------------------------------
 65  
     public ActivityBuilder correlate(Expression correlationExpression) {
 66  4
         this.correlationExpression = correlationExpression;
 67  4
         return this;
 68  
     }
 69  
 
 70  
     public ActivityBuilder name(String name) {
 71  4
         activityRules.setActivityName(name);
 72  4
         return this;
 73  
     }
 74  
 
 75  
     /**
 76  
      * Create a temporal rule for when this step starts
 77  
      */
 78  
     public TimeExpression starts() {
 79  2
         return new TimeExpression(this, ActivityLifecycle.Started) {
 80  2
             public Date evaluate(ProcessInstance instance, ActivityState state) {
 81  0
                 return state.getTimeStarted();
 82  
             }
 83  
         };
 84  
     }
 85  
 
 86  
     /**
 87  
      * Create a temporal rule for when this step completes
 88  
      */
 89  
     public TimeExpression completes() {
 90  2
         return new TimeExpression(this, ActivityLifecycle.Completed) {
 91  2
             public Date evaluate(ProcessInstance instance, ActivityState state) {
 92  6
                 return state.getTimeCompleted();
 93  
             }
 94  
         };
 95  
     }
 96  
 
 97  
     // Properties
 98  
     //-----------------------------------------------------------------------
 99  
     public Expression getCorrelationExpression() {
 100  4
         return correlationExpression;
 101  
     }
 102  
 
 103  
     public ActivityRules getActivityRules() {
 104  8
         return activityRules;
 105  
     }
 106  
 
 107  
     public ProcessBuilder getProcessBuilder() {
 108  4
         return processBuilder;
 109  
     }
 110  
 }