001    // Copyright 2009 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.annotations;
016    
017    import java.lang.annotation.Documented;
018    import static java.lang.annotation.ElementType.FIELD;
019    import java.lang.annotation.Retention;
020    import static java.lang.annotation.RetentionPolicy.RUNTIME;
021    import java.lang.annotation.Target;
022    
023    import static org.apache.tapestry5.ioc.annotations.AnnotationUseContext.*;
024    import org.apache.tapestry5.ioc.annotations.UseWith;
025    
026    /**
027     * Marker annotation for a field that is a <em>session state object</em> (SSO) as controlled by the {@link
028     * org.apache.tapestry5.services.ApplicationStateManager}. An SSO stored as global session object (i.e., in the {@link
029     * javax.servlet.ServletContext}); every page or component. In fact, the built-in strategies for ASO management are
030     * <em>very</em> user specific, ultimately storing data in the {@link org.apache.tapestry5.services.Session}.
031     * <p/>
032     * An SSO field may have a companion field, of type boolean, used to see if the SSO has been created yet. If another
033     * field exists with the same name, suffixed with "Exists" (i.e., "sso" for the SSO field, and "ssoExists" for the
034     * companion field) and the type of that field is boolean, then access to the field will determine whether the SSO has
035     * already been created. This is necessary because even a null check ("sso != null") may force the SSO to be created.
036     * Instead, check the companion boolean field ("asoExists").
037     * <p/>
038     * Note: Tapestry 5.0 called these objects "Application State Objects"; thus many of the underlying services have a
039     * confusing name (ApplicationStateManager, which really should be SessionStateManager ... but can't be renamed for
040     * backwards compatibility reasons).
041     *
042     * @since 5.1.0.4
043     */
044    @Target(FIELD)
045    @Documented
046    @Retention(RUNTIME)
047    @UseWith({COMPONENT,MIXIN,PAGE})
048    public @interface SessionState
049    {
050        /**
051         * If true (the default), then referencing an field marked with the annotation will create the SSO.  If false, then
052         * accessing the field will not create the SSO, it will only allow access to it if it already exists.
053         */
054        boolean create() default true;
055    }