001    // Copyright 2007, 2008 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 org.apache.tapestry.services.ApplicationStateManager;
018    
019    import java.lang.annotation.Documented;
020    import static java.lang.annotation.ElementType.FIELD;
021    import java.lang.annotation.Retention;
022    import static java.lang.annotation.RetentionPolicy.RUNTIME;
023    import java.lang.annotation.Target;
024    
025    /**
026     * Marker annotation for a field that is an <em>application state object</em> as controlled by the {@link
027     * ApplicationStateManager}.
028     * <p/>
029     * An ASO file may have a companion field, of type boolean, used to see if the ASO has been created yet. If another
030     * field exists with the same name, suffixed with "Exists" (i.e., "_aso" for the ASO field, and "_asoExists" for the
031     * companion field) and the type of that field is boolean, then access to the field will determine whether the ASO has
032     * already been created. This is necessary because even a null check ("_aso != null") will force the ASO to be created.
033     * Instead, check the companion boolean field ("_asoExists").
034     */
035    @Target(FIELD)
036    @Documented
037    @Retention(RUNTIME)
038    public @interface ApplicationState
039    {
040        /**
041         * If true (the default), then referencing an field marked with the annotation will create the ASO.  If false, then
042         * accessing the field will not create the ASO, it will only allow access to it if it already exists.
043         */
044        boolean create() default true;
045    }