001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * 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, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.commons.jxpath.servlet;
018
019import java.util.ArrayList;
020import java.util.Enumeration;
021
022import org.apache.commons.jxpath.DynamicPropertyHandler;
023
024/**
025 * Implementation of the {@link DynamicPropertyHandler} interface that provides
026 * access to attributes of a {@link PageScopeContext}.
027 *
028 * @author Dmitri Plotnikov
029 * @version $Revision: 652845 $ $Date: 2008-05-02 19:46:46 +0200 (Fr, 02 Mai 2008) $
030 */
031public class PageScopeContextHandler implements DynamicPropertyHandler {
032
033    private static final int DEFAULT_LIST_SIZE = 16;
034
035    public String[] getPropertyNames(Object pageScope) {
036        Enumeration e = ((PageScopeContext) pageScope).getAttributeNames();
037        ArrayList list = new ArrayList(DEFAULT_LIST_SIZE);
038        while (e.hasMoreElements()) {
039            list.add(e.nextElement());
040        }
041        return (String[]) list.toArray(new String[list.size()]);
042    }
043
044    public Object getProperty(Object pageScope, String property) {
045        return ((PageScopeContext) pageScope).getAttribute(property);
046    }
047
048    public void setProperty(Object pageScope, String property, Object value) {
049        ((PageScopeContext) pageScope).setAttribute(property, value);
050    }
051}