Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||||
EnhancementOperation |
|
| 1.0;1 |
1 | // Copyright 2004, 2005 The Apache Software Foundation |
|
2 | // |
|
3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
|
4 | // you may not use this file except in compliance with the License. |
|
5 | // You may obtain a copy of the License at |
|
6 | // |
|
7 | // http://www.apache.org/licenses/LICENSE-2.0 |
|
8 | // |
|
9 | // Unless required by applicable law or agreed to in writing, software |
|
10 | // distributed under the License is distributed on an "AS IS" BASIS, |
|
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
12 | // See the License for the specific language governing permissions and |
|
13 | // limitations under the License. |
|
14 | ||
15 | package org.apache.tapestry.enhance; |
|
16 | ||
17 | import org.apache.hivemind.Location; |
|
18 | import org.apache.hivemind.service.MethodSignature; |
|
19 | ||
20 | import java.util.List; |
|
21 | ||
22 | /** |
|
23 | * A process object representing enhancements to a component class. The |
|
24 | * operation is passed to {@link org.apache.tapestry.enhance.EnhancementWorker}objects |
|
25 | * that perform enhancements. |
|
26 | * |
|
27 | * @author Howard M. Lewis Ship |
|
28 | * @since 4.0 |
|
29 | */ |
|
30 | public interface EnhancementOperation |
|
31 | { |
|
32 | ||
33 | /** |
|
34 | * Claims a property. Most enhancements are concerned with adding |
|
35 | * properties. Some enhancement workers exist to fill in defaults, and they |
|
36 | * need to know what properties have already been spoken for by eariler |
|
37 | * enhancement works. |
|
38 | * |
|
39 | * @throws org.apache.hivemind.ApplicationRuntimeException |
|
40 | * if the property was previously claimed |
|
41 | */ |
|
42 | ||
43 | void claimProperty(String propertyName); |
|
44 | ||
45 | /** |
|
46 | * Claims a property as read-only. This will check to see if the property |
|
47 | * has an abstract setter method. |
|
48 | * |
|
49 | * @throws org.apache.hivemind.ApplicationRuntimeException |
|
50 | * if the property was previously claimed, or if the property |
|
51 | * includes an accessor method. |
|
52 | */ |
|
53 | ||
54 | void claimReadonlyProperty(String propertyName); |
|
55 | ||
56 | /** |
|
57 | * Checks to see if the specified property can be claimed as read only. |
|
58 | * |
|
59 | * @param propertyName |
|
60 | * The property to check. |
|
61 | * |
|
62 | * @return True, if no setter method has been created for the specified property and |
|
63 | * the property hasn't been claimed by someone else. |
|
64 | */ |
|
65 | boolean canClaimAsReadOnlyProperty(String propertyName); |
|
66 | ||
67 | /** |
|
68 | * Returns a list of the names of existing properties that are not claimed |
|
69 | * and which have abstract accessor methods. |
|
70 | */ |
|
71 | ||
72 | List findUnclaimedAbstractProperties(); |
|
73 | ||
74 | /** |
|
75 | * Adds a field to the enhanced class; the field will be private and use the |
|
76 | * provided name and type. |
|
77 | */ |
|
78 | ||
79 | void addField(String name, Class type); |
|
80 | ||
81 | /** |
|
82 | * Adds a field containing an initial value, which is injected into the |
|
83 | * class via its fabricated constructor. This method may be called multiple |
|
84 | * times with the same value and will return the same variable name (an |
|
85 | * identity map is kept internally). |
|
86 | * |
|
87 | * @param fieldName |
|
88 | * The default name for the field, used if a new field (and |
|
89 | * contructor argument) is being created. Only used if a field |
|
90 | * for the value doesn't exist. |
|
91 | * @param fieldType |
|
92 | * The type of the field to be created. |
|
93 | * @param value |
|
94 | * the value to be referenced, which may not be null |
|
95 | * @return the name of the field containing the value. This may or may not |
|
96 | * match fieldName. The provided fieldName may be modified to |
|
97 | * prevent naming conflicts. |
|
98 | */ |
|
99 | ||
100 | String addInjectedField(String fieldName, Class fieldType, Object value); |
|
101 | ||
102 | /** |
|
103 | * Converts a type name (an object class name, a primtive name, or an array) |
|
104 | * into the corresponding Class object. |
|
105 | */ |
|
106 | ||
107 | Class convertTypeName(String type); |
|
108 | ||
109 | /** |
|
110 | * Confirms that the named property either doesn't exist (in the component |
|
111 | * base class), or that the type of the property exactly matches the |
|
112 | * indicated type. |
|
113 | */ |
|
114 | ||
115 | void validateProperty(String name, Class expectedType); |
|
116 | ||
117 | /** |
|
118 | * Returns the name of the accessor method for the given property (if it |
|
119 | * exists in the component base class), or fabricates a new name if it does |
|
120 | * not. |
|
121 | * |
|
122 | * @param propertyName |
|
123 | * The property to get an accessor method name of. |
|
124 | * |
|
125 | * @return The existing/future name of an appropriate accessor method for the property. |
|
126 | */ |
|
127 | ||
128 | String getAccessorMethodName(String propertyName); |
|
129 | ||
130 | /** |
|
131 | * Adds a method to the enhanced class. |
|
132 | * |
|
133 | * @param modifier |
|
134 | * as defined by {@link java.lang.reflect.Modifier}, typically |
|
135 | * {@link java.lang.reflect.Modifier#PUBLIC} |
|
136 | * @param sig |
|
137 | * the method signature (defining name, return type, etc.) |
|
138 | * @param methodBody |
|
139 | * a Javassist code snippet for the method body |
|
140 | * @param location |
|
141 | * a location used to identify "why" the method was added; the |
|
142 | * location may later be used to describe conflicts. May not be |
|
143 | * null. |
|
144 | */ |
|
145 | void addMethod(int modifier, MethodSignature sig, String methodBody, Location location); |
|
146 | ||
147 | /** |
|
148 | * Returns the base component class, as defined in the specification (or |
|
149 | * defaulted). An enhaced subclass of the component class will usually be |
|
150 | * created. |
|
151 | * |
|
152 | * @return The class this enhancement operation is operating on. |
|
153 | */ |
|
154 | Class getBaseClass(); |
|
155 | ||
156 | /** |
|
157 | * Returns a reference to a particular class. This will, effectively, by the |
|
158 | * name of a private field. |
|
159 | * |
|
160 | * @param clazz The class to get a string equivalent reference of. |
|
161 | * |
|
162 | * @return The enhancement (javassist) compatiable string version of the specified class. |
|
163 | */ |
|
164 | ||
165 | String getClassReference(Class clazz); |
|
166 | ||
167 | /** |
|
168 | * Returns the type of an existing property of the base component class. If |
|
169 | * the property does not exist, then returns null. |
|
170 | * |
|
171 | * @param name |
|
172 | * The property name. |
|
173 | * |
|
174 | * @return The property type, or null if it doesn't exist. |
|
175 | */ |
|
176 | ||
177 | Class getPropertyType(String name); |
|
178 | ||
179 | /** |
|
180 | * Allows for a kind of distributed construction of a particular method, |
|
181 | * within a particular interface. Code can be appended to the method's |
|
182 | * implementation throughout the course of the enhancement operation. When |
|
183 | * the enhanced class is finialized, the method is added with whatever |
|
184 | * contents are in its body. If the base class implements the method, then |
|
185 | * the method body will include an initial call to that implementation. |
|
186 | * <p> |
|
187 | * At this time, this works best for void methods (since there isn't an easy |
|
188 | * way to ensure code would be inserted before a final return statement). |
|
189 | * |
|
190 | * @param interfaceClass |
|
191 | * the interface containing the method. If the base class does |
|
192 | * not implement the interface, then the enhanced class will have |
|
193 | * the interface added. |
|
194 | * @param methodSignature |
|
195 | * the signature of the method to be added. |
|
196 | * @param code |
|
197 | * the Javassist markup to be added to the body of the method. |
|
198 | */ |
|
199 | void extendMethodImplementation(Class interfaceClass, MethodSignature methodSignature, String code); |
|
200 | ||
201 | /** |
|
202 | * Returns true if the class implements the specified interface. Checks the |
|
203 | * base class (as identified in the specification), but <em>also</em> |
|
204 | * accounts for any additional interfaces that may be added by |
|
205 | * {@link #extendMethodImplementation(Class, MethodSignature, String)}. |
|
206 | * |
|
207 | * @param interfaceClass |
|
208 | * The class to check if the base class implements. |
|
209 | * |
|
210 | * @return Whether or not the specified interface is implemented by the base class |
|
211 | * being enhanced. |
|
212 | */ |
|
213 | ||
214 | boolean implementsInterface(Class interfaceClass); |
|
215 | } |