01: // Copyright 2007 The Apache Software Foundation
02: //
03: // Licensed under the Apache License, Version 2.0 (the "License");
04: // you may not use this file except in compliance with the License.
05: // You may obtain a copy of the License at
06: //
07: // http://www.apache.org/licenses/LICENSE-2.0
08: //
09: // 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.internal.services;
16:
17: import java.lang.reflect.Modifier;
18:
19: import org.apache.tapestry.MarkupWriter;
20: import org.apache.tapestry.internal.InternalComponentResourcesCommon;
21: import org.apache.tapestry.model.MutableComponentModel;
22: import org.apache.tapestry.runtime.RenderCommand;
23: import org.apache.tapestry.runtime.RenderQueue;
24: import org.apache.tapestry.services.ClassTransformation;
25: import org.apache.tapestry.services.ComponentClassTransformWorker;
26: import org.apache.tapestry.services.MethodSignature;
27:
28: /**
29: * Ensures that all components implement {@link RenderCommand} by delegating to
30: * {@link InternalComponentResourcesCommon#queueRender(org.apache.tapestry.runtime.RenderQueue)}.
31: */
32: public class RenderCommandWorker implements
33: ComponentClassTransformWorker {
34: private final MethodSignature RENDER_SIGNATURE = new MethodSignature(
35: Modifier.PUBLIC, "void", "render", new String[] {
36: MarkupWriter.class.getName(),
37: RenderQueue.class.getName() }, null);
38:
39: public void transform(ClassTransformation transformation,
40: MutableComponentModel model) {
41: // Subclasses don't need to bother, they'll inherit from super-classes.
42:
43: if (model.getParentModel() != null)
44: return;
45:
46: transformation.addImplementedInterface(RenderCommand.class);
47:
48: String body = String.format("%s.queueRender($2);",
49: transformation.getResourcesFieldName());
50:
51: transformation.addMethod(RENDER_SIGNATURE, body);
52: }
53: }
|