com.google.code.rees.scope.conversation.configuration.ConversationConfiguration Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of struts2-conversation-scope-plugin Show documentation
Show all versions of struts2-conversation-scope-plugin Show documentation
A Struts2 plugin for leveraging conversation scopes in Struts2
/*******************************************************************************
*
* Struts2-Conversation-Plugin - An Open Source Conversation- and Flow-Scope Solution for Struts2-based Applications
* =================================================================================================================
*
* Copyright (C) 2012 by Rees Byars
* http://code.google.com/p/struts2-conversation/
*
* **********************************************************************************************************************
*
* 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.
*
* **********************************************************************************************************************
*
* $Id: ConversationConfiguration.java reesbyars $
******************************************************************************/
package com.google.code.rees.scope.conversation.configuration;
import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import com.google.code.rees.scope.conversation.ConversationAdapter;
import com.google.code.rees.scope.conversation.ConversationConstants;
import com.google.code.rees.scope.conversation.ConversationUtil;
import com.google.code.rees.scope.conversation.processing.ConversationManager;
/**
* This class is used to cache the fields and action IDs for a single
* class for a single conversation.
*
* @see {@link ConversationConfigurationProvider}
* @see {@link ConversationManager}
*
* @author rees.byars
*
*/
public class ConversationConfiguration {
private Map fields;
private Set actionIds;
private Set beginActionIds;
private Set endActionIds;
private String conversationName;
public ConversationConfiguration(String conversationName) {
fields = new HashMap();
actionIds = new HashSet();
beginActionIds = new HashSet();
endActionIds = new HashSet();
this.conversationName = ConversationUtil
.sanitizeName(conversationName)
+ ConversationConstants.CONVERSATION_NAME_SUFFIX;
}
/**
* Add a field to the configuration
*
* @param name
* @param field
*/
public void addField(String name, Field field) {
fields.put(name, field);
}
/**
* Get the cached fields for conversation
*
* @return
*/
public Map getFields() {
return fields;
}
/**
* Add an actionId for an intermediate action
*
* @see {@link ConversationAdapter#getActionId()}
* @see {@link ConversationArbitrator#getName(Method)}
* @param actionId
*/
public void addAction(String actionId) {
actionIds.add(actionId);
}
/**
* Add an actionId for a begin action
*
* @see {@link ConversationAdapter#getActionId()}
* @see {@link ConversationArbitrator#getName(Method)}
* @param actionId
*/
public void addBeginAction(String actionId) {
actionIds.add(actionId);
beginActionIds.add(actionId);
}
/**
* Add an actionId for an end action
*
* @see {@link ConversationAdapter#getActionId()}
* @see {@link ConversationArbitrator#getName(Method)}
* @param actionId
*/
public void addEndAction(String actionId) {
actionIds.add(actionId);
endActionIds.add(actionId);
}
/**
* Indicates whether the actionId identifies the action as an intermediate
* member for this conversation
*
* @see {@link ConversationAdapter#getActionId()}
* @see {@link ConversationArbitrator#getName(Method)}
* @param actionId
* @return
*/
public boolean containsAction(String actionId) {
return actionIds.contains(actionId);
}
/**
* Indicates whether the actionId identifies the action as a begin
* member for this conversation
*
* @see {@link ConversationAdapter#getActionId()}
* @see {@link ConversationArbitrator#getName(Method)}
* @param actionId
* @return
*/
public boolean isBeginAction(String actionId) {
return beginActionIds.contains(actionId);
}
/**
* Indicates whether the actionId identifies the action as an end
* member for this conversation
*
* @see {@link ConversationAdapter#getActionId()}
* @see {@link ConversationArbitrator#getName(Method)}
* @param actionId
* @return
*/
public boolean isEndAction(String actionId) {
return endActionIds.contains(actionId);
}
/**
* Returns the name of the conversation that this configuration is for
*
* @return
*/
public String getConversationName() {
return conversationName;
}
}