1 // Copyright 2005 The Apache Software Foundation 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package org.apache.tapestry.annotations; 16 17 import java.lang.annotation.Documented; 18 import java.lang.annotation.ElementType; 19 import java.lang.annotation.Retention; 20 import java.lang.annotation.RetentionPolicy; 21 import java.lang.annotation.Target; 22 23 import org.apache.tapestry.spec.BeanLifecycle; 24 25 /** 26 * Annotation used to <em>define</em> new managed beans, including limited/lightweight 27 * initialization. For complex initialiation, the XML specification is necessary. 28 * <p> 29 * One of the advantages is that, on the XML side, it is always necessary to provide complete class 30 * names; here on the Java/annotation side, we can leverage imports. 31 * <p> 32 * The managed bean will have a name that matches the property name; this allows such a bean to be 33 * referenced via the "bean:" binding prefix, or via 34 * {@link org.apache.tapestry.IComponent#getBeans()}. 35 * <p> 36 * This annotation adds a new {@link org.apache.tapestry.spec.IBeanSpecification} to the 37 * {@link org.apache.tapestry.spec.IComponentSpecification}. 38 * 39 * @author Howard M. Lewis Ship 40 * @since 4.0 41 */ 42 43 @Target( 44 { ElementType.METHOD }) 45 @Retention(RetentionPolicy.RUNTIME) 46 @Documented 47 public @interface Bean { 48 /** 49 * The Java class to instantiate. The default is Object.class; if a non-default value is 50 * specified, that will be the class to instantiate; otherwise, the bean class will be 51 * determined from the property type. Generally, this annotation is only used when the property 52 * type is an interface (or abstract base class). 53 */ 54 55 Class value() default Object.class; 56 57 /** 58 * Optional initializer string for the bean, as <em>lightweight initialization</em> (a list of 59 * properties and values). 60 */ 61 62 String initializer() default ""; 63 64 /** 65 * The lifecycle of the bean, defaults to Lifecycle.REQUEST. 66 * 67 * @see BeanLifecycle 68 */ 69 70 Lifecycle lifecycle() default Lifecycle.REQUEST; 71 }