All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.squeakysand.jsp.AttributeScope Maven / Gradle / Ivy

/*
 * Copyright 2010-2012 Craig S. Dickson (http://craigsdickson.com)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.squeakysand.jsp;

import javax.servlet.jsp.PageContext;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * An enumeration of the standard scopes associated with a {@link PageContext} object in a JSP page. Currently in the {@link javax.servlet.jsp} API, the scopes
 * are defined as simple integer values, but the addition of enums in Java 5 now make them a cleaner solution.
 * 
 * @author Craig S. Dickson
 */
public enum AttributeScope {

    /**
     * @see PageContext#APPLICATION_SCOPE
     */
    APPLICATION(PageContext.APPLICATION_SCOPE),

    /**
     * @see PageContext#SESSION_SCOPE
     */
    SESSION(PageContext.SESSION_SCOPE),

    /**
     * @see PageContext#REQUEST_SCOPE
     */
    REQUEST(PageContext.REQUEST_SCOPE),

    /**
     * @see PageContext#PAGE_SCOPE
     */
    PAGE(PageContext.PAGE_SCOPE);

    private static final Logger LOG = LoggerFactory.getLogger(AttributeScope.class);

    public static AttributeScope valueOf(int scopeId) {
        AttributeScope result = null;
        for (AttributeScope attributeScope : AttributeScope.values()) {
            if (attributeScope.getScopeId() == scopeId) {
                result = attributeScope;
                break;
            }
        }
        if (result == null) {
            LOG.warn("{} is not a recognized attribute scope id", scopeId);
        }
        return result;
    }

    private int scopeId;

    private AttributeScope(int scopeId) {
        this.scopeId = scopeId;
    }

    public int getScopeId() {
        return scopeId;
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy