001 // Copyright 2011 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
015 package org.apache.tapestry5.internal.transform;
016
017 import org.apache.tapestry5.internal.services.ComponentClassCache;
018 import org.apache.tapestry5.ioc.ObjectLocator;
019 import org.apache.tapestry5.ioc.services.Coercion;
020 import org.apache.tapestry5.model.MutableComponentModel;
021 import org.apache.tapestry5.plastic.PlasticField;
022 import org.apache.tapestry5.services.InjectionProvider;
023 import org.apache.tapestry5.services.transform.InjectionProvider2;
024
025
026 /**
027 * Converts the deprecated {@link InjectionProvider} to the new {@link InjectionProvider2}.
028 *
029 * @since 5.3
030 */
031 public class InjectionProviderToInjectionProvider2 implements Coercion<InjectionProvider, InjectionProvider2>
032 {
033 private final ComponentClassCache classCache;
034
035 public InjectionProviderToInjectionProvider2(ComponentClassCache classCache)
036 {
037 this.classCache = classCache;
038 }
039
040 public InjectionProvider2 coerce(final InjectionProvider input)
041 {
042 return new InjectionProvider2()
043 {
044 public boolean provideInjection(PlasticField field, ObjectLocator locator, MutableComponentModel componentModel)
045 {
046 Class fieldType = classCache.forName(field.getTypeName());
047
048 // We don't currently provide a TransformationSupport into the BridgeClassTransformation,
049 // as it should not be needed.
050
051 return input.provideInjection(field.getName(), fieldType, locator,
052 new BridgeClassTransformation(field.getPlasticClass(), null, componentModel), componentModel);
053 }
054 };
055 }
056 }