001// Licensed to the Apache Software Foundation (ASF) under one
002// or more contributor license agreements.  See the NOTICE file
003// distributed with this work for additional information
004// regarding copyright ownership.  The ASF licenses this file
005// to you under the Apache License, Version 2.0 (the
006// "License"); you may not use this file except in compliance
007// with the License.  You may obtain a copy of the License at
008//
009// http://www.apache.org/licenses/LICENSE-2.0
010//
011// Unless required by applicable law or agreed to in writing,
012// software distributed under the License is distributed on an
013// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
014// KIND, either express or implied.  See the License for the
015// specific language governing permissions and limitations
016// under the License.
017
018package org.apache.tapestry5.annotations;
019
020import org.apache.tapestry5.ioc.annotations.UseWith;
021
022import java.lang.annotation.Documented;
023import java.lang.annotation.Retention;
024import java.lang.annotation.Target;
025
026import static java.lang.annotation.ElementType.FIELD;
027import static java.lang.annotation.RetentionPolicy.RUNTIME;
028import static org.apache.tapestry5.ioc.annotations.AnnotationUseContext.*;
029
030/**
031 * Marker annotation for a property that is a <em>session state object</em> (SSO) as controlled by
032 * the {@link org.apache.tapestry5.services.ApplicationStateManager}. An SSO property is stored as
033 * global session object (i.e., in the {@link javax.servlet.ServletContext}), accessible to every
034 * page or component, but in fact the built-in strategies for SSO management are
035 * session-specific, ultimately storing data in the {@link org.apache.tapestry5.http.services.Session}.
036 * <p>
037 * For each SSO property, you may declare a companion boolean property that can be checked to see if
038 * the SSO has been created yet. The companion boolean property must have the same name as the SSO
039 * property but suffixed with "Exists" (e.g., an SSO property named "user" and a companion boolean
040 * property named "userExists"). You can access the boolean property to determine whether the SSO
041 * has already been created. This mechanism is necessary because even a null check ("user != null")
042 * may force the SSO to be created. Instead, check the companion boolean field ("userExists").
043 * <p>
044 * <em>Note: Tapestry 5.0 called these objects "Application State Objects"; thus some of the underlying
045 * services have confusing names (e.g., ApplicationStateManager, which really should be SessionStateManager)
046 * but can't be renamed for backward compatibility reasons.</em>
047 *
048 * @since 5.1.0.4
049 */
050@Target(FIELD)
051@Documented
052@Retention(RUNTIME)
053@UseWith({COMPONENT,MIXIN,PAGE})
054public @interface SessionState
055{
056    /**
057     * If true (the default), then referencing an field marked with the annotation will create the SSO.  If false, then
058     * accessing the field will not create the SSO, it will only allow access to it if it already exists.
059     */
060    boolean create() default true;
061}