001// Copyright 2005 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.tapestry.annotations; 016 017import java.lang.annotation.Documented; 018import java.lang.annotation.ElementType; 019import java.lang.annotation.Retention; 020import java.lang.annotation.RetentionPolicy; 021import java.lang.annotation.Target; 022 023/** 024 * Annotation used to <em>define</em> new managed beans, including limited/lightweight 025 * initialization. For complex initialiation, the XML specification is necessary. 026 * <p> 027 * One of the advantages is that, on the XML side, it is always necessary to provide complete class 028 * names; here on the Java/annotation side, we can leverage imports. 029 * <p> 030 * The managed bean will have a name that matches the property name; this allows such a bean to be 031 * referenced via the "bean:" binding prefix, or via 032 * {@link org.apache.tapestry.IComponent#getBeans()}. 033 * <p> 034 * This annotation adds a new {@link org.apache.tapestry.spec.IBeanSpecification} to the 035 * {@link org.apache.tapestry.spec.IComponentSpecification}. 036 * 037 * @author Howard M. Lewis Ship 038 * @since 4.0 039 */ 040 041@Target( 042{ ElementType.METHOD }) 043@Retention(RetentionPolicy.RUNTIME) 044@Documented 045public @interface Bean { 046 /** 047 * The Java class to instantiate. The default is Object.class; if a non-default value is 048 * specified, that will be the class to instantiate; otherwise, the bean class will be 049 * determined from the property type. Generally, this annotation is only used when the property 050 * type is an interface (or abstract base class). 051 */ 052 053 Class value() default Object.class; 054 055 /** 056 * Optional initializer string for the bean, as <em>lightweight initialization</em> (a list of 057 * properties and values). 058 */ 059 060 String initializer() default ""; 061 062 /** 063 * The lifecycle of the bean, defaults to Lifecycle.REQUEST. 064 * 065 * @see BeanLifecycle 066 */ 067 068 Lifecycle lifecycle() default Lifecycle.REQUEST; 069}