Author: julien(a)jboss.com
Date: 2007-04-02 17:41:23 -0400 (Mon, 02 Apr 2007)
New Revision: 6902
Added:
trunk/core/src/main/org/jboss/portal/core/model/portal/ns/
trunk/core/src/main/org/jboss/portal/core/model/portal/ns/PortalObjectNavigationalStateContext.java
trunk/core/src/main/org/jboss/portal/core/model/portal/ns/WindowNavigationalState.java
Log:
added missing files
Added:
trunk/core/src/main/org/jboss/portal/core/model/portal/ns/PortalObjectNavigationalStateContext.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/core/model/portal/ns/PortalObjectNavigationalStateContext.java
(rev 0)
+++
trunk/core/src/main/org/jboss/portal/core/model/portal/ns/PortalObjectNavigationalStateContext.java 2007-04-02
21:41:23 UTC (rev 6902)
@@ -0,0 +1,320 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.core.model.portal.ns;
+
+import org.jboss.portal.core.ns.NavigationalStateContext;
+import org.jboss.portal.core.ns.NavigationalStateKey;
+import org.jboss.portal.core.ns.NavigationalStateObjectChange;
+import org.jboss.portal.core.ns.NavigationalStateObjectCreated;
+import org.jboss.portal.core.ns.NavigationalStateObjectUpdated;
+import org.jboss.portal.core.ns.NavigationalStateObjectDestroyed;
+import org.jboss.portal.common.invocation.AttributeResolver;
+import org.jboss.portal.WindowState;
+import org.jboss.portal.Mode;
+import org.jboss.portal.portlet.StateString;
+
+import java.util.Set;
+import java.util.LinkedHashMap;
+import java.util.Iterator;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class PortalObjectNavigationalStateContext implements NavigationalStateContext
+{
+
+ /** . */
+ private static final String VIEW_ID_KEY = "view_id";
+
+ /** . */
+ private static final int MODE_TYPE = 0;
+
+ /** . */
+ private static final int WINDOW_STATE_TYPE = 1;
+
+ /** . */
+ private static final int STATE_STRING_TYPE = 2;
+
+ /** . */
+ private static final int WINDOW_TYPE = 3;
+
+ /** . */
+ private static final int UNKNOWN_TYPE = 4;
+
+ /** Where we delegate the storage. */
+ private AttributeResolver store;
+
+ /** The changes. */
+ private LinkedHashMap changes;
+
+ public PortalObjectNavigationalStateContext(AttributeResolver store)
+ {
+ this.store = store;
+ }
+
+ public Set getKeys()
+ {
+ throw new UnsupportedOperationException("todo");
+ }
+
+ public Object getAttribute(Object attrKey) throws IllegalArgumentException
+ {
+ NavigationalStateKey nsKey = (NavigationalStateKey)attrKey;
+
+ // Browse changes first
+ if (changes != null)
+ {
+ NavigationalStateObjectChange change =
(NavigationalStateObjectChange)changes.get(nsKey);
+ if (change instanceof NavigationalStateObjectCreated)
+ {
+ NavigationalStateObjectCreated created =
(NavigationalStateObjectCreated)change;
+ return created.getValue();
+ }
+ else if (change instanceof NavigationalStateObjectUpdated)
+ {
+ NavigationalStateObjectUpdated updated =
(NavigationalStateObjectUpdated)change;
+ return updated.getNewValue();
+ }
+ else if (change instanceof NavigationalStateObjectDestroyed)
+ {
+ return null;
+ }
+ }
+
+ //
+ return store.getAttribute(nsKey);
+ }
+
+ public void setAttribute(Object attrKey, Object attrValue) throws
IllegalArgumentException
+ {
+ NavigationalStateKey wantedKey = (NavigationalStateKey)attrKey;
+ Class typeClass = wantedKey.getType();
+
+ // Get the effective lookup key
+ int typeValue = UNKNOWN_TYPE;
+ if (typeClass == WindowState.class)
+ {
+ typeValue = WINDOW_STATE_TYPE;
+ }
+ else if (typeClass == Mode.class)
+ {
+ typeValue = MODE_TYPE;
+ }
+ else if (StateString.class.isAssignableFrom(typeClass))
+ {
+ typeValue = STATE_STRING_TYPE;
+ }
+ else if (typeClass == WindowNavigationalState.class)
+ {
+ typeValue = WINDOW_TYPE;
+ }
+
+ if (typeValue == UNKNOWN_TYPE)
+ {
+ throw new IllegalArgumentException("Cannot handle the type " +
typeClass.getName());
+ }
+
+ // Compute the effective key
+ NavigationalStateKey effectiveKey = typeValue == WINDOW_TYPE ? wantedKey : new
NavigationalStateKey(WindowNavigationalState.class, wantedKey.getId());
+
+ //
+ WindowNavigationalState oldNS = null;
+
+ // Look first the old ns in the changes
+ if (changes != null)
+ {
+ NavigationalStateObjectChange change =
(NavigationalStateObjectChange)changes.get(effectiveKey);
+ if (change != null)
+ {
+ // Discard any change done so far
+ changes.remove(effectiveKey);
+
+ //
+ if (change instanceof NavigationalStateObjectCreated)
+ {
+ NavigationalStateObjectCreated created =
(NavigationalStateObjectCreated)change;
+ oldNS = (WindowNavigationalState)created.getValue();
+ }
+ else if (change instanceof NavigationalStateObjectUpdated)
+ {
+ NavigationalStateObjectUpdated updated =
(NavigationalStateObjectUpdated)change;
+ oldNS = (WindowNavigationalState)updated.getNewValue();
+ }
+
+ //
+ }
+ }
+
+ // If we don't have the old ns then we try the store
+ if (oldNS == null)
+ {
+ oldNS = (WindowNavigationalState)store.getAttribute(effectiveKey);
+ }
+
+ //
+ NavigationalStateObjectChange change;
+ if (attrValue == null)
+ {
+ if (oldNS != null)
+ {
+ change = new NavigationalStateObjectDestroyed(effectiveKey, oldNS);
+ }
+ else
+ {
+ // Remove a non existing value, we do nothing
+ change = null;
+ }
+ }
+ else
+ {
+ WindowNavigationalState newNS;
+ if (typeValue == WINDOW_TYPE)
+ {
+ newNS = (WindowNavigationalState)attrValue;
+ }
+ else
+ {
+ WindowState windowState = WindowState.NORMAL;
+ Mode mode = Mode.VIEW;
+ StateString stateString = null;
+
+ //
+ if (oldNS != null)
+ {
+ windowState = oldNS.getWindowState();
+ mode = oldNS.getMode();
+ stateString = oldNS.getNavigationalState();
+ }
+
+ //
+ switch (typeValue)
+ {
+ case WINDOW_STATE_TYPE:
+ windowState = (WindowState)attrValue;
+ break;
+ case MODE_TYPE:
+ mode = (Mode)attrValue;
+ break;
+ case STATE_STRING_TYPE:
+ stateString = (StateString)attrValue;
+ break;
+ }
+
+ //
+ newNS = new WindowNavigationalState(windowState, mode, stateString);
+ }
+
+ //
+ if (oldNS != null)
+ {
+ change = new NavigationalStateObjectUpdated(effectiveKey, oldNS, newNS);
+ }
+ else
+ {
+ change = new NavigationalStateObjectCreated(effectiveKey, newNS);
+ }
+ }
+
+ // Store the change
+ if (change != null)
+ {
+ if (changes == null)
+ {
+ changes = new LinkedHashMap();
+ }
+
+ //
+ changes.put(effectiveKey, change);
+ }
+ }
+
+ public Iterator getChanges()
+ {
+ return changes.values().iterator();
+ }
+
+ /**
+ * Apply the navigational state changes to the real storage.
+ *
+ * @return true if state changed
+ */
+ public boolean applyChanges()
+ {
+ if (changes != null && changes.size() > 0)
+ {
+ for (Iterator i = changes.values().iterator();i.hasNext();)
+ {
+ NavigationalStateObjectChange change =
(NavigationalStateObjectChange)i.next();
+ if (change instanceof NavigationalStateObjectCreated)
+ {
+ NavigationalStateObjectCreated created =
(NavigationalStateObjectCreated)change;
+ store.setAttribute(created.getKey(), created.getValue());
+ }
+ else if (change instanceof NavigationalStateObjectUpdated)
+ {
+ NavigationalStateObjectUpdated updated =
(NavigationalStateObjectUpdated)change;
+ store.setAttribute(updated.getKey(), updated.getNewValue());
+ }
+ else
+ {
+ NavigationalStateObjectDestroyed destroyed =
(NavigationalStateObjectDestroyed)change;
+ store.setAttribute(destroyed.getKey(), null);
+ }
+ }
+
+ //
+ changes.clear();
+
+ // Increase view id
+ Integer viewId = (Integer)store.getAttribute(VIEW_ID_KEY);
+ if (viewId == null)
+ {
+ viewId = new Integer(0);
+ }
+ else
+ {
+ viewId = new Integer(viewId.intValue() + 1);
+ }
+ store.setAttribute(VIEW_ID_KEY, viewId);
+
+ //
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ /**
+ * Returns the current view id.
+ *
+ * @return the view id
+ */
+ public String getViewId()
+ {
+ Integer viewId = (Integer)store.getAttribute(VIEW_ID_KEY);
+ return viewId != null ? viewId.toString() : "0";
+ }
+}
Added:
trunk/core/src/main/org/jboss/portal/core/model/portal/ns/WindowNavigationalState.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/core/model/portal/ns/WindowNavigationalState.java
(rev 0)
+++
trunk/core/src/main/org/jboss/portal/core/model/portal/ns/WindowNavigationalState.java 2007-04-02
21:41:23 UTC (rev 6902)
@@ -0,0 +1,71 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.core.model.portal.ns;
+
+import org.jboss.portal.WindowState;
+import org.jboss.portal.Mode;
+import org.jboss.portal.portlet.StateString;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public final class WindowNavigationalState
+{
+
+ /** . */
+ private final WindowState windowState;
+
+ /** . */
+ private final Mode mode;
+
+ /** . */
+ private final StateString navigationalState;
+
+ public WindowNavigationalState(WindowState windowState, Mode mode, StateString
navigationalState)
+ {
+ this.windowState = windowState;
+ this.mode = mode;
+ this.navigationalState = navigationalState;
+ }
+
+ public WindowNavigationalState()
+ {
+ this(WindowState.NORMAL, Mode.VIEW, null);
+ }
+
+ public WindowState getWindowState()
+ {
+ return windowState;
+ }
+
+ public Mode getMode()
+ {
+ return mode;
+ }
+
+ public StateString getNavigationalState()
+ {
+ return navigationalState;
+ }
+}