KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > scriptella > core > ElementInterceptor


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
19 /**
20  * Base class for executable elements interceptors.
21  * <p>Based on Chain-Of-Responsibility (GOF CoR) pattern.
22  * <p>The purpose of this class is to provide an AOP-style approach for adding additional functionality.
23  *
24  * @author Fyodor Kupolov
25  * @version 1.0
26  * @see DynamicContextDecorator
27  */

28 public abstract class ElementInterceptor implements ExecutableElement {
29     private ExecutableElement next;
30     private DynamicContextDecorator ctxDecorator;
31
32     protected ElementInterceptor(ExecutableElement next) {
33         this.next = next;
34     }
35
36     protected ElementInterceptor(ExecutableElement next,
37                                  DynamicContextDecorator ctxDecorator) {
38         this.next = next;
39         this.ctxDecorator = ctxDecorator;
40     }
41
42     protected DynamicContextDecorator getCtxDecorator() {
43         return ctxDecorator;
44     }
45
46     protected ExecutableElement getNext() {
47         return next;
48     }
49
50     /**
51      * Executes next element in the chain.
52      * @param ctx dynamic context.
53      * @see ExecutableElement#execute(DynamicContext)
54      */

55     protected void executeNext(final DynamicContext ctx) {
56         getNext().execute(ctx);
57     }
58 }
59
Popular Tags