001 // Copyright 2010 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.services.meta;
016
017 import java.lang.annotation.Annotation;
018
019 import org.apache.tapestry5.ioc.internal.util.InternalUtils;
020 import org.apache.tapestry5.model.MutableComponentModel;
021
022 /**
023 * Implementation of {@link MetaDataExtractor} that is used to set a fixed
024 * value for a fixed meta-data key, when a given annotation is present.
025 *
026 * @since 5.2.0
027 */
028 public class FixedExtractor<T extends Annotation> implements MetaDataExtractor<T>
029 {
030 private final String key;
031
032 private final String value;
033
034 /** Defaults the value to "true". */
035 public FixedExtractor(String key)
036 {
037 this(key, "true");
038 }
039
040 public FixedExtractor(String key, String value)
041 {
042 assert InternalUtils.isNonBlank(key);
043 this.key = key;
044 assert InternalUtils.isNonBlank(value);
045 this.value = value;
046 }
047
048 public void extractMetaData(MutableComponentModel model, T annotation)
049 {
050 model.setMeta(key, value);
051 }
052
053 }