Author: julien(a)jboss.com
Date: 2008-06-03 09:02:14 -0400 (Tue, 03 Jun 2008)
New Revision: 10911
Added:
modules/presentation/trunk/portal/src/main/java/org/jboss/portal/presentation/portal/model/PortalNodeAdapter.java
modules/presentation/trunk/portal/src/main/java/org/jboss/portal/presentation/portal/model/PortalNodeManager.java
modules/presentation/trunk/portal/src/main/java/org/jboss/portal/presentation/portal/model/PortalNodeState.java
modules/presentation/trunk/portal/src/main/java/org/jboss/portal/presentation/portal/model/structural/
modules/presentation/trunk/portal/src/main/java/org/jboss/portal/presentation/portal/model/structural/StructuralAdapter.java
modules/presentation/trunk/portal/src/main/java/org/jboss/portal/presentation/portal/model/structural/StructuralObjectImpl.java
modules/presentation/trunk/portal/src/main/java/org/jboss/portal/presentation/portal/model/structural/StructuralStateContextImpl.java
Removed:
modules/presentation/trunk/portal/src/main/java/org/jboss/portal/presentation/portal/model/StructuralNode.java
modules/presentation/trunk/portal/src/main/java/org/jboss/portal/presentation/portal/model/StructuralObjectImpl.java
modules/presentation/trunk/portal/src/main/java/org/jboss/portal/presentation/portal/model/StructuralStateContextImpl.java
modules/presentation/trunk/portal/src/main/java/org/jboss/portal/presentation/portal/model/StructuralStateImpl.java
Modified:
modules/presentation/trunk/portal/src/main/artifacts/presentation-portal-war/WEB-INF/jboss-beans.xml
modules/presentation/trunk/portal/src/main/java/org/jboss/portal/presentation/portal/PresentationServerImpl.java
modules/presentation/trunk/portal/src/main/java/org/jboss/portal/presentation/portal/model/ContextNode.java
modules/presentation/trunk/portal/src/main/java/org/jboss/portal/presentation/portal/model/PageNode.java
modules/presentation/trunk/portal/src/main/java/org/jboss/portal/presentation/portal/model/PaneNode.java
modules/presentation/trunk/portal/src/main/java/org/jboss/portal/presentation/portal/model/PortalNode.java
modules/presentation/trunk/portal/src/main/java/org/jboss/portal/presentation/portal/model/WindowNode.java
modules/presentation/trunk/portal/src/main/java/org/jboss/portal/presentation/portal/servlet/StructuralStateContextImporter.java
modules/presentation/trunk/portal/src/test/java/org/jboss/portal/presentation/portal/model/StructuralStateContextTestCase.java
Log:
decouple the portal node tree and the structural object facade
Modified:
modules/presentation/trunk/portal/src/main/artifacts/presentation-portal-war/WEB-INF/jboss-beans.xml
===================================================================
---
modules/presentation/trunk/portal/src/main/artifacts/presentation-portal-war/WEB-INF/jboss-beans.xml 2008-06-03
11:44:57 UTC (rev 10910)
+++
modules/presentation/trunk/portal/src/main/artifacts/presentation-portal-war/WEB-INF/jboss-beans.xml 2008-06-03
13:02:14 UTC (rev 10911)
@@ -131,7 +131,7 @@
</constructor>
</bean>
- <bean name="StructuralStateContext"
class="org.jboss.portal.presentation.portal.model.StructuralStateContextImpl"/>
+ <bean name="StructuralStateContext"
class="org.jboss.portal.presentation.portal.model.PortalNodeManager"/>
<bean name="StructuralStateContextImporter"
class="org.jboss.portal.presentation.portal.servlet.StructuralStateContextImporter">
<property name="servletContext"><inject
bean="ServletContext"/></property>
Modified:
modules/presentation/trunk/portal/src/main/java/org/jboss/portal/presentation/portal/PresentationServerImpl.java
===================================================================
---
modules/presentation/trunk/portal/src/main/java/org/jboss/portal/presentation/portal/PresentationServerImpl.java 2008-06-03
11:44:57 UTC (rev 10910)
+++
modules/presentation/trunk/portal/src/main/java/org/jboss/portal/presentation/portal/PresentationServerImpl.java 2008-06-03
13:02:14 UTC (rev 10911)
@@ -24,7 +24,7 @@
import org.jboss.portal.presentation.client.PresentationClient;
import org.jboss.portal.presentation.portal.model.PortalNode;
-import org.jboss.portal.presentation.portal.model.StructuralStateContextImpl;
+import org.jboss.portal.presentation.portal.model.PortalNodeManager;
import org.jboss.portal.presentation.portal.model.WindowNode;
import org.jboss.portal.presentation.portal.model.PageNode;
import org.jboss.portal.presentation.portal.content.protocol.ContentAction;
@@ -53,12 +53,12 @@
{
/** . */
- private StructuralStateContextImpl structuralStateContext;
+ private PortalNodeManager structuralStateContext;
/** . */
private ContentHandlerRegistry contentHandlerRegistry;
- public PresentationServerImpl(StructuralStateContextImpl structuralStateContext,
ContentHandlerRegistry contentHandlerRegistry)
+ public PresentationServerImpl(PortalNodeManager structuralStateContext,
ContentHandlerRegistry contentHandlerRegistry)
{
this.structuralStateContext = structuralStateContext;
this.contentHandlerRegistry = contentHandlerRegistry;
@@ -66,7 +66,7 @@
public StructuralStateContext getStructuralStateContext()
{
- return structuralStateContext;
+ return structuralStateContext.getStructuralStateContext();
}
public WindowContent renderWindow(PresentationClient client, String windowId) throws
PresentationServerException
Modified:
modules/presentation/trunk/portal/src/main/java/org/jboss/portal/presentation/portal/model/ContextNode.java
===================================================================
---
modules/presentation/trunk/portal/src/main/java/org/jboss/portal/presentation/portal/model/ContextNode.java 2008-06-03
11:44:57 UTC (rev 10910)
+++
modules/presentation/trunk/portal/src/main/java/org/jboss/portal/presentation/portal/model/ContextNode.java 2008-06-03
13:02:14 UTC (rev 10911)
@@ -31,7 +31,7 @@
*/
public class ContextNode extends PortalNode
{
- public ContextNode(String name, StructuralStateContextImpl structuralStateContext)
+ public ContextNode(String name, PortalNodeManager structuralStateContext)
{
super(name, structuralStateContext);
}
Modified:
modules/presentation/trunk/portal/src/main/java/org/jboss/portal/presentation/portal/model/PageNode.java
===================================================================
---
modules/presentation/trunk/portal/src/main/java/org/jboss/portal/presentation/portal/model/PageNode.java 2008-06-03
11:44:57 UTC (rev 10910)
+++
modules/presentation/trunk/portal/src/main/java/org/jboss/portal/presentation/portal/model/PageNode.java 2008-06-03
13:02:14 UTC (rev 10911)
@@ -35,7 +35,7 @@
*/
public class PageNode extends PortalNode
{
- public PageNode(String name, StructuralStateContextImpl structuralStateContext)
+ public PageNode(String name, PortalNodeManager structuralStateContext)
{
super(name, structuralStateContext);
}
Modified:
modules/presentation/trunk/portal/src/main/java/org/jboss/portal/presentation/portal/model/PaneNode.java
===================================================================
---
modules/presentation/trunk/portal/src/main/java/org/jboss/portal/presentation/portal/model/PaneNode.java 2008-06-03
11:44:57 UTC (rev 10910)
+++
modules/presentation/trunk/portal/src/main/java/org/jboss/portal/presentation/portal/model/PaneNode.java 2008-06-03
13:02:14 UTC (rev 10911)
@@ -32,7 +32,7 @@
public class PaneNode extends PortalNode
{
- public PaneNode(String name, StructuralStateContextImpl structuralStateContext)
+ public PaneNode(String name, PortalNodeManager structuralStateContext)
{
super(name, structuralStateContext);
}
Modified:
modules/presentation/trunk/portal/src/main/java/org/jboss/portal/presentation/portal/model/PortalNode.java
===================================================================
---
modules/presentation/trunk/portal/src/main/java/org/jboss/portal/presentation/portal/model/PortalNode.java 2008-06-03
11:44:57 UTC (rev 10910)
+++
modules/presentation/trunk/portal/src/main/java/org/jboss/portal/presentation/portal/model/PortalNode.java 2008-06-03
13:02:14 UTC (rev 10911)
@@ -23,8 +23,6 @@
package org.jboss.portal.presentation.portal.model;
import org.jboss.portal.presentation.model.ui.UIObject;
-import org.jboss.portal.presentation.state.StaleStateException;
-import org.jboss.portal.presentation.state.structural.StructuralObject;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
@@ -32,7 +30,6 @@
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.io.Serializable;
@@ -45,30 +42,27 @@
{
/** . */
- private final Set<String> EMPTY_STRING_SET = Collections.emptySet();
-
- /** . */
private PortalNode parent;
/** . */
- private final Map<String, PortalNode> children = new HashMap<String,
PortalNode>();
+ final Map<String, PortalNode> children = new HashMap<String,
PortalNode>();
/** . */
- private final StructuralStateContextImpl structuralStateContext;
+ private final PortalNodeManager structuralStateContext;
/** . */
- private final String id;
+ final String id;
/** . */
- private final String name;
+ private boolean valid;
/** . */
- private boolean valid;
+ final String name;
/** . */
- private final Map<String, Serializable> properties;
+ final Map<String, Serializable> properties;
- protected PortalNode(String name, StructuralStateContextImpl structuralStateContext)
+ protected PortalNode(String name, PortalNodeManager structuralStateContext)
{
this.name = name;
this.id = structuralStateContext.nextId();
@@ -79,112 +73,6 @@
public abstract Class<? extends UIObject> getType();
- Collection<StructuralObject> takeChildrenSnapshot(StructuralObject
structuralObject)
- {
- synchronized (this)
- {
- if (!takeSnapshot().equals(structuralObject))
- {
- throw new StaleStateException();
- }
-
- //
- Set<StructuralObject> structuralChildren = new
HashSet<StructuralObject>();
- for (PortalNode child : children.values())
- {
- structuralChildren.add(child.takeSnapshot());
- }
-
- //
- return structuralChildren;
- }
- }
-
- StructuralObject takeParentSnapshot(StructuralObject structuralObject)
- {
- synchronized (this)
- {
- if (!takeSnapshot().equals(structuralObject))
- {
- throw new StaleStateException();
- }
-
- //
- return parent != null ? parent.takeSnapshot() : null;
- }
- }
-
- StructuralObject takeSnapshot()
- {
- synchronized (this)
- {
- StructuralStateImpl state = new StructuralStateImpl(
- getType(),
- name,
- Collections.unmodifiableMap(new HashMap<String,
Serializable>(properties)));
-
- //
- Set<String> childrenIds = new HashSet<String>();
- for (PortalNode child : children.values())
- {
- childrenIds.add(child.id);
- }
-
- //
- String parentId = parent != null ? parent.id : null;
-
- //
- return new StructuralObjectImpl(id, parentId,
Collections.unmodifiableSet(childrenIds), state);
- }
- }
-
- StructuralObject.Refresh refresh(StructuralObjectImpl structuralObject)
- {
- synchronized (this)
- {
- Map<String, PortalNode> childrenMap = new HashMap<String,
PortalNode>();
- for (PortalNode child : children.values())
- {
- childrenMap.put(child.getId(), child);
- }
-
- //
- Map<String, PortalNode> addedChildrenMap = new HashMap<String,
PortalNode>(childrenMap);
- addedChildrenMap.keySet().removeAll(structuralObject.getChildrenIds());
-
- //
- Map<String, PortalNode> staleChildren = new HashMap<String,
PortalNode>(childrenMap);
- staleChildren.keySet().retainAll(structuralObject.getChildrenIds());
-
- //
- Set<String> removedChildrenIds = new
HashSet<String>(structuralObject.getChildrenIds());
- removedChildrenIds.removeAll(staleChildren.keySet());
-
- //
- Set<StructuralObject> addedStructuralChildren = new
HashSet<StructuralObject>();
- for (PortalNode addedChild : addedChildrenMap.values())
- {
- addedStructuralChildren.add(addedChild.takeSnapshot());
- }
-
- //
- Map<String, StructuralObject> staleStructuralChildren = new
HashMap<String, StructuralObject>();
- for (PortalNode stateChild : staleChildren.values())
- {
- staleStructuralChildren.put(stateChild.getId(), stateChild.takeSnapshot());
- }
-
- //
- return new StructuralObject.Refresh(
- parent != null ? parent.takeSnapshot() : null,
- takeSnapshot(),
- addedStructuralChildren,
- removedChildrenIds,
- staleStructuralChildren,
- EMPTY_STRING_SET);
- }
- }
-
public boolean isValid()
{
return valid;
@@ -210,6 +98,11 @@
return Collections.unmodifiableSet(properties.keySet());
}
+ public Map<String, Serializable> getProperties()
+ {
+ return Collections.unmodifiableMap(properties);
+ }
+
public Serializable getProperty(String propertyName)
{
if (propertyName == null)
@@ -265,7 +158,7 @@
T child;
try
{
- Constructor<T> ctor = type.getConstructor(String.class,
StructuralStateContextImpl.class);
+ Constructor<T> ctor = type.getConstructor(String.class,
PortalNodeManager.class);
child = ctor.newInstance(name, structuralStateContext);
}
catch (InstantiationException e)
Added:
modules/presentation/trunk/portal/src/main/java/org/jboss/portal/presentation/portal/model/PortalNodeAdapter.java
===================================================================
---
modules/presentation/trunk/portal/src/main/java/org/jboss/portal/presentation/portal/model/PortalNodeAdapter.java
(rev 0)
+++
modules/presentation/trunk/portal/src/main/java/org/jboss/portal/presentation/portal/model/PortalNodeAdapter.java 2008-06-03
13:02:14 UTC (rev 10911)
@@ -0,0 +1,158 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2008, 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.presentation.portal.model;
+
+import org.jboss.portal.presentation.portal.model.structural.StructuralAdapter;
+import org.jboss.portal.presentation.model.ui.UIObject;
+import org.jboss.portal.presentation.state.structural.StructuralState;
+import org.jboss.portal.common.NotYetImplemented;
+
+import java.util.Collection;
+import java.util.Map;
+import java.util.HashMap;
+import java.io.Serializable;
+
+/**
+ * @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
+ * @version $Revision: 630 $
+ */
+public class PortalNodeAdapter implements StructuralAdapter<Object>
+{
+
+ /** . */
+ private PortalNodeManager nodeManager;
+
+ public PortalNodeAdapter(PortalNodeManager nodeManager)
+ {
+ this.nodeManager = nodeManager;
+ }
+
+ public String getRootId()
+ {
+ return nodeManager.getRoot().getId();
+ }
+
+ public Object getNode(String id)
+ {
+ return nodeManager.getNode(id);
+ }
+
+ public Object getParent(Object o)
+ {
+ if (o instanceof PortalNode)
+ {
+ return ((PortalNode)o).getParent();
+ }
+ else
+ {
+ throw new NotYetImplemented();
+ }
+ }
+
+ public Collection<?> getChilren(Object o)
+ {
+ if (o instanceof PortalNode)
+ {
+ return ((PortalNode)o).getChildren();
+ }
+ else
+ {
+ throw new NotYetImplemented();
+ }
+ }
+
+ public String getId(Object o)
+ {
+ if (o instanceof PortalNode)
+ {
+ return ((PortalNode)o).getId();
+ }
+ else
+ {
+ throw new NotYetImplemented();
+ }
+ }
+
+ public Class<? extends UIObject> getType(Object o)
+ {
+ if (o instanceof PortalNode)
+ {
+ return ((PortalNode)o).getType();
+ }
+ else
+ {
+ throw new NotYetImplemented();
+ }
+ }
+
+ public String getName(Object o)
+ {
+ if (o instanceof PortalNode)
+ {
+ return ((PortalNode)o).getName();
+ }
+ else
+ {
+ throw new NotYetImplemented();
+ }
+ }
+
+ public Map<String, Serializable> getProperties(Object o)
+ {
+ if (o instanceof PortalNode)
+ {
+ return ((PortalNode)o).getProperties();
+ }
+ else
+ {
+ throw new NotYetImplemented();
+ }
+ }
+
+ public StructuralState getState(Object o)
+ {
+ if (o instanceof PortalNode)
+ {
+ PortalNode portalNode = (PortalNode)o;
+
+ //
+ return new PortalNodeState(
+ portalNode.getType(),
+ portalNode.getName(),
+ new HashMap<String, Serializable>(portalNode.getProperties())
+ );
+ }
+ else
+ {
+ throw new NotYetImplemented();
+ }
+ }
+
+ public void lock(Object o)
+ {
+ }
+
+ public void unlock(Object o)
+ {
+ }
+}
Copied:
modules/presentation/trunk/portal/src/main/java/org/jboss/portal/presentation/portal/model/PortalNodeManager.java
(from rev 10906,
modules/presentation/trunk/portal/src/main/java/org/jboss/portal/presentation/portal/model/StructuralStateContextImpl.java)
===================================================================
---
modules/presentation/trunk/portal/src/main/java/org/jboss/portal/presentation/portal/model/PortalNodeManager.java
(rev 0)
+++
modules/presentation/trunk/portal/src/main/java/org/jboss/portal/presentation/portal/model/PortalNodeManager.java 2008-06-03
13:02:14 UTC (rev 10911)
@@ -0,0 +1,105 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2008, 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.presentation.portal.model;
+
+import org.jboss.portal.presentation.state.structural.StructuralStateContext;
+import org.jboss.portal.presentation.portal.model.structural.StructuralStateContextImpl;
+
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.atomic.AtomicLong;
+
+/**
+ * @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
+ * @version $Revision: 630 $
+ */
+public class PortalNodeManager
+{
+
+ /** . */
+ private final AtomicLong sequence = new AtomicLong();
+
+ /** . */
+ final ConcurrentMap<String, PortalNode> nodes = new ConcurrentHashMap<String,
PortalNode>();
+
+ /** . */
+ private final ContextNode root = new ContextNode("", this);
+
+ /** . */
+ private final StructuralStateContext structuralStateContext;
+
+ public PortalNodeManager()
+ {
+ nodes.put(root.getId(), root);
+ structuralStateContext = new StructuralStateContextImpl<Object>(new
PortalNodeAdapter(this));
+ }
+
+ String nextId()
+ {
+ return Long.toString(sequence.getAndIncrement());
+ }
+
+ public StructuralStateContext getStructuralStateContext()
+ {
+ return structuralStateContext;
+ }
+
+ public PortalNode getNode(String nodeId)
+ {
+ if (nodeId == null)
+ {
+ throw new IllegalArgumentException();
+ }
+
+ //
+ return nodes.get(nodeId);
+ }
+
+ public ContextNode getRoot()
+ {
+ return root;
+ }
+
+ public void destroy(String objectId)
+ {
+ if (objectId == null)
+ {
+ throw new IllegalArgumentException();
+ }
+
+ //
+ PortalNode node = nodes.get(objectId);
+
+ //
+ PortalNode parent = node.getParent();
+
+ //
+ if (parent == null)
+ {
+ throw new IllegalArgumentException("Cannot destroy root");
+ }
+
+ //
+ parent.destroyChild(node.getName());
+ }
+}
Copied:
modules/presentation/trunk/portal/src/main/java/org/jboss/portal/presentation/portal/model/PortalNodeState.java
(from rev 10905,
modules/presentation/trunk/portal/src/main/java/org/jboss/portal/presentation/portal/model/StructuralStateImpl.java)
===================================================================
---
modules/presentation/trunk/portal/src/main/java/org/jboss/portal/presentation/portal/model/PortalNodeState.java
(rev 0)
+++
modules/presentation/trunk/portal/src/main/java/org/jboss/portal/presentation/portal/model/PortalNodeState.java 2008-06-03
13:02:14 UTC (rev 10911)
@@ -0,0 +1,99 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2008, 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.presentation.portal.model;
+
+import org.jboss.portal.presentation.model.ui.UIObject;
+import org.jboss.portal.presentation.state.structural.StructuralState;
+
+import java.util.Map;
+import java.io.Serializable;
+
+/**
+ * @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
+ * @version $Revision: 630 $
+ */
+public class PortalNodeState implements StructuralState
+{
+
+ /** . */
+ private final Class<? extends UIObject> type;
+
+ /** . */
+ private final String name;
+
+ /** . */
+ private final Map<String, Serializable> properties;
+
+ public PortalNodeState(
+ Class<? extends UIObject> type,
+ String name,
+ Map<String, Serializable> properties)
+ {
+ this.type = type;
+ this.name = name;
+ this.properties = properties;
+ }
+
+ public Class<? extends UIObject> getType()
+ {
+ return type;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public Map<String, Serializable> getProperties()
+ {
+ return properties;
+ }
+
+ public boolean equals(Object obj)
+ {
+ if (obj == this)
+ {
+ return true;
+ }
+ if (obj instanceof PortalNodeState)
+ {
+ PortalNodeState that = (PortalNodeState)obj;
+
+ //
+ if (!that.type.equals(this.type))
+ {
+ return false;
+ }
+
+ //
+ if (!that.name.equals(this.name))
+ {
+ return false;
+ }
+
+ //
+ return that.properties.equals(this.properties);
+ }
+ return false;
+ }
+}
Deleted:
modules/presentation/trunk/portal/src/main/java/org/jboss/portal/presentation/portal/model/StructuralNode.java
===================================================================
---
modules/presentation/trunk/portal/src/main/java/org/jboss/portal/presentation/portal/model/StructuralNode.java 2008-06-03
11:44:57 UTC (rev 10910)
+++
modules/presentation/trunk/portal/src/main/java/org/jboss/portal/presentation/portal/model/StructuralNode.java 2008-06-03
13:02:14 UTC (rev 10911)
@@ -1,353 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2008, 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.presentation.portal.model;
-
-import org.jboss.portal.presentation.model.ui.UIObject;
-import org.jboss.portal.presentation.state.StaleStateException;
-import org.jboss.portal.presentation.state.structural.StructuralObject;
-
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-import java.io.Serializable;
-
-/**
- * @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
- * @version $Revision: 630 $
- */
-public abstract class StructuralNode
-{
-
- /** . */
- private final Set<String> EMPTY_STRING_SET = Collections.emptySet();
-
- /** . */
- private StructuralNode parent;
-
- /** . */
- private final Map<String, StructuralNode> children = new HashMap<String,
StructuralNode>();
-
- /** . */
- private final StructuralStateContextImpl structuralStateContext;
-
- /** . */
- private final String id;
-
- /** . */
- private final String name;
-
- /** . */
- private boolean valid;
-
- /** . */
- private final Map<String, Serializable> properties;
-
- protected StructuralNode(String name, StructuralStateContextImpl
structuralStateContext)
- {
- this.name = name;
- this.id = structuralStateContext.nextId();
- this.structuralStateContext = structuralStateContext;
- this.properties = new HashMap<String, Serializable>();
- this.valid = true;
- }
-
- public abstract Class<? extends UIObject> getType();
-
- Collection<StructuralObject> takeChildrenSnapshot(StructuralObject
structuralObject)
- {
- synchronized (this)
- {
- if (!takeSnapshot().equals(structuralObject))
- {
- throw new StaleStateException();
- }
-
- //
- Set<StructuralObject> structuralChildren = new
HashSet<StructuralObject>();
- for (StructuralNode child : children.values())
- {
- structuralChildren.add(child.takeSnapshot());
- }
-
- //
- return structuralChildren;
- }
- }
-
- StructuralObject takeParentSnapshot(StructuralObject structuralObject)
- {
- synchronized (this)
- {
- if (!takeSnapshot().equals(structuralObject))
- {
- throw new StaleStateException();
- }
-
- //
- return parent != null ? parent.takeSnapshot() : null;
- }
- }
-
- StructuralObject takeSnapshot()
- {
- synchronized (this)
- {
- StructuralStateImpl state = new StructuralStateImpl(
- getType(),
- name,
- Collections.unmodifiableMap(new HashMap<String,
Serializable>(properties)));
-
- //
- Set<String> childrenIds = new HashSet<String>();
- for (StructuralNode child : children.values())
- {
- childrenIds.add(child.id);
- }
-
- //
- String parentId = parent != null ? parent.id : null;
-
- //
- return new StructuralObjectImpl(id, parentId,
Collections.unmodifiableSet(childrenIds), state);
- }
- }
-
- StructuralObject.Refresh refresh(StructuralObjectImpl structuralObject)
- {
- synchronized (this)
- {
- Map<String, StructuralNode> childrenMap = new HashMap<String,
StructuralNode>();
- for (StructuralNode child : children.values())
- {
- childrenMap.put(child.getId(), child);
- }
-
- //
- Map<String, StructuralNode> addedChildrenMap = new HashMap<String,
StructuralNode>(childrenMap);
- addedChildrenMap.keySet().removeAll(structuralObject.getChildrenIds());
-
- //
- Map<String, StructuralNode> staleChildren = new HashMap<String,
StructuralNode>(childrenMap);
- staleChildren.keySet().retainAll(structuralObject.getChildrenIds());
-
- //
- Set<String> removedChildrenIds = new
HashSet<String>(structuralObject.getChildrenIds());
- removedChildrenIds.removeAll(staleChildren.keySet());
-
- //
- Set<StructuralObject> addedStructuralChildren = new
HashSet<StructuralObject>();
- for (StructuralNode addedChild : addedChildrenMap.values())
- {
- addedStructuralChildren.add(addedChild.takeSnapshot());
- }
-
- //
- Map<String, StructuralObject> staleStructuralChildren = new
HashMap<String, StructuralObject>();
- for (StructuralNode stateChild : staleChildren.values())
- {
- staleStructuralChildren.put(stateChild.getId(), stateChild.takeSnapshot());
- }
-
- //
- return new StructuralObject.Refresh(
- parent != null ? parent.takeSnapshot() : null,
- takeSnapshot(),
- addedStructuralChildren,
- removedChildrenIds,
- staleStructuralChildren,
- EMPTY_STRING_SET);
- }
- }
-
- public boolean isValid()
- {
- return valid;
- }
-
- public String getId()
- {
- return id;
- }
-
- public String getName()
- {
- return name;
- }
-
- public StructuralNode getParent()
- {
- return parent;
- }
-
- public Set<String> getPropertyNames()
- {
- return Collections.unmodifiableSet(properties.keySet());
- }
-
- public Serializable getProperty(String propertyName)
- {
- if (propertyName == null)
- {
- throw new IllegalArgumentException("No null property name");
- }
-
- //
- synchronized (this)
- {
- return properties.get(propertyName);
- }
- }
-
- public void setProperty(String propertyName, Serializable propertyValue)
- {
- if (propertyName == null)
- {
- throw new IllegalArgumentException("No null property name");
- }
-
- //
- synchronized (this)
- {
- if (propertyValue != null)
- {
- properties.put(propertyName, propertyValue);
- }
- else
- {
- properties.remove(propertyName);
- }
- }
- }
-
- public Collection<? extends StructuralNode> getChildren()
- {
- return Collections.unmodifiableCollection(children.values());
- }
-
- public <T extends StructuralNode> T addChild(String name, Class<T> type)
- {
- if (name == null)
- {
- throw new IllegalArgumentException();
- }
- if (type == null)
- {
- throw new IllegalArgumentException();
- }
-
- //
- T child;
- try
- {
- Constructor<T> ctor = type.getConstructor(String.class,
StructuralStateContextImpl.class);
- child = ctor.newInstance(name, structuralStateContext);
- }
- catch (InstantiationException e)
- {
- throw new AssertionError(e);
- }
- catch (IllegalAccessException e)
- {
- throw new AssertionError(e);
- }
- catch (NoSuchMethodException e)
- {
- throw new AssertionError(e);
- }
- catch (InvocationTargetException e)
- {
- throw new AssertionError(e);
- }
-
- //
- synchronized (this)
- {
- if (children.containsKey(name))
- {
- throw new IllegalArgumentException("Child already exist");
- }
- children.put(name, child);
- child.parent = this;
- }
-
- //
- structuralStateContext.nodes.put(child.id, child);
-
- //
- return child;
- }
-
- public void destroyChild(String name)
- {
- if (name == null)
- {
- throw new IllegalArgumentException();
- }
-
- //
- StructuralNode child;
- synchronized (this)
- {
- if (!children.containsKey(name))
- {
- throw new IllegalArgumentException("No such child " + name);
- }
-
- child = children.get(name);
-
- //
- for (String blah : new ArrayList<String>(child.children.keySet()))
- {
- child.destroyChild(blah);
- }
-
- //
- children.remove(name);
- structuralStateContext.nodes.remove(child.id);
-
- //
- child.valid = false;
- child.parent = null;
- }
- }
-
- public StructuralNode getChild(String name)
- {
- if (name == null)
- {
- throw new IllegalArgumentException();
- }
-
- //
- synchronized (this)
- {
- return children.get(name);
- }
- }
-}
Deleted:
modules/presentation/trunk/portal/src/main/java/org/jboss/portal/presentation/portal/model/StructuralObjectImpl.java
===================================================================
---
modules/presentation/trunk/portal/src/main/java/org/jboss/portal/presentation/portal/model/StructuralObjectImpl.java 2008-06-03
11:44:57 UTC (rev 10910)
+++
modules/presentation/trunk/portal/src/main/java/org/jboss/portal/presentation/portal/model/StructuralObjectImpl.java 2008-06-03
13:02:14 UTC (rev 10911)
@@ -1,121 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2008, 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.presentation.portal.model;
-
-import org.jboss.portal.presentation.state.structural.StructuralObject;
-import org.jboss.portal.presentation.state.structural.StructuralState;
-
-import java.util.Set;
-
-/**
- * @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
- * @version $Revision: 630 $
- */
-public class StructuralObjectImpl implements StructuralObject
-{
-
- /** . */
- private final String id;
-
- /** . */
- private final StructuralStateImpl state;
-
- /** . */
- private final String parentId;
-
- /** . */
- private final Set<String> childrenIds;
-
- public StructuralObjectImpl(
- String id,
- String parentId,
- Set<String> childrenIds,
- StructuralStateImpl state)
- {
- this.id = id;
- this.parentId = parentId;
- this.childrenIds = childrenIds;
- this.state = state;
- }
-
- String getParentId()
- {
- return parentId;
- }
-
- Set<String> getChildrenIds()
- {
- return childrenIds;
- }
-
- public String getId()
- {
- return id;
- }
-
- public StructuralState getState()
- {
- return state;
- }
-
- public boolean equals(Object obj)
- {
- if (obj == this)
- {
- return true;
- }
- if (obj instanceof StructuralObjectImpl)
- {
- StructuralObjectImpl that = (StructuralObjectImpl)obj;
-
- //
- if (!that.id.equals(this.id))
- {
- return false;
- }
-
- //
- if (!that.state.equals(this.state))
- {
- return false;
- }
-
- //
- if (that.parentId == null)
- {
- if (this.parentId != null)
- {
- return false;
- }
- }
- else if (!that.parentId.equals(this.parentId))
- {
- return false;
- }
-
- //
- return that.childrenIds.equals(this.childrenIds);
- }
- return false;
- }
-}
Deleted:
modules/presentation/trunk/portal/src/main/java/org/jboss/portal/presentation/portal/model/StructuralStateContextImpl.java
===================================================================
---
modules/presentation/trunk/portal/src/main/java/org/jboss/portal/presentation/portal/model/StructuralStateContextImpl.java 2008-06-03
11:44:57 UTC (rev 10910)
+++
modules/presentation/trunk/portal/src/main/java/org/jboss/portal/presentation/portal/model/StructuralStateContextImpl.java 2008-06-03
13:02:14 UTC (rev 10911)
@@ -1,202 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2008, 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.presentation.portal.model;
-
-import org.jboss.portal.presentation.state.NoSuchStateException;
-import org.jboss.portal.presentation.state.StaleStateException;
-import org.jboss.portal.presentation.state.StateException;
-import org.jboss.portal.presentation.state.structural.StructuralObject;
-import org.jboss.portal.presentation.state.structural.StructuralStateContext;
-
-import java.util.Collection;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
-import java.util.concurrent.atomic.AtomicLong;
-
-/**
- * @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
- * @version $Revision: 630 $
- */
-public class StructuralStateContextImpl implements StructuralStateContext
-{
-
- /** . */
- private final AtomicLong sequence = new AtomicLong();
-
- /** . */
- final ConcurrentMap<String, PortalNode> nodes = new ConcurrentHashMap<String,
PortalNode>();
-
- /** . */
- private final ContextNode root = new ContextNode("", this);
-
- public StructuralStateContextImpl()
- {
- nodes.put(root.getId(), root);
- }
-
- String nextId()
- {
- return Long.toString(sequence.getAndIncrement());
- }
-
- public PortalNode getNode(String nodeId)
- {
- if (nodeId == null)
- {
- throw new IllegalArgumentException();
- }
-
- //
- return nodes.get(nodeId);
- }
-
- public ContextNode getRoot()
- {
- return root;
- }
-
- public void destroy(String objectId)
- {
- if (objectId == null)
- {
- throw new IllegalArgumentException();
- }
-
- //
- PortalNode node = nodes.get(objectId);
-
- //
- PortalNode parent = node.getParent();
-
- //
- if (parent == null)
- {
- throw new IllegalArgumentException("Cannot destroy root");
- }
-
- //
- parent.destroyChild(node.getName());
- }
-
- public StructuralObject load(String objectId) throws IllegalArgumentException
- {
- if (objectId == null)
- {
- throw new IllegalArgumentException();
- }
-
- //
- PortalNode node = nodes.get(objectId);
-
- //
- return node != null ? node.takeSnapshot() : null;
- }
-
- public Collection<StructuralObject> loadChildren(StructuralObject
structuralParent) throws IllegalArgumentException, StateException
- {
- if (structuralParent == null)
- {
- throw new IllegalArgumentException();
- }
-
- //
- PortalNode parentNode = nodes.get(structuralParent.getId());
-
- //
- if (parentNode == null)
- {
- throw new NoSuchStateException();
- }
-
- //
- return parentNode.takeChildrenSnapshot(structuralParent);
- }
-
- public StructuralObject loadParent(StructuralObject structuralChild) throws
IllegalArgumentException, StateException
- {
- if (structuralChild == null)
- {
- throw new IllegalArgumentException();
- }
-
- //
- PortalNode childNode = nodes.get(structuralChild.getId());
-
- //
- if (childNode == null)
- {
- throw new NoSuchStateException();
- }
-
- //
- return childNode.takeParentSnapshot(structuralChild);
- }
-
- public String getRootId()
- {
- return root.getId();
- }
-
- public void validate(StructuralObject structuralObject) throws
IllegalArgumentException, StateException
- {
- if (structuralObject == null)
- {
- throw new IllegalArgumentException();
- }
-
- //
- PortalNode portalNode = nodes.get(structuralObject.getId());
-
- //
- if (portalNode == null)
- {
- throw new NoSuchStateException();
- }
-
- //
- if (!portalNode.takeSnapshot().equals(structuralObject))
- {
- throw new StaleStateException();
- }
- }
-
- public StructuralObject.Refresh refresh(StructuralObject structuralObject) throws
IllegalArgumentException, StateException
- {
- if (structuralObject == null)
- {
- throw new IllegalArgumentException();
- }
-
- //
- PortalNode portalNode = nodes.get(structuralObject.getId());
-
- //
- if (portalNode == null)
- {
- throw new NoSuchStateException();
- }
-
- //
- return portalNode.refresh((StructuralObjectImpl)structuralObject);
- }
-}
Deleted:
modules/presentation/trunk/portal/src/main/java/org/jboss/portal/presentation/portal/model/StructuralStateImpl.java
===================================================================
---
modules/presentation/trunk/portal/src/main/java/org/jboss/portal/presentation/portal/model/StructuralStateImpl.java 2008-06-03
11:44:57 UTC (rev 10910)
+++
modules/presentation/trunk/portal/src/main/java/org/jboss/portal/presentation/portal/model/StructuralStateImpl.java 2008-06-03
13:02:14 UTC (rev 10911)
@@ -1,99 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2008, 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.presentation.portal.model;
-
-import org.jboss.portal.presentation.model.ui.UIObject;
-import org.jboss.portal.presentation.state.structural.StructuralState;
-
-import java.util.Map;
-import java.io.Serializable;
-
-/**
- * @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
- * @version $Revision: 630 $
- */
-public class StructuralStateImpl implements StructuralState
-{
-
- /** . */
- private final Class<? extends UIObject> type;
-
- /** . */
- private final String name;
-
- /** . */
- private final Map<String, Serializable> properties;
-
- public StructuralStateImpl(
- Class<? extends UIObject> type,
- String name,
- Map<String, Serializable> properties)
- {
- this.type = type;
- this.name = name;
- this.properties = properties;
- }
-
- public Class<? extends UIObject> getType()
- {
- return type;
- }
-
- public String getName()
- {
- return name;
- }
-
- public Map<String, Serializable> getProperties()
- {
- return properties;
- }
-
- public boolean equals(Object obj)
- {
- if (obj == this)
- {
- return true;
- }
- if (obj instanceof StructuralStateImpl)
- {
- StructuralStateImpl that = (StructuralStateImpl)obj;
-
- //
- if (!that.type.equals(this.type))
- {
- return false;
- }
-
- //
- if (!that.name.equals(this.name))
- {
- return false;
- }
-
- //
- return that.properties.equals(this.properties);
- }
- return false;
- }
-}
Modified:
modules/presentation/trunk/portal/src/main/java/org/jboss/portal/presentation/portal/model/WindowNode.java
===================================================================
---
modules/presentation/trunk/portal/src/main/java/org/jboss/portal/presentation/portal/model/WindowNode.java 2008-06-03
11:44:57 UTC (rev 10910)
+++
modules/presentation/trunk/portal/src/main/java/org/jboss/portal/presentation/portal/model/WindowNode.java 2008-06-03
13:02:14 UTC (rev 10911)
@@ -39,7 +39,7 @@
/** . */
private Content content;
- public WindowNode(String name, StructuralStateContextImpl structuralStateContext)
+ public WindowNode(String name, PortalNodeManager structuralStateContext)
{
super(name, structuralStateContext);
}
Added:
modules/presentation/trunk/portal/src/main/java/org/jboss/portal/presentation/portal/model/structural/StructuralAdapter.java
===================================================================
---
modules/presentation/trunk/portal/src/main/java/org/jboss/portal/presentation/portal/model/structural/StructuralAdapter.java
(rev 0)
+++
modules/presentation/trunk/portal/src/main/java/org/jboss/portal/presentation/portal/model/structural/StructuralAdapter.java 2008-06-03
13:02:14 UTC (rev 10911)
@@ -0,0 +1,61 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2008, 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.presentation.portal.model.structural;
+
+import org.jboss.portal.presentation.model.ui.UIObject;
+import org.jboss.portal.presentation.state.structural.StructuralState;
+
+import java.util.Collection;
+import java.util.Map;
+import java.io.Serializable;
+
+/**
+ * @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
+ * @version $Revision: 630 $
+ */
+public interface StructuralAdapter<N>
+{
+
+ String getRootId();
+
+ N getNode(String id);
+
+ N getParent(N n);
+
+ Collection<? extends N> getChilren(N n);
+
+ String getId(N n);
+
+ Class<? extends UIObject> getType(N n);
+
+ String getName(N n);
+
+ Map<String, Serializable> getProperties(N n);
+
+ StructuralState getState(N n);
+
+ void lock(N n);
+
+ void unlock(N n);
+
+}
Added:
modules/presentation/trunk/portal/src/main/java/org/jboss/portal/presentation/portal/model/structural/StructuralObjectImpl.java
===================================================================
---
modules/presentation/trunk/portal/src/main/java/org/jboss/portal/presentation/portal/model/structural/StructuralObjectImpl.java
(rev 0)
+++
modules/presentation/trunk/portal/src/main/java/org/jboss/portal/presentation/portal/model/structural/StructuralObjectImpl.java 2008-06-03
13:02:14 UTC (rev 10911)
@@ -0,0 +1,121 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2008, 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.presentation.portal.model.structural;
+
+import org.jboss.portal.presentation.state.structural.StructuralObject;
+import org.jboss.portal.presentation.state.structural.StructuralState;
+
+import java.util.Set;
+
+/**
+ * @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
+ * @version $Revision: 630 $
+ */
+public class StructuralObjectImpl implements StructuralObject
+{
+
+ /** . */
+ private final String id;
+
+ /** . */
+ private final StructuralState state;
+
+ /** . */
+ private final String parentId;
+
+ /** . */
+ private final Set<String> childrenIds;
+
+ public StructuralObjectImpl(
+ String id,
+ String parentId,
+ Set<String> childrenIds,
+ StructuralState state)
+ {
+ this.id = id;
+ this.parentId = parentId;
+ this.childrenIds = childrenIds;
+ this.state = state;
+ }
+
+ String getParentId()
+ {
+ return parentId;
+ }
+
+ Set<String> getChildrenIds()
+ {
+ return childrenIds;
+ }
+
+ public String getId()
+ {
+ return id;
+ }
+
+ public StructuralState getState()
+ {
+ return state;
+ }
+
+ public boolean equals(Object obj)
+ {
+ if (obj == this)
+ {
+ return true;
+ }
+ if (obj instanceof StructuralObjectImpl)
+ {
+ StructuralObjectImpl that = (StructuralObjectImpl)obj;
+
+ //
+ if (!that.id.equals(this.id))
+ {
+ return false;
+ }
+
+ //
+ if (!that.state.equals(this.state))
+ {
+ return false;
+ }
+
+ //
+ if (that.parentId == null)
+ {
+ if (this.parentId != null)
+ {
+ return false;
+ }
+ }
+ else if (!that.parentId.equals(this.parentId))
+ {
+ return false;
+ }
+
+ //
+ return that.childrenIds.equals(this.childrenIds);
+ }
+ return false;
+ }
+}
\ No newline at end of file
Added:
modules/presentation/trunk/portal/src/main/java/org/jboss/portal/presentation/portal/model/structural/StructuralStateContextImpl.java
===================================================================
---
modules/presentation/trunk/portal/src/main/java/org/jboss/portal/presentation/portal/model/structural/StructuralStateContextImpl.java
(rev 0)
+++
modules/presentation/trunk/portal/src/main/java/org/jboss/portal/presentation/portal/model/structural/StructuralStateContextImpl.java 2008-06-03
13:02:14 UTC (rev 10911)
@@ -0,0 +1,267 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2008, 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.presentation.portal.model.structural;
+
+import org.jboss.portal.presentation.state.NoSuchStateException;
+import org.jboss.portal.presentation.state.StaleStateException;
+import org.jboss.portal.presentation.state.StateException;
+import org.jboss.portal.presentation.state.structural.StructuralObject;
+import org.jboss.portal.presentation.state.structural.StructuralStateContext;
+import org.jboss.portal.presentation.state.structural.StructuralState;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Set;
+import java.util.HashSet;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
+ * @version $Revision: 630 $
+ */
+public class StructuralStateContextImpl<N> implements StructuralStateContext
+{
+
+ /** . */
+ private final Set<String> EMPTY_STRING_SET = Collections.emptySet();
+
+ /** . */
+ private final StructuralAdapter<N> adapter;
+
+ public StructuralStateContextImpl(StructuralAdapter<N> adapter)
+ {
+ this.adapter = adapter;
+ }
+
+ public StructuralObject load(String objectId) throws IllegalArgumentException
+ {
+ if (objectId == null)
+ {
+ throw new IllegalArgumentException();
+ }
+
+ //
+ N node = adapter.getNode(objectId);
+
+ //
+ return node != null ? takeSnapshot(node) : null;
+ }
+
+ private StructuralObjectImpl takeSnapshot(N node)
+ {
+ adapter.lock(node);
+
+ //
+ try
+ {
+ StructuralState state = adapter.getState(node);
+
+ //
+ Set<String> childrenIds = new HashSet<String>();
+ for (N childNode : adapter.getChilren(node))
+ {
+ childrenIds.add(adapter.getId(childNode));
+ }
+
+ //
+ N parent = adapter.getParent(node);
+
+ //
+ String parentId = parent != null ? adapter.getId(parent) : null;
+
+ //
+ return new StructuralObjectImpl(adapter.getId(node), parentId,
Collections.unmodifiableSet(childrenIds), state);
+ }
+ finally
+ {
+ adapter.unlock(node);
+ }
+ }
+
+ public Collection<StructuralObject> loadChildren(StructuralObject
structuralParent) throws IllegalArgumentException, StateException
+ {
+ if (structuralParent == null)
+ {
+ throw new IllegalArgumentException();
+ }
+
+ //
+ N parentNode = adapter.getNode(structuralParent.getId());
+
+ //
+ if (parentNode == null)
+ {
+ throw new NoSuchStateException();
+ }
+
+ if (!takeSnapshot(parentNode).equals(structuralParent))
+ {
+ throw new StaleStateException();
+ }
+
+ // todo : the returned children node might have changed before we take the snapshot
we need to find a way to prevent that
+
+ //
+ Set<StructuralObject> structuralChildren = new
HashSet<StructuralObject>();
+ for (N childNode : adapter.getChilren(parentNode))
+ {
+ structuralChildren.add(takeSnapshot(childNode));
+ }
+
+ //
+ return structuralChildren;
+ }
+
+ public StructuralObject loadParent(StructuralObject structuralChild) throws
IllegalArgumentException, StateException
+ {
+ if (structuralChild == null)
+ {
+ throw new IllegalArgumentException();
+ }
+
+ //
+ N childNode = adapter.getNode(structuralChild.getId());
+
+ //
+ if (childNode == null)
+ {
+ throw new NoSuchStateException();
+ }
+
+ //
+ if (!takeSnapshot(childNode).equals(structuralChild))
+ {
+ throw new StaleStateException();
+ }
+
+ //
+ N parentNode = adapter.getParent(childNode);
+
+ // todo : the returned parent node might have changed before we take the snapshot
we need to find a way to prevent that
+
+ //
+ return parentNode != null ? takeSnapshot(parentNode) : null;
+ }
+
+ public String getRootId()
+ {
+ return adapter.getRootId();
+ }
+
+ public void validate(StructuralObject structuralObject) throws
IllegalArgumentException, StateException
+ {
+ if (structuralObject == null)
+ {
+ throw new IllegalArgumentException();
+ }
+
+ //
+ N node = adapter.getNode(structuralObject.getId());
+
+ //
+ if (node == null)
+ {
+ throw new NoSuchStateException();
+ }
+
+ //
+ if (!takeSnapshot(node).equals(structuralObject))
+ {
+ throw new StaleStateException();
+ }
+ }
+
+ public StructuralObject.Refresh refresh(StructuralObject structuralObject) throws
IllegalArgumentException, StateException
+ {
+ return refresh((StructuralObjectImpl)structuralObject);
+
+ }
+
+ /**
+ * todo : implement correct concurrency
+ */
+ private StructuralObject.Refresh refresh(StructuralObjectImpl structuralObject) throws
IllegalArgumentException, StateException
+ {
+ if (structuralObject == null)
+ {
+ throw new IllegalArgumentException();
+ }
+
+ //
+ N node = adapter.getNode(structuralObject.getId());
+
+ //
+ if (node == null)
+ {
+ throw new NoSuchStateException();
+ }
+
+ //
+ StructuralObjectImpl nodeSnapshot = takeSnapshot(node);
+
+ Map<String, N> childrenMap = new HashMap<String, N>();
+ for (N childNode : adapter.getChilren(node))
+ {
+ childrenMap.put(adapter.getId(childNode), childNode);
+ }
+
+ //
+ Map<String, N> addedChildrenMap = new HashMap<String, N>(childrenMap);
+ addedChildrenMap.keySet().removeAll(structuralObject.getChildrenIds());
+
+ //
+ Map<String, N> staleChildren = new HashMap<String, N>(childrenMap);
+ staleChildren.keySet().retainAll(structuralObject.getChildrenIds());
+
+ //
+ Set<String> removedChildrenIds = new
HashSet<String>(structuralObject.getChildrenIds());
+ removedChildrenIds.removeAll(staleChildren.keySet());
+
+ //
+ Set<StructuralObject> addedStructuralChildren = new
HashSet<StructuralObject>();
+ for (N addedChild : addedChildrenMap.values())
+ {
+ addedStructuralChildren.add(takeSnapshot(addedChild));
+ }
+
+ //
+ Map<String, StructuralObject> staleStructuralChildren = new
HashMap<String, StructuralObject>();
+ for (N staleChildNode : staleChildren.values())
+ {
+ staleStructuralChildren.put(adapter.getId(staleChildNode),
takeSnapshot(staleChildNode));
+ }
+
+ //
+ N parentNode = adapter.getParent(node);
+
+ //
+ return new StructuralObject.Refresh(
+ parentNode != null ? takeSnapshot(parentNode) : null,
+ nodeSnapshot,
+ addedStructuralChildren,
+ removedChildrenIds,
+ staleStructuralChildren,
+ EMPTY_STRING_SET);
+ }
+}
\ No newline at end of file
Modified:
modules/presentation/trunk/portal/src/main/java/org/jboss/portal/presentation/portal/servlet/StructuralStateContextImporter.java
===================================================================
---
modules/presentation/trunk/portal/src/main/java/org/jboss/portal/presentation/portal/servlet/StructuralStateContextImporter.java 2008-06-03
11:44:57 UTC (rev 10910)
+++
modules/presentation/trunk/portal/src/main/java/org/jboss/portal/presentation/portal/servlet/StructuralStateContextImporter.java 2008-06-03
13:02:14 UTC (rev 10911)
@@ -22,7 +22,7 @@
******************************************************************************/
package org.jboss.portal.presentation.portal.servlet;
-import org.jboss.portal.presentation.portal.model.StructuralStateContextImpl;
+import org.jboss.portal.presentation.portal.model.PortalNodeManager;
import org.jboss.portal.presentation.portal.model.NodeImporter;
import org.jboss.portal.presentation.portal.model.ContextNode;
import org.jboss.portal.common.io.IOTools;
@@ -41,7 +41,7 @@
private ServletContext servletContext;
/** . */
- private StructuralStateContextImpl structuralStateContext;
+ private PortalNodeManager structuralStateContext;
public ServletContext getServletContext()
{
@@ -53,12 +53,12 @@
this.servletContext = servletContext;
}
- public StructuralStateContextImpl getStructuralStateContext()
+ public PortalNodeManager getStructuralStateContext()
{
return structuralStateContext;
}
- public void setStructuralStateContext(StructuralStateContextImpl
structuralStateContext)
+ public void setStructuralStateContext(PortalNodeManager structuralStateContext)
{
this.structuralStateContext = structuralStateContext;
}
Modified:
modules/presentation/trunk/portal/src/test/java/org/jboss/portal/presentation/portal/model/StructuralStateContextTestCase.java
===================================================================
---
modules/presentation/trunk/portal/src/test/java/org/jboss/portal/presentation/portal/model/StructuralStateContextTestCase.java 2008-06-03
11:44:57 UTC (rev 10910)
+++
modules/presentation/trunk/portal/src/test/java/org/jboss/portal/presentation/portal/model/StructuralStateContextTestCase.java 2008-06-03
13:02:14 UTC (rev 10911)
@@ -42,11 +42,11 @@
{
/** . */
- private StructuralStateContextImpl structuralStateContext;
+ private PortalNodeManager structuralStateContext;
protected StructuralStateContext getStructuralStateContext()
{
- return structuralStateContext;
+ return structuralStateContext.getStructuralStateContext();
}
protected PortalNode getRoot()
@@ -132,6 +132,6 @@
protected void setUp() throws Exception
{
- structuralStateContext = new StructuralStateContextImpl();
+ structuralStateContext = new PortalNodeManager();
}
}