KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jasper > compiler > tagplugin > TagPluginContext


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
18 package org.apache.jasper.compiler.tagplugin;
19
20
21 /**
22  * This interface allows the plugin author to make inqueries about the
23  * properties of the current tag, and to use Jasper resources to generate
24  * direct Java codes in place of tag handler invocations.
25  */

26
27 public interface TagPluginContext {
28     /**
29      * @return true if the body of the tag is scriptless.
30      */

31     boolean isScriptless();
32
33     /**
34      * @param attribute Name of the attribute
35      * @return true if the attribute is specified in the tag
36      */

37     boolean isAttributeSpecified(String JavaDoc attribute);
38
39     /**
40      * @return An unique temporary variable name that the plugin can use.
41      */

42     String JavaDoc getTemporaryVariableName();
43
44     /**
45      * Generate an import statement
46      * @param s Name of the import class, '*' allowed.
47      */

48     void generateImport(String JavaDoc s);
49
50     /**
51      * Generate a declaration in the of the generated class. This can be
52      * used to declare an innter class, a method, or a class variable.
53      * @param id An unique ID identifying the declaration. It is not
54      * part of the declaration, and is used to ensure that the
55      * declaration will only appear once. If this method is
56      * invoked with the same id more than once in the translation
57      * unit, only the first declaration will be taken.
58      * @param text The text of the declaration.
59      **/

60     void generateDeclaration(String JavaDoc id, String JavaDoc text);
61
62     /**
63      * Generate Java source codes
64      */

65     void generateJavaSource(String JavaDoc s);
66
67     /**
68      * @return true if the attribute is specified and its value is a
69      * translation-time constant.
70      */

71     boolean isConstantAttribute(String JavaDoc attribute);
72
73     /**
74      * @return A string that is the value of a constant attribute. Undefined
75      * if the attribute is not a (translation-time) constant.
76      * null if the attribute is not specified.
77      */

78     String JavaDoc getConstantAttribute(String JavaDoc attribute);
79
80     /**
81      * Generate codesto evaluate value of a attribute in the custom tag
82      * The codes is a Java expression.
83      * NOTE: Currently cannot handle attributes that are fragments.
84      * @param attribute The specified attribute
85      */

86     void generateAttribute(String JavaDoc attribute);
87
88     /**
89      * Generate codes for the body of the custom tag
90      */

91     void generateBody();
92
93     /**
94      * Abandon optimization for this tag handler, and instruct
95      * Jasper to generate the tag handler calls, as usual.
96      * Should be invoked if errors are detected, or when the tag body
97      * is deemed too compilicated for optimization.
98      */

99     void dontUseTagPlugin();
100
101     /**
102      * Get the PluginContext for the parent of this custom tag. NOTE:
103      * The operations available for PluginContext so obtained is limited
104      * to getPluginAttribute and setPluginAttribute, and queries (e.g.
105      * isScriptless(). There should be no calls to generate*().
106      * @return The pluginContext for the parent node.
107      * null if the parent is not a custom tag, or if the pluginConxt
108      * if not available (because useTagPlugin is false, e.g).
109      */

110     TagPluginContext getParentContext();
111
112     /**
113      * Associate the attribute with a value in the current tagplugin context.
114      * The plugin attributes can be used for communication among tags that
115      * must work together as a group. See <c:when> for an example.
116      */

117     void setPluginAttribute(String JavaDoc attr, Object JavaDoc value);
118
119     /**
120      * Get the value of an attribute in the current tagplugin context.
121      */

122     Object JavaDoc getPluginAttribute(String JavaDoc attr);
123 }
124
125
Popular Tags