com.aspectran.core.activity.ActivityData Maven / Gradle / Ivy
/*
* Copyright (c) 2008-2024 The Aspectran Project
*
* 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.aspectran.core.activity;
import com.aspectran.core.activity.process.result.ActionResult;
import com.aspectran.core.activity.process.result.ContentResult;
import com.aspectran.core.adapter.RequestAdapter;
import com.aspectran.core.adapter.SessionAdapter;
import com.aspectran.utils.annotation.jsr305.NonNull;
import java.io.Serial;
import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* A map of data for saving activity results.
* It is often used as a model for providing data used in views.
*
* This class is generally not thread-safe.
* It is primarily designed for use in a single thread only.
*/
public class ActivityData extends HashMap {
@Serial
private static final long serialVersionUID = -4557424414862800204L;
private static final Object PREEMPTED = new Object();
private final Activity activity;
/**
* Instantiates a new ActivityData.
* @param activity the activity
*/
public ActivityData(Activity activity) {
super();
this.activity = activity;
refresh();
}
@Override
public Object get(Object key) {
Object value = super.get(key);
if (value != null && !value.equals(PREEMPTED)) {
return value;
}
if (key == null) {
return null;
}
String name = key.toString();
Object data = getActionResultWithoutCache(name);
if (data != null) {
preempt(name, value);
return data;
}
data = getAttributeWithoutCache(name);
if (data != null) {
preempt(name, value);
return data;
}
data = getParameterWithoutCache(name);
if (data != null) {
preempt(name, value);
return data;
}
data = getSessionAttributeWithoutCache(name);
if (data != null) {
preempt(name, value);
return data;
}
return null;
}
@Override
public Object put(String key, Object value) {
if (this == value) {
throw new IllegalArgumentException("Same instance as this map can not be stored");
}
return super.put(key, value);
}
@Override
@NonNull
public Collection