Author: sohil.shah(a)jboss.com
Date: 2007-11-15 11:30:05 -0500 (Thu, 15 Nov 2007)
New Revision: 8950
Added:
branches/UIServer/core/src/main/org/jboss/portal/core/presentation/model/
branches/UIServer/core/src/main/org/jboss/portal/core/presentation/model/ModelLoaderImpl.java
branches/UIServer/core/src/main/org/jboss/portal/test/core/presentation/
branches/UIServer/core/src/main/org/jboss/portal/test/core/presentation/model/
branches/UIServer/core/src/main/org/jboss/portal/test/core/presentation/model/UIModelTester.java
branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/test/model/
branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/test/model/MockModelLoaderImpl.java
branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/test/model/UIModelTester.java
Modified:
branches/UIServer/core/build.xml
branches/UIServer/core/src/main/org/jboss/portal/core/presentation/server/PresentationServerImpl.java
branches/UIServer/core/src/resources/portal-core-sar/META-INF/jboss-service.xml
branches/UIServer/core/src/resources/portal-core-test-jar/org/jboss/portal/test/core/model/portal/persistent-jboss-beans.xml
branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/impl/model2/UIContextImpl.java
branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/impl/model2/UIObjectImpl.java
branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/model2/UIContext.java
branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/model2/UIObject.java
branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/model2/UIWindow.java
branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/model2/state/ObjectState.java
branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/server/PresentationServer.java
Log:
integrated UI model population from PortalObjectContainer
Modified: branches/UIServer/core/build.xml
===================================================================
--- branches/UIServer/core/build.xml 2007-11-15 16:20:16 UTC (rev 8949)
+++ branches/UIServer/core/build.xml 2007-11-15 16:30:05 UTC (rev 8950)
@@ -641,7 +641,11 @@
<test todir="${test.reports}"
name="org.jboss.portal.test.core.model.portal.PortalObjectPathTestCase"/>
-
+ <zest todir="${test.reports}"
name="org.jboss.portal.test.core.presentation.model.UIModelTester"
+ outfile="TEST-UIModelTester">
+ <parameter name="CacheNaturalId" value="true"/>
+ <parameter name="Config"
value="persistent-jboss-beans.xml"/>
+ </zest>
</x-test>
<x-classpath>
<pathelement location="${build.lib}/portal-core-lib.jar"/>
@@ -672,7 +676,61 @@
</x-classpath>
</execute-tests>
</target>
+
+ <target name="test-presentation" depends="init">
+ <execute-tests>
+ <x-sysproperty>
+
+ <!--
+ <jvmarg value="-Xdebug"/>
+ <jvmarg
value="-Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=y"/>
+ -->
+ <sysproperty
+ key="jboss.aop.path"
+
value="${build.resources}/jboss-portal.sar/portal-aop.xml${path.separator}${source.etc}/jboss-aop/base-aop.xml"/>
+ <sysproperty
+ key="jboss.aop.class.path"
+
value="${jbossas/core.libs.lib}/jboss-aspect-library.jar"/>
+
+ </x-sysproperty>
+ <x-test>
+ <zest todir="${test.reports}"
name="org.jboss.portal.test.core.presentation.model.UIModelTester"
+ outfile="TEST-UIModelTester">
+ <parameter name="CacheNaturalId" value="true"/>
+ <parameter name="Config"
value="persistent-jboss-beans.xml"/>
+ </zest>
+ </x-test>
+ <x-classpath>
+ <pathelement
location="${build.lib}/portal-core-lib.jar"/>
+ <pathelement
location="${build.lib}/portal-core-test-lib.jar"/>
+ <pathelement
location="${build.resources}/jboss-portal.sar"/>
+ <pathelement location="${jboss.portal-test.root}/etc"/>
+ <pathelement location="${build.resources}"/>
+
+ <path refid="apache.collections.classpath"/>
+ <path refid="apache.logging.classpath"/>
+ <path refid="apache.xerces.classpath"/>
+ <path refid="jboss.jbossxb.classpath"/>
+ <path refid="oswego.concurrent.classpath"/>
+ <path refid="jboss.microcontainer.classpath"/>
+ <path refid="apache.httpclient.classpath"/>
+ <path refid="aop.classpath"/>
+ <path refid="dom4j.dom4j.classpath"/>
+ <path refid="cglib.cglib.classpath"/>
+ <path refid="antlr.antlr.classpath"/>
+ <path refid="asm.asm.classpath"/>
+
+ <path refid="library.classpath"/>
+ <path refid="dependentmodule.classpath"/>
+ <pathelement
location="${nekohtml.nekohtml.lib}/nekohtml.jar"/>
+ <pathelement
location="${dbunit.dbunit.lib}/dbunit.jar"/>
+ <pathelement
location="${jdbc.connectors.lib}/mysql-connector-java.jar"/>
+ <!--<pathelement
location="postgresql-8.1-407.jdbc3.jar"/>-->
+ </x-classpath>
+ </execute-tests>
+ </target>
+
<!--
Run a single unit test.
ant -Dtest=org.jboss.portal.test.core.model.portal.PortalObjectContainerTestCase
one-test
Added:
branches/UIServer/core/src/main/org/jboss/portal/core/presentation/model/ModelLoaderImpl.java
===================================================================
---
branches/UIServer/core/src/main/org/jboss/portal/core/presentation/model/ModelLoaderImpl.java
(rev 0)
+++
branches/UIServer/core/src/main/org/jboss/portal/core/presentation/model/ModelLoaderImpl.java 2007-11-15
16:30:05 UTC (rev 8950)
@@ -0,0 +1,172 @@
+/******************************************************************************
+ * 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.presentation.model;
+
+import java.util.StringTokenizer;
+import java.util.Map;
+import java.util.List;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.ArrayList;
+
+import org.jboss.portal.presentation.model2.UIObject;
+import org.jboss.portal.presentation.impl.model2.UIPortalImpl;
+import org.jboss.portal.presentation.impl.model2.UIPageImpl;
+import org.jboss.portal.presentation.impl.model2.UIWindowImpl;
+import org.jboss.portal.presentation.model2.state.ModelLoader;
+import org.jboss.portal.presentation.model2.state.ObjectState;
+
+import org.jboss.portal.core.model.portal.PortalObjectContainer;
+import org.jboss.portal.core.model.portal.PortalContainer;
+import org.jboss.portal.core.model.portal.PortalObject;
+import org.jboss.portal.core.model.portal.Page;
+import org.jboss.portal.core.model.portal.Window;
+import org.jboss.portal.core.model.portal.Portal;
+
+/**
+ * @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
+ *
+ */
+public class ModelLoaderImpl implements ModelLoader
+{
+ /**
+ *
+ */
+ private PortalObjectContainer portalObjectContainer = null;
+
+ /**
+ *
+ * @return
+ */
+ public PortalObjectContainer getPortalObjectContainer()
+ {
+ return portalObjectContainer;
+ }
+
+ /**
+ *
+ * @param portalObjectContainer
+ */
+ public void setPortalObjectContainer(
+ PortalObjectContainer portalObjectContainer)
+ {
+ this.portalObjectContainer = portalObjectContainer;
+ }
+
+ /**
+ *
+ */
+ public ObjectState loadState(String objectId) throws IllegalArgumentException
+ {
+ ObjectState objectState = null;
+
+ //Get the PortalObject corresponding to this objectId from the
PortalObjectContainer
+ PortalContainer portalContainer = this.portalObjectContainer.getContext();
+
+ StringTokenizer st = new StringTokenizer(objectId, "/");
+ PortalObject portalObject = portalContainer.getChild(st.nextToken());
+ while(st.hasMoreTokens())
+ {
+ String token = st.nextToken();
+ portalObject = portalObject.getChild(token);
+ }
+
+ //Type
+ Class<? extends UIObject> type = this.getType(portalObject);
+
+ //Name
+ String name = portalObject.getName();
+
+ //Properties
+ Map<String, String> properties = portalObject.getDeclaredProperties();
+
+ //Parent Id
+ String parentId = portalObject.getParent().getId().toString();
+ if(parentId.equals("/"))
+ {
+ parentId = "";
+ }
+
+ //Children Ids
+ List<String> childrenIds = new ArrayList<String>();
+ Collection children = portalObject.getChildren();
+ for(Iterator itr=children.iterator(); itr.hasNext();)
+ {
+ PortalObject child = (PortalObject)itr.next();
+ childrenIds.add(child.getId().toString());
+ }
+
+ objectState = new ObjectState(
+ type, //type
+ name,
+ properties, //properties
+ parentId,
+ childrenIds // childrenIds
+ );
+
+ return objectState;
+ }
+
+ /**
+ *
+ * @param portalObject
+ * @return
+ */
+ private Class<? extends UIObject> getType(PortalObject portalObject)
+ {
+ Class<? extends UIObject> type = null;
+
+ if(portalObject instanceof Portal)
+ {
+ type = UIPortalImpl.class;
+ }
+ else if(portalObject instanceof Page)
+ {
+ type = UIPageImpl.class;
+ }
+ else if(portalObject instanceof Window)
+ {
+ type = UIWindowImpl.class;
+ }
+
+ return type;
+ }
+
+ /**
+ *
+ *
+ */
+ public void start()
+ {
+
+ }
+
+ /**
+ *
+ *
+ */
+ public void stop()
+ {
+
+ }
+}
Modified:
branches/UIServer/core/src/main/org/jboss/portal/core/presentation/server/PresentationServerImpl.java
===================================================================
---
branches/UIServer/core/src/main/org/jboss/portal/core/presentation/server/PresentationServerImpl.java 2007-11-15
16:20:16 UTC (rev 8949)
+++
branches/UIServer/core/src/main/org/jboss/portal/core/presentation/server/PresentationServerImpl.java 2007-11-15
16:30:05 UTC (rev 8950)
@@ -22,9 +22,12 @@
******************************************************************************/
package org.jboss.portal.core.presentation.server;
+import org.jboss.portal.presentation.RequestContext;
import org.jboss.portal.presentation.server.Processor;
+import org.jboss.portal.presentation.server.PresentationServer;
import org.jboss.portal.presentation.server.PortalObjectReader;
-import org.jboss.portal.presentation.server.PresentationServer;
+import org.jboss.portal.presentation.model2.UIWindow;
+import org.jboss.portal.presentation.model2.state.ModelLoader;
/**
* @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
@@ -32,11 +35,18 @@
*/
public class PresentationServerImpl implements PresentationServer
{
+ /**
+ *
+ */
private Processor processor = null;
- private PortalObjectReader portalObjectReader = null;
/**
*
+ */
+ private ModelLoader modelLoader = null;
+
+ /**
+ *
*
*/
public PresentationServerImpl()
@@ -65,18 +75,18 @@
/**
*
*/
- public PortalObjectReader getPortalObjectReader()
+ public ModelLoader getModelLoader()
{
- return this.portalObjectReader;
+ return modelLoader;
}
-
+
/**
*
- * @param portalObjectReader
+ * @param modelLoader
*/
- public void setPortalObjectReader(PortalObjectReader portalObjectReader)
+ public void setModelLoader(ModelLoader modelLoader)
{
- this.portalObjectReader = portalObjectReader;
+ this.modelLoader = modelLoader;
}
/**
@@ -95,4 +105,20 @@
{
this.processor = processor;
}
+
+ /**
+ * @deprecated
+ */
+ public PortalObjectReader getPortalObjectReader()
+ {
+ return null;
+ }
+
+ /**
+ *
+ */
+ public String getMarkup(RequestContext context, UIWindow window) throws Exception
+ {
+ return null;
+ }
}
Added:
branches/UIServer/core/src/main/org/jboss/portal/test/core/presentation/model/UIModelTester.java
===================================================================
---
branches/UIServer/core/src/main/org/jboss/portal/test/core/presentation/model/UIModelTester.java
(rev 0)
+++
branches/UIServer/core/src/main/org/jboss/portal/test/core/presentation/model/UIModelTester.java 2007-11-15
16:30:05 UTC (rev 8950)
@@ -0,0 +1,149 @@
+/******************************************************************************
+ * 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.test.core.presentation.model;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import junit.framework.TestSuite;
+
+import org.apache.log4j.Logger;
+import org.jboss.portal.test.core.model.portal.AbstractPortalObjectContainerTestCase;
+import org.jboss.portal.test.framework.AbstractPortalTestCase;
+
+import org.jboss.portal.common.junit.TransactionAssert;
+import org.jboss.portal.core.model.portal.*;
+import org.jboss.portal.core.model.content.ContentType;
+import org.jboss.portal.core.presentation.model.ModelLoaderImpl;
+import org.jboss.portal.presentation.model2.*;
+import org.jboss.portal.presentation.impl.model2.*;
+
+/**
+ * @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
+ *
+ */
+public class UIModelTester extends AbstractPortalObjectContainerTestCase
+{
+ private Logger logger = Logger.getLogger(this.getClass());
+
+ private UIContext uiContext = null;
+
+ /**
+ *
+ * @return
+ * @throws Exception
+ */
+ public static TestSuite suite() throws Exception
+ {
+ return AbstractPortalTestCase.suite(UIModelTester.class);
+ }
+
+ /**
+ *
+ */
+ public void setUp() throws Exception
+ {
+ super.setUp();
+ ModelLoaderImpl modelLoader = new ModelLoaderImpl();
+ modelLoader.setPortalObjectContainer(this.container);
+ this.uiContext = new UIContextImpl();
+ ((UIContextImpl)this.uiContext).setModelLoader(modelLoader);
+ this.loadPortalObjectContainer();
+ }
+
+ /**
+ *
+ */
+ public void tearDown() throws Exception
+ {
+ super.tearDown();
+ this.uiContext = null;
+ }
+
+ /**
+ *
+ * @throws Exception
+ */
+ public void testModelLoading() throws Exception
+ {
+ TransactionAssert.beginTransaction();
+
+ //Setup rootChildrenInfo
+ Map rootChildrenInfo = new HashMap();
+ rootChildrenInfo.put("defaultPortal", UIPortalImpl.class);
+
+ UIContext objectTree = this.uiContext.initUIObjectTree(rootChildrenInfo);
+ UIObject defaultPortal = objectTree.getChildren(UIPortalImpl.class).get(0);
+
+ assertEquals(defaultPortal.getName(), "defaultPortal");
+ assertEquals(defaultPortal.getId(), "/defaultPortal");
+ assertTrue(defaultPortal instanceof UIPortal);
+
+ List<UIObject> lazyLoadedChildren = defaultPortal.getChildren();
+
+ assertTrue((lazyLoadedChildren != null &&
lazyLoadedChildren.size()>0));
+ for(int i=0; i<lazyLoadedChildren.size(); i++)
+ {
+ UIObject child = lazyLoadedChildren.get(i);
+ assertEquals(child.getParent().getName(), "defaultPortal");
+ assertEquals(child.getParent().getId(), "/defaultPortal");
+ assertTrue(child instanceof UIPage);
+ assertTrue(child.getId().equals("/defaultPortal/page1") ||
child.getId().equals("/defaultPortal/page2"));
+
+ if(child.getId().equals("/defaultPortal/page1"))
+ {
+ List<UIObject> subchildren = child.getChildren();
+ for(int j=0; j<subchildren.size(); j++)
+ {
+ UIObject subchild = subchildren.get(j);
+
+ logger.info("------------------------------");
+
logger.info("Child="+subchild+"("+subchild.getId()+")");
+ logger.info("------------------------------");
+ }
+ }
+ }
+
+
+ TransactionAssert.commitTransaction();
+ }
+
+ /**
+ *
+ *
+ */
+ private void loadPortalObjectContainer() throws Exception
+ {
+ TransactionAssert.beginTransaction();
+ PortalContainer ctx = container.getContext();
+ Portal portal_1 = ctx.createPortal("defaultPortal");
+ Page page_1_1 = portal_1.createPage("page1");
+ Page page_1_2 = portal_1.createPage("page2");
+ Page page_1_1_1 = page_1_1.createPage("subpage1");
+ Page page_1_1_3 = page_1_1.createPage("subpage2");
+ Window window_1_1_2 = page_1_1.createWindow("window1",
ContentType.PORTLET, "uri");
+ Window window_1_1_4 = page_1_1.createWindow("window3",
ContentType.PORTLET, "uri");
+ TransactionAssert.commitTransaction();
+ }
+}
Modified: branches/UIServer/core/src/resources/portal-core-sar/META-INF/jboss-service.xml
===================================================================
---
branches/UIServer/core/src/resources/portal-core-sar/META-INF/jboss-service.xml 2007-11-15
16:20:16 UTC (rev 8949)
+++
branches/UIServer/core/src/resources/portal-core-sar/META-INF/jboss-service.xml 2007-11-15
16:30:05 UTC (rev 8950)
@@ -1097,8 +1097,8 @@
xmbean-dd=""
xmbean-code="org.jboss.portal.jems.as.system.JBossServiceModelMBean">
<xmbean/>
- <depends optional-attribute-name="PortalObjectReader"
proxy-type="attribute">portal:container=PortalObjectReader</depends>
<depends optional-attribute-name="Processor"
proxy-type="attribute">portal:service=Processor</depends>
+ <depends optional-attribute-name="ModelLoader"
proxy-type="attribute">portal:container=ModelLoader</depends>
<depends>portal:service=PageService</depends>
<depends>portal:commandFactory=DefaultPortal</depends>
<depends>portal:urlFactory=Delegating</depends>
@@ -1130,8 +1130,8 @@
<depends>portal:service=ControlPolicy,type=Page</depends>
</mbean>
<mbean
- code="org.jboss.portal.core.presentation.server.PortalObjectReaderImpl"
- name="portal:container=PortalObjectReader"
+ code="org.jboss.portal.core.presentation.model.ModelLoaderImpl"
+ name="portal:container=ModelLoader"
xmbean-dd=""
xmbean-code="org.jboss.portal.jems.as.system.JBossServiceModelMBean">
<xmbean/>
@@ -1147,8 +1147,7 @@
<depends>portal:service=ContentProviderRegistry</depends>
<depends>portal:service=ResponseHandler,type=Selector</depends>
<depends>portal:service=ControlPolicy,type=Page</depends>
- </mbean>
-
+ </mbean>
<!-- The controller factory -->
<mbean
Modified:
branches/UIServer/core/src/resources/portal-core-test-jar/org/jboss/portal/test/core/model/portal/persistent-jboss-beans.xml
===================================================================
---
branches/UIServer/core/src/resources/portal-core-test-jar/org/jboss/portal/test/core/model/portal/persistent-jboss-beans.xml 2007-11-15
16:20:16 UTC (rev 8949)
+++
branches/UIServer/core/src/resources/portal-core-test-jar/org/jboss/portal/test/core/model/portal/persistent-jboss-beans.xml 2007-11-15
16:30:05 UTC (rev 8950)
@@ -90,7 +90,7 @@
<property name="portalAuthorizationManagerFactory"><inject
bean="AuthorizationManagerFactory"/></property>
<property name="contentProviderRegistry"><inject
bean="ContentProviderRegistry"/></property>
</bean>
-
+
<bean name="TestBean"
class="org.jboss.portal.test.core.model.portal.PortalObjectContainerTestCase">
<constructor factoryMethod="getBean">
<factory bean="BeanFactory"/>
@@ -99,5 +99,5 @@
<property name="hibernate"><inject
bean="HibernateSupport"/></property>
<property name="portalObjectContainer"><inject
bean="PortalObjectContainer"/></property>
<property name="authorizationManagerFactory"><inject
bean="AuthorizationManagerFactory"/></property>
- </bean>
+ </bean>
</deployment>
Modified:
branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/impl/model2/UIContextImpl.java
===================================================================
---
branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/impl/model2/UIContextImpl.java 2007-11-15
16:20:16 UTC (rev 8949)
+++
branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/impl/model2/UIContextImpl.java 2007-11-15
16:30:05 UTC (rev 8950)
@@ -22,8 +22,12 @@
******************************************************************************/
package org.jboss.portal.presentation.impl.model2;
+import java.util.Map;
+import java.util.Iterator;
import org.jboss.portal.presentation.model2.UIContext;
import org.jboss.portal.presentation.model2.UIObject;
+import org.jboss.portal.presentation.model2.state.ModelLoader;
+import org.jboss.portal.presentation.model2.state.ObjectState;
/**
* @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
@@ -34,8 +38,79 @@
/**
*
*/
- public UIObject getObject(String id)
+ private ModelLoader modelLoader = null;
+
+ /**
+ *
+ *
+ */
+ public UIContextImpl()
{
- return null;
}
+
+ /**
+ *
+ */
+ public <T extends UIObject> T getObject(String id, Class<T> type)
+ {
+ try
+ {
+ T uiObject = null;
+
+ //Fetch the state of the UIObject in question
+ ObjectState objectState = this.modelLoader.loadState(id);
+
+ uiObject = type.newInstance();
+ ((UIObjectImpl)uiObject).setState(this,objectState, true);
+
+ return uiObject;
+ }
+ catch(InstantiationException ie)
+ {
+ throw new RuntimeException(ie);
+ }
+ catch(IllegalAccessException iae)
+ {
+ throw new RuntimeException(iae);
+ }
+ }
+
+ /**
+ *
+ */
+ public UIContext initUIObjectTree(Map<String,Class<? extends UIObject>>
rootChildrenInfo)
+ {
+ UIContext uiContext = new UIContextImpl();
+ ((UIContextImpl)uiContext).setModelLoader(this.getModelLoader());
+
+ //load the children of the UIContext
+ Iterator<String> childrenNames = rootChildrenInfo.keySet().iterator();
+ while(childrenNames.hasNext())
+ {
+ String childName = childrenNames.next();
+ Class<? extends UIObject> type = rootChildrenInfo.get(childName);
+ UIObject child = uiContext.createChild(childName, type);
+ ObjectState objectState = this.modelLoader.loadState(child.getId());
+ ((UIObjectImpl)child).setState(this,objectState, false);
+ }
+
+ return uiContext;
+ }
+
+ /**
+ *
+ */
+ public ModelLoader getModelLoader()
+ {
+ return this.modelLoader;
+ }
+
+ /**
+ *
+ * @param modelLoader
+ */
+ public void setModelLoader(ModelLoader modelLoader)
+ {
+ this.modelLoader = modelLoader;
+ }
}
Modified:
branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/impl/model2/UIObjectImpl.java
===================================================================
---
branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/impl/model2/UIObjectImpl.java 2007-11-15
16:20:16 UTC (rev 8949)
+++
branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/impl/model2/UIObjectImpl.java 2007-11-15
16:30:05 UTC (rev 8950)
@@ -24,14 +24,17 @@
import java.util.List;
import java.util.ArrayList;
+import java.io.Serializable;
import org.jboss.portal.presentation.model2.UIObject;
+import org.jboss.portal.presentation.model2.UIContext;
+import org.jboss.portal.presentation.model2.state.ObjectState;
/**
* @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
*
*/
-public abstract class UIObjectImpl implements UIObject
+public abstract class UIObjectImpl implements UIObject, Serializable
{
/**
*
@@ -46,20 +49,33 @@
/**
*
*/
- protected List<UIObject> children = new ArrayList<UIObject>();
+ protected UIObject parent = null;
/**
*
*/
- protected UIObject parent = null;
+ protected List<UIObject> children = new ArrayList<UIObject>(); //Lazy
loaded
/**
+ * used to see if the children of this UIObject are fully loaded or not. Used for
helping with lazy loading
+ */
+ private boolean childrenFullyLoaded = false;
+
+
+ /**
+ * This is used to assist with data needed during lazy loading, other state related
data etc
+ */
+ private ObjectState state = null;
+
+
+ /**
*
*/
public UIObjectImpl()
{
}
+ //UIObject interface
implementation-----------------------------------------------------------------------------------------------------------------------------
/**
*
*/
@@ -80,55 +96,90 @@
*
*/
public UIObject getParent()
- {
+ {
return this.parent;
}
/**
*
*/
+ public List<UIObject> getChildren()
+ {
+ if(!this.childrenFullyLoaded)
+ {
+ //Lazy Load just the children of this UIObject. Don't load the children of
each child though
+ if(this.state != null)
+ {
+ List<String> childrenIds = this.state.getChildrenIds();
+ if(childrenIds != null)
+ {
+ for(int i=0; i<childrenIds.size(); i++)
+ {
+ String childId = childrenIds.get(i);
+ ObjectState childState =
this.getUIContext().getModelLoader().loadState(childId);
+ this.createChild(childState.getName(), childState.getType());
+ }
+ }
+ }
+
+ this.childrenFullyLoaded = true;
+ }
+
+ return this.children;
+ }
+
+ /**
+ *
+ */
+ public <T extends UIObject> List<UIObject> getChildren(Class<T>
type)
+ {
+ List<UIObject> filteredList = new ArrayList<UIObject>();
+
+ //Making sure all children are fully loaded
+ List<UIObject> allChildren = this.getChildren();
+
+ if(allChildren != null)
+ {
+ for(int i=0; i<allChildren.size(); i++)
+ {
+ UIObject child = allChildren.get(i);
+ if(type == child.getClass())
+ {
+ filteredList.add(child);
+ }
+ }
+ }
+ return filteredList;
+ }
+
+ /**
+ *
+ */
public <T extends UIObject> T createChild(String name, Class<T> type)
throws IllegalArgumentException
{
try
{
T child = null;
- if(type == UIContainerImpl.class)
+ if(type == UIContextImpl.class)
{
- child = type.newInstance();
- ((UIContainerImpl)child).name = name;
- ((UIContainerImpl)child).parent = this;
- ((UIContainerImpl)child).id = this.generateId(name);
+ throw new IllegalArgumentException("UIContext must be the root of the
UIObject tree. It should not be added to any UIObject as a child");
}
- else if(type == UIContextImpl.class)
- {
- child = type.newInstance();
- ((UIContextImpl)child).name = name;
- ((UIContextImpl)child).parent = this;
- ((UIContextImpl)child).id = this.generateId(name);
- }
- else if(type == UIPageImpl.class)
- {
- child = type.newInstance();
- ((UIPageImpl)child).name = name;
- ((UIPageImpl)child).parent = this;
- ((UIPageImpl)child).id = this.generateId(name);
- }
- else if(type == UIPortalImpl.class)
- {
- child = type.newInstance();
- ((UIPortalImpl)child).name = name;
- ((UIPortalImpl)child).parent = this;
- ((UIPortalImpl)child).id = this.generateId(name);
- }
- else if(type == UIWindowImpl.class)
- {
- child = type.newInstance();
- ((UIWindowImpl)child).name = name;
- ((UIWindowImpl)child).parent = this;
- ((UIWindowImpl)child).id = this.generateId(name);
- }
+ child = type.newInstance();
+
+ //Name
+ ((UIObjectImpl)child).name = name;
+
+ //Parent
+ ((UIObjectImpl)child).parent = this;
+
+ //Id
+ ((UIObjectImpl)child).id = this.generateChildId(name);
+
+ //State
+ ((UIObjectImpl)child).state =
this.getUIContext().getModelLoader().loadState(((UIObjectImpl)child).id);
+
this.children.add(child);
return child;
}
@@ -146,7 +197,9 @@
*
*/
public void destroyChild(String name)
- {
+ {
+ //Make sure all children are loaded
+ this.getChildren();
if(this.children != null)
{
for(int i=0; i<this.children.size(); i++)
@@ -159,53 +212,127 @@
}
}
}
+ }
+ //-----UIObjectImpl implementation specific
methods------------------------------------------------------------------------------------------------------------
+ protected void setState(UIContext uiContext, ObjectState state, boolean loadParent)
+ {
+ //Name
+ this.name = state.getName();
+
+ //Parent..load using parentId from state being used
+ if(loadParent && state.getParentId() != null &&
state.getParentId().trim().length()>0)
+ {
+ ObjectState parentState =
uiContext.getModelLoader().loadState(state.getParentId());
+ this.parent = uiContext.getObject(state.getParentId(), parentState.getType());
+ }
+
+ //Id
+ this.id = this.generateId();
+
+ //State
+ this.state = state;
}
-
+
//--------------------------------------------------------------------------------------------------------------------------------------------------------------
/**
*
+ * @return
*/
- public List<UIObject> getChildren()
+ private String generateId()
{
- return this.children;
+ String newId = null;
+
+ String myName = "";
+ if(this.getName() != null && this.getName().trim().length()>0)
+ {
+ myName = this.getName();
+ }
+
+ //Generate a new id concatenating its entire path in the UIObject tree
+ StringBuffer buffer = new StringBuffer();
+ if(this.getParent() != null && !(this.getParent() instanceof UIContext))
+ {
+
buffer.append("/"+this.getParent().getId().substring(1)+"/");
+ if(myName.trim().length()>0)
+ {
+ buffer.append(myName);
+ }
+ newId = buffer.toString();
+ }
+ else
+ {
+ buffer.append("/");
+ if(myName.trim().length()>0)
+ {
+ buffer.append(myName);
+ }
+ newId = buffer.toString();
+ }
+
+ return newId;
}
-
+
/**
*
+ * @return
*/
- public <T extends UIObject> List<UIObject> getChildren(Class<T>
type)
+ private String generateChildId(String childName)
{
- List<UIObject> filteredList = new ArrayList<UIObject>();
- if(this.children != null)
+ String newId = null;
+
+ String myName = "";
+ if(this.getName() != null && this.getName().trim().length()>0)
{
- for(int i=0; i<this.children.size(); i++)
+ myName = this.getName();
+ }
+
+ //Generate a new id concatenating its entire path in the UIObject tree
+ StringBuffer buffer = new StringBuffer();
+ if(this.getParent() != null && !(this.getParent() instanceof UIContext))
+ {
+
buffer.append("/"+this.getParent().getId().substring(1)+"/");
+ if(myName.trim().length()>0)
{
- UIObject child = this.children.get(i);
- if(type == child.getClass())
- {
- filteredList.add(child);
- }
+ buffer.append(myName+"/");
}
+ buffer.append(childName);
+ newId = buffer.toString();
}
- return filteredList;
- }
+ else
+ {
+ buffer.append("/");
+ if(myName.trim().length()>0)
+ {
+ buffer.append(myName+"/");
+ }
+ buffer.append(childName);
+ newId = buffer.toString();
+ }
+
+ return newId;
+ }
/**
*
* @return
*/
- private String generateId(String childName)
+ private UIContext getUIContext()
{
- String newId = null;
+ UIContext uiContext = null;
- if(this.parent != null)
+ //Make sure this UIObject is not the root UIContext object
+ if(this.getParent() == null)
{
- newId = this.parent.getId() + "/" + this.name + "/" +
childName;
+ return (UIContext)this;
}
- else
+
+ //Move up the tree to the UIContext and get the ModelLoader
+ UIObject parent = this.getParent();
+ while(!(parent instanceof UIContext))
{
- newId = this.name + "/" + childName;
+ parent = parent.getParent();
}
+ uiContext = (UIContext)parent;
- return newId;
+ return uiContext;
}
}
Modified:
branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/model2/UIContext.java
===================================================================
---
branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/model2/UIContext.java 2007-11-15
16:20:16 UTC (rev 8949)
+++
branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/model2/UIContext.java 2007-11-15
16:30:05 UTC (rev 8950)
@@ -22,13 +22,33 @@
******************************************************************************/
package org.jboss.portal.presentation.model2;
+import java.util.Map;
+import org.jboss.portal.presentation.model2.state.ModelLoader;
+
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision: 1.1 $
*/
public interface UIContext extends UIObject
{
-
- UIObject getObject(String id);
-
+ /**
+ *
+ * @param id
+ * @return
+ */
+ public <T extends UIObject> T getObject(String id, Class<T> type);
+
+ /**
+ *
+ * @param <T>
+ * @param childrenInfo
+ * @return
+ */
+ public UIContext initUIObjectTree(Map<String,Class<? extends UIObject>>
rootChildrenInfo);
+
+ /**
+ *
+ * @return
+ */
+ public ModelLoader getModelLoader();
}
Modified:
branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/model2/UIObject.java
===================================================================
---
branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/model2/UIObject.java 2007-11-15
16:20:16 UTC (rev 8949)
+++
branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/model2/UIObject.java 2007-11-15
16:30:05 UTC (rev 8950)
@@ -34,19 +34,19 @@
*
* @return
*/
- String getId();
+ public String getId();
/**
*
* @return
*/
- String getName();
+ public String getName();
/**
*
* @return
*/
- UIObject getParent();
+ public UIObject getParent();
/**
* Create a child with a specified type.
@@ -56,19 +56,19 @@
* @return the newly created child
* @throws IllegalArgumentException if the name is null, already exists or this kind
of object does not accept children of the specified type
*/
- <T extends UIObject>T createChild(String name, Class<T> type) throws
IllegalArgumentException;
+ public <T extends UIObject>T createChild(String name, Class<T> type)
throws IllegalArgumentException;
/**
*
* @param name
*/
- void destroyChild(String name);
+ public void destroyChild(String name);
/**
*
* @return
*/
- List<UIObject> getChildren();
+ public List<UIObject> getChildren();
/**
*
@@ -76,5 +76,5 @@
* @param type
* @return
*/
- <T extends UIObject> List<UIObject> getChildren(Class<T> type);
+ public <T extends UIObject> List<UIObject> getChildren(Class<T>
type);
}
Modified:
branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/model2/UIWindow.java
===================================================================
---
branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/model2/UIWindow.java 2007-11-15
16:20:16 UTC (rev 8949)
+++
branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/model2/UIWindow.java 2007-11-15
16:30:05 UTC (rev 8950)
@@ -31,17 +31,39 @@
*/
public interface UIWindow extends UIObject
{
+ /**
+ *
+ * @return
+ */
+ public String getTitle();
- String getTitle();
+ /**
+ *
+ * @param title
+ */
+ public void setTitle(String title);
- void setTitle(String title);
+ /**
+ *
+ * @return
+ */
+ public WindowState getWindowState();
- WindowState getWindowState();
-
- void setWindowState(WindowState windowState);
+ /**
+ *
+ * @param windowState
+ */
+ public void setWindowState(WindowState windowState);
- Mode getMode();
+ /**
+ *
+ * @return
+ */
+ public Mode getMode();
- void setMode(Mode mode);
-
+ /**
+ *
+ * @param mode
+ */
+ public void setMode(Mode mode);
}
Modified:
branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/model2/state/ObjectState.java
===================================================================
---
branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/model2/state/ObjectState.java 2007-11-15
16:20:16 UTC (rev 8949)
+++
branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/model2/state/ObjectState.java 2007-11-15
16:30:05 UTC (rev 8950)
@@ -24,6 +24,7 @@
import org.jboss.portal.presentation.model2.UIObject;
+import java.io.Serializable;
import java.util.Map;
import java.util.List;
@@ -31,7 +32,7 @@
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision: 1.1 $
*/
-public class ObjectState
+public class ObjectState implements Serializable
{
/** . */
Modified:
branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/server/PresentationServer.java
===================================================================
---
branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/server/PresentationServer.java 2007-11-15
16:20:16 UTC (rev 8949)
+++
branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/server/PresentationServer.java 2007-11-15
16:30:05 UTC (rev 8950)
@@ -24,6 +24,7 @@
import org.jboss.portal.presentation.RequestContext;
import org.jboss.portal.presentation.model2.UIWindow;
+import org.jboss.portal.presentation.model2.state.ModelLoader;
/**
* @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
@@ -53,5 +54,9 @@
*/
String getMarkup(RequestContext context, UIWindow window) throws Exception;
-
+ /**
+ *
+ * @return
+ */
+ ModelLoader getModelLoader();
}
Added:
branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/test/model/MockModelLoaderImpl.java
===================================================================
---
branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/test/model/MockModelLoaderImpl.java
(rev 0)
+++
branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/test/model/MockModelLoaderImpl.java 2007-11-15
16:30:05 UTC (rev 8950)
@@ -0,0 +1,69 @@
+/******************************************************************************
+ * 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.presentation.test.model;
+
+import java.util.List;
+import java.util.ArrayList;
+
+import org.jboss.portal.presentation.impl.model2.UIPortalImpl;
+import org.jboss.portal.presentation.model2.state.ModelLoader;
+import org.jboss.portal.presentation.model2.state.ObjectState;
+
+/**
+ * @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
+ *
+ */
+public class MockModelLoaderImpl implements ModelLoader
+{
+ /**
+ *
+ */
+ public ObjectState loadState(String objectId) throws IllegalArgumentException
+ {
+ ObjectState state = null;
+
+ int lastIndex = objectId.lastIndexOf('/');
+ String name = objectId.substring(lastIndex+1);
+ String parentId = objectId.substring(0, lastIndex);
+
+ //Just stub children
+ List<String> childrenIds = null;
+ if(name.contains("testingLazyLoading"))
+ {
+ childrenIds = new ArrayList<String>();
+ childrenIds.add(objectId+"/child1");
+ childrenIds.add(objectId+"/child2");
+ childrenIds.add(objectId+"/child3");
+ }
+
+
+ state = new ObjectState(UIPortalImpl.class,
+ name,
+ null, //properties
+ parentId,
+ childrenIds //childrenIds
+ );
+
+ return state;
+ }
+}
Added:
branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/test/model/UIModelTester.java
===================================================================
---
branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/test/model/UIModelTester.java
(rev 0)
+++
branches/UIServer/uiserver/src/main/org/jboss/portal/presentation/test/model/UIModelTester.java 2007-11-15
16:30:05 UTC (rev 8950)
@@ -0,0 +1,202 @@
+/******************************************************************************
+ * 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.presentation.test.model;
+
+import junit.framework.TestCase;
+import org.apache.log4j.Logger;
+
+import java.util.List;
+import java.util.Map;
+import java.util.HashMap;
+
+import org.jboss.portal.presentation.model2.*;
+import org.jboss.portal.presentation.impl.model2.*;
+
+/**
+ * @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
+ *
+ */
+public class UIModelTester extends TestCase
+{
+ private Logger logger = Logger.getLogger(this.getClass());
+ private UIContext uiContext = null;
+
+ /**
+ *
+ */
+ protected void setUp() throws Exception
+ {
+ this.uiContext = new UIContextImpl();
+ ((UIContextImpl)this.uiContext).setModelLoader(new MockModelLoaderImpl());
+ }
+
+ /**
+ *
+ */
+ protected void tearDown() throws Exception
+ {
+ this.uiContext = null;
+ }
+
+ /**
+ *
+ * @throws Exception
+ */
+ public void testCreateChild() throws Exception
+ {
+ //Adding a UIContext...this should result in an IllegalArgumentException
+ try
+ {
+ this.uiContext.createChild("duplicateRoot", UIContextImpl.class);
+ }
+ catch(Exception e)
+ {
+ this.assertEquals(e.getClass(), IllegalArgumentException.class);
+ }
+
+ //Add a UIPage to the UIContext
+ this.uiContext.createChild("defaultPortal", UIPortalImpl.class);
+
+ //Assert the state of UIPortal added to the UIObject tree
+ UIObject portal = this.uiContext.getChildren(UIPortalImpl.class).get(0);
+ assertEquals(portal.getName(), "defaultPortal");
+ assertEquals(portal.getId(), "/defaultPortal");
+ assertTrue(portal.getParent() instanceof UIContext);
+
+ //Add a UIPage to the UIPortal
+ portal.createChild("defaultPage", UIPageImpl.class);
+ UIObject page = portal.getChildren(UIPageImpl.class).get(0);
+ assertEquals(page.getName(), "defaultPage");
+ assertEquals(page.getId(), "/defaultPortal/defaultPage");
+ assertTrue(page.getParent() instanceof UIPortal);
+
+ //Add a UIPage to the UIContainer
+ page.createChild("defaultContainer", UIContainerImpl.class);
+ UIObject container = page.getChildren(UIContainerImpl.class).get(0);
+ assertEquals(container.getName(), "defaultContainer");
+ assertEquals(container.getId(),
"/defaultPortal/defaultPage/defaultContainer");
+ assertTrue(container.getParent() instanceof UIPage);
+
+ //Add a UIWindow to UIPage
+ container.createChild("defaultWindow", UIWindowImpl.class);
+ UIObject window = container.getChildren(UIWindowImpl.class).get(0);
+ assertEquals(window.getName(), "defaultWindow");
+ assertEquals(window.getId(),
"/defaultPortal/defaultPage/defaultContainer/defaultWindow");
+ assertTrue(window.getParent() instanceof UIContainer);
+ }
+
+ /**
+ *
+ * @throws Exception
+ */
+ public void testDestroyChild() throws Exception
+ {
+ //Add a UIPage to the UIContext
+ this.uiContext.createChild("defaultPortal", UIPortalImpl.class);
+
+ //Assert the state of UIPortal added to the UIObject tree
+ UIObject portal = this.uiContext.getChildren(UIPortalImpl.class).get(0);
+
+ //Add a UIPage to the UIPortal
+ portal.createChild("defaultPage", UIPageImpl.class);
+ UIObject page = portal.getChildren(UIPageImpl.class).get(0);
+
+ //Add a UIPage to the UIContainer
+ page.createChild("defaultContainer", UIContainerImpl.class);
+ UIObject container = page.getChildren(UIContainerImpl.class).get(0);
+
+ //Add a UIWindow to UIPage
+ container.createChild("defaultWindow", UIWindowImpl.class);
+ UIObject window = container.getChildren(UIWindowImpl.class).get(0);
+
+ //Destroy the container. When this is done, both container and window must be
destroyed from the UIObject tree
+ page.destroyChild(container.getName());
+ List<UIObject> pageChildren = page.getChildren();
+ assertTrue(pageChildren == null || pageChildren.size() == 0);
+ }
+
+ /**
+ *
+ * @throws Exception
+ */
+ public void testModelLoading() throws Exception
+ {
+ //Setup rootChildrenInfo
+ Map rootChildrenInfo = new HashMap();
+ rootChildrenInfo.put("defaultPortal", UIPortalImpl.class);
+ rootChildrenInfo.put("someOtherPortal", UIPortalImpl.class);
+
+ UIContext objectTree = this.uiContext.initUIObjectTree(rootChildrenInfo);
+ UIObject defaultPortal = objectTree.getChildren(UIPortalImpl.class).get(0);
+ UIObject someOtherPortal = objectTree.getChildren(UIPortalImpl.class).get(1);
+
+ assertEquals(defaultPortal.getName(), "defaultPortal");
+ assertEquals(defaultPortal.getId(), "/defaultPortal");
+ assertEquals(someOtherPortal.getName(), "someOtherPortal");
+ assertEquals(someOtherPortal.getId(), "/someOtherPortal");
+ }
+
+ /**
+ *
+ * @throws Exception
+ */
+ public void testParentLoading() throws Exception
+ {
+ //Setup rootChildrenInfo
+ Map rootChildrenInfo = new HashMap();
+ rootChildrenInfo.put("defaultPortal", UIPortalImpl.class);
+
+ UIContext objectTree = this.uiContext.initUIObjectTree(rootChildrenInfo);
+
+ UIObject uiObject = objectTree.getObject("/defaultPortal/defaultPage",
UIPortalImpl.class);
+ UIObject parent = uiObject.getParent();
+
+ assertEquals(parent.getName(), "defaultPortal");
+ assertEquals(parent.getId(), "/defaultPortal");
+ }
+
+ /**
+ *
+ * @throws Exception
+ */
+ public void testLazyLoading() throws Exception
+ {
+ Map rootChildrenInfo = new HashMap();
+ rootChildrenInfo.put("testingLazyLoading", UIPortalImpl.class);
+
+ UIContext objectTree = this.uiContext.initUIObjectTree(rootChildrenInfo);
+ UIObject defaultPortal = objectTree.getChildren(UIPortalImpl.class).get(0);
+ List<UIObject> lazyLoadedChildren = defaultPortal.getChildren();
+
+ assertTrue((lazyLoadedChildren != null &&
lazyLoadedChildren.size()>0));
+
logger.info("-----------------------------------------------------------");
+ for(int i=0; i<lazyLoadedChildren.size(); i++)
+ {
+ UIObject child = lazyLoadedChildren.get(i);
+ logger.info(child.getId());
+ assertEquals(child.getParent().getName(), "testingLazyLoading");
+ assertEquals(child.getParent().getId(), "/testingLazyLoading");
+ }
+ logger.info("--------------------------------------------------------");
+ }
+}