    001    // Copyright 2008, 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.ioc.AnnotationProvider;
    021    import org.apache.tapestry5.ioc.services.TypeCoercer;
    022
    023    /**
    024     * A PropertyConduit for a literal value in an expression, such as a number, or "true", "false" or "null".
    025     */
    026    public class LiteralPropertyConduit extends PropertyConduitDelegate implements InternalPropertyConduit
    027    {
    028        private final Class propertyType;
    029
    030        private final AnnotationProvider annotationProvider;
    031
    032        private final String description;
    033
    034        private final Object value;
    035
    036        public LiteralPropertyConduit(TypeCoercer typeCoercer, Class propertyType, AnnotationProvider annotationProvider,
    037                String description, Object value)
    038        {
    039            super(typeCoercer);
    040
    041            this.propertyType = propertyType;
    042            this.annotationProvider = annotationProvider;
    043            this.description = description;
    044
    045            this.value = value;
    046        }
    047
    048        public Object get(Object instance)
    049        {
    050            return value;
    051        }
    052
    053        public void set(Object instance, Object value)
    054        {
    055            throw new RuntimeException(ServicesMessages.literalConduitNotUpdateable());
    056        }
    057
    058        public Class getPropertyType()
    059        {
    060            return propertyType;
    061        }
    062
    063        public <T extends Annotation> T getAnnotation(Class<T> annotationClass)
    064        {
    065            return annotationProvider.getAnnotation(annotationClass);
    066        }
    067
    068        public String getPropertyName()
    069        {
    070            return null;
    071        }
    072
    073        @Override
    074        public String toString()
    075        {
    076            return description;
    077        }
    078
    079    }