[jboss-cvs] jboss-seam/src/main/org/jboss/seam/pages ...
Gavin King
gavin.king at jboss.com
Sun Dec 17 14:46:41 EST 2006
User: gavin
Date: 06/12/17 14:46:41
Added: src/main/org/jboss/seam/pages ActionNavigation.java
ConversationControl.java NavigationHandler.java
Outcome.java Page.java Param.java
RedirectNavigationHandler.java
RenderNavigationHandler.java
Log:
refactor all the inner classes
Revision Changes Path
1.1 date: 2006/12/17 19:46:41; author: gavin; state: Exp;jboss-seam/src/main/org/jboss/seam/pages/ActionNavigation.java
Index: ActionNavigation.java
===================================================================
/**
*
*/
package org.jboss.seam.pages;
import java.util.HashMap;
import java.util.Map;
import org.jboss.seam.core.Expressions.ValueBinding;
public final class ActionNavigation
{
private ValueBinding<Object> outcomeValueBinding;
private Map<String, Outcome> outcomes = new HashMap<String, Outcome>();
private Outcome nullOutcome;
private Outcome anyOutcome;
public Map<String, Outcome> getOutcomes()
{
return outcomes;
}
public void setNullOutcome(Outcome outcome)
{
this.nullOutcome = outcome;
}
public Outcome getNullOutcome()
{
return nullOutcome;
}
public void setOutcomeValueBinding(ValueBinding<Object> outcomeValueBinding)
{
this.outcomeValueBinding = outcomeValueBinding;
}
public ValueBinding<Object> getOutcomeValueBinding()
{
return outcomeValueBinding;
}
public Outcome getAnyOutcome()
{
return anyOutcome;
}
public void setAnyOutcome(Outcome outcome)
{
this.anyOutcome = outcome;
}
}
1.1 date: 2006/12/17 19:46:41; author: gavin; state: Exp;jboss-seam/src/main/org/jboss/seam/pages/ConversationControl.java
Index: ConversationControl.java
===================================================================
/**
*
*/
package org.jboss.seam.pages;
import org.jboss.seam.annotations.FlushModeType;
import org.jboss.seam.core.Conversation;
import org.jboss.seam.core.Pageflow;
public class ConversationControl
{
private boolean isBeginConversation;
private boolean isEndConversation;
private boolean join;
private boolean nested;
private FlushModeType flushMode;
private String pageflow;
public boolean isBeginConversation()
{
return isBeginConversation;
}
public void setBeginConversation(boolean isBeginConversation)
{
this.isBeginConversation = isBeginConversation;
}
public boolean isEndConversation()
{
return isEndConversation;
}
public void setEndConversation(boolean isEndConversation)
{
this.isEndConversation = isEndConversation;
}
public void beginOrEndConversation()
{
if ( isEndConversation )
{
Conversation.instance().end();
}
if ( isBeginConversation )
{
boolean begun = Conversation.instance().begin(join, nested);
if (begun)
{
if (flushMode!=null)
{
Conversation.instance().changeFlushMode(flushMode);
}
if ( pageflow!=null )
{
Pageflow.instance().begin(pageflow);
}
}
}
}
public FlushModeType getFlushMode()
{
return flushMode;
}
public void setFlushMode(FlushModeType flushMode)
{
this.flushMode = flushMode;
}
public boolean isJoin()
{
return join;
}
public void setJoin(boolean join)
{
this.join = join;
}
public boolean isNested()
{
return nested;
}
public void setNested(boolean nested)
{
this.nested = nested;
}
public String getPageflow()
{
return pageflow;
}
public void setPageflow(String pageflow)
{
this.pageflow = pageflow;
}
}
1.1 date: 2006/12/17 19:46:41; author: gavin; state: Exp;jboss-seam/src/main/org/jboss/seam/pages/NavigationHandler.java
Index: NavigationHandler.java
===================================================================
/**
*
*/
package org.jboss.seam.pages;
import javax.faces.context.FacesContext;
import org.jboss.seam.core.Navigator;
public abstract class NavigationHandler extends Navigator
{
public abstract void navigate(FacesContext context);
}
1.1 date: 2006/12/17 19:46:41; author: gavin; state: Exp;jboss-seam/src/main/org/jboss/seam/pages/Outcome.java
Index: Outcome.java
===================================================================
/**
*
*/
package org.jboss.seam.pages;
public final class Outcome
{
private NavigationHandler navigationHandler;
private ConversationControl conversationControl = new ConversationControl();
public NavigationHandler getNavigationHandler()
{
return navigationHandler;
}
public void setNavigationHandler(NavigationHandler result)
{
this.navigationHandler = result;
}
public ConversationControl getConversationControl()
{
return conversationControl;
}
}
1.1 date: 2006/12/17 19:46:41; author: gavin; state: Exp;jboss-seam/src/main/org/jboss/seam/pages/Page.java
Index: Page.java
===================================================================
package org.jboss.seam.pages;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.MissingResourceException;
import org.jboss.seam.core.Interpolator;
import org.jboss.seam.core.Locale;
import org.jboss.seam.core.Expressions.MethodBinding;
/**
* Metadata about page actions, page parameters, action navigation,
* resource bundle, etc, for a particular JSF view id.
*/
public final class Page
{
private final String viewId;
private String description;
private Integer timeout;
private MethodBinding action;
private String outcome;
private String noConversationViewId;
private String resourceBundleName;
private boolean switchEnabled = true;
private List<Param> pageParameters = new ArrayList<Param>();
private Map<String, ActionNavigation> navigations = new HashMap<String, ActionNavigation>();
private ActionNavigation defaultNavigation;
private boolean conversationRequired;
private ConversationControl conversationControl = new ConversationControl();
public Page(String viewId)
{
this.viewId = viewId;
if (viewId!=null)
{
int loc = viewId.lastIndexOf('.');
if ( loc>0 && viewId.startsWith("/") )
{
this.setResourceBundleName( viewId.substring(1, loc) );
}
}
}
public java.util.ResourceBundle getResourceBundle()
{
String resourceBundleName = getResourceBundleName();
if (resourceBundleName==null)
{
return null;
}
else
{
try
{
return java.util.ResourceBundle.getBundle(
resourceBundleName,
Locale.instance(),
Thread.currentThread().getContextClassLoader()
);
}
catch (MissingResourceException mre)
{
return null;
}
}
}
@Override
public String toString()
{
return "Page(" + getViewId() + ")";
}
public String getViewId()
{
return viewId;
}
public String renderDescription()
{
return Interpolator.instance().interpolate( getDescription() );
}
public void setDescription(String description)
{
this.description = description;
}
public String getDescription()
{
return description;
}
public void setTimeout(Integer timeout)
{
this.timeout = timeout;
}
public Integer getTimeout()
{
return timeout;
}
public void setAction(MethodBinding action)
{
this.action = action;
}
public MethodBinding getAction()
{
return action;
}
public void setOutcome(String outcome)
{
this.outcome = outcome;
}
public String getOutcome()
{
return outcome;
}
public void setNoConversationViewId(String noConversationViewId)
{
this.noConversationViewId = noConversationViewId;
}
public String getNoConversationViewId()
{
return noConversationViewId;
}
public void setResourceBundleName(String resourceBundleName)
{
this.resourceBundleName = resourceBundleName;
}
public String getResourceBundleName()
{
return resourceBundleName;
}
public void setSwitchEnabled(boolean switchEnabled)
{
this.switchEnabled = switchEnabled;
}
public boolean isSwitchEnabled()
{
return switchEnabled;
}
public List<Param> getPageParameters()
{
return pageParameters;
}
public Map<String, ActionNavigation> getNavigations()
{
return navigations;
}
public boolean hasDescription()
{
return description!=null;
}
public boolean isConversationRequired()
{
return conversationRequired;
}
public void setConversationRequired(boolean conversationRequired)
{
this.conversationRequired = conversationRequired;
}
public ActionNavigation getDefaultNavigation()
{
return defaultNavigation;
}
public void setDefaultNavigation(ActionNavigation defaultActionOutcomeMapping)
{
this.defaultNavigation = defaultActionOutcomeMapping;
}
public ConversationControl getConversationControl()
{
return conversationControl;
}
}
1.1 date: 2006/12/17 19:46:41; author: gavin; state: Exp;jboss-seam/src/main/org/jboss/seam/pages/Param.java
Index: Param.java
===================================================================
/**
*
*/
package org.jboss.seam.pages;
import java.util.Map;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import org.jboss.seam.core.Expressions.ValueBinding;
public final class Param
{
private final String name;
private ValueBinding valueBinding;
private ValueBinding converterValueBinding;
private String converterId;
public Param(String name)
{
this.name = name;
}
public Converter getConverter()
{
if (converterId!=null)
{
return FacesContext.getCurrentInstance().getApplication().createConverter(converterId);
}
else if (converterValueBinding!=null)
{
return (Converter) converterValueBinding.getValue();
}
else if (valueBinding==null)
{
return null;
}
else
{
Class<?> type = valueBinding.getType();
return FacesContext.getCurrentInstance().getApplication().createConverter(type);
}
}
public String getName()
{
return name;
}
public void setValueBinding(ValueBinding valueBinding)
{
this.valueBinding = valueBinding;
}
public ValueBinding getValueBinding()
{
return valueBinding;
}
public void setConverterValueBinding(ValueBinding converterValueBinding)
{
this.converterValueBinding = converterValueBinding;
}
public ValueBinding getConverterValueBinding()
{
return converterValueBinding;
}
public void setConverterId(String converterId)
{
this.converterId = converterId;
}
public String getConverterId()
{
return converterId;
}
@Override
public String toString()
{
return "PageParameter(" + name + ")";
}
/**
* Get the current value of a page or redirection parameter
* from the model, and convert to a String
*/
public Object getValueFromModel(FacesContext facesContext)
{
Object value = getValueBinding().getValue();
if (value==null)
{
return null;
}
else
{
Converter converter = null;
try
{
converter = getConverter();
}
catch (RuntimeException re)
{
//YUCK! due to bad JSF/MyFaces error handling
return null;
}
return converter==null ?
value :
converter.getAsString( facesContext, facesContext.getViewRoot(), value );
}
}
/**
* Get the current value of a page parameter from the request parameters
*/
public Object getValueFromRequest(FacesContext facesContext, Map<String, String[]> requestParameters)
{
String[] parameterValues = requestParameters.get( getName() );
if (parameterValues==null || parameterValues.length==0)
{
return null;
}
if (parameterValues.length>1)
{
throw new IllegalArgumentException("page parameter may not be multi-valued: " + getName());
}
String stringValue = parameterValues[0];
Converter converter = null;
try
{
converter = getConverter();
}
catch (RuntimeException re)
{
//YUCK! due to bad JSF/MyFaces error handling
return null;
}
return converter==null ?
stringValue :
converter.getAsObject( facesContext, facesContext.getViewRoot(), stringValue );
}
}
1.1 date: 2006/12/17 19:46:41; author: gavin; state: Exp;jboss-seam/src/main/org/jboss/seam/pages/RedirectNavigationHandler.java
Index: RedirectNavigationHandler.java
===================================================================
/**
*
*/
package org.jboss.seam.pages;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.faces.context.FacesContext;
public final class RedirectNavigationHandler extends NavigationHandler
{
private final String viewId;
private final List<Param> params;
public RedirectNavigationHandler(String viewId, List<Param> params)
{
this.viewId = viewId;
this.params = params;
}
@Override
public void navigate(FacesContext context)
{
Map<String, Object> parameters = new HashMap<String, Object>();
for ( Param pageParameter: params )
{
parameters.put( pageParameter.getName(), pageParameter.getValueFromModel(context) );
}
redirect(viewId, parameters);
}
}
1.1 date: 2006/12/17 19:46:41; author: gavin; state: Exp;jboss-seam/src/main/org/jboss/seam/pages/RenderNavigationHandler.java
Index: RenderNavigationHandler.java
===================================================================
/**
*
*/
package org.jboss.seam.pages;
import javax.faces.context.FacesContext;
public final class RenderNavigationHandler extends NavigationHandler
{
private final String viewId;
public RenderNavigationHandler(String viewId)
{
this.viewId = viewId;
}
@Override
public void navigate(FacesContext context)
{
render(viewId);
}
}
More information about the jboss-cvs-commits
mailing list