001// Copyright 2005 The Apache Software Foundation 002// 003// Licensed under the Apache License, Version 2.0 (the "License"); 004// you may not use this file except in compliance with the License. 005// You may obtain a copy of the License at 006// 007// http://www.apache.org/licenses/LICENSE-2.0 008// 009// Unless required by applicable law or agreed to in writing, software 010// distributed under the License is distributed on an "AS IS" BASIS, 011// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 012// See the License for the specific language governing permissions and 013// limitations under the License. 014 015package org.apache.tapestry.annotations; 016 017import java.lang.reflect.Method; 018 019import org.apache.hivemind.Location; 020import org.apache.tapestry.enhance.EnhancementOperation; 021import org.apache.tapestry.enhance.InjectObjectWorker; 022import org.apache.tapestry.services.InjectedValueProvider; 023import org.apache.tapestry.spec.IComponentSpecification; 024 025/** 026 * Performs injection of objects, in much the same way as the <inject> element in a 027 * specification. 028 * 029 * @author Howard M. Lewis Ship 030 * @since 4.0 031 * @see org.apache.tapestry.enhance.InjectObjectWorker 032 * @see org.apache.tapestry.annotations.InjectObject 033 */ 034 035public class InjectObjectAnnotationWorker implements MethodAnnotationEnhancementWorker 036{ 037 final InjectObjectWorker _delegate; 038 039 public InjectObjectAnnotationWorker() 040 { 041 this(new InjectObjectWorker()); 042 } 043 044 InjectObjectAnnotationWorker(InjectObjectWorker delegate) 045 { 046 _delegate = delegate; 047 } 048 049 public void performEnhancement(EnhancementOperation op, IComponentSpecification spec, 050 Method method, Location location) 051 { 052 InjectObject io = method.getAnnotation(InjectObject.class); 053 054 String object = io.value(); 055 056 String propertyName = AnnotationUtils.getPropertyName(method); 057 058 _delegate.injectObject(op, object, propertyName, location); 059 } 060 061 public void setProvider(InjectedValueProvider provider) 062 { 063 _delegate.setProvider(provider); 064 } 065}