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