Author: julien(a)jboss.com
Date: 2008-06-08 10:13:28 -0400 (Sun, 08 Jun 2008)
New Revision: 10945
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/PortalNodeState.java
Modified:
modules/presentation/trunk/portal/src/main/artifacts/presentation-portal-war/WEB-INF/jboss-beans.xml
modules/presentation/trunk/portal/src/test/java/org/jboss/portal/presentation/portal/model/StructuralStateContextTestCase.java
Log:
minor refactor
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-08
14:10:51 UTC (rev 10944)
+++
modules/presentation/trunk/portal/src/main/artifacts/presentation-portal-war/WEB-INF/jboss-beans.xml 2008-06-08
14:13:28 UTC (rev 10945)
@@ -135,7 +135,7 @@
<bean name="LayoutStore"
class="org.jboss.portal.presentation.portal.model.layout.LayoutStore"/>
- <bean name="PortalNodeAdapter"
class="org.jboss.portal.presentation.portal.model.object.PortalNodeAdapter">
+ <bean name="PortalNodeAdapter"
class="org.jboss.portal.presentation.portal.model.PortalNodeAdapter">
<constructor>
<parameter><inject
bean="PortalNodeManager"/></parameter>
<parameter><inject bean="LayoutStore"/></parameter>
Copied:
modules/presentation/trunk/portal/src/main/java/org/jboss/portal/presentation/portal/model/PortalNodeAdapter.java
(from rev 10943,
modules/presentation/trunk/portal/src/main/java/org/jboss/portal/presentation/portal/model/object/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-08
14:13:28 UTC (rev 10945)
@@ -0,0 +1,288 @@
+/******************************************************************************
+ * 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.impl.state.structural.adapter.StructuralAdapter;
+import org.jboss.portal.presentation.portal.model.layout.LayoutStructure;
+import org.jboss.portal.presentation.portal.model.layout.LayoutElement;
+import org.jboss.portal.presentation.portal.model.layout.StructureElement;
+import org.jboss.portal.presentation.portal.model.layout.NestedStructure;
+import org.jboss.portal.presentation.portal.model.layout.ObjectStructure;
+import org.jboss.portal.presentation.portal.model.layout.LayoutStore;
+import org.jboss.portal.presentation.portal.model.layout.LayoutObject;
+import org.jboss.portal.presentation.portal.model.layout.ObjectElement;
+import org.jboss.portal.presentation.portal.model.object.PortalNodeManager;
+import org.jboss.portal.presentation.portal.model.object.PortalNode;
+import org.jboss.portal.presentation.portal.model.object.PageNode;
+import org.jboss.portal.presentation.portal.model.object.WindowNode;
+import org.jboss.portal.presentation.model.ui.UIObject;
+import org.jboss.portal.presentation.model.ui.UIPane;
+import org.jboss.portal.presentation.model.ui.UIWindow;
+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.util.Collections;
+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;
+
+ /** . */
+ private LayoutStore layoutStore;
+
+ public PortalNodeAdapter(PortalNodeManager nodeManager, LayoutStore layoutStore)
+ {
+ this.nodeManager = nodeManager;
+ this.layoutStore = layoutStore;
+ }
+
+ public String getRootId()
+ {
+ return "node." + nodeManager.getRoot().getId();
+ }
+
+ public Object getNode(String id)
+ {
+ if (id.startsWith("node."))
+ {
+ return nodeManager.getNode(id.substring(5));
+ }
+ else if (id.startsWith("structure."))
+ {
+ return layoutStore.getObject(id.substring(10));
+ }
+ else
+ {
+ throw new IllegalArgumentException("Unrecognized id " + id);
+ }
+ }
+
+ public Object getParent(Object o)
+ {
+ if (o instanceof PortalNode)
+ {
+ return ((PortalNode)o).getParent();
+ }
+ else if (o instanceof LayoutElement)
+ {
+ LayoutStructure layout = ((LayoutElement)o).getStructure();
+
+ //
+ if (layout instanceof NestedStructure)
+ {
+ return ((NestedStructure)layout).getStructureElement();
+ }
+ else
+ {
+ ObjectStructure objectStructure = (ObjectStructure)layout;
+ String objectId = objectStructure.getObjectRef();
+ return nodeManager.getNode(objectId);
+ }
+ }
+ else
+ {
+ throw new NotYetImplemented();
+ }
+ }
+
+ public Collection<?> getChilren(Object o)
+ {
+ if (o instanceof PortalNode)
+ {
+ if (o instanceof PageNode)
+ {
+ String layoutStructureId = ((PageNode)o).getLayoutStructureId();
+
+ //
+ LayoutStructure layoutStructure =
(LayoutStructure)layoutStore.getObject(layoutStructureId);
+
+ //
+ return layoutStructure.getElements();
+ }
+ else
+ {
+ return ((PortalNode)o).getChildren();
+ }
+ }
+ else if (o instanceof LayoutElement)
+ {
+ if (o instanceof StructureElement)
+ {
+ return ((StructureElement)o).getNestedStructure().getElements();
+ }
+ else
+ {
+ return Collections.emptyList();
+ }
+ }
+ else
+ {
+ throw new NotYetImplemented();
+ }
+ }
+
+ public String getId(Object o)
+ {
+ if (o instanceof PortalNode)
+ {
+ return "node." + ((PortalNode)o).getId();
+ }
+ else if (o instanceof LayoutObject)
+ {
+ return "structure." + ((LayoutObject)o).getId();
+ }
+ else
+ {
+ throw new NotYetImplemented();
+ }
+ }
+
+ public Class<? extends UIObject> getType(Object o)
+ {
+ if (o instanceof PortalNode)
+ {
+ return ((PortalNode)o).getType();
+ }
+ else if (o instanceof LayoutElement)
+ {
+ if (o instanceof StructureElement)
+ {
+ return UIPane.class;
+ }
+ else if (o instanceof ObjectElement)
+ {
+ return UIWindow.class;
+ }
+ else
+ {
+ throw new NotYetImplemented();
+ }
+ }
+ else
+ {
+ throw new NotYetImplemented();
+ }
+ }
+
+ public String getName(Object o)
+ {
+ if (o instanceof PortalNode)
+ {
+ return ((PortalNode)o).getName();
+ }
+ else if (o instanceof LayoutObject)
+ {
+ // no natural name, for now use id
+ return ((LayoutObject)o).getId();
+ }
+ else
+ {
+ throw new NotYetImplemented();
+ }
+ }
+
+ public Map<String, Serializable> getProperties(Object o)
+ {
+ if (o instanceof PageNode)
+ {
+ PageNode page = (PageNode)o;
+
+ //
+ String layoutStructureId = ((PageNode)o).getLayoutStructureId();
+
+ //
+ LayoutStructure layoutStructure =
(LayoutStructure)layoutStore.getObject(layoutStructureId);
+
+ //
+ Map<String, Serializable> properties = new HashMap<String,
Serializable>(page.getProperties());
+
+ //
+ properties.putAll(layoutStructure.getState().getProperties());
+
+ //
+ return properties;
+ }
+ else if (o instanceof PortalNode)
+ {
+ return ((PortalNode)o).getProperties();
+ }
+ else if (o instanceof LayoutObject)
+ {
+ if (o instanceof ObjectElement)
+ {
+ ObjectElement element = (ObjectElement)o;
+
+ //
+ String windowId = element.getObjectRef();
+
+ //
+ WindowNode window = (WindowNode)nodeManager.getNode(windowId);
+
+ //
+ Map<String, Serializable> properties = new HashMap<String,
Serializable>(window.getProperties());
+
+ //
+ properties.putAll(element.getState().getProperties());
+
+ //
+ return properties;
+ }
+ else
+ {
+ return ((LayoutObject)o).getState().getProperties();
+ }
+ }
+ else
+ {
+ throw new NotYetImplemented();
+ }
+ }
+
+ public StructuralState getState(Object o)
+ {
+ Class<? extends UIObject> type = getType(o);
+ String name = getName(o);
+ Map<String, Serializable> properties = getProperties(o);
+
+ //
+ return new PortalNodeState(type, name, properties);
+ }
+
+ public void lock(Object o)
+ {
+ }
+
+ public void unlock(Object o)
+ {
+ }
+}
Copied:
modules/presentation/trunk/portal/src/main/java/org/jboss/portal/presentation/portal/model/PortalNodeState.java
(from rev 10942,
modules/presentation/trunk/portal/src/main/java/org/jboss/portal/presentation/portal/model/object/PortalNodeState.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-08
14:13:28 UTC (rev 10945)
@@ -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 $
+ */
+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;
+ }
+}
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-08
14:10:51 UTC (rev 10944)
+++
modules/presentation/trunk/portal/src/test/java/org/jboss/portal/presentation/portal/model/StructuralStateContextTestCase.java 2008-06-08
14:13:28 UTC (rev 10945)
@@ -34,7 +34,7 @@
import org.jboss.portal.presentation.portal.model.object.ContextNode;
import org.jboss.portal.presentation.portal.model.object.PageNode;
import org.jboss.portal.presentation.portal.model.object.PortalNode;
-import org.jboss.portal.presentation.portal.model.object.PortalNodeAdapter;
+import org.jboss.portal.presentation.portal.model.PortalNodeAdapter;
import org.jboss.portal.presentation.portal.model.object.PortalNodeManager;
import org.jboss.portal.presentation.portal.model.object.WindowNode;