KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > scriptella > core > ContentExecutor


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.ContentEl;
19 import scriptella.configuration.Location;
20 import scriptella.configuration.ScriptingElement;
21 import scriptella.spi.DialectIdentifier;
22 import scriptella.spi.Resource;
23
24 /**
25  * Base class for Script/Query executors.
26  *
27  * @author Fyodor Kupolov
28  * @version 1.0
29  */

30 public abstract class ContentExecutor<T extends ScriptingElement> implements ExecutableElement {
31     private Resource cachedContent; //initialized on the first execution
32
private T element;
33
34     /**
35      * Initializes and stores reference to script element.
36      *
37      * @param scriptingElement query or script.
38      */

39     protected ContentExecutor(T scriptingElement) {
40         this.element = scriptingElement;
41     }
42
43     /**
44      * Returns scripting element specified in {@link #ContentExecutor constructor}
45      *
46      * @return scripting element
47      */

48     public T getElement() {
49         return element;
50     }
51
52     /**
53      * Returns content satisfying dialect information.
54      * <p>This method caches contents based on dialects.
55      * For now we assume dialectIdentifier is constant for element.
56      *
57      * @param dialectIdentifier dialect identifier.
58      * @return content for dialect. Not null.
59      */

60     public Resource getContent(DialectIdentifier dialectIdentifier) {
61         if (cachedContent == null) {
62             cachedContent = element.getDialectContent(dialectIdentifier);
63         }
64         if (cachedContent == null) { //avoid double initialization
65
cachedContent = ContentEl.NULL_CONTENT;
66         }
67         return cachedContent;
68
69     }
70
71
72     /**
73      * A short for {@link #getElement()}.{@link scriptella.configuration.ScriptingElement#getLocation() getLocation()}
74      */

75     public Location getLocation() {
76         return getElement().getLocation();
77     }
78 }
79
Popular Tags