Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 // Copyright 2005 The Apache Software Foundation
 //
 // 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 org.apache.tapestry.engine.state;
import  org.apache.hivemind.PoolManageable;

This implementation expects to be pooled.

Author(s):
Howard M. Lewis Ship
Since:
4.0
public class ApplicationStateManagerImpl implements ApplicationStateManager, PoolManageable
{

    
Keyed on application static object name, value is the current state object.
    private Map _stateObjects = new HashMap();
    public void activateService()
    {
    }
    public void passivateService()
    {
        .clear();
    }
    public boolean exists(String objectName)
    {
        return .containsKey(objectName) || .get(objectName).exists();
    }
    public Object get(String objectName)
    {
        Object result = .get(objectName);
        if (result == null)
        {
            result = .get(objectName).get();
            .put(objectNameresult);
        }
        return result;
    }
    public void store(String objectNameObject stateObject)
    {
        .get(objectName).store(stateObject);
        .put(objectNamestateObject);
    }
    public void flush()
    {
        Iterator i = .entrySet().iterator();
        while (i.hasNext())
        {
            Map.Entry e = (Map.Entryi.next();
            String objectName = (Stringe.getKey();
            Object stateObject = e.getValue();
            // Slight bending of law-of-demeter
            .get(objectName).store(stateObject);
        }
    }
    public void setRegistry(StateObjectManagerRegistry registry)
    {
         = registry;
    }
New to GrepCode? Check out our FAQ X