Author: alexsmirnov
Date: 2007-10-12 18:45:06 -0400 (Fri, 12 Oct 2007)
New Revision: 3355
Added:
trunk/framework/impl/src/main/java/org/ajax4jsf/application/AjaxStateHolder.java
trunk/framework/impl/src/main/java/org/ajax4jsf/util/LRUMap.java
Modified:
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/application/PortletStateHolder.java
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/lifecycle/RestoreViewPhase.java
trunk/framework/impl/src/main/java/org/ajax4jsf/application/AjaxStateManager.java
trunk/framework/impl/src/main/java/org/ajax4jsf/application/ComponentsLoaderImpl.java
Log:
Continue working on the portal brige
Modified:
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/application/PortletStateHolder.java
===================================================================
---
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/application/PortletStateHolder.java 2007-10-12
22:18:13 UTC (rev 3354)
+++
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/application/PortletStateHolder.java 2007-10-12
22:45:06 UTC (rev 3355)
@@ -49,13 +49,7 @@
*
* @param context
*/
- private PortletStateHolder(FacesContext context) {
- ExternalContext externalContext = context.getExternalContext();
- Object request = externalContext.getRequest();
- if (request instanceof PortletRequest) {
- PortletRequest portletRequest = (PortletRequest) request;
- lastMode = portletRequest.getPortletMode();
- }
+ private PortletStateHolder() {
}
/**
@@ -74,8 +68,12 @@
instance = (PortletStateHolder) sessionMap.get(STATE_HOLDER);
if (null == instance) {
// Create and store in session new state holder.
- instance = new PortletStateHolder(context);
-
+ instance = new PortletStateHolder();
+ Object request = externalContext.getRequest();
+ if (request instanceof PortletRequest) {
+ PortletRequest portletRequest = (PortletRequest) request;
+ instance.setLastMode(portletRequest.getPortletMode());
+ }
sessionMap.put(STATE_HOLDER, instance);
}
}
@@ -211,4 +209,18 @@
}
}
+
+ /**
+ * @return the lastMode
+ */
+ public PortletMode getLastMode() {
+ return lastMode;
+ }
+
+ /**
+ * @param lastMode the lastMode to set
+ */
+ public void setLastMode(PortletMode lastMode) {
+ this.lastMode = lastMode;
+ }
}
Modified:
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/lifecycle/RestoreViewPhase.java
===================================================================
---
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/lifecycle/RestoreViewPhase.java 2007-10-12
22:18:13 UTC (rev 3354)
+++
trunk/extensions/portlet/src/main/java/org/ajax4jsf/portlet/lifecycle/RestoreViewPhase.java 2007-10-12
22:45:06 UTC (rev 3355)
@@ -5,14 +5,12 @@
import java.util.Iterator;
-import javax.el.ELContext;
-import javax.el.ValueExpression;
import javax.faces.FactoryFinder;
import javax.faces.application.ViewHandler;
-import javax.faces.component.UICommand;
import javax.faces.component.UIComponent;
import javax.faces.component.UIViewRoot;
import javax.faces.context.FacesContext;
+import javax.faces.el.ValueBinding;
import javax.faces.event.PhaseId;
import javax.faces.lifecycle.Lifecycle;
import javax.faces.render.RenderKit;
@@ -64,13 +62,12 @@
public void executePhase(FacesContext context) {
// Check pre-created ViewRoot.
UIViewRoot viewRoot = context.getViewRoot();
- ELContext elContext = context.getELContext();
if (null != viewRoot) {
if (_log.isDebugEnabled()) {
_log.debug("Found created UIViewRoot in facesContext");
}
viewRoot.setLocale(context.getExternalContext().getRequestLocale());
- processBindings(elContext, viewRoot);
+ processBindings(context, viewRoot);
} else {
// Restore or Create new view.
String viewId = calculateViewId(context);
@@ -79,7 +76,7 @@
// TODO - check for a null and throw exception.
viewRoot = viewHandler.restoreView(context, viewId);
if (null != viewRoot) {
- processBindings(elContext, viewRoot);
+ processBindings(context, viewRoot);
}
} else {
viewRoot = viewHandler.createView(context, viewId);
@@ -117,15 +114,15 @@
return viewId;
}
- private void processBindings(ELContext elContext, UIComponent component) {
- ValueExpression binding = component.getValueExpression("binding");
+ private void processBindings(FacesContext context, UIComponent component) {
+ ValueBinding binding = component.getValueBinding("binding");
if (null != binding) {
- binding.setValue(elContext, component);
+ binding.setValue(context, component);
}
for (Iterator iterator = component.getFacetsAndChildren(); iterator
.hasNext();) {
UIComponent child = (UIComponent) iterator.next();
- processBindings(elContext, child);
+ processBindings(context, child);
}
}
Added: trunk/framework/impl/src/main/java/org/ajax4jsf/application/AjaxStateHolder.java
===================================================================
--- trunk/framework/impl/src/main/java/org/ajax4jsf/application/AjaxStateHolder.java
(rev 0)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/application/AjaxStateHolder.java 2007-10-12
22:45:06 UTC (rev 3355)
@@ -0,0 +1,74 @@
+/**
+ *
+ */
+package org.ajax4jsf.application;
+
+import java.io.Serializable;
+import java.util.Map;
+
+import javax.faces.context.ExternalContext;
+import javax.faces.context.FacesContext;
+
+import org.ajax4jsf.util.LRUMap;
+
+/**
+ * @author asmirnov
+ *
+ */
+public class AjaxStateHolder implements Serializable {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 6414488517358423688L;
+ private static final Object STATE_HOLDER = AjaxStateHolder.class.getName();
+
+ private final LRUMap views;
+
+ private AjaxStateHolder(int capacity) {
+ views = new LRUMap(capacity);
+ }
+
+ public static AjaxStateHolder getInstance(FacesContext context) {
+ ExternalContext externalContext = context.getExternalContext();
+ Object session = externalContext.getSession(true);
+ Map sessionMap = externalContext.getSessionMap();
+ AjaxStateHolder instance = null;
+ synchronized (session) {
+ instance = (AjaxStateHolder) sessionMap.get(STATE_HOLDER);
+ if (null == instance) {
+ // Create and store in session new state holder.
+ // TODO - make size parameter configurable
+ instance = new AjaxStateHolder(
+ AjaxStateManager.DEFAULT_NUMBER_OF_VIEWS);
+ sessionMap.put(STATE_HOLDER, instance);
+ }
+ }
+ return instance;
+ }
+
+ public synchronized Object getState(String viewId, Object sequence) {
+ Object state = null;
+ LRUMap viewVersions = (LRUMap) views.get(viewId);
+ if (null != viewVersions) {
+ if (null != sequence) {
+ state = viewVersions.get(sequence);
+ }
+ if (null == state) {
+ state = viewVersions.values().iterator().next();
+ }
+ }
+ return state;
+ }
+
+ public synchronized void saveState(String viewId, Object sequence,
+ Object state) {
+ LRUMap viewVersions = (LRUMap) views.get(viewId);
+ if (null == viewVersions) {
+ // TODO - make size parameter configurable
+ viewVersions = new LRUMap(AjaxStateManager.DEFAULT_NUMBER_OF_VIEWS);
+ views.put(viewId, viewVersions);
+ }
+ viewVersions.put(sequence, state);
+ }
+}
Property changes on:
trunk/framework/impl/src/main/java/org/ajax4jsf/application/AjaxStateHolder.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Date Revision Author
Modified:
trunk/framework/impl/src/main/java/org/ajax4jsf/application/AjaxStateManager.java
===================================================================
---
trunk/framework/impl/src/main/java/org/ajax4jsf/application/AjaxStateManager.java 2007-10-12
22:18:13 UTC (rev 3354)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/application/AjaxStateManager.java 2007-10-12
22:45:06 UTC (rev 3355)
@@ -75,7 +75,7 @@
private final ComponentsLoader componentLoader;
- private int viewSequence = 0;
+ private volatile int viewSequence = 0;
private Object viewSequenceMutex = "MUTEX";
@@ -146,12 +146,12 @@
}
} });
- if(_log.isDebugEnabled()){
+ if (_log.isDebugEnabled()) {
_log.debug("Create instance of the SeamStateManager");
}
} catch (Exception e) {
seamStateManager = null;
- if(_log.isDebugEnabled()){
+ if (_log.isDebugEnabled()) {
_log.debug("SeamStateManager is not present");
}
}
@@ -230,7 +230,8 @@
treeStructure = (TreeStrutureNode) responseStateManager
.getTreeStructureToRestore(context, viewId);
// viewRoot = parent.restoreView(context, viewId, renderKitId);
- state = (Object[]) responseStateManager.getComponentStateToRestore(context);
+ state = (Object[]) responseStateManager
+ .getComponentStateToRestore(context);
} else {
Object[] serializedView = restoreStateFromSession(context, viewId,
renderKitId);
@@ -328,7 +329,7 @@
TreeStrutureNode treeStructure = new TreeStrutureNode();
treeStructure.apply(context, viewRoot, new HashSet());
Object treeState = viewRoot.processSaveState(context);
- Object state[]={treeState,getAdditionalState(context)};
+ Object state[] = { treeState, getAdditionalState(context) };
if (isSavingStateInClient(context)) {
serializedView = new SerializedView(treeStructure, state);
} else {
@@ -353,20 +354,18 @@
ExternalContext externalContext = context.getExternalContext();
Object session = externalContext.getSession(true);
synchronized (session) {
- LRUMap viewStates = (LRUMap) externalContext
- .getSessionMap().get(VIEW_STATES_MAP);
+ LRUMap viewStates = (LRUMap) externalContext.getSessionMap().get(
+ VIEW_STATES_MAP);
if (null == viewStates) {
- viewStates = new LRUMap(
- getNumberOfViews(externalContext));
- externalContext.getSessionMap().put(VIEW_STATES_MAP,
- viewStates);
+ viewStates = new LRUMap(getNumberOfViews(externalContext));
+ externalContext.getSessionMap()
+ .put(VIEW_STATES_MAP, viewStates);
}
Object id = getNextViewId(context);
LRUMap logicalViewsMap = (LRUMap) viewStates.get(viewRoot
.getViewId());
if (null == logicalViewsMap) {
- logicalViewsMap = new LRUMap(
- getNumberOfViews(externalContext));
+ logicalViewsMap = new LRUMap(getNumberOfViews(externalContext));
}
// Renew last seen view.
viewStates.put(viewRoot.getViewId(), logicalViewsMap);
@@ -375,14 +374,13 @@
}
return serializedView;
}
-
-
- protected Object getAdditionalState(FacesContext context){
+
+ protected Object getAdditionalState(FacesContext context) {
return null;
}
-
- protected void restoreAdditionalState(FacesContext context,Object state){
-
+
+ protected void restoreAdditionalState(FacesContext context, Object state) {
+
}
protected Object getNextViewId(FacesContext context) {
@@ -398,8 +396,8 @@
if (viewSequence++ == Character.MAX_VALUE) {
viewSequence = 0;
}
- return UIViewRoot.UNIQUE_ID_PREFIX + ((int) viewSequence);
}
+ return UIViewRoot.UNIQUE_ID_PREFIX + ((int) viewSequence);
}
protected int getNumberOfViews(ExternalContext externalContext) {
@@ -420,7 +418,7 @@
/**
* TODO - implement Externalizable to reduce serialized state.
*/
- private static final long serialVersionUID = -9038742487716977254L;
+ private static final long serialVersionUID = -9038742487716977911L;
private static final String NULL_ID = "";
Modified:
trunk/framework/impl/src/main/java/org/ajax4jsf/application/ComponentsLoaderImpl.java
===================================================================
---
trunk/framework/impl/src/main/java/org/ajax4jsf/application/ComponentsLoaderImpl.java 2007-10-12
22:18:13 UTC (rev 3354)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/application/ComponentsLoaderImpl.java 2007-10-12
22:45:06 UTC (rev 3355)
@@ -19,7 +19,7 @@
*/
public class ComponentsLoaderImpl implements Transformer, ComponentsLoader {
- private Map classes;
+ private volatile Map classes;
private ClassLoader loader;
Added: trunk/framework/impl/src/main/java/org/ajax4jsf/util/LRUMap.java
===================================================================
--- trunk/framework/impl/src/main/java/org/ajax4jsf/util/LRUMap.java
(rev 0)
+++ trunk/framework/impl/src/main/java/org/ajax4jsf/util/LRUMap.java 2007-10-12 22:45:06
UTC (rev 3355)
@@ -0,0 +1,32 @@
+/**
+ *
+ */
+package org.ajax4jsf.util;
+
+import java.io.Serializable;
+import java.util.LinkedHashMap;
+import java.util.Map.Entry;
+
+/**
+ * Last Recent Used Map cache. See {@link LinkedHashMap} for details.
+ * @author asmirnov
+ *
+ */
+public class LRUMap extends LinkedHashMap implements Serializable {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = -7232885382582796665L;
+ private int capacity;
+
+ public LRUMap(int capacity) {
+ super(capacity, 1.0f,true);
+ this.capacity = capacity;
+ }
+
+ protected boolean removeEldestEntry(Entry arg0) {
+ // Remove last entry if size exceeded.
+ return size()>capacity;
+ }
+}
Property changes on: trunk/framework/impl/src/main/java/org/ajax4jsf/util/LRUMap.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Date Revision Author