KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > scriptella > core > StatisticInterceptor


1 /*
2  * Copyright 2006-2007 The Scriptella Project Team.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package scriptella.core;
17
18 import scriptella.configuration.Location;
19 import scriptella.execution.ExecutionStatisticsBuilder;
20
21
22 /**
23  * Collects execution statistics.
24  *
25  * @author Fyodor Kupolov
26  * @version 1.0
27  */

28 public class StatisticInterceptor extends ElementInterceptor {
29     private Location location;
30
31     public StatisticInterceptor(ExecutableElement next, Location location) {
32         super(next);
33         this.location = location;
34     }
35
36     public void execute(final DynamicContext ctx) {
37         boolean ok = false;
38         final ExecutionStatisticsBuilder statisticsBuilder = ctx.getGlobalContext().getStatisticsBuilder();
39         try {
40             statisticsBuilder.elementStarted(location, ctx.getConnection());
41             executeNext(ctx);
42             ok = true;
43         } finally {
44             if (ok) {
45                 statisticsBuilder.elementExecuted();
46             } else {
47                 statisticsBuilder.elementFailed();
48             }
49         }
50
51     }
52
53     public static ExecutableElement prepare(
54             final ExecutableElement next, final Location location) {
55         return new StatisticInterceptor(next, location);
56     }
57
58
59 }
60
Popular Tags