001    // Copyright 2007, 2008, 2009, 2010, 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.services;
016    
017    import java.lang.annotation.Annotation;
018    
019    import org.apache.tapestry5.internal.InternalPropertyConduit;
020    import org.apache.tapestry5.internal.util.IntegerRange;
021    import org.apache.tapestry5.ioc.AnnotationProvider;
022    import org.apache.tapestry5.ioc.internal.util.InternalUtils;
023    import org.apache.tapestry5.ioc.services.TypeCoercer;
024    
025    /**
026     * Companion class for {@link org.apache.tapestry5.PropertyConduit} instances created by the
027     * {@link org.apache.tapestry5.services.PropertyConduitSource}.
028     */
029    @SuppressWarnings("all")
030    public class PropertyConduitDelegate
031    {
032        private final TypeCoercer typeCoercer;
033    
034        public PropertyConduitDelegate(TypeCoercer typeCoercer)
035        {
036            this.typeCoercer = typeCoercer;
037        }
038    
039        public final IntegerRange range(int from, int to)
040        {
041            return new IntegerRange(from, to);
042        }
043    
044        public final <T> T coerce(Object value, Class<T> type)
045        {
046            return typeCoercer.coerce(value, type);
047        }
048    
049        public final boolean invert(Object value)
050        {
051            return coerce(value, Boolean.class).equals(Boolean.FALSE);
052        }
053    }