    001    // Copyright 2007 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.services;
    016
    017    import org.apache.tapestry5.PropertyConduit;
    018    import org.apache.tapestry5.ioc.services.TypeCoercer;
    019
    020    import java.lang.annotation.Annotation;
    021
    022    public class CoercingPropertyConduitWrapper implements PropertyConduit
    023    {
    024        private final PropertyConduit conduit;
    025
    026        private final TypeCoercer coercer;
    027
    028        public CoercingPropertyConduitWrapper(final PropertyConduit conduit, final TypeCoercer coercer)
    029        {
    030            this.conduit = conduit;
    031            this.coercer = coercer;
    032        }
    033
    034        public Object get(Object instance)
    035        {
    036            return conduit.get(instance);
    037        }
    038
    039        public <T extends Annotation> T getAnnotation(Class<T> annotationClass)
    040        {
    041            return conduit.getAnnotation(annotationClass);
    042        }
    043
    044        public Class getPropertyType()
    045        {
    046            return conduit.getPropertyType();
    047        }
    048
    049        @SuppressWarnings("unchecked")
    050        public void set(Object instance, Object value)
    051        {
    052            Object coerced = coercer.coerce(value, getPropertyType());
    053
    054            conduit.set(instance, coerced);
    055        }
    056
    057    }