Coverage Report - org.apache.camel.bam.TimeExpression
 
Classes in this File Line Coverage Branch Coverage Complexity
TimeExpression
78% 
50% 
1.2
 
 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 org.apache.camel.bam.model.ActivityState;
 20  
 import org.apache.camel.bam.model.ProcessInstance;
 21  
 import org.apache.camel.bam.rules.ActivityRules;
 22  
 import org.apache.camel.bam.rules.TemporalRule;
 23  
 import org.apache.camel.util.ObjectHelper;
 24  
 
 25  
 import java.util.Date;
 26  
 
 27  
 /**
 28  
  * @version $Revision: $
 29  
  */
 30  
 public abstract class TimeExpression {
 31  
     private ActivityRules activityRules;
 32  
     private ActivityBuilder builder;
 33  
     private ActivityLifecycle lifecycle;
 34  
 
 35  2
     public TimeExpression(ActivityBuilder builder, ActivityLifecycle lifecycle) {
 36  2
         this.lifecycle = lifecycle;
 37  2
         this.builder = builder;
 38  2
         this.activityRules = builder.getActivityRules();
 39  2
     }
 40  
 
 41  
     public boolean isActivityLifecycle(ActivityRules activityRules, ActivityLifecycle lifecycle) {
 42  0
         return ObjectHelper.equals(activityRules, this.activityRules) && ObjectHelper.equals(lifecycle, this.lifecycle);
 43  
     }
 44  
 
 45  
     /**
 46  
      * Creates a new temporal rule on this expression and the other expression
 47  
      */
 48  
     public TemporalRule after(TimeExpression expression) {
 49  1
         TemporalRule rule = new TemporalRule(expression, this);
 50  1
         rule.getSecond().getActivityRules().addRule(rule);
 51  1
         return rule;
 52  
     }
 53  
 
 54  
     public Date evaluate(ProcessInstance processInstance) {
 55  1
         ActivityState state = processInstance.getActivityState(activityRules);
 56  1
         if (state != null) {
 57  1
             return evaluate(processInstance, state);
 58  
         }
 59  0
         return null;
 60  
     }
 61  
 
 62  
     public abstract Date evaluate(ProcessInstance instance, ActivityState state);
 63  
 
 64  
     // Properties
 65  
     //-------------------------------------------------------------------------
 66  
 
 67  
     public ActivityBuilder getBuilder() {
 68  2
         return builder;
 69  
     }
 70  
 
 71  
     public ActivityRules getActivityRules() {
 72  1
         return activityRules;
 73  
     }
 74  
 
 75  
     public ActivityLifecycle getLifecycle() {
 76  0
         return lifecycle;
 77  
     }
 78  
 
 79  
     public ActivityState getActivityState(ProcessInstance instance) {
 80  0
         return instance.getActivityState(activityRules);
 81  
     }
 82  
 
 83  
     public ActivityState getOrCreateActivityState(ProcessInstance instance) {
 84  1
         return instance.getOrCreateActivityState(activityRules);
 85  
     }
 86  
 }