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