01: // Copyright 2006, 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 static java.lang.String.format;
18:
19: import org.apache.tapestry.ComponentResources;
20: import org.apache.tapestry.ioc.ObjectLocator;
21: import org.apache.tapestry.model.MutableComponentModel;
22: import org.apache.tapestry.services.ClassTransformation;
23: import org.apache.tapestry.services.InjectionProvider;
24:
25: /**
26: * Allows for the injection of the component's {@link org.apache.tapestry.ComponentResources}.
27: */
28: public class ComponentResourcesInjectionProvider implements
29: InjectionProvider {
30: private static final String COMPONENT_RESOURCES_CLASS_NAME = ComponentResources.class
31: .getName();
32:
33: public boolean provideInjection(String fieldName, String fieldType,
34: ObjectLocator locator, ClassTransformation transformation,
35: MutableComponentModel componentModel) {
36: if (fieldType.equals(COMPONENT_RESOURCES_CLASS_NAME)) {
37: String body = format("%s = %s;", fieldName, transformation
38: .getResourcesFieldName());
39:
40: transformation.extendConstructor(body);
41:
42: transformation.makeReadOnly(fieldName);
43:
44: return true;
45: }
46:
47: return false;
48: }
49: }
|