JBoss Portal SVN: r11319 - in branches/JBoss_Portal_Branch_2_6/wsrp/src: main/org/jboss/portal/test/wsrp/framework and 4 other directories.
by portal-commits@lists.jboss.org
Author: chris.laprun(a)jboss.com
Date: 2008-07-07 12:14:32 -0400 (Mon, 07 Jul 2008)
New Revision: 11319
Added:
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/test/wsrp/v1/consumer/InteropServiceDescriptionTestCase.java
Modified:
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/test/wsrp/WSRPConsumerBaseTest.java
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/test/wsrp/framework/ServiceDescriptionBehavior.java
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/test/wsrp/v1/consumer/MarkupTestCase.java
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/test/wsrp/v1/consumer/ServiceDescriptionTestCase.java
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/test/wsrp/v1/consumer/V1ConsumerBaseTest.java
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/test/wsrp/v1/consumer/behaviors/GroupedPortletsServiceDescriptionBehavior.java
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/WSRPUtils.java
branches/JBoss_Portal_Branch_2_6/wsrp/src/resources/tests/test-wsrp-consumer-servicedescription-sar/META-INF/jboss-service.xml
Log:
- Improved WSRP consumer test framework to make it easier to emulate producer behaviors.
- Added test case to emulate Liferay non-conforming service description and added better work-around for its behavior.
Modified: branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/test/wsrp/WSRPConsumerBaseTest.java
===================================================================
--- branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/test/wsrp/WSRPConsumerBaseTest.java 2008-07-07 15:58:11 UTC (rev 11318)
+++ branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/test/wsrp/WSRPConsumerBaseTest.java 2008-07-07 16:14:32 UTC (rev 11319)
@@ -24,9 +24,29 @@
package org.jboss.portal.test.wsrp;
import org.jboss.portal.common.junit.ExtendedAssert;
+import org.jboss.portal.test.wsrp.framework.BehaviorRegistry;
+import org.jboss.portal.test.wsrp.framework.MarkupBehavior;
+import org.jboss.portal.test.wsrp.framework.PortletManagementBehavior;
+import org.jboss.portal.test.wsrp.framework.RegistrationBehavior;
+import org.jboss.portal.test.wsrp.framework.ServiceDescriptionBehavior;
+import org.jboss.portal.test.wsrp.framework.TestProducerBehavior;
import org.jboss.portal.test.wsrp.framework.TestWSRPProducer;
+import org.jboss.portal.test.wsrp.framework.support.MockConsumerRegistry;
+import org.jboss.portal.test.wsrp.v1.consumer.behaviors.BasicMarkupBehavior;
+import org.jboss.portal.test.wsrp.v1.consumer.behaviors.BasicPortletManagementBehavior;
+import org.jboss.portal.test.wsrp.v1.consumer.behaviors.BasicServiceDescriptionBehavior;
+import org.jboss.portal.test.wsrp.v1.consumer.behaviors.EmptyMarkupBehavior;
+import org.jboss.portal.test.wsrp.v1.consumer.behaviors.InitCookieNotRequiredMarkupBehavior;
+import org.jboss.portal.test.wsrp.v1.consumer.behaviors.NullMarkupBehavior;
+import org.jboss.portal.test.wsrp.v1.consumer.behaviors.PerGroupInitCookieMarkupBehavior;
+import org.jboss.portal.test.wsrp.v1.consumer.behaviors.PerUserInitCookieMarkupBehavior;
+import org.jboss.portal.test.wsrp.v1.consumer.behaviors.ResourceMarkupBehavior;
+import org.jboss.portal.test.wsrp.v1.consumer.behaviors.SessionMarkupBehavior;
import org.jboss.portal.wsrp.WSRPConsumer;
+import org.jboss.portal.wsrp.producer.WSRPValidator;
+import java.util.Set;
+
/**
* @author <a href="mailto:boleslaw.dawidowicz@jboss.org">Boleslaw Dawidowicz</a>
* @version $Revision$
@@ -43,6 +63,12 @@
/** . */
protected WSRPConsumer consumer;
+ private boolean strict = true;
+ private String sdClassName;
+ private String mClassName;
+ private String pmClassName;
+ private String rClassName;
+
protected WSRPConsumerBaseTest(String name) throws Exception
{
super(name);
@@ -54,9 +80,59 @@
public void setUp() throws Exception
{
+ // reset producer state
+ producer.reset();
+
+ // set the test producer identifier
consumer.getProducerInfo().setId(TEST_PRODUCER_ID);
+
+ // reset the behaviors
+ BehaviorRegistry registry = producer.getBehaviorRegistry();
+ setSDClassName(sdClassName);
+ setMClassName(mClassName);
+ setPMClassName(pmClassName);
+ setRClassName(rClassName);
+ registerAdditionalMarkupBehaviors(registry);
+
+ // use a fresh ConsumerRegistry
+ consumer.getProducerInfo().setRegistry(new MockConsumerRegistry());
+
+ // make sure we use clean producer info for each test
+ consumer.refreshProducerInfo();
+
+ // use cache to avoid un-necessary calls
+ consumer.getProducerInfo().setExpirationCacheSeconds(120);
}
+ protected void setRegistrationBehavior(RegistrationBehavior behavior)
+ {
+ producer.getBehaviorRegistry().setRegistrationBehavior(behavior);
+ }
+
+ protected void setServiceDescriptionBehavior(ServiceDescriptionBehavior behavior)
+ {
+ if (behavior == null)
+ {
+ log.info("Given service description behavior was null, using the default one instead!");
+ behavior = new BasicServiceDescriptionBehavior();
+ }
+
+ producer.getBehaviorRegistry().setServiceDescriptionBehavior(behavior);
+ }
+
+ protected void setPortletManagementBehavior(PortletManagementBehavior behavior)
+ {
+ BehaviorRegistry registry = producer.getBehaviorRegistry();
+
+ if (behavior == null)
+ {
+ log.info("Given portlet management behavior was null, using the default one instead!");
+ behavior = new BasicPortletManagementBehavior(registry);
+ }
+
+ registry.setPortletManagementBehavior(behavior);
+ }
+
public TestWSRPProducer getProducer()
{
return producer;
@@ -81,4 +157,98 @@
{
ExtendedAssert.assertEquals(TEST_PRODUCER_ID, consumer.getProducerId());
}
+
+ public void setSDClassName(String behaviorClassName)
+ {
+ sdClassName = behaviorClassName;
+ setServiceDescriptionBehavior(createBehavior(behaviorClassName, ServiceDescriptionBehavior.class));
+ }
+
+ public void setMClassName(String behaviorClassName)
+ {
+ mClassName = behaviorClassName;
+ if (behaviorClassName != null)
+ {
+ producer.getBehaviorRegistry().registerMarkupBehavior(createBehavior(behaviorClassName, MarkupBehavior.class));
+ }
+ }
+
+ public void setPMClassName(String behaviorClassName)
+ {
+ pmClassName = behaviorClassName;
+ setPortletManagementBehavior(createBehavior(behaviorClassName, PortletManagementBehavior.class));
+ }
+
+ public void setRClassName(String behaviorClassName)
+ {
+ rClassName = behaviorClassName;
+ setRegistrationBehavior(createBehavior(behaviorClassName, RegistrationBehavior.class));
+ }
+
+ public void setStrict(boolean strict)
+ {
+ this.strict = strict;
+ producer.setUseStrictMode(strict);
+ WSRPValidator.setStrict(strict);
+ }
+
+ public boolean isStrict()
+ {
+ return strict;
+ }
+
+ private <T extends TestProducerBehavior> T createBehavior(String behaviorClassName, Class<T> expectedBehaviorClass)
+ {
+ if (behaviorClassName != null)
+ {
+ try
+ {
+ Class behaviorClass = getClass().getClassLoader().loadClass(behaviorClassName);
+ if (expectedBehaviorClass.isAssignableFrom(behaviorClass))
+ {
+ return (T)behaviorClass.newInstance();
+ }
+ else
+ {
+ throw new IllegalArgumentException(behaviorClassName + " is not a " + expectedBehaviorClass.getSimpleName());
+ }
+ }
+ catch (ClassNotFoundException e)
+ {
+ throw new IllegalArgumentException("Could not find behavior: " + behaviorClassName, e);
+ }
+ catch (IllegalAccessException e)
+ {
+ throw new IllegalArgumentException("Could not access behavior: " + behaviorClassName, e);
+ }
+ catch (InstantiationException e)
+ {
+ throw new IllegalArgumentException("Could not instantiate behavior: " + behaviorClassName, e);
+ }
+ }
+
+ return null;
+ }
+
+ protected void registerAdditionalMarkupBehaviors(BehaviorRegistry registry)
+ {
+ registry.registerMarkupBehavior(new BasicMarkupBehavior(registry));
+ registry.registerMarkupBehavior(new EmptyMarkupBehavior(registry));
+ registry.registerMarkupBehavior(new InitCookieNotRequiredMarkupBehavior(registry));
+ registry.registerMarkupBehavior(new PerGroupInitCookieMarkupBehavior(registry));
+ registry.registerMarkupBehavior(new PerUserInitCookieMarkupBehavior(registry));
+ registry.registerMarkupBehavior(new NullMarkupBehavior(registry));
+ registry.registerMarkupBehavior(new SessionMarkupBehavior(registry));
+ registry.registerMarkupBehavior(new ResourceMarkupBehavior(registry));
+ }
+
+ protected Set<String> getPortletHandles()
+ {
+ return producer.getBehaviorRegistry().getServiceDescriptionBehavior().getPortletHandles();
+ }
+
+ protected int getPortletNumber()
+ {
+ return producer.getBehaviorRegistry().getServiceDescriptionBehavior().getPortletNumber();
+ }
}
Modified: branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/test/wsrp/framework/ServiceDescriptionBehavior.java
===================================================================
--- branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/test/wsrp/framework/ServiceDescriptionBehavior.java 2008-07-07 15:58:11 UTC (rev 11318)
+++ branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/test/wsrp/framework/ServiceDescriptionBehavior.java 2008-07-07 16:14:32 UTC (rev 11319)
@@ -36,7 +36,9 @@
import org.jboss.portal.wsrp.core.WSRP_v1_ServiceDescription_PortType;
import java.rmi.RemoteException;
+import java.util.HashSet;
import java.util.List;
+import java.util.Set;
/**
* @author <a href="mailto:chris.laprun@jboss.com?subject=org.jboss.portal.test.wsrp.framework.ServiceDescriptionBehavior">Chris
@@ -57,7 +59,7 @@
}
public ServiceDescription getServiceDescription(GetServiceDescription getServiceDescription) throws
- OperationFailedFault, InvalidRegistrationFault, RemoteException
+ OperationFailedFault, InvalidRegistrationFault, RemoteException
{
incrementCallCount();
return serviceDescription;
@@ -92,12 +94,30 @@
}
else
{
- List portlets = Tools.toList(initial);
+ List<PortletDescription> portlets = Tools.toList(initial);
portlets.add(portletDescription);
- serviceDescription.setOfferedPortlets((PortletDescription[])portlets.toArray(new PortletDescription[0]));
+ serviceDescription.setOfferedPortlets(portlets.toArray(new PortletDescription[portlets.size()]));
}
}
+ public Set<String> getPortletHandles()
+ {
+ PortletDescription[] portletDescriptions = serviceDescription.getOfferedPortlets();
+ Set<String> handles = new HashSet<String>(portletDescriptions.length);
+
+ for (PortletDescription description : portletDescriptions)
+ {
+ handles.add(description.getPortletHandle());
+ }
+
+ return handles;
+ }
+
+ public int getPortletNumber()
+ {
+ return serviceDescription.getOfferedPortlets().length;
+ }
+
public static ServiceDescription createServiceDescription(boolean requiresRegistration, int numberOfProperties)
{
ServiceDescription sd = WSRPTypeFactory.createServiceDescription(requiresRegistration);
Added: branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/test/wsrp/v1/consumer/InteropServiceDescriptionTestCase.java
===================================================================
--- branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/test/wsrp/v1/consumer/InteropServiceDescriptionTestCase.java (rev 0)
+++ branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/test/wsrp/v1/consumer/InteropServiceDescriptionTestCase.java 2008-07-07 16:14:32 UTC (rev 11319)
@@ -0,0 +1,79 @@
+/*
+* 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.test.wsrp.v1.consumer;
+
+import org.jboss.portal.common.junit.ExtendedAssert;
+import org.jboss.portal.portlet.Portlet;
+import org.jboss.portal.portlet.PortletInvokerException;
+import org.jboss.portal.test.wsrp.framework.BehaviorRegistry;
+
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris Laprun</a>
+ * @version $Revision$
+ */
+public class InteropServiceDescriptionTestCase extends V1ConsumerBaseTest
+{
+ public InteropServiceDescriptionTestCase() throws Exception
+ {
+ super();
+ }
+
+ @Override
+ public void setUp() throws Exception
+ {
+ setStrict(false);
+ super.setUp();
+ }
+
+ public void testUsesRelaxedMode()
+ {
+ ExtendedAssert.assertFalse(isStrict());
+ }
+
+ public void testGetPortlets() throws PortletInvokerException
+ {
+ //invoke consumer
+ Set returnedPortlets = consumer.getPortlets();
+
+ int portletNumber = returnedPortlets.size();
+ ExtendedAssert.assertEquals(getPortletNumber(), portletNumber);
+ Set<String> handles = getPortletHandles();
+ Set<String> consumerHandles = new HashSet<String>(portletNumber);
+ for (Object o : returnedPortlets)
+ {
+ Portlet portlet = (Portlet)o;
+ consumerHandles.add(portlet.getContext().getId());
+ }
+
+ ExtendedAssert.assertTrue(handles.containsAll(consumerHandles));
+ }
+
+ @Override
+ protected void registerAdditionalMarkupBehaviors(BehaviorRegistry registry)
+ {
+ // do nothing so that we don't pollute the service description with markup behaviors
+ }
+}
Modified: branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/test/wsrp/v1/consumer/MarkupTestCase.java
===================================================================
--- branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/test/wsrp/v1/consumer/MarkupTestCase.java 2008-07-07 15:58:11 UTC (rev 11318)
+++ branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/test/wsrp/v1/consumer/MarkupTestCase.java 2008-07-07 16:14:32 UTC (rev 11319)
@@ -35,6 +35,7 @@
import org.jboss.portal.portlet.invocation.response.PortletInvocationResponse;
import org.jboss.portal.portlet.invocation.response.RenderResponse;
import org.jboss.portal.portlet.spi.WindowContext;
+import org.jboss.portal.test.wsrp.framework.BehaviorRegistry;
import org.jboss.portal.test.wsrp.framework.support.BasicInstanceContext;
import org.jboss.portal.test.wsrp.framework.support.BasicSecurityContext;
import org.jboss.portal.test.wsrp.framework.support.BasicUserContext;
@@ -52,8 +53,11 @@
import org.jboss.portal.wsrp.consumer.ProducerSessionInformation;
import org.jboss.portal.wsrp.core.CookieProtocol;
import org.jboss.portal.wsrp.core.InvalidHandleFault;
+import org.jboss.portal.wsrp.core.InvalidRegistrationFault;
+import org.jboss.portal.wsrp.core.OperationFailedFault;
import javax.servlet.http.HttpSession;
+import java.rmi.RemoteException;
/**
* @author <a href="mailto:chris.laprun@jboss.com">Chris Laprun</a>
@@ -98,7 +102,7 @@
public void testRender() throws Exception
{
RenderInvocation render = createRenderInvocation(BasicMarkupBehavior.PORTLET_HANDLE, Mode.EDIT,
- WindowState.NORMAL, "someNS");
+ WindowState.NORMAL, "someNS");
FragmentResponse result = checkRenderResult(consumer.invoke(render), "portlet1:edit:normal:someNS");
ExtendedAssert.assertEquals(15, result.getExpirationSecs());
@@ -166,13 +170,15 @@
ExtendedAssert.assertEquals(1, behavior.getInitCookieCallCount());
}
- public void testInitCookiePerGroup() throws PortletInvokerException, InvalidHandleFault
+ public void testInitCookiePerGroup() throws PortletInvokerException, InvalidHandleFault, RemoteException, InvalidRegistrationFault, OperationFailedFault
{
- // need to setup with a specific service description behavior
- setUpWith(new GroupedPortletsServiceDescriptionBehavior());
+ BehaviorRegistry registry = producer.getBehaviorRegistry();
+ // need to setup with a specific service description behavior: we wrap the current service description
+ setServiceDescriptionBehavior(new GroupedPortletsServiceDescriptionBehavior(registry.getServiceDescriptionBehavior().getServiceDescription(null)));
+
String handle = PerGroupInitCookieMarkupBehavior.PER_GROUP_INIT_COOKIE_HANDLE;
- InitCookieMarkupBehavior behavior = (InitCookieMarkupBehavior)producer.getBehaviorRegistry().getMarkupBehaviorFor(handle);
+ InitCookieMarkupBehavior behavior = (InitCookieMarkupBehavior)registry.getMarkupBehaviorFor(handle);
ProducerSessionInformation sessionInfo = commonInitCookieTest(handle, behavior, CookieProtocol.perGroup);
ExtendedAssert.assertTrue(sessionInfo.isPerGroupCookies());
@@ -191,7 +197,7 @@
}
private ProducerSessionInformation commonInitCookieTest(String handle, InitCookieMarkupBehavior behavior, CookieProtocol cookieProtocol)
- throws PortletInvokerException
+ throws PortletInvokerException
{
RenderInvocation render = createRenderInvocation(handle);
TestPortletInvocationContext invocationContext = (TestPortletInvocationContext)render.getContext();
Modified: branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/test/wsrp/v1/consumer/ServiceDescriptionTestCase.java
===================================================================
--- branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/test/wsrp/v1/consumer/ServiceDescriptionTestCase.java 2008-07-07 15:58:11 UTC (rev 11318)
+++ branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/test/wsrp/v1/consumer/ServiceDescriptionTestCase.java 2008-07-07 16:14:32 UTC (rev 11319)
@@ -26,18 +26,15 @@
import org.jboss.portal.portlet.Portlet;
import org.jboss.portal.portlet.PortletContext;
import org.jboss.portal.test.wsrp.v1.consumer.behaviors.BasicMarkupBehavior;
-import org.jboss.portal.test.wsrp.v1.consumer.behaviors.BasicServiceDescriptionBehavior;
import org.jboss.portal.test.wsrp.v1.consumer.behaviors.SessionMarkupBehavior;
-import java.util.Set;
-
/**
* @author <a href="mailto:boleslaw.dawidowicz@jboss.org">Boleslaw Dawidowicz</a>
* @author <a href="mailto:chris.laprun@jboss.com">Chris Laprun</a>
* @version $Revision$
* @since 2.4
*/
-public class ServiceDescriptionTestCase extends V1ConsumerBaseTest
+public class ServiceDescriptionTestCase extends InteropServiceDescriptionTestCase
{
public ServiceDescriptionTestCase() throws Exception
@@ -46,27 +43,18 @@
}
+ @Override
public void setUp() throws Exception
{
super.setUp();
- // override default service description behavior to make sure we have the correct state
- producer.getBehaviorRegistry().setServiceDescriptionBehavior(new BasicServiceDescriptionBehavior());
- consumer.refreshProducerInfo();
+
+ // use strict mode
+ setStrict(true);
}
- public void testGetportlets() throws Exception
+ public void testUsesRelaxedMode()
{
- //invoke consumer
- Set returnedPortlets = consumer.getPortlets();
-
- //assert we have our two portlets
- ExtendedAssert.assertEquals(2, returnedPortlets.size());
- Portlet[] portletArray = (Portlet[])returnedPortlets.toArray(new Portlet[0]);
- Portlet p1 = portletArray[0];
- Portlet p2 = portletArray[1];
-
- ExtendedAssert.assertTrue((p1.getContext().getId().equals(BasicMarkupBehavior.PORTLET_HANDLE) && p2.getContext().getId().equals(SessionMarkupBehavior.PORTLET_HANDLE)) ||
- (p2.getContext().getId().equals(BasicMarkupBehavior.PORTLET_HANDLE) && p1.getContext().getId().equals(SessionMarkupBehavior.PORTLET_HANDLE)));
+ ExtendedAssert.assertTrue(isStrict());
}
public void testGetPortlet() throws Exception
Modified: branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/test/wsrp/v1/consumer/V1ConsumerBaseTest.java
===================================================================
--- branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/test/wsrp/v1/consumer/V1ConsumerBaseTest.java 2008-07-07 15:58:11 UTC (rev 11318)
+++ branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/test/wsrp/v1/consumer/V1ConsumerBaseTest.java 2008-07-07 16:14:32 UTC (rev 11319)
@@ -24,22 +24,9 @@
import org.jboss.portal.common.junit.ExtendedAssert;
import org.jboss.portal.portlet.Portlet;
-import org.jboss.portal.portlet.PortletInvokerException;
import org.jboss.portal.portlet.info.MetaInfo;
import org.jboss.portal.test.wsrp.WSRPConsumerBaseTest;
-import org.jboss.portal.test.wsrp.framework.BehaviorRegistry;
-import org.jboss.portal.test.wsrp.framework.ServiceDescriptionBehavior;
-import org.jboss.portal.test.wsrp.framework.support.MockConsumerRegistry;
import org.jboss.portal.test.wsrp.framework.support.ServiceObjectFactory;
-import org.jboss.portal.test.wsrp.v1.consumer.behaviors.BasicMarkupBehavior;
-import org.jboss.portal.test.wsrp.v1.consumer.behaviors.BasicPortletManagementBehavior;
-import org.jboss.portal.test.wsrp.v1.consumer.behaviors.EmptyMarkupBehavior;
-import org.jboss.portal.test.wsrp.v1.consumer.behaviors.InitCookieNotRequiredMarkupBehavior;
-import org.jboss.portal.test.wsrp.v1.consumer.behaviors.NullMarkupBehavior;
-import org.jboss.portal.test.wsrp.v1.consumer.behaviors.PerGroupInitCookieMarkupBehavior;
-import org.jboss.portal.test.wsrp.v1.consumer.behaviors.PerUserInitCookieMarkupBehavior;
-import org.jboss.portal.test.wsrp.v1.consumer.behaviors.ResourceMarkupBehavior;
-import org.jboss.portal.test.wsrp.v1.consumer.behaviors.SessionMarkupBehavior;
/**
* @author <a href="mailto:boleslaw.dawidowicz@jboss.org">Boleslaw Dawidowicz</a>
@@ -66,34 +53,5 @@
public void setUp() throws Exception
{
super.setUp();
- setUpWith(new ServiceDescriptionBehavior());
}
-
- protected void setUpWith(ServiceDescriptionBehavior serviceDescriptionBehavior) throws PortletInvokerException
- {
- // reset producer state
- producer.reset();
-
- // reset the behaviors
- BehaviorRegistry registry = producer.getBehaviorRegistry();
- registry.setPortletManagementBehavior(new BasicPortletManagementBehavior(registry));
- registry.setServiceDescriptionBehavior(serviceDescriptionBehavior);
- registry.registerMarkupBehavior(new BasicMarkupBehavior(registry));
- registry.registerMarkupBehavior(new EmptyMarkupBehavior(registry));
- registry.registerMarkupBehavior(new InitCookieNotRequiredMarkupBehavior(registry));
- registry.registerMarkupBehavior(new PerGroupInitCookieMarkupBehavior(registry));
- registry.registerMarkupBehavior(new PerUserInitCookieMarkupBehavior(registry));
- registry.registerMarkupBehavior(new NullMarkupBehavior(registry));
- registry.registerMarkupBehavior(new SessionMarkupBehavior(registry));
- registry.registerMarkupBehavior(new ResourceMarkupBehavior(registry));
-
- // use a fresh ConsumerRegistry
- consumer.getProducerInfo().setRegistry(new MockConsumerRegistry());
-
- // make sure we use clean producer info for each test
- consumer.refreshProducerInfo();
-
- // use cache to avoid un-necessary calls
- consumer.getProducerInfo().setExpirationCacheSeconds(120);
- }
}
Modified: branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/test/wsrp/v1/consumer/behaviors/GroupedPortletsServiceDescriptionBehavior.java
===================================================================
--- branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/test/wsrp/v1/consumer/behaviors/GroupedPortletsServiceDescriptionBehavior.java 2008-07-07 15:58:11 UTC (rev 11318)
+++ branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/test/wsrp/v1/consumer/behaviors/GroupedPortletsServiceDescriptionBehavior.java 2008-07-07 16:14:32 UTC (rev 11319)
@@ -32,11 +32,18 @@
import java.rmi.RemoteException;
/**
+ * Wraps a service description to add group information on portlet descriptions...
+ *
* @author <a href="mailto:chris.laprun@jboss.com">Chris Laprun</a>
* @version $Revision$
*/
public class GroupedPortletsServiceDescriptionBehavior extends ServiceDescriptionBehavior
{
+ public GroupedPortletsServiceDescriptionBehavior(ServiceDescription sd)
+ {
+ serviceDescription = sd;
+ }
+
@Override
public ServiceDescription getServiceDescription(GetServiceDescription getServiceDescription) throws OperationFailedFault, InvalidRegistrationFault, RemoteException
{
Modified: branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/WSRPUtils.java
===================================================================
--- branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/WSRPUtils.java 2008-07-07 15:58:11 UTC (rev 11318)
+++ branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/WSRPUtils.java 2008-07-07 16:14:32 UTC (rev 11319)
@@ -309,7 +309,7 @@
{
ParameterValidation.throwIllegalArgExceptionIfNull(propertyDescription, "RegistrationPropertyDescription");
PropertyDescription propDesc = WSRPTypeFactory.createPropertyDescription(propertyDescription.getName().toString(),
- propertyDescription.getType());
+ propertyDescription.getType());
// todo: deal with languages properly!!
LocalizedString hint = propertyDescription.getHint();
@@ -334,7 +334,7 @@
{
ParameterValidation.throwIllegalArgExceptionIfNull(propertyDescription, "PropertyDescription");
RegistrationPropertyDescription desc = new RegistrationPropertyDescription(propertyDescription.getName(),
- propertyDescription.getType());
+ propertyDescription.getType());
desc.setLabel(getLocalizedStringOrNull(propertyDescription.getLabel()));
desc.setHint(getLocalizedStringOrNull(propertyDescription.getHint()));
@@ -386,7 +386,7 @@
{
ParameterValidation.throwIllegalArgExceptionIfNull(regLocalizedString, "LocalizedString");
return WSRPTypeFactory.createLocalizedString(toString(regLocalizedString.getLocale()),
- regLocalizedString.getResourceName(), regLocalizedString.getValue());
+ regLocalizedString.getResourceName(), regLocalizedString.getValue());
}
/**
@@ -440,7 +440,16 @@
}
catch (ConversionException e)
{
- throw new IllegalArgumentException(e);
+ if (WSRPUtils.strict)
+ {
+ throw new IllegalArgumentException(e);
+ }
+ else
+ {
+ log.debug("Was given an invalid language: '" + possiblyRelaxed
+ + "'. Since we're using relaxed validation, we will assume " + Locale.ENGLISH + " to avoid crashing!", e);
+ return Locale.ENGLISH;
+ }
}
}
@@ -473,7 +482,7 @@
sb.append("(secure)");
}
sb.append("[M=").append(params.getMode()).append("][WS=").append(params.getWindowState()).append("]")
- .append("[NS=").append(params.getNavigationalState()).append("]");
+ .append("[NS=").append(params.getNavigationalState()).append("]");
return sb.toString();
}
return null;
@@ -492,7 +501,7 @@
{
StringBuffer sb = new StringBuffer("InteractionParams");
sb.append("[IS=").append(interactionParams.getInteractionState()).append("]")
- .append("[StateChange=").append(interactionParams.getPortletStateChange().getValue()).append("]");
+ .append("[StateChange=").append(interactionParams.getPortletStateChange().getValue()).append("]");
NamedString[] formParams = interactionParams.getFormParameters();
if (formParams != null)
{
Modified: branches/JBoss_Portal_Branch_2_6/wsrp/src/resources/tests/test-wsrp-consumer-servicedescription-sar/META-INF/jboss-service.xml
===================================================================
--- branches/JBoss_Portal_Branch_2_6/wsrp/src/resources/tests/test-wsrp-consumer-servicedescription-sar/META-INF/jboss-service.xml 2008-07-07 15:58:11 UTC (rev 11318)
+++ branches/JBoss_Portal_Branch_2_6/wsrp/src/resources/tests/test-wsrp-consumer-servicedescription-sar/META-INF/jboss-service.xml 2008-07-07 16:14:32 UTC (rev 11319)
@@ -24,14 +24,30 @@
<server>
<mbean
- code="org.jboss.portal.test.wsrp.v1.consumer.ServiceDescriptionTestCase"
- name="portal.test:test=ServiceDescription"
- xmbean-dd=""
- xmbean-code="org.jboss.portal.jems.as.system.JBossServiceModelMBean">
+ code="org.jboss.portal.test.wsrp.v1.consumer.ServiceDescriptionTestCase"
+ name="portal.test:test=ServiceDescription"
+ xmbean-dd=""
+ xmbean-code="org.jboss.portal.jems.as.system.JBossServiceModelMBean">
<xmbean/>
<depends optional-attribute-name="TestDriverRegistry"
- proxy-type="attribute">portal.test:service=TestDriverServer</depends>
+ proxy-type="attribute">portal.test:service=TestDriverServer
+ </depends>
<depends optional-attribute-name="Consumer" proxy-type="attribute">portal.wsrp:service=WSRPConsumer</depends>
<depends optional-attribute-name="Producer" proxy-type="attribute">portal.wsrp:service=WSRPProducer</depends>
</mbean>
+ <mbean
+ code="org.jboss.portal.test.wsrp.v1.consumer.InteropServiceDescriptionTestCase"
+ name="portal.test:test=LiferayServiceDescription"
+ xmbean-dd=""
+ xmbean-code="org.jboss.portal.jems.as.system.JBossServiceModelMBean">
+ <xmbean/>
+ <depends optional-attribute-name="TestDriverRegistry"
+ proxy-type="attribute">portal.test:service=TestDriverServer
+ </depends>
+ <depends optional-attribute-name="Consumer" proxy-type="attribute">portal.wsrp:service=WSRPConsumer</depends>
+ <depends optional-attribute-name="Producer" proxy-type="attribute">portal.wsrp:service=WSRPProducer</depends>
+ <attribute name="SDClassName">
+ org.jboss.portal.test.wsrp.v1.consumer.behaviors.interop.LiferayServiceDescriptionBehavior
+ </attribute>
+ </mbean>
</server>
16 years
JBoss Portal SVN: r11318 - in branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal: test/wsrp/v1/consumer/behaviors and 4 other directories.
by portal-commits@lists.jboss.org
Author: chris.laprun(a)jboss.com
Date: 2008-07-07 11:58:11 -0400 (Mon, 07 Jul 2008)
New Revision: 11318
Added:
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/test/wsrp/v1/consumer/behaviors/interop/
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/test/wsrp/v1/consumer/behaviors/interop/LiferayServiceDescriptionBehavior.java
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/producer/WSRPValidator.java
Modified:
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/test/wsrp/framework/TestProducerBehavior.java
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/test/wsrp/framework/TestWSRPProducerImpl.java
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/WSRPConstants.java
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/WSRPTypeFactory.java
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/consumer/ProducerInfo.java
branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/producer/WSRPProducerImpl.java
Log:
- Encapsulated access to default locales and MIME types and return copies on WSRPConstants to prevent client-side modification.
- Encapsulated validation mode handling in WSRPValidator class.
Modified: branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/test/wsrp/framework/TestProducerBehavior.java
===================================================================
--- branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/test/wsrp/framework/TestProducerBehavior.java 2008-07-07 15:56:08 UTC (rev 11317)
+++ branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/test/wsrp/framework/TestProducerBehavior.java 2008-07-07 15:58:11 UTC (rev 11318)
@@ -60,7 +60,7 @@
PortletDescription portletDesc = new PortletDescription();
portletDesc.setPortletHandle(portletHandle);
portletDesc.setMarkupTypes(new MarkupType[]{new MarkupType("text/html", new String[]{WSRPConstants.VIEW_MODE},
- new String[]{WSRPConstants.NORMAL_WINDOW_STATE}, WSRPConstants.DEFAULT_LOCALES, null)});
+ new String[]{WSRPConstants.NORMAL_WINDOW_STATE}, WSRPConstants.getDefaultLocales(), null)});
String suffixString = suffix == null ? "" : suffix;
portletDesc.setDescription(ServiceObjectFactory.createLocalizedString(ServiceObjectFactory.SAMPLE_DESCRIPTION + suffixString));
Modified: branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/test/wsrp/framework/TestWSRPProducerImpl.java
===================================================================
--- branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/test/wsrp/framework/TestWSRPProducerImpl.java 2008-07-07 15:56:08 UTC (rev 11317)
+++ branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/test/wsrp/framework/TestWSRPProducerImpl.java 2008-07-07 15:58:11 UTC (rev 11318)
@@ -65,6 +65,7 @@
import org.jboss.portal.wsrp.core.UnsupportedMimeTypeFault;
import org.jboss.portal.wsrp.core.UnsupportedModeFault;
import org.jboss.portal.wsrp.core.UnsupportedWindowStateFault;
+import org.jboss.portal.wsrp.producer.WSRPValidator;
import org.jboss.portal.wsrp.producer.config.ProducerConfiguration;
import org.jboss.portal.wsrp.producer.config.ProducerRegistrationRequirements;
@@ -283,6 +284,6 @@
public void setUseStrictMode(boolean strict)
{
- throw new UnsupportedOperationException("setUseStrictMode not implemented");
+ WSRPValidator.setStrict(strict);
}
}
Added: branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/test/wsrp/v1/consumer/behaviors/interop/LiferayServiceDescriptionBehavior.java
===================================================================
--- branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/test/wsrp/v1/consumer/behaviors/interop/LiferayServiceDescriptionBehavior.java (rev 0)
+++ branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/test/wsrp/v1/consumer/behaviors/interop/LiferayServiceDescriptionBehavior.java 2008-07-07 15:58:11 UTC (rev 11318)
@@ -0,0 +1,72 @@
+/*
+* 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.test.wsrp.v1.consumer.behaviors.interop;
+
+import org.jboss.portal.test.wsrp.framework.ServiceDescriptionBehavior;
+import org.jboss.portal.wsrp.core.LocalizedString;
+import org.jboss.portal.wsrp.core.PortletDescription;
+
+import java.util.Set;
+
+/**
+ * Liferay behavior as exhibited at http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4162201#4162201
+ *
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris Laprun</a>
+ * @version $Revision$
+ */
+public class LiferayServiceDescriptionBehavior extends ServiceDescriptionBehavior
+{
+ public LiferayServiceDescriptionBehavior()
+ {
+ /*
+ <portletHandle>98</portletHandle>
+<markupTypes>
+ <mimeType>text/html</mimeType>
+ <modes>wsrp:view</modes>
+ <windowStates>wsrp:normal</windowStates>
+ <windowStates>wsrp:minimized</windowStates>
+ <windowStates>wsrp:maximized</windowStates>
+ <locales>en_US</locales>
+</markupTypes>
+<groupID>98</groupID>
+<shortTitle lang='English'>
+ <value>javax.portlet.short-title.98</value>
+</shortTitle>
+<title lang='English'>
+ <value>Software Catalog</value>
+</title>
+ */
+ PortletDescription pd = createPortletDescription("98", null);
+ pd.getMarkupTypes()[0].getLocales()[0] = "en_US";
+ LocalizedString locString = pd.getShortTitle();
+ pd.setGroupID("98");
+ String lang = "English";
+ locString.setLang(lang);
+ locString.setValue("javax.portlet.short-title.98");
+ locString = pd.getTitle();
+ locString.setLang(lang);
+ locString.setValue("Software Catalog");
+
+ serviceDescription.setOfferedPortlets(new PortletDescription[]{pd});
+ }
+}
\ No newline at end of file
Modified: branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/WSRPConstants.java
===================================================================
--- branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/WSRPConstants.java 2008-07-07 15:56:08 UTC (rev 11317)
+++ branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/WSRPConstants.java 2008-07-07 15:58:11 UTC (rev 11318)
@@ -116,20 +116,8 @@
// WSRP Defaults ****************************************************************************************************
/** Default character set used to generate markup. */
- public static final String DEFAULT_CHARACTER_SET = "UTF-8";
+ public static final String DEFAULT_CHARACTER_SET = "UTF-8";
- /** Default locales. */
- public static final String[] DEFAULT_LOCALES;
-
- static
- {
- String defaultLocale = WSRPUtils.toString(Locale.getDefault());
- DEFAULT_LOCALES = new String[]{defaultLocale, "en"};
- }
-
- /** Default MIME types. */
- public static final String[] DEFAULT_MIME_TYPES = new String[]{"text/html"};
-
// Registration data related ****************************************************************************************
/** Default consumer name if none has been provided in the WSRP descriptor (*-wsrp.xml) */
@@ -182,4 +170,17 @@
private WSRPConstants()
{
}
+
+ // init default locale at loading time as it is slow
+ private static String defaultLocale = WSRPUtils.toString(Locale.getDefault());
+
+ public static String[] getDefaultLocales()
+ {
+ return new String[]{defaultLocale, "en"}; // return copy to prevent modifications by client code
+ }
+
+ public static String[] getDefaultMimeTypes()
+ {
+ return new String[]{"text/html"}; // return copy to prevent modifications by client code
+ }
}
Modified: branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/WSRPTypeFactory.java
===================================================================
--- branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/WSRPTypeFactory.java 2008-07-07 15:56:08 UTC (rev 11317)
+++ branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/WSRPTypeFactory.java 2008-07-07 15:58:11 UTC (rev 11318)
@@ -288,14 +288,14 @@
}
/**
- * Same as createMarkupParams(false, {@link WSRPConstants#DEFAULT_LOCALES}, {@link WSRPConstants#DEFAULT_MIME_TYPES},
+ * Same as createMarkupParams(false, {@link WSRPConstants#getDefaultLocales()}, {@link WSRPConstants#getDefaultMimeTypes()},
* {@link WSRPConstants#VIEW_MODE}, {@link WSRPConstants#NORMAL_WINDOW_STATE})
*
* @return
*/
public static MarkupParams createDefaultMarkupParams()
{
- return createMarkupParams(false, WSRPConstants.DEFAULT_LOCALES, WSRPConstants.DEFAULT_MIME_TYPES,
+ return createMarkupParams(false, WSRPConstants.getDefaultLocales(), WSRPConstants.getDefaultMimeTypes(),
WSRPConstants.VIEW_MODE, WSRPConstants.NORMAL_WINDOW_STATE);
}
Modified: branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/consumer/ProducerInfo.java
===================================================================
--- branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/consumer/ProducerInfo.java 2008-07-07 15:56:08 UTC (rev 11317)
+++ branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/consumer/ProducerInfo.java 2008-07-07 15:58:11 UTC (rev 11318)
@@ -710,7 +710,7 @@
//todo: might need to implement customization of default service description
GetServiceDescription gsd = WSRPTypeFactory.createGetServiceDescription();
- gsd.setDesiredLocales(WSRPConstants.DEFAULT_LOCALES);
+ gsd.setDesiredLocales(WSRPConstants.getDefaultLocales());
if (asUnregistred)
{
return gsd;
Modified: branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/producer/WSRPProducerImpl.java
===================================================================
--- branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/producer/WSRPProducerImpl.java 2008-07-07 15:56:08 UTC (rev 11317)
+++ branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/producer/WSRPProducerImpl.java 2008-07-07 15:58:11 UTC (rev 11318)
@@ -33,13 +33,10 @@
import org.jboss.portal.registration.Registration;
import org.jboss.portal.registration.RegistrationLocal;
import org.jboss.portal.registration.RegistrationManager;
-import org.jboss.portal.registration.RegistrationUtils;
import org.jboss.portal.wsrp.ResponseDebugFactory;
import org.jboss.portal.wsrp.WSRPConstants;
import org.jboss.portal.wsrp.WSRPExceptionFactory;
-import org.jboss.portal.wsrp.WSRPPortletURL;
import org.jboss.portal.wsrp.WSRPProducer;
-import org.jboss.portal.wsrp.WSRPUtils;
import org.jboss.portal.wsrp.core.AccessDeniedFault;
import org.jboss.portal.wsrp.core.BlockingInteractionResponse;
import org.jboss.portal.wsrp.core.ClonePortlet;
@@ -124,7 +121,7 @@
private CookieProtocol requiresInitCookie = CookieProtocol.none;
/** Supported locales. */
- private String[] supportedLocales = WSRPConstants.DEFAULT_LOCALES;
+ private String[] supportedLocales = WSRPConstants.getDefaultLocales();
private ProducerConfigurationService configurationService;
@@ -273,9 +270,7 @@
public void setUseStrictMode(boolean strict)
{
- RegistrationUtils.setStrict(strict);
- WSRPUtils.setStrict(strict);
- WSRPPortletURL.setStrict(strict);
+ WSRPValidator.setStrict(strict);
}
protected void startService() throws Exception
Added: branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/producer/WSRPValidator.java
===================================================================
--- branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/producer/WSRPValidator.java (rev 0)
+++ branches/JBoss_Portal_Branch_2_6/wsrp/src/main/org/jboss/portal/wsrp/producer/WSRPValidator.java 2008-07-07 15:58:11 UTC (rev 11318)
@@ -0,0 +1,49 @@
+/*
+* 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.wsrp.producer;
+
+import org.jboss.portal.registration.RegistrationUtils;
+import org.jboss.portal.wsrp.WSRPPortletURL;
+import org.jboss.portal.wsrp.WSRPUtils;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris Laprun</a>
+ * @version $Revision$
+ */
+public class WSRPValidator
+{
+ private static boolean strict = true;
+
+ public static void setStrict(boolean strictMode)
+ {
+ strict = strictMode;
+ RegistrationUtils.setStrict(strict);
+ WSRPUtils.setStrict(strict);
+ WSRPPortletURL.setStrict(strict);
+ }
+
+ public static boolean isStrict()
+ {
+ return strict;
+ }
+}
16 years
JBoss Portal SVN: r11317 - in branches/JBoss_Portal_Branch_2_7/wsrp/src/main/org/jboss/portal: wsrp and 2 other directories.
by portal-commits@lists.jboss.org
Author: chris.laprun(a)jboss.com
Date: 2008-07-07 11:56:08 -0400 (Mon, 07 Jul 2008)
New Revision: 11317
Added:
branches/JBoss_Portal_Branch_2_7/wsrp/src/main/org/jboss/portal/wsrp/producer/WSRPValidator.java
Modified:
branches/JBoss_Portal_Branch_2_7/wsrp/src/main/org/jboss/portal/test/wsrp/framework/TestProducerBehavior.java
branches/JBoss_Portal_Branch_2_7/wsrp/src/main/org/jboss/portal/test/wsrp/framework/TestWSRPProducerImpl.java
branches/JBoss_Portal_Branch_2_7/wsrp/src/main/org/jboss/portal/wsrp/WSRPConstants.java
branches/JBoss_Portal_Branch_2_7/wsrp/src/main/org/jboss/portal/wsrp/WSRPTypeFactory.java
branches/JBoss_Portal_Branch_2_7/wsrp/src/main/org/jboss/portal/wsrp/consumer/ProducerInfo.java
branches/JBoss_Portal_Branch_2_7/wsrp/src/main/org/jboss/portal/wsrp/producer/WSRPProducerImpl.java
Log:
- Encapsulated access to default locales and MIME types and return copies on WSRPConstants to prevent client-side modification.
- Encapsulated validation mode handling in WSRPValidator class.
Modified: branches/JBoss_Portal_Branch_2_7/wsrp/src/main/org/jboss/portal/test/wsrp/framework/TestProducerBehavior.java
===================================================================
--- branches/JBoss_Portal_Branch_2_7/wsrp/src/main/org/jboss/portal/test/wsrp/framework/TestProducerBehavior.java 2008-07-07 12:56:40 UTC (rev 11316)
+++ branches/JBoss_Portal_Branch_2_7/wsrp/src/main/org/jboss/portal/test/wsrp/framework/TestProducerBehavior.java 2008-07-07 15:56:08 UTC (rev 11317)
@@ -61,7 +61,7 @@
PortletDescription portletDesc = new PortletDescription();
portletDesc.setPortletHandle(portletHandle);
portletDesc.setMarkupTypes(new MarkupType[]{new MarkupType(MediaType.TEXT_HTML.getValue(), new String[]{WSRPConstants.VIEW_MODE},
- new String[]{WSRPConstants.NORMAL_WINDOW_STATE}, WSRPConstants.DEFAULT_LOCALES, null)});
+ new String[]{WSRPConstants.NORMAL_WINDOW_STATE}, WSRPConstants.getDefaultLocales(), null)});
String suffixString = suffix == null ? "" : suffix;
portletDesc.setDescription(ServiceObjectFactory.createLocalizedString(ServiceObjectFactory.SAMPLE_DESCRIPTION + suffixString));
Modified: branches/JBoss_Portal_Branch_2_7/wsrp/src/main/org/jboss/portal/test/wsrp/framework/TestWSRPProducerImpl.java
===================================================================
--- branches/JBoss_Portal_Branch_2_7/wsrp/src/main/org/jboss/portal/test/wsrp/framework/TestWSRPProducerImpl.java 2008-07-07 12:56:40 UTC (rev 11316)
+++ branches/JBoss_Portal_Branch_2_7/wsrp/src/main/org/jboss/portal/test/wsrp/framework/TestWSRPProducerImpl.java 2008-07-07 15:56:08 UTC (rev 11317)
@@ -65,6 +65,7 @@
import org.jboss.portal.wsrp.core.UnsupportedMimeTypeFault;
import org.jboss.portal.wsrp.core.UnsupportedModeFault;
import org.jboss.portal.wsrp.core.UnsupportedWindowStateFault;
+import org.jboss.portal.wsrp.producer.WSRPValidator;
import org.jboss.portal.wsrp.producer.config.ProducerConfiguration;
import org.jboss.portal.wsrp.producer.config.ProducerRegistrationRequirements;
@@ -131,7 +132,7 @@
// ServiceDescription implementation ********************************************************************************
public ServiceDescription getServiceDescription(GetServiceDescription gs)
- throws InvalidRegistrationFault, OperationFailedFault, RemoteException
+ throws InvalidRegistrationFault, OperationFailedFault, RemoteException
{
return getServiceDescriptionBehavior().getServiceDescription(gs);
}
@@ -139,35 +140,35 @@
// MarkupService implementation *************************************************************************************
public MarkupResponse getMarkup(GetMarkup getMarkup)
- throws UnsupportedWindowStateFault, InvalidCookieFault, InvalidSessionFault, AccessDeniedFault,
- InconsistentParametersFault, InvalidHandleFault, UnsupportedLocaleFault, UnsupportedModeFault,
- OperationFailedFault, MissingParametersFault, InvalidUserCategoryFault, InvalidRegistrationFault,
- UnsupportedMimeTypeFault, RemoteException
+ throws UnsupportedWindowStateFault, InvalidCookieFault, InvalidSessionFault, AccessDeniedFault,
+ InconsistentParametersFault, InvalidHandleFault, UnsupportedLocaleFault, UnsupportedModeFault,
+ OperationFailedFault, MissingParametersFault, InvalidUserCategoryFault, InvalidRegistrationFault,
+ UnsupportedMimeTypeFault, RemoteException
{
return getMarkupBehaviorFor(getMarkup.getPortletContext().getPortletHandle())
- .getMarkup(getMarkup);
+ .getMarkup(getMarkup);
}
public BlockingInteractionResponse performBlockingInteraction(PerformBlockingInteraction performBlockingInteraction)
- throws InvalidSessionFault, UnsupportedModeFault, UnsupportedMimeTypeFault, OperationFailedFault,
- UnsupportedWindowStateFault, UnsupportedLocaleFault, AccessDeniedFault, PortletStateChangeRequiredFault,
- InvalidRegistrationFault, MissingParametersFault, InvalidUserCategoryFault, InconsistentParametersFault,
- InvalidHandleFault, InvalidCookieFault, RemoteException
+ throws InvalidSessionFault, UnsupportedModeFault, UnsupportedMimeTypeFault, OperationFailedFault,
+ UnsupportedWindowStateFault, UnsupportedLocaleFault, AccessDeniedFault, PortletStateChangeRequiredFault,
+ InvalidRegistrationFault, MissingParametersFault, InvalidUserCategoryFault, InconsistentParametersFault,
+ InvalidHandleFault, InvalidCookieFault, RemoteException
{
return getMarkupBehaviorFor(performBlockingInteraction.getPortletContext().getPortletHandle())
- .performBlockingInteraction(performBlockingInteraction);
+ .performBlockingInteraction(performBlockingInteraction);
}
public ReturnAny releaseSessions(ReleaseSessions releaseSessions)
- throws InvalidRegistrationFault, OperationFailedFault, MissingParametersFault, AccessDeniedFault, RemoteException
+ throws InvalidRegistrationFault, OperationFailedFault, MissingParametersFault, AccessDeniedFault, RemoteException
{
return null;
}
public ReturnAny initCookie(InitCookie initCookie)
- throws AccessDeniedFault, OperationFailedFault, InvalidRegistrationFault, RemoteException
+ throws AccessDeniedFault, OperationFailedFault, InvalidRegistrationFault, RemoteException
{
// should only be called if we required cookies to be initialized
if (requiresInitCookie == null || CookieProtocol.none.equals(requiresInitCookie))
@@ -205,8 +206,8 @@
// PortletManagement implementation *********************************************************************************
public PortletDescriptionResponse getPortletDescription(GetPortletDescription getPortletDescription)
- throws AccessDeniedFault, InvalidHandleFault, InvalidUserCategoryFault, InconsistentParametersFault,
- MissingParametersFault, InvalidRegistrationFault, OperationFailedFault, RemoteException
+ throws AccessDeniedFault, InvalidHandleFault, InvalidUserCategoryFault, InconsistentParametersFault,
+ MissingParametersFault, InvalidRegistrationFault, OperationFailedFault, RemoteException
{
return getPortletManagementBehavior().getPortletDescription(getPortletDescription);
}
@@ -283,6 +284,6 @@
public void usingStrictModeChangedTo(boolean strictMode)
{
- throw new UnsupportedOperationException("usingStrictModeChangedTo not implemented");
+ WSRPValidator.setStrict(strictMode);
}
}
Modified: branches/JBoss_Portal_Branch_2_7/wsrp/src/main/org/jboss/portal/wsrp/WSRPConstants.java
===================================================================
--- branches/JBoss_Portal_Branch_2_7/wsrp/src/main/org/jboss/portal/wsrp/WSRPConstants.java 2008-07-07 12:56:40 UTC (rev 11316)
+++ branches/JBoss_Portal_Branch_2_7/wsrp/src/main/org/jboss/portal/wsrp/WSRPConstants.java 2008-07-07 15:56:08 UTC (rev 11317)
@@ -118,26 +118,14 @@
/** Default character set used to generate markup. */
public static final String DEFAULT_CHARACTER_SET = "UTF-8";
- /** Default locales. */
- public static final String[] DEFAULT_LOCALES;
-
- static
- {
- String defaultLocale = WSRPUtils.toString(Locale.getDefault());
- DEFAULT_LOCALES = new String[]{defaultLocale, "en"};
- }
-
- /** Default MIME types. */
- public static final String[] DEFAULT_MIME_TYPES = new String[]{"text/html"};
-
// Registration data related ****************************************************************************************
/** Default consumer name if none has been provided in the WSRP descriptor (*-wsrp.xml) */
public static final String DEFAULT_CONSUMER_NAME;
/** The String identifying the portal consumer agent */
public static final String CONSUMER_AGENT = PortalConstants.VERSION.getName() + "."
- + PortalConstants.VERSION.getMajor() + "." + PortalConstants.VERSION.getMinor() + "."
- + PortalConstants.VERSION.getQualifier();
+ + PortalConstants.VERSION.getMajor() + "." + PortalConstants.VERSION.getMinor() + "."
+ + PortalConstants.VERSION.getQualifier();
static
{
@@ -182,4 +170,17 @@
private WSRPConstants()
{
}
+
+ // init default locale at loading time as it is slow
+ private static String defaultLocale = WSRPUtils.toString(Locale.getDefault());
+
+ public static String[] getDefaultLocales()
+ {
+ return new String[]{defaultLocale, "en"}; // return copy to prevent modifications by client code
+ }
+
+ public static String[] getDefaultMimeTypes()
+ {
+ return new String[]{"text/html"}; // return copy to prevent modifications by client code
+ }
}
Modified: branches/JBoss_Portal_Branch_2_7/wsrp/src/main/org/jboss/portal/wsrp/WSRPTypeFactory.java
===================================================================
--- branches/JBoss_Portal_Branch_2_7/wsrp/src/main/org/jboss/portal/wsrp/WSRPTypeFactory.java 2008-07-07 12:56:40 UTC (rev 11316)
+++ branches/JBoss_Portal_Branch_2_7/wsrp/src/main/org/jboss/portal/wsrp/WSRPTypeFactory.java 2008-07-07 15:56:08 UTC (rev 11317)
@@ -25,7 +25,6 @@
import org.jboss.portal.Mode;
import org.jboss.portal.WindowState;
-import org.jboss.portal.common.net.media.MediaType;
import org.jboss.portal.common.util.ParameterValidation;
import org.jboss.portal.common.util.Tools;
import org.jboss.portal.portlet.ActionURL;
@@ -147,7 +146,7 @@
public static PerformBlockingInteraction createDefaultPerformBlockingInteraction(String portletHandle)
{
return createPerformBlockingInteraction(createPortletContext(portletHandle), createDefaultRuntimeContext(), createDefaultMarkupParams(),
- createDefaultInteractionParams());
+ createDefaultInteractionParams());
}
/**
@@ -161,9 +160,9 @@
* @return
*/
public static PerformBlockingInteraction createPerformBlockingInteraction(
- PortletContext portletContext, RuntimeContext runtimeContext,
- MarkupParams markupParams,
- InteractionParams interactionParams)
+ PortletContext portletContext, RuntimeContext runtimeContext,
+ MarkupParams markupParams,
+ InteractionParams interactionParams)
{
ParameterValidation.throwIllegalArgExceptionIfNull(portletContext, "PortletContext");
ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(portletContext.getPortletHandle(), "portlet handle", "PortletContext");
@@ -172,7 +171,7 @@
ParameterValidation.throwIllegalArgExceptionIfNull(interactionParams, "InteractionParams");
return new PerformBlockingInteraction(null, portletContext, runtimeContext, null,
- markupParams, interactionParams);
+ markupParams, interactionParams);
}
/**
@@ -287,20 +286,20 @@
if (portletHandle.length() > 255)
{
throw new IllegalArgumentException("Portlet handles must be less than 255 characters long. Was "
- + portletHandle.length() + " long.");
+ + portletHandle.length() + " long.");
}
}
/**
- * Same as createMarkupParams(false, {@link WSRPConstants#DEFAULT_LOCALES}, {@link WSRPConstants#DEFAULT_MIME_TYPES},
- * {@link WSRPConstants#VIEW_MODE}, {@link WSRPConstants#NORMAL_WINDOW_STATE})
+ * Same as createMarkupParams(false, {@link WSRPConstants#getDefaultLocales()}, {@link
+ * WSRPConstants#getDefaultMimeTypes()}, {@link WSRPConstants#VIEW_MODE}, {@link WSRPConstants#NORMAL_WINDOW_STATE})
*
* @return
*/
public static MarkupParams createDefaultMarkupParams()
{
- return createMarkupParams(false, WSRPConstants.DEFAULT_LOCALES, WSRPConstants.DEFAULT_MIME_TYPES,
- WSRPConstants.VIEW_MODE, WSRPConstants.NORMAL_WINDOW_STATE);
+ return createMarkupParams(false, WSRPConstants.getDefaultLocales(), WSRPConstants.getDefaultMimeTypes(),
+ WSRPConstants.VIEW_MODE, WSRPConstants.NORMAL_WINDOW_STATE);
}
/**
@@ -321,7 +320,7 @@
ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(windowState, "window state", "MarkupParams");
return new MarkupParams(secureClientCommunication, locales, mimeTypes, mode, windowState, null, null, null,
- null, null, null, null);
+ null, null, null, null);
}
/**
@@ -470,11 +469,11 @@
* markupBinary(xsd:base64Binary)), locale(xsd:string)?, requiresUrlRewriting(xsd:boolean[false])?,
* cacheControl(CacheControl)?, preferredTitle(xsd:string)?, extensions(Extension)*
*
- * @param mimeType The mime type of the returned markup. The mimeType field MUST be specified whenever markup is
- * returned, and if the markupBinary field is used to return the markup, the mime type MUST include
- * the character set for textual mime types using the syntax specified in RFC1522[14] (e.g.
- * "text/html; charset=UTF-8"). In this particular case this character set MAY be different than the
- * response message.
+ * @param mediaType The mime type of the returned markup. The mimeType field MUST be specified whenever markup is
+ * returned, and if the markupBinary field is used to return the markup, the mime type MUST include
+ * the character set for textual mime types using the syntax specified in RFC1522[14] (e.g.
+ * "text/html; charset=UTF-8"). In this particular case this character set MAY be different than the
+ * response message.
* @return a new MarkupContext
*/
public static MarkupContext createMarkupContext(String mediaType, byte[] markupBinary)
@@ -552,7 +551,7 @@
public static RegistrationData createDefaultRegistrationData()
{
return new RegistrationData(WSRPConstants.DEFAULT_CONSUMER_NAME, WSRPConstants.CONSUMER_AGENT, false, null, null,
- null, null, null, null);
+ null, null, null, null);
}
/**
@@ -673,7 +672,7 @@
if (expires < -1)
{
throw new IllegalArgumentException("Cache expiration time must be greater than -1, " +
- "-1 indicating that the cache will never expire.");
+ "-1 indicating that the cache will never expire.");
}
return new CacheControl(expires, userScope, null, null);
@@ -833,9 +832,9 @@
* @since 2.6
*/
public static SetPortletProperties createSetPortletProperties(
- RegistrationContext registrationContext,
- PortletContext portletContext,
- PropertyList propertyList)
+ RegistrationContext registrationContext,
+ PortletContext portletContext,
+ PropertyList propertyList)
{
ParameterValidation.throwIllegalArgExceptionIfNull(portletContext, "PortletContext");
ParameterValidation.throwIllegalArgExceptionIfNull(propertyList, "PropertyList");
Modified: branches/JBoss_Portal_Branch_2_7/wsrp/src/main/org/jboss/portal/wsrp/consumer/ProducerInfo.java
===================================================================
--- branches/JBoss_Portal_Branch_2_7/wsrp/src/main/org/jboss/portal/wsrp/consumer/ProducerInfo.java 2008-07-07 12:56:40 UTC (rev 11316)
+++ branches/JBoss_Portal_Branch_2_7/wsrp/src/main/org/jboss/portal/wsrp/consumer/ProducerInfo.java 2008-07-07 15:56:08 UTC (rev 11317)
@@ -710,7 +710,7 @@
//todo: might need to implement customization of default service description
GetServiceDescription gsd = WSRPTypeFactory.createGetServiceDescription();
- gsd.setDesiredLocales(WSRPConstants.DEFAULT_LOCALES);
+ gsd.setDesiredLocales(WSRPConstants.getDefaultLocales());
if (asUnregistred)
{
return gsd;
Modified: branches/JBoss_Portal_Branch_2_7/wsrp/src/main/org/jboss/portal/wsrp/producer/WSRPProducerImpl.java
===================================================================
--- branches/JBoss_Portal_Branch_2_7/wsrp/src/main/org/jboss/portal/wsrp/producer/WSRPProducerImpl.java 2008-07-07 12:56:40 UTC (rev 11316)
+++ branches/JBoss_Portal_Branch_2_7/wsrp/src/main/org/jboss/portal/wsrp/producer/WSRPProducerImpl.java 2008-07-07 15:56:08 UTC (rev 11317)
@@ -34,13 +34,10 @@
import org.jboss.portal.registration.Registration;
import org.jboss.portal.registration.RegistrationLocal;
import org.jboss.portal.registration.RegistrationManager;
-import org.jboss.portal.registration.RegistrationUtils;
import org.jboss.portal.wsrp.ResponseDebugFactory;
import org.jboss.portal.wsrp.WSRPConstants;
import org.jboss.portal.wsrp.WSRPExceptionFactory;
-import org.jboss.portal.wsrp.WSRPPortletURL;
import org.jboss.portal.wsrp.WSRPProducer;
-import org.jboss.portal.wsrp.WSRPUtils;
import org.jboss.portal.wsrp.core.AccessDeniedFault;
import org.jboss.portal.wsrp.core.BlockingInteractionResponse;
import org.jboss.portal.wsrp.core.ClonePortlet;
@@ -126,7 +123,7 @@
private CookieProtocol requiresInitCookie = CookieProtocol.none;
/** Supported locales. */
- private String[] supportedLocales = WSRPConstants.DEFAULT_LOCALES;
+ private String[] supportedLocales = WSRPConstants.getDefaultLocales();
private ProducerConfigurationService configurationService;
@@ -146,7 +143,7 @@
// ServiceDescription implementation ********************************************************************************
public ServiceDescription getServiceDescription(GetServiceDescription gs)
- throws InvalidRegistrationFault, OperationFailedFault, RemoteException
+ throws InvalidRegistrationFault, OperationFailedFault, RemoteException
{
log.debug("getServiceDescription invoked");
ServiceDescription sd = serviceDescriptionHandler.getServiceDescription(gs);
@@ -173,10 +170,10 @@
// MarkupService implementation *************************************************************************************
public MarkupResponse getMarkup(GetMarkup getMarkup)
- throws UnsupportedWindowStateFault, InvalidCookieFault, InvalidSessionFault, AccessDeniedFault,
- InconsistentParametersFault, InvalidHandleFault, UnsupportedLocaleFault, UnsupportedModeFault,
- OperationFailedFault, MissingParametersFault, InvalidUserCategoryFault, InvalidRegistrationFault,
- UnsupportedMimeTypeFault, RemoteException
+ throws UnsupportedWindowStateFault, InvalidCookieFault, InvalidSessionFault, AccessDeniedFault,
+ InconsistentParametersFault, InvalidHandleFault, UnsupportedLocaleFault, UnsupportedModeFault,
+ OperationFailedFault, MissingParametersFault, InvalidUserCategoryFault, InvalidRegistrationFault,
+ UnsupportedMimeTypeFault, RemoteException
{
log.debug("getMarkup invoked");
MarkupResponse response = markupHandler.getMarkup(getMarkup);
@@ -185,10 +182,10 @@
}
public BlockingInteractionResponse performBlockingInteraction(PerformBlockingInteraction performBlockingInteraction)
- throws InvalidSessionFault, UnsupportedModeFault, UnsupportedMimeTypeFault, OperationFailedFault,
- UnsupportedWindowStateFault, UnsupportedLocaleFault, AccessDeniedFault, PortletStateChangeRequiredFault,
- InvalidRegistrationFault, MissingParametersFault, InvalidUserCategoryFault, InconsistentParametersFault,
- InvalidHandleFault, InvalidCookieFault, RemoteException
+ throws InvalidSessionFault, UnsupportedModeFault, UnsupportedMimeTypeFault, OperationFailedFault,
+ UnsupportedWindowStateFault, UnsupportedLocaleFault, AccessDeniedFault, PortletStateChangeRequiredFault,
+ InvalidRegistrationFault, MissingParametersFault, InvalidUserCategoryFault, InconsistentParametersFault,
+ InvalidHandleFault, InvalidCookieFault, RemoteException
{
log.debug("performBlockingInteraction invoked");
BlockingInteractionResponse interactionResponse = markupHandler.performBlockingInteraction(performBlockingInteraction);
@@ -197,7 +194,7 @@
}
public ReturnAny releaseSessions(ReleaseSessions releaseSessions)
- throws InvalidRegistrationFault, OperationFailedFault, MissingParametersFault, AccessDeniedFault, RemoteException
+ throws InvalidRegistrationFault, OperationFailedFault, MissingParametersFault, AccessDeniedFault, RemoteException
{
log.debug("releaseSessions invoked");
ReturnAny returnAny = markupHandler.releaseSessions(releaseSessions);
@@ -206,7 +203,7 @@
}
public ReturnAny initCookie(InitCookie initCookie)
- throws AccessDeniedFault, OperationFailedFault, InvalidRegistrationFault, RemoteException
+ throws AccessDeniedFault, OperationFailedFault, InvalidRegistrationFault, RemoteException
{
log.debug("initCookie invoked");
ReturnAny returnAny = markupHandler.initCookie(initCookie);
@@ -217,7 +214,7 @@
// Registration implementation **************************************************************************************
public RegistrationContext register(RegistrationData register) throws MissingParametersFault, OperationFailedFault,
- RemoteException
+ RemoteException
{
log.debug("register invoked");
RegistrationContext registrationContext = registrationHandler.register(register);
@@ -226,7 +223,7 @@
}
public ReturnAny deregister(RegistrationContext deregister) throws OperationFailedFault, InvalidRegistrationFault,
- RemoteException
+ RemoteException
{
log.debug("deregister invoked");
ReturnAny returnAny = registrationHandler.deregister(deregister);
@@ -235,7 +232,7 @@
}
public RegistrationState modifyRegistration(ModifyRegistration modifyRegistration) throws MissingParametersFault,
- OperationFailedFault, InvalidRegistrationFault, RemoteException
+ OperationFailedFault, InvalidRegistrationFault, RemoteException
{
log.debug("modifyRegistration invoked");
RegistrationState registrationState = registrationHandler.modifyRegistration(modifyRegistration);
@@ -307,8 +304,8 @@
// PortletManagement implementation *********************************************************************************
public PortletDescriptionResponse getPortletDescription(GetPortletDescription getPortletDescription)
- throws AccessDeniedFault, InvalidHandleFault, InvalidUserCategoryFault, InconsistentParametersFault,
- MissingParametersFault, InvalidRegistrationFault, OperationFailedFault, RemoteException
+ throws AccessDeniedFault, InvalidHandleFault, InvalidUserCategoryFault, InconsistentParametersFault,
+ MissingParametersFault, InvalidRegistrationFault, OperationFailedFault, RemoteException
{
log.debug("getPortletDescription invoked");
PortletDescriptionResponse description = portletManagementHandler.getPortletDescription(getPortletDescription);
@@ -317,8 +314,8 @@
}
public PortletContext clonePortlet(ClonePortlet clonePortlet) throws InvalidUserCategoryFault, AccessDeniedFault,
- OperationFailedFault, InvalidHandleFault, InvalidRegistrationFault, InconsistentParametersFault,
- MissingParametersFault, RemoteException
+ OperationFailedFault, InvalidHandleFault, InvalidRegistrationFault, InconsistentParametersFault,
+ MissingParametersFault, RemoteException
{
log.debug("clonePortlet invoked");
PortletContext portletContext = portletManagementHandler.clonePortlet(clonePortlet);
@@ -327,7 +324,7 @@
}
public DestroyPortletsResponse destroyPortlets(DestroyPortlets destroyPortlets) throws InconsistentParametersFault,
- MissingParametersFault, InvalidRegistrationFault, OperationFailedFault, RemoteException
+ MissingParametersFault, InvalidRegistrationFault, OperationFailedFault, RemoteException
{
log.debug("destroyPortlets invoked");
DestroyPortletsResponse destroyPortletsResponse = portletManagementHandler.destroyPortlets(destroyPortlets);
@@ -336,8 +333,8 @@
}
public PortletContext setPortletProperties(SetPortletProperties setPortletProperties) throws OperationFailedFault,
- InvalidHandleFault, MissingParametersFault, InconsistentParametersFault, InvalidUserCategoryFault,
- AccessDeniedFault, InvalidRegistrationFault, RemoteException
+ InvalidHandleFault, MissingParametersFault, InconsistentParametersFault, InvalidUserCategoryFault,
+ AccessDeniedFault, InvalidRegistrationFault, RemoteException
{
log.debug("setPortletProperties invoked");
PortletContext portletContext = portletManagementHandler.setPortletProperties(setPortletProperties);
@@ -346,8 +343,8 @@
}
public PropertyList getPortletProperties(GetPortletProperties getPortletProperties) throws InvalidHandleFault,
- MissingParametersFault, InvalidRegistrationFault, AccessDeniedFault, OperationFailedFault,
- InconsistentParametersFault, InvalidUserCategoryFault, RemoteException
+ MissingParametersFault, InvalidRegistrationFault, AccessDeniedFault, OperationFailedFault,
+ InconsistentParametersFault, InvalidUserCategoryFault, RemoteException
{
log.debug("getPortletProperties invoked");
PropertyList list = portletManagementHandler.getPortletProperties(getPortletProperties);
@@ -356,8 +353,8 @@
}
public PortletPropertyDescriptionResponse getPortletPropertyDescription(GetPortletPropertyDescription getPortletPropertyDescription)
- throws MissingParametersFault, InconsistentParametersFault, InvalidUserCategoryFault, InvalidRegistrationFault,
- AccessDeniedFault, InvalidHandleFault, OperationFailedFault, RemoteException
+ throws MissingParametersFault, InconsistentParametersFault, InvalidUserCategoryFault, InvalidRegistrationFault,
+ AccessDeniedFault, InvalidHandleFault, OperationFailedFault, RemoteException
{
log.debug("getPortletPropertyDescription invoked");
PortletPropertyDescriptionResponse descriptionResponse = portletManagementHandler.getPortletPropertyDescription(getPortletPropertyDescription);
@@ -409,7 +406,7 @@
catch (NoSuchPortletException e)
{
throw WSRPExceptionFactory.throwSOAPFaultException(WSRPExceptionFactory.INVALID_HANDLE,
- "Couldn't find portlet with handle '" + portletContext.getId() + "'", null);
+ "Couldn't find portlet with handle '" + portletContext.getId() + "'", null);
}
finally
{
@@ -419,7 +416,7 @@
if (!isRemotable(portlet))
{
throw WSRPExceptionFactory.throwSOAPFaultException(WSRPExceptionFactory.INVALID_HANDLE,
- "Portlet '" + portletContext.getId() + "' is not remotely available.", null);
+ "Portlet '" + portletContext.getId() + "' is not remotely available.", null);
}
return portlet;
@@ -534,8 +531,6 @@
public void usingStrictModeChangedTo(boolean strictMode)
{
- RegistrationUtils.setStrict(strictMode);
- WSRPUtils.setStrict(strictMode);
- WSRPPortletURL.setStrict(strictMode);
+ WSRPValidator.setStrict(strictMode);
}
}
Added: branches/JBoss_Portal_Branch_2_7/wsrp/src/main/org/jboss/portal/wsrp/producer/WSRPValidator.java
===================================================================
--- branches/JBoss_Portal_Branch_2_7/wsrp/src/main/org/jboss/portal/wsrp/producer/WSRPValidator.java (rev 0)
+++ branches/JBoss_Portal_Branch_2_7/wsrp/src/main/org/jboss/portal/wsrp/producer/WSRPValidator.java 2008-07-07 15:56:08 UTC (rev 11317)
@@ -0,0 +1,49 @@
+/*
+* 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.wsrp.producer;
+
+import org.jboss.portal.registration.RegistrationUtils;
+import org.jboss.portal.wsrp.WSRPPortletURL;
+import org.jboss.portal.wsrp.WSRPUtils;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris Laprun</a>
+ * @version $Revision$
+ */
+public class WSRPValidator
+{
+ private static boolean strict = true;
+
+ public static void setStrict(boolean strictMode)
+ {
+ strict = strictMode;
+ RegistrationUtils.setStrict(strict);
+ WSRPUtils.setStrict(strict);
+ WSRPPortletURL.setStrict(strict);
+ }
+
+ public static boolean isStrict()
+ {
+ return strict;
+ }
+}
16 years
JBoss Portal SVN: r11316 - in modules/presentation/trunk/presentation/src: main/java/org/jboss/portal/presentation/impl/model/pull and 2 other directories.
by portal-commits@lists.jboss.org
Author: julien(a)jboss.com
Date: 2008-07-07 08:56:40 -0400 (Mon, 07 Jul 2008)
New Revision: 11316
Modified:
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/UpdatePhase.java
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/pull/DetachedViewPortContext.java
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/model/ViewPortContext.java
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/NodeDef.java
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/UIObjectNode.java
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/UIObjectTree.java
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/UpdateObjectTestCase.java
Log:
correctly implement property state update
Modified: modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/UpdatePhase.java
===================================================================
--- modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/UpdatePhase.java 2008-07-07 12:36:48 UTC (rev 11315)
+++ modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/UpdatePhase.java 2008-07-07 12:56:40 UTC (rev 11316)
@@ -170,6 +170,16 @@
}
else if (diff instanceof ObjectDiff.Update)
{
+ ObjectDiff.Update update = (ObjectDiff.Update)diff;
+
+ //
+ context.updateObject(
+ diff.getObjectId(),
+ update.getRemovedProperties(),
+ update.getUpdatedProperties(),
+ update.getAddedProperties());
+
+ //
if (diff instanceof ObjectDiff.RecursiveUpdate)
{
ObjectDiff.RecursiveUpdate recursiveUpdate = (ObjectDiff.RecursiveUpdate)diff;
Modified: modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/pull/DetachedViewPortContext.java
===================================================================
--- modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/pull/DetachedViewPortContext.java 2008-07-07 12:36:48 UTC (rev 11315)
+++ modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/pull/DetachedViewPortContext.java 2008-07-07 12:56:40 UTC (rev 11316)
@@ -27,6 +27,8 @@
import java.util.HashMap;
import java.util.Map;
+import java.util.Set;
+import java.io.Serializable;
/**
* @author <a href="mailto:julien@jboss-portal.org">Julien Viet</a>
@@ -66,7 +68,7 @@
nodes.put(node.getId(), node);
}
- public void updateObject(String objectId)
+ public void updateObject(String objectId, Set<String> removedProperties, Map<String, Serializable> updatedProperties, Map<String, Serializable> addedProperties)
{
throw new UnsupportedOperationException();
}
Modified: modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/model/ViewPortContext.java
===================================================================
--- modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/model/ViewPortContext.java 2008-07-07 12:36:48 UTC (rev 11315)
+++ modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/model/ViewPortContext.java 2008-07-07 12:56:40 UTC (rev 11316)
@@ -24,6 +24,10 @@
import org.jboss.portal.presentation.model.ui.UIObject;
+import java.util.Set;
+import java.util.Map;
+import java.io.Serializable;
+
/**
* This interface defines read-write access to the structural information of a viewport.
*
@@ -52,8 +56,11 @@
* Signals the context that the object state has been updated.
*
* @param objectId the object id
+ * @param removedProperties the removed properties
+ * @param updatedProperties the updated properties
+ * @param addedProperties the added properties
*/
- void updateObject(String objectId);
+ void updateObject(String objectId, Set<String> removedProperties, Map<String, Serializable> updatedProperties, Map<String, Serializable> addedProperties);
/**
* Removes the specified object from the context.
Modified: modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/NodeDef.java
===================================================================
--- modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/NodeDef.java 2008-07-07 12:36:48 UTC (rev 11315)
+++ modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/NodeDef.java 2008-07-07 12:56:40 UTC (rev 11316)
@@ -35,6 +35,7 @@
import java.util.Map;
import java.util.Set;
import java.util.Collection;
+import java.io.Serializable;
/**
* @author <a href="mailto:julien@jboss-portal.org">Julien Viet</a>
@@ -196,7 +197,7 @@
for (String propertyName : properties.keySet())
{
String expectedProperty = properties.get(propertyName);
- String property = objectNode.getProperties().get(propertyName);
+ Serializable property = objectNode.getProperties().get(propertyName);
Assert.assertEquals(expectedProperty, property);
}
Modified: modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/UIObjectNode.java
===================================================================
--- modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/UIObjectNode.java 2008-07-07 12:36:48 UTC (rev 11315)
+++ modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/UIObjectNode.java 2008-07-07 12:56:40 UTC (rev 11316)
@@ -27,6 +27,7 @@
import java.util.HashMap;
import java.util.Map;
+import java.io.Serializable;
/**
* @author <a href="mailto:julien@jboss-portal.org">Julien Viet</a>
@@ -42,7 +43,7 @@
private Map<String, UIObjectNode> children;
/** . */
- private Map<String, String> properties;
+ Map<String, Serializable> properties;
public UIObjectNode(UIObject object)
{
@@ -53,13 +54,13 @@
//
this.object = object;
- this.properties = new HashMap<String, String>();
+ this.properties = new HashMap<String, Serializable>();
//
updateState();
}
- public Map<String, String> getProperties()
+ public Map<String, Serializable> getProperties()
{
return properties;
}
Modified: modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/UIObjectTree.java
===================================================================
--- modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/UIObjectTree.java 2008-07-07 12:36:48 UTC (rev 11315)
+++ modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/UIObjectTree.java 2008-07-07 12:56:40 UTC (rev 11316)
@@ -30,6 +30,8 @@
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>
@@ -76,18 +78,6 @@
return node != null ? node.getObject() : null;
}
- public void updateObject(String objectId)
- {
- UIObjectNode node = nodes.get(objectId);
- if (node == null)
- {
- throw new IllegalStateException("No such object " + objectId);
- }
-
- //
- node.updateState();
- }
-
public void removeObject(String objectId)
{
if (nodes.remove(objectId) == null)
@@ -110,6 +100,22 @@
nodes.put(id, new UIObjectNode(object));
}
+// public void updateObject(String objectId)
+// {
+// UIObjectNode node = nodes.get(objectId);
+//
+// //
+// node.updateState();
+// }
+
+ public void updateObject(String objectId, Set<String> removedProperties, Map<String, Serializable> updatedProperties, Map<String, Serializable> addedProperties)
+ {
+ UIObjectNode node = nodes.get(objectId);
+ node.properties.keySet().removeAll(removedProperties);
+ node.properties.putAll(updatedProperties);
+ node.properties.putAll(addedProperties);
+ }
+
public void addChild(String parentId, String childId)
{
UIObjectNode parent = nodes.get(parentId);
Modified: modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/UpdateObjectTestCase.java
===================================================================
--- modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/UpdateObjectTestCase.java 2008-07-07 12:36:48 UTC (rev 11315)
+++ modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/UpdateObjectTestCase.java 2008-07-07 12:56:40 UTC (rev 11316)
@@ -56,17 +56,27 @@
rootDef.assertEquals(context.getNode(model.getRootId()));
//
- mockModel.getRoot().getChild("foo").setPropertyValue("juu", "daa");
+ mockModel.getRoot().getChild("foo").setPropertyValue("juu", "juu_value");
+ mockModel.getRoot().getChild("foo").setPropertyValue("daa", "daa_value1");
//
+ rootDef.getChild("foo").setProperty("juu", "juu_value");
+ rootDef.getChild("foo").setProperty("daa", "daa_value1");
+
+ //
viewPort.refresh();
rootDef.assertEquals(context.getNode(model.getRootId()));
//
mockModel.getRoot().getChild("foo").setPropertyValue("juu", null);
- mockModel.getRoot().getChild("foo").setPropertyValue("daa", "juu2");
+ mockModel.getRoot().getChild("foo").setPropertyValue("daa", "daa_value2");
+ mockModel.getRoot().getChild("foo").setPropertyValue("bar", "bar_value");
//
+ rootDef.getChild("foo").setProperty("daa", "daa_value2");
+ rootDef.getChild("foo").setProperty("bar", "bar_value");
+
+ //
viewPort.refresh();
rootDef.assertEquals(context.getNode(model.getRootId()));
}
16 years
JBoss Portal SVN: r11315 - in modules/presentation/trunk/presentation/src: test/java/org/jboss/portal/presentation/test/model and 1 other directories.
by portal-commits@lists.jboss.org
Author: julien(a)jboss.com
Date: 2008-07-07 08:36:48 -0400 (Mon, 07 Jul 2008)
New Revision: 11315
Removed:
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/CreateDiffPhase.java
Modified:
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/UpdateObjectTestCase.java
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/state/mock/impl/StructuralObjectImpl.java
Log:
oups removed too much
Deleted: modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/CreateDiffPhase.java
===================================================================
--- modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/CreateDiffPhase.java 2008-07-07 12:34:55 UTC (rev 11314)
+++ modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/CreateDiffPhase.java 2008-07-07 12:36:48 UTC (rev 11315)
@@ -1,276 +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.impl.model;
-
-import org.jboss.portal.presentation.model.ObjectTraversalType;
-import org.jboss.portal.presentation.model.ViewPortContext;
-import org.jboss.portal.presentation.model.ViewPortScope;
-import org.jboss.portal.presentation.state.navigational.NavigationalStateContext;
-import org.jboss.portal.presentation.state.structural.StructuralObject;
-import org.jboss.portal.presentation.state.structural.StructuralStateContext;
-import org.jboss.portal.presentation.impl.model.ui.UIObjectImpl;
-
-import java.util.Collection;
-import java.util.ArrayList;
-
-/**
- * @author <a href="mailto:julien@jboss-portal.org">Julien Viet</a>
- * @version $Revision: 630 $
- */
-public class CreateDiffPhase
-{
-
- /** . */
- private final ViewPortContext context;
-
- /** . */
- private final ViewPortScope scope;
-
- /** . */
- private final NavigationalStateContext navigationalStateContext;
-
- /** . */
- private final StructuralStateContext structuralStateContext;
-
- /** . */
- private ObjectDiff rootDiff;
-
- public CreateDiffPhase(
- ViewPortContext context,
- ViewPortScope scope,
- NavigationalStateContext navigationalStateContext,
- StructuralStateContext structuralStateContext)
- {
- this.context = context;
- this.scope = scope;
- this.navigationalStateContext = navigationalStateContext;
- this.structuralStateContext = structuralStateContext;
- }
-
- public void perform()
- {
- rootDiff = diff(scope.getRootId());
- }
-
- public ObjectDiff getRootVisit()
- {
- return rootDiff;
- }
-
- private ObjectDiff diff(String objectId)
- {
- UIObjectImpl object = (UIObjectImpl)context.getObject(objectId);
-
- //
- if (object == null)
- {
- StructuralObject structuralObject = structuralStateContext.load(objectId);
-
- //
- if (structuralObject == null)
- {
- throw new UnsupportedOperationException();
- }
-
- //
- return load(structuralObject);
- }
- else
- {
- return diff(object);
- }
- }
-
- private ObjectDiff.Evict createEvict(UIObjectImpl object)
- {
- Collection<ObjectDiff.Evict> evictedChildren = createEvictedChildren(object);
-
- //
- return ObjectDiff.createEvict(object, evictedChildren);
- }
-
- private Collection<ObjectDiff.Evict> createEvictedChildren(UIObjectImpl object)
- {
- InternalObjectContext objectContext = (InternalObjectContext)object.getContext();
-
- //
- if (objectContext.childRefs != null)
- {
- Collection<ObjectDiff.Evict> evictedChildren = new ArrayList<ObjectDiff.Evict>();
-
- //
- for (UIObjectRef removedChildRef : objectContext.childRefs.values())
- {
- if (removedChildRef.loaded)
- {
- UIObjectImpl child = (UIObjectImpl)context.getObject(removedChildRef.getId());
-
- //
- evictedChildren.add(createEvict(child));
- }
- }
-
- //
- return evictedChildren;
- }
- else
- {
- // On purpose to indicate that no children was initialized and therefore there is no
- // destroy children callback to do
- return null;
- }
- }
-
- private ObjectDiff diff(UIObjectImpl object)
- {
- ObjectTraversalType traversalType = scope.enterObject(object);
-
- //
- try
- {
- if (traversalType == ObjectTraversalType.SKIP)
- {
- return createEvict(object);
- }
- else
- {
- StructuralObject.Refresh refresh = structuralStateContext.refresh(object.getStructuralObject());
-
- //
- if (traversalType == ObjectTraversalType.RECURSIVE)
- {
- Collection<ObjectDiff> addedObjects = new ArrayList<ObjectDiff>();
- Collection<ObjectDiff> validObjects = new ArrayList<ObjectDiff>();
- Collection<ObjectDiff> staleObjects = new ArrayList<ObjectDiff>();
- Collection<ObjectDiff.Evict> removedObjects = new ArrayList<ObjectDiff.Evict>();
-
- //
- boolean createChildren = ((InternalObjectContext)object.getContext()).childRefs == null;
-
- //
- for (StructuralObject addedStructuralChild : refresh.getAddedChildren())
- {
- addedObjects.add(load(addedStructuralChild));
- }
-
- //
- for (StructuralObject staleStructuralChild : refresh.getStaleChildren().values())
- {
- ObjectDiff childDiff = diff(staleStructuralChild.getId());
- staleObjects.add(childDiff);
- }
-
- //
- for (String validChildId : refresh.getValidChildren())
- {
- ObjectDiff childDiff = diff(validChildId);
- validObjects.add(childDiff);
- }
-
- //
- for (String removedChildId : refresh.getRemovedChildren())
- {
- UIObjectImpl removedChild = (UIObjectImpl)context.getObject(removedChildId);
-
- //
- if (removedChild != null)
- {
- ObjectDiff.Evict childVisit = createEvict(removedChild);
- removedObjects.add(childVisit);
- }
- else
- {
- // It means that the child was not loaded previously and it has
- // been removed in the current refresh, so we do nothing
- }
- }
-
- //
- return ObjectDiff.createRecursiveUpdate(
- object,
- refresh.getRemovedProperties(),
- refresh.getUpdatedProperties(),
- refresh.getAddedProperties(),
- createChildren,
- addedObjects,
- validObjects,
- staleObjects,
- removedObjects);
- }
- else
- {
- Collection<ObjectDiff.Evict> evictedChildren = createEvictedChildren(object);
-
- //
- return ObjectDiff.createSingleUpdate(
- object,
- refresh.getRemovedProperties(),
- refresh.getUpdatedProperties(),
- refresh.getAddedProperties(),
- evictedChildren);
- }
- }
- }
- finally
- {
- scope.leaveObject(object);
- }
- }
-
- private ObjectDiff load(StructuralObject structuralObject)
- {
- UIObjectImpl object = UIObjectImpl.create(structuralObject, new InternalObjectContext(navigationalStateContext));
-
- //
- ObjectTraversalType traversalType = scope.enterObject(object);
-
- //
- try
- {
- if (traversalType == ObjectTraversalType.SKIP)
- {
- return ObjectDiff.createSkip(object);
- }
- else
- {
- if (traversalType == ObjectTraversalType.RECURSIVE)
- {
- Collection<ObjectDiff> addedChildren = new ArrayList<ObjectDiff>();
- for (StructuralObject structuralChild : structuralStateContext.loadChildren(structuralObject))
- {
- addedChildren.add(load(structuralChild));
- }
- return ObjectDiff.createRecursiveLoad(object, addedChildren);
- }
- else
- {
- return ObjectDiff.createSingleLoad(object);
- }
- }
- }
- finally
- {
- scope.leaveObject(object);
- }
- }
-}
Modified: modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/UpdateObjectTestCase.java
===================================================================
--- modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/UpdateObjectTestCase.java 2008-07-07 12:34:55 UTC (rev 11314)
+++ modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/model/UpdateObjectTestCase.java 2008-07-07 12:36:48 UTC (rev 11315)
@@ -64,7 +64,7 @@
//
mockModel.getRoot().getChild("foo").setPropertyValue("juu", null);
- mockModel.getRoot().getChild("foo").setPropertyValue("daa", "juu");
+ mockModel.getRoot().getChild("foo").setPropertyValue("daa", "juu2");
//
viewPort.refresh();
Modified: modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/state/mock/impl/StructuralObjectImpl.java
===================================================================
--- modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/state/mock/impl/StructuralObjectImpl.java 2008-07-07 12:34:55 UTC (rev 11314)
+++ modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/state/mock/impl/StructuralObjectImpl.java 2008-07-07 12:36:48 UTC (rev 11315)
@@ -62,4 +62,9 @@
{
return handle.id;
}
+
+ public StructuralStateImpl getState()
+ {
+ return state;
+ }
}
16 years
JBoss Portal SVN: r11314 - in modules/presentation/trunk/presentation/src: main/java/org/jboss/portal/presentation/state/structural and 1 other directories.
by portal-commits@lists.jboss.org
Author: julien(a)jboss.com
Date: 2008-07-07 08:34:55 -0400 (Mon, 07 Jul 2008)
New Revision: 11314
Modified:
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/state/structural/adapter/StructuralObjectImpl.java
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/state/structural/StructuralObject.java
modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/state/mock/impl/StructuralObjectImpl.java
Log:
removing the need for equals method on StructuralObject since now state comparison is done with the refresh operation
Modified: modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/state/structural/adapter/StructuralObjectImpl.java
===================================================================
--- modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/state/structural/adapter/StructuralObjectImpl.java 2008-07-07 12:32:50 UTC (rev 11313)
+++ modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/state/structural/adapter/StructuralObjectImpl.java 2008-07-07 12:34:55 UTC (rev 11314)
@@ -77,46 +77,4 @@
{
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;
-// throw new UnsupportedOperationException();
- }
}
\ No newline at end of file
Modified: modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/state/structural/StructuralObject.java
===================================================================
--- modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/state/structural/StructuralObject.java 2008-07-07 12:32:50 UTC (rev 11313)
+++ modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/state/structural/StructuralObject.java 2008-07-07 12:34:55 UTC (rev 11314)
@@ -37,8 +37,6 @@
StructuralState getState();
- boolean equals(Object obj);
-
/**
* A comparison between two structural objects.
*/
Modified: modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/state/mock/impl/StructuralObjectImpl.java
===================================================================
--- modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/state/mock/impl/StructuralObjectImpl.java 2008-07-07 12:32:50 UTC (rev 11313)
+++ modules/presentation/trunk/presentation/src/test/java/org/jboss/portal/presentation/test/state/mock/impl/StructuralObjectImpl.java 2008-07-07 12:34:55 UTC (rev 11314)
@@ -62,26 +62,4 @@
{
return handle.id;
}
-
- public StructuralState getState()
- {
- return state;
- }
-
- public boolean equals(Object obj)
- {
- if (obj == this)
- {
- return true;
- }
- if (obj instanceof StructuralObjectImpl)
- {
- StructuralObjectImpl that = (StructuralObjectImpl)obj;
-
- //
- return handle.equals(that.handle);
- }
- return false;
-// throw new UnsupportedOperationException();
- }
}
16 years
JBoss Portal SVN: r11313 - modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model.
by portal-commits@lists.jboss.org
Author: julien(a)jboss.com
Date: 2008-07-07 08:32:50 -0400 (Mon, 07 Jul 2008)
New Revision: 11313
Modified:
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/ObjectDiff.java
Log:
bit of javadoc
Modified: modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/ObjectDiff.java
===================================================================
--- modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/ObjectDiff.java 2008-07-07 12:30:10 UTC (rev 11312)
+++ modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/ObjectDiff.java 2008-07-07 12:32:50 UTC (rev 11313)
@@ -108,6 +108,12 @@
return object.getId();
}
+ /**
+ * Returns the object that either was created during the phase or is the same object that
+ * was retrieved from the viewport context.
+ *
+ * @return the object.
+ */
public UIObjectImpl getObject()
{
return object;
16 years
JBoss Portal SVN: r11312 - modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model.
by portal-commits@lists.jboss.org
Author: julien(a)jboss.com
Date: 2008-07-07 08:30:10 -0400 (Mon, 07 Jul 2008)
New Revision: 11312
Modified:
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/UpdatePhase.java
Log:
bit of javadoc
Modified: modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/UpdatePhase.java
===================================================================
--- modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/UpdatePhase.java 2008-07-07 12:26:25 UTC (rev 11311)
+++ modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/UpdatePhase.java 2008-07-07 12:30:10 UTC (rev 11312)
@@ -29,6 +29,12 @@
import java.util.HashMap;
/**
+ * The update phase takes care of applying the result produced by the diff phase to the viewport context.
+ * It is splitted into two phases, the first one performs removals and the second one performs updates
+ * and loadings. The main reason of having two phases is to deal with object moves within the same viewport
+ * scope. If a load resulting from a move would be applied before the object is evicted it would result
+ * of a corruption of the viewport scope (two objects with the same id).
+ *
* @author <a href="mailto:julien@jboss-portal.org">Julien Viet</a>
* @version $Revision: 630 $
*/
@@ -53,6 +59,9 @@
perform2ndPhase();
}
+ /**
+ * The first phase take care of removals.
+ */
private void perform1stPhase()
{
perform1stPhase(rootDiff);
@@ -127,6 +136,9 @@
}
}
+ /**
+ * The second phase takes care of updates and loads.
+ */
private void perform2ndPhase()
{
perform2ndPhase(rootDiff);
@@ -196,7 +208,7 @@
}
else if (diff instanceof ObjectDiff.Update)
{
- // Nothing ?
+ // Nothing
}
else if (diff instanceof ObjectDiff.Skip)
{
16 years
JBoss Portal SVN: r11311 - modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model.
by portal-commits@lists.jboss.org
Author: julien(a)jboss.com
Date: 2008-07-07 08:26:25 -0400 (Mon, 07 Jul 2008)
New Revision: 11311
Added:
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/DiffPhase.java
Modified:
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/ViewPortImpl.java
Log:
simple renaming of CreateDiffPhase to DiffPhase
Copied: modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/DiffPhase.java (from rev 11310, modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/CreateDiffPhase.java)
===================================================================
--- modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/DiffPhase.java (rev 0)
+++ modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/DiffPhase.java 2008-07-07 12:26:25 UTC (rev 11311)
@@ -0,0 +1,276 @@
+/******************************************************************************
+ * 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.impl.model;
+
+import org.jboss.portal.presentation.model.ObjectTraversalType;
+import org.jboss.portal.presentation.model.ViewPortContext;
+import org.jboss.portal.presentation.model.ViewPortScope;
+import org.jboss.portal.presentation.state.navigational.NavigationalStateContext;
+import org.jboss.portal.presentation.state.structural.StructuralObject;
+import org.jboss.portal.presentation.state.structural.StructuralStateContext;
+import org.jboss.portal.presentation.impl.model.ui.UIObjectImpl;
+
+import java.util.Collection;
+import java.util.ArrayList;
+
+/**
+ * @author <a href="mailto:julien@jboss-portal.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+public class DiffPhase
+{
+
+ /** . */
+ private final ViewPortContext context;
+
+ /** . */
+ private final ViewPortScope scope;
+
+ /** . */
+ private final NavigationalStateContext navigationalStateContext;
+
+ /** . */
+ private final StructuralStateContext structuralStateContext;
+
+ /** . */
+ private ObjectDiff rootDiff;
+
+ public DiffPhase(
+ ViewPortContext context,
+ ViewPortScope scope,
+ NavigationalStateContext navigationalStateContext,
+ StructuralStateContext structuralStateContext)
+ {
+ this.context = context;
+ this.scope = scope;
+ this.navigationalStateContext = navigationalStateContext;
+ this.structuralStateContext = structuralStateContext;
+ }
+
+ public void perform()
+ {
+ rootDiff = diff(scope.getRootId());
+ }
+
+ public ObjectDiff getRootVisit()
+ {
+ return rootDiff;
+ }
+
+ private ObjectDiff diff(String objectId)
+ {
+ UIObjectImpl object = (UIObjectImpl)context.getObject(objectId);
+
+ //
+ if (object == null)
+ {
+ StructuralObject structuralObject = structuralStateContext.load(objectId);
+
+ //
+ if (structuralObject == null)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ //
+ return load(structuralObject);
+ }
+ else
+ {
+ return diff(object);
+ }
+ }
+
+ private ObjectDiff.Evict createEvict(UIObjectImpl object)
+ {
+ Collection<ObjectDiff.Evict> evictedChildren = createEvictedChildren(object);
+
+ //
+ return ObjectDiff.createEvict(object, evictedChildren);
+ }
+
+ private Collection<ObjectDiff.Evict> createEvictedChildren(UIObjectImpl object)
+ {
+ InternalObjectContext objectContext = (InternalObjectContext)object.getContext();
+
+ //
+ if (objectContext.childRefs != null)
+ {
+ Collection<ObjectDiff.Evict> evictedChildren = new ArrayList<ObjectDiff.Evict>();
+
+ //
+ for (UIObjectRef removedChildRef : objectContext.childRefs.values())
+ {
+ if (removedChildRef.loaded)
+ {
+ UIObjectImpl child = (UIObjectImpl)context.getObject(removedChildRef.getId());
+
+ //
+ evictedChildren.add(createEvict(child));
+ }
+ }
+
+ //
+ return evictedChildren;
+ }
+ else
+ {
+ // On purpose to indicate that no children was initialized and therefore there is no
+ // destroy children callback to do
+ return null;
+ }
+ }
+
+ private ObjectDiff diff(UIObjectImpl object)
+ {
+ ObjectTraversalType traversalType = scope.enterObject(object);
+
+ //
+ try
+ {
+ if (traversalType == ObjectTraversalType.SKIP)
+ {
+ return createEvict(object);
+ }
+ else
+ {
+ StructuralObject.Refresh refresh = structuralStateContext.refresh(object.getStructuralObject());
+
+ //
+ if (traversalType == ObjectTraversalType.RECURSIVE)
+ {
+ Collection<ObjectDiff> addedObjects = new ArrayList<ObjectDiff>();
+ Collection<ObjectDiff> validObjects = new ArrayList<ObjectDiff>();
+ Collection<ObjectDiff> staleObjects = new ArrayList<ObjectDiff>();
+ Collection<ObjectDiff.Evict> removedObjects = new ArrayList<ObjectDiff.Evict>();
+
+ //
+ boolean createChildren = ((InternalObjectContext)object.getContext()).childRefs == null;
+
+ //
+ for (StructuralObject addedStructuralChild : refresh.getAddedChildren())
+ {
+ addedObjects.add(load(addedStructuralChild));
+ }
+
+ //
+ for (StructuralObject staleStructuralChild : refresh.getStaleChildren().values())
+ {
+ ObjectDiff childDiff = diff(staleStructuralChild.getId());
+ staleObjects.add(childDiff);
+ }
+
+ //
+ for (String validChildId : refresh.getValidChildren())
+ {
+ ObjectDiff childDiff = diff(validChildId);
+ validObjects.add(childDiff);
+ }
+
+ //
+ for (String removedChildId : refresh.getRemovedChildren())
+ {
+ UIObjectImpl removedChild = (UIObjectImpl)context.getObject(removedChildId);
+
+ //
+ if (removedChild != null)
+ {
+ ObjectDiff.Evict childVisit = createEvict(removedChild);
+ removedObjects.add(childVisit);
+ }
+ else
+ {
+ // It means that the child was not loaded previously and it has
+ // been removed in the current refresh, so we do nothing
+ }
+ }
+
+ //
+ return ObjectDiff.createRecursiveUpdate(
+ object,
+ refresh.getRemovedProperties(),
+ refresh.getUpdatedProperties(),
+ refresh.getAddedProperties(),
+ createChildren,
+ addedObjects,
+ validObjects,
+ staleObjects,
+ removedObjects);
+ }
+ else
+ {
+ Collection<ObjectDiff.Evict> evictedChildren = createEvictedChildren(object);
+
+ //
+ return ObjectDiff.createSingleUpdate(
+ object,
+ refresh.getRemovedProperties(),
+ refresh.getUpdatedProperties(),
+ refresh.getAddedProperties(),
+ evictedChildren);
+ }
+ }
+ }
+ finally
+ {
+ scope.leaveObject(object);
+ }
+ }
+
+ private ObjectDiff load(StructuralObject structuralObject)
+ {
+ UIObjectImpl object = UIObjectImpl.create(structuralObject, new InternalObjectContext(navigationalStateContext));
+
+ //
+ ObjectTraversalType traversalType = scope.enterObject(object);
+
+ //
+ try
+ {
+ if (traversalType == ObjectTraversalType.SKIP)
+ {
+ return ObjectDiff.createSkip(object);
+ }
+ else
+ {
+ if (traversalType == ObjectTraversalType.RECURSIVE)
+ {
+ Collection<ObjectDiff> addedChildren = new ArrayList<ObjectDiff>();
+ for (StructuralObject structuralChild : structuralStateContext.loadChildren(structuralObject))
+ {
+ addedChildren.add(load(structuralChild));
+ }
+ return ObjectDiff.createRecursiveLoad(object, addedChildren);
+ }
+ else
+ {
+ return ObjectDiff.createSingleLoad(object);
+ }
+ }
+ }
+ finally
+ {
+ scope.leaveObject(object);
+ }
+ }
+}
Modified: modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/ViewPortImpl.java
===================================================================
--- modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/ViewPortImpl.java 2008-07-07 12:25:32 UTC (rev 11310)
+++ modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/ViewPortImpl.java 2008-07-07 12:26:25 UTC (rev 11311)
@@ -51,14 +51,15 @@
public void refresh()
{
- CreateDiffPhase createDiffPhase = new CreateDiffPhase(context, scope, model.navigationalStateContext, model.structuralStateContext);
+ DiffPhase diffPhase = new DiffPhase(context, scope, model.navigationalStateContext, model.structuralStateContext);
//
- createDiffPhase.perform();
+ diffPhase.perform();
//
- ObjectDiff rootDiff = createDiffPhase.getRootVisit();
+ ObjectDiff rootDiff = diffPhase.getRootVisit();
+ //
UpdatePhase phase = new UpdatePhase(context, rootDiff);
//
16 years
JBoss Portal SVN: r11310 - modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model.
by portal-commits@lists.jboss.org
Author: julien(a)jboss.com
Date: 2008-07-07 08:25:32 -0400 (Mon, 07 Jul 2008)
New Revision: 11310
Added:
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/UpdatePhase.java
Removed:
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/CreateUpdatePhase.java
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/ObjectUpdate.java
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/ObjectVisit.java
Modified:
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/CreateDiffPhase.java
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/ObjectDiff.java
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/ViewPortImpl.java
Log:
rewrote the update phase in a simpler manner
Modified: modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/CreateDiffPhase.java
===================================================================
--- modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/CreateDiffPhase.java 2008-07-07 06:23:05 UTC (rev 11309)
+++ modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/CreateDiffPhase.java 2008-07-07 12:25:32 UTC (rev 11310)
@@ -111,14 +111,14 @@
private Collection<ObjectDiff.Evict> createEvictedChildren(UIObjectImpl object)
{
- Collection<ObjectDiff.Evict> evictedChildren = new ArrayList<ObjectDiff.Evict>();
-
- //
InternalObjectContext objectContext = (InternalObjectContext)object.getContext();
//
if (objectContext.childRefs != null)
{
+ Collection<ObjectDiff.Evict> evictedChildren = new ArrayList<ObjectDiff.Evict>();
+
+ //
for (UIObjectRef removedChildRef : objectContext.childRefs.values())
{
if (removedChildRef.loaded)
@@ -129,8 +129,16 @@
evictedChildren.add(createEvict(child));
}
}
+
+ //
+ return evictedChildren;
}
- return evictedChildren;
+ else
+ {
+ // On purpose to indicate that no children was initialized and therefore there is no
+ // destroy children callback to do
+ return null;
+ }
}
private ObjectDiff diff(UIObjectImpl object)
@@ -154,9 +162,12 @@
Collection<ObjectDiff> addedObjects = new ArrayList<ObjectDiff>();
Collection<ObjectDiff> validObjects = new ArrayList<ObjectDiff>();
Collection<ObjectDiff> staleObjects = new ArrayList<ObjectDiff>();
- Collection<ObjectDiff> removedObjects = new ArrayList<ObjectDiff>();
+ Collection<ObjectDiff.Evict> removedObjects = new ArrayList<ObjectDiff.Evict>();
//
+ boolean createChildren = ((InternalObjectContext)object.getContext()).childRefs == null;
+
+ //
for (StructuralObject addedStructuralChild : refresh.getAddedChildren())
{
addedObjects.add(load(addedStructuralChild));
@@ -200,6 +211,7 @@
refresh.getRemovedProperties(),
refresh.getUpdatedProperties(),
refresh.getAddedProperties(),
+ createChildren,
addedObjects,
validObjects,
staleObjects,
@@ -207,7 +219,6 @@
}
else
{
-
Collection<ObjectDiff.Evict> evictedChildren = createEvictedChildren(object);
//
Deleted: modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/CreateUpdatePhase.java
===================================================================
--- modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/CreateUpdatePhase.java 2008-07-07 06:23:05 UTC (rev 11309)
+++ modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/CreateUpdatePhase.java 2008-07-07 12:25:32 UTC (rev 11310)
@@ -1,308 +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.impl.model;
-
-import org.jboss.portal.presentation.model.ViewPortContext;
-import org.jboss.portal.presentation.impl.model.ui.UIObjectImpl;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.Collection;
-import java.util.Collections;
-
-/**
- * @author <a href="mailto:julien@jboss-portal.org">Julien Viet</a>
- * @version $Revision: 630 $
- */
-public class CreateUpdatePhase
-{
-
- /** . */
- private final ViewPortContext context;
-
- /** . */
- private ObjectDiff rootDiff;
-
- /** . */
- private ObjectUpdate rootUpdate;
-
- /** . */
- private Map<String, ObjectUpdate.AddChild> deferredAddChildUpdates;
-
- /** . */
- private Set<String> removedChildren;
-
- public CreateUpdatePhase(ViewPortContext context, ObjectDiff rootDiff)
- {
- this.context = context;
- this.rootDiff = rootDiff;
- }
-
- public ObjectUpdate getRootUpdate()
- {
- return rootUpdate;
- }
-
- public void perform()
- {
- deferredAddChildUpdates = new HashMap<String, ObjectUpdate.AddChild>();
- removedChildren = new HashSet<String>();
-
- //
- rootUpdate = createUpdate(rootDiff);
-
- //
- if (deferredAddChildUpdates.size() > 0)
- {
- throw new IllegalStateException("Was expecting the deferred update to be empty");
- }
- }
-
- private ObjectUpdate createUpdate(ObjectDiff diff)
- {
- UIObjectImpl object = (UIObjectImpl)context.getObject(diff.getObjectId());
-
- if (diff instanceof ObjectDiff.RecursiveLoad || diff instanceof ObjectDiff.RecursiveUpdate)
- {
- Collection<ObjectDiff> addedObjects;
- Collection<ObjectDiff> validObjects;
- Collection<ObjectDiff> staleObjects;
- Collection<ObjectDiff> removedObjects;
- if (diff instanceof ObjectDiff.RecursiveUpdate)
- {
- addedObjects = ((ObjectDiff.RecursiveUpdate)diff).getAddedChildren();
- validObjects = ((ObjectDiff.RecursiveUpdate)diff).getValidChildren();
- staleObjects = ((ObjectDiff.RecursiveUpdate)diff).getStaleChildren();
- removedObjects = ((ObjectDiff.RecursiveUpdate)diff).getRemovedChildren();
- }
- else
- {
- addedObjects = ((ObjectDiff.RecursiveLoad)diff).getAddedChildren();
- validObjects = Collections.emptyList();
- staleObjects = Collections.emptyList();
- removedObjects = Collections.emptyList();
- }
-
- //
- if (object != null)
- {
- if (object != diff.getObject())
- {
- // The object is stale, we need to update the state maybe
- }
- }
-
- //
- Map<String, Boolean> childrenStatus = new HashMap<String, Boolean>();
- List<ObjectUpdate.AddChild> addedChildrenUpdates = new ArrayList<ObjectUpdate.AddChild>();
- List<ObjectUpdate.RemoveChild> removedChildrenUpdates = new ArrayList<ObjectUpdate.RemoveChild>();
- List<ObjectUpdate.UpdateObject> updateChildrenUpdates = new ArrayList<ObjectUpdate.UpdateObject>();
-
- //
- for (ObjectDiff addedObjectDiff : addedObjects)
- {
- ObjectUpdate childUpdate = createUpdate(addedObjectDiff);
-
- //
- if (childUpdate instanceof ObjectUpdate.AddObject)
- {
- addedChildrenUpdates.add(new ObjectUpdate.AddChild(diff.getObjectId(), (ObjectUpdate.AddObject)childUpdate));
- childrenStatus.put(addedObjectDiff.getObjectId(), true);
- }
- else if (childUpdate == null)
- {
- childrenStatus.put(addedObjectDiff.getObjectId(), false);
- }
- else if (childUpdate instanceof ObjectUpdate.UpdateObject)
- {
- // This is 'the' trick becaue this is likely a 'move' operation that we may need
- // to handle differently as a deferred add child
- ObjectUpdate.UpdateObject updateChildUpdate = (ObjectUpdate.UpdateObject)childUpdate;
-
- //
- ObjectUpdate.AddObject addObjectUpdate = new ObjectUpdate.AddObject(
- addedObjectDiff.getObject(),
- updateChildUpdate.childrenStatus,
- updateChildUpdate.addedChildrenUpdates,
- updateChildUpdate.removedChildrenUpdates,
- updateChildUpdate.updateChildrenUpdates);
-
- //
- ObjectUpdate.AddChild addChildUpdate = new ObjectUpdate.AddChild(diff.getObjectId(), addObjectUpdate);
-
- //
- if (removedChildren.contains(addedObjectDiff.getObjectId()))
- {
- addedChildrenUpdates.add(addChildUpdate);
- }
- else
- {
- deferredAddChildUpdates.put(addedObjectDiff.getObjectId(), addChildUpdate);
- }
-
- //
- childrenStatus.put(addedObjectDiff.getObjectId(), true);
- }
- else
- {
- throw new UnsupportedOperationException("Was not expecting update of type " + childUpdate.getClass().getSimpleName());
- }
- }
-
- //
- for (ObjectDiff removedChildDiff : removedObjects)
- {
- removedChildrenUpdates.add(new ObjectUpdate.RemoveChild(diff.getObjectId(), createRemove((ObjectDiff.Evict)removedChildDiff)));
- }
-
- List<ObjectDiff> existingObjectDiffs = new ArrayList<ObjectDiff>();
- existingObjectDiffs.addAll(validObjects);
- existingObjectDiffs.addAll(staleObjects);
-
- //
- for (ObjectDiff validObjectDiff : existingObjectDiffs)
- {
- ObjectUpdate childUpdate = createUpdate(validObjectDiff);
-
- //
- if (childUpdate == null)
- {
- childrenStatus.put(validObjectDiff.getObjectId(), false);
- }
- else if (childUpdate instanceof ObjectUpdate.UpdateObject)
- {
- updateChildrenUpdates.add((ObjectUpdate.UpdateObject)childUpdate);
- childrenStatus.put(validObjectDiff.getObjectId(), true);
- }
- else if (childUpdate instanceof ObjectUpdate.RemoveObject)
- {
- removedChildrenUpdates.add(new ObjectUpdate.RemoveChild(diff.getObjectId(), (ObjectUpdate.RemoveObject)childUpdate));
- childrenStatus.put(validObjectDiff.getObjectId(), false);
- }
- else if (childUpdate instanceof ObjectUpdate.AddObject)
- {
- addedChildrenUpdates.add(new ObjectUpdate.AddChild(diff.getObjectId(), (ObjectUpdate.AddObject)childUpdate));
- childrenStatus.put(validObjectDiff.getObjectId(), true);
- }
- else
- {
- throw new UnsupportedOperationException("Was not expecting update of type " + childUpdate.getClass().getSimpleName());
- }
- }
-
- //
- for (ObjectUpdate.RemoveChild removeChildUpdate : removedChildrenUpdates)
- {
- removedChildren.add(removeChildUpdate.removedObjectUpdate.objectId);
- }
-
- //
- if (object != null)
- {
- return new ObjectUpdate.UpdateObject(
- object.getStructuralObject(),
- childrenStatus,
- addedChildrenUpdates,
- removedChildrenUpdates,
- updateChildrenUpdates);
- }
- else
- {
- return new ObjectUpdate.AddObject(
- diff.getObject(),
- childrenStatus,
- addedChildrenUpdates,
- removedChildrenUpdates,
- updateChildrenUpdates);
- }
- }
- else if (diff instanceof ObjectDiff.Load)
- {
- return new ObjectUpdate.AddObject(diff.getObject());
- }
- else if (diff instanceof ObjectDiff.SingleUpdate)
- {
- List<ObjectUpdate.RemoveChild> removedChildrenUpdates = new ArrayList<ObjectUpdate.RemoveChild>();
-
- //
- for (ObjectDiff.Evict evict : ((ObjectDiff.SingleUpdate)diff).getEvictedChildren())
- {
- removedChildrenUpdates.add(new ObjectUpdate.RemoveChild(diff.getObjectId(), createRemove(evict)));
- }
-
- //
- for (ObjectUpdate.RemoveChild removeChildUpdate : removedChildrenUpdates)
- {
- removedChildren.add(removeChildUpdate.removedObjectUpdate.objectId);
- }
-
- //
- return new ObjectUpdate.UpdateObject(object.getStructuralObject(), removedChildrenUpdates);
- }
- else if (diff instanceof ObjectDiff.Skip)
- {
- if (object != null)
- {
- throw new AssertionError();
- }
-
- //
- return null;
- }
- else if (diff instanceof ObjectDiff.Evict)
- {
- if (object == null)
- {
- throw new AssertionError();
- }
-
- //
- return createRemove((ObjectDiff.Evict)diff);
- }
- else
- {
- throw new AssertionError("Cannot execute visit of " + diff);
- }
- }
-
- private ObjectUpdate.RemoveObject createRemove(ObjectDiff.Evict evict)
- {
- List<ObjectUpdate.RemoveObject> removedChildrenUpdates = new ArrayList<ObjectUpdate.RemoveObject>();
-
- //
- for (ObjectDiff.Evict evictedChild : evict.evictedChildren)
- {
- removedChildrenUpdates.add(createRemove(evictedChild));
- }
-
- //
- ObjectUpdate.AddChild addChildUpdate = deferredAddChildUpdates.remove(evict.getObjectId());
-
- //
- return new ObjectUpdate.RemoveObject(evict.getObjectId(), removedChildrenUpdates, addChildUpdate);
- }
-}
Modified: modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/ObjectDiff.java
===================================================================
--- modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/ObjectDiff.java 2008-07-07 06:23:05 UTC (rev 11309)
+++ modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/ObjectDiff.java 2008-07-07 12:25:32 UTC (rev 11310)
@@ -71,16 +71,18 @@
Set<String> removedProperties,
Map<String, Serializable> updatedProperties,
Map<String, Serializable> addedProperties,
+ boolean createChildren,
Collection<ObjectDiff> addedChildren,
Collection<ObjectDiff> validChildren,
Collection<ObjectDiff> staleChildren,
- Collection<ObjectDiff> removedChildren)
+ Collection<Evict> removedChildren)
{
return new RecursiveUpdate(
object,
removedProperties,
updatedProperties,
addedProperties,
+ createChildren,
addedChildren,
validChildren,
staleChildren,
@@ -176,6 +178,9 @@
{
/** . */
+ private final boolean createChildren;
+
+ /** . */
private final Collection<ObjectDiff> addedChildren;
/** . */
@@ -185,17 +190,18 @@
private final Collection<ObjectDiff> staleChildren;
/** . */
- private final Collection<ObjectDiff> removedChildren;
+ private final Collection<Evict> removedChildren;
private RecursiveUpdate(
UIObjectImpl object,
Set<String> removedProperties,
Map<String, Serializable> updatedProperties,
Map<String, Serializable> addedProperties,
+ boolean createChildren,
Collection<ObjectDiff> addedChildren,
Collection<ObjectDiff> validChildren,
Collection<ObjectDiff> staleChildren,
- Collection<ObjectDiff> removedChildren)
+ Collection<Evict> removedChildren)
{
super(
object,
@@ -231,12 +237,18 @@
}
//
+ this.createChildren = createChildren;
this.addedChildren = addedChildren;
this.validChildren = validChildren;
this.staleChildren = staleChildren;
this.removedChildren = removedChildren;
}
+ public boolean getCreateChildren()
+ {
+ return createChildren;
+ }
+
public Collection<ObjectDiff> getAddedChildren()
{
return addedChildren;
@@ -252,7 +264,7 @@
return staleChildren;
}
- public Collection<ObjectDiff> getRemovedChildren()
+ public Collection<Evict> getRemovedChildren()
{
return removedChildren;
}
@@ -281,6 +293,13 @@
this.evictedChildren = evictedChildren;
}
+ /**
+ * Returns the list of children to evict. If the list is not null it means that the children
+ * collection should be destroyed even if the list is empty. If the list is null it means
+ * that there is no operation to perform on the object with respect to its children.
+ *
+ * @return the list of evicted children
+ */
public Collection<Evict> getEvictedChildren()
{
return evictedChildren;
@@ -332,8 +351,8 @@
public static class Evict extends ObjectDiff
{
- /** . */
- final Collection<Evict> evictedChildren;
+ /** If null it means that we did not have any children initialized. */
+ private final Collection<Evict> evictedChildren;
public Evict(UIObjectImpl object, Collection<Evict> evictedChildren)
{
@@ -342,5 +361,17 @@
//
this.evictedChildren = evictedChildren;
}
+
+ /**
+ * Returns the list of children to evict. If the list is not null it means that the children
+ * collection should be destroyed even if the list is empty. If the list is null it means
+ * that there is no operation to perform on the object with respect to its children.
+ *
+ * @return the list of evicted children
+ */
+ public Collection<Evict> getEvictedChildren()
+ {
+ return evictedChildren;
+ }
}
}
Deleted: modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/ObjectUpdate.java
===================================================================
--- modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/ObjectUpdate.java 2008-07-07 06:23:05 UTC (rev 11309)
+++ modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/ObjectUpdate.java 2008-07-07 12:25:32 UTC (rev 11310)
@@ -1,365 +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.impl.model;
-
-import org.jboss.portal.presentation.model.ViewPortContext;
-import org.jboss.portal.presentation.state.structural.StructuralObject;
-import org.jboss.portal.presentation.impl.model.ui.UIObjectImpl;
-
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- * @author <a href="mailto:julien@jboss-portal.org">Julien Viet</a>
- * @version $Revision: 630 $
- */
-public abstract class ObjectUpdate
-{
-
- public abstract void execute(ViewPortContext context);
-
- /**
- * Not really carrying any state for now... until we really implement it.
- */
- public static class UpdateObject extends ObjectUpdate
- {
-
- /** . */
- final StructuralObject structuralObject;
-
- /** . */
- final Map<String, Boolean> childrenStatus;
-
- /** . */
- final List<AddChild> addedChildrenUpdates;
-
- /** . */
- final List<RemoveChild> removedChildrenUpdates;
-
- /** . */
- final List<UpdateObject> updateChildrenUpdates;
-
- public UpdateObject(StructuralObject structuralObject, List<RemoveChild> removeChildrenUpdates)
- {
- if (structuralObject == null)
- {
- throw new IllegalArgumentException("No null object id accepted");
- }
- if (removeChildrenUpdates == null)
- {
- throw new IllegalArgumentException("No null removed children accepted");
- }
-
- //
- this.structuralObject = structuralObject;
- this.childrenStatus = null;
- this.addedChildrenUpdates = null;
- this.removedChildrenUpdates = removeChildrenUpdates;
- this.updateChildrenUpdates = null;
- }
-
- public UpdateObject(
- StructuralObject structuralObject,
- Map<String, Boolean> childrenStatus,
- List<AddChild> addedChildrenUpdates,
- List<RemoveChild> removedChildrenUpdates,
- List<UpdateObject> updateChildrenUpdates)
- {
- if (structuralObject == null)
- {
- throw new IllegalArgumentException("No null object id accepted");
- }
- if (addedChildrenUpdates == null)
- {
- throw new IllegalArgumentException("No null added children accepted");
- }
- if (removedChildrenUpdates == null)
- {
- throw new IllegalArgumentException("No null removed children accepted");
- }
- if (updateChildrenUpdates == null)
- {
- throw new IllegalArgumentException("No null update children accepted");
- }
-
- //
- this.structuralObject = structuralObject;
- this.childrenStatus = childrenStatus;
- this.addedChildrenUpdates = addedChildrenUpdates;
- this.removedChildrenUpdates = removedChildrenUpdates;
- this.updateChildrenUpdates = updateChildrenUpdates;
- }
-
- public void execute(ViewPortContext context)
- {
- UIObjectImpl object = (UIObjectImpl)context.getObject(structuralObject.getId());
-
- // Normally should be ok because if we have removed children updates it means
- // that it was created because the existing object was referencing children
- for (RemoveChild removedChildUpdate : removedChildrenUpdates)
- {
- removedChildUpdate.execute(context);
- }
-
- // Perform state update
- if (object.getStructuralObject().equals(structuralObject))
- {
- object.setStructuralObject(structuralObject);
- context.updateObject(structuralObject.getId());
- }
-
- //
- InternalObjectContext objectContext = (InternalObjectContext)object.getContext();
-
- //
- if (childrenStatus != null)
- {
- if (objectContext.childRefs == null)
- {
- objectContext.childRefs = new HashMap<String, UIObjectRef>();
- for (Map.Entry<String, Boolean> childRefEntry : childrenStatus.entrySet())
- {
- objectContext.childRefs.put(childRefEntry.getKey(), new UIObjectRef(childRefEntry.getKey(), childRefEntry.getValue()));
- }
-
- //
- context.createChildren(structuralObject.getId());
- }
-
- //
- for (AddChild addedChildUpdate : addedChildrenUpdates)
- {
- addedChildUpdate.execute(context);
- }
-
- //
- for (UpdateObject updateChildUpdate : updateChildrenUpdates)
- {
- updateChildUpdate.execute(context);
- }
- }
- else
- {
- if (objectContext.childRefs != null)
- {
- context.destroyChildren(structuralObject.getId());
- }
- }
- }
- }
-
- public static class AddObject extends ObjectUpdate
- {
-
- /** . */
- private final UIObjectImpl object;
-
- /** . */
- private final Map<String, Boolean> childrenStatus;
-
- /** . */
- private final List<AddChild> addedChildrenUpdates;
-
- /** . */
- private final List<RemoveChild> removedChildrenUpdates;
-
- /** . */
- private final List<UpdateObject> updateChildrenUpdates;
-
- public AddObject(UIObjectImpl object)
- {
- if (object == null)
- {
- throw new IllegalArgumentException("No null object accepted");
- }
-
- //
- this.object = object;
- this.childrenStatus = null;
- this.addedChildrenUpdates = null;
- this.removedChildrenUpdates = null;
- this.updateChildrenUpdates = null;
- }
-
- public AddObject(
- UIObjectImpl object,
- Map<String, Boolean> childrenStatus,
- List<AddChild> addedChildrenUpdates,
- List<RemoveChild> removedChildrenUpdates,
- List<UpdateObject> updateChildrenUpdates)
- {
- if (object == null)
- {
- throw new IllegalArgumentException("No null object accepted");
- }
- if (addedChildrenUpdates == null)
- {
- throw new IllegalArgumentException("No null added children accepted");
- }
- if (removedChildrenUpdates == null)
- {
- throw new IllegalArgumentException("No null removed children accepted");
- }
- if (updateChildrenUpdates == null)
- {
- throw new IllegalArgumentException("No null update children accepted");
- }
-
-
- //
- this.object = object;
- this.childrenStatus = childrenStatus;
- this.addedChildrenUpdates = addedChildrenUpdates;
- this.removedChildrenUpdates = removedChildrenUpdates;
- this.updateChildrenUpdates = updateChildrenUpdates;
- }
-
- public void execute(ViewPortContext context)
- {
- context.addObject(object);
-
- //
- if (childrenStatus != null)
- {
- InternalObjectContext objectContext = (InternalObjectContext)object.getContext();
-
- //
- objectContext.childRefs = new HashMap<String, UIObjectRef>();
- for (Map.Entry<String, Boolean> childRefEntry : childrenStatus.entrySet())
- {
- objectContext.childRefs.put(childRefEntry.getKey(), new UIObjectRef(childRefEntry.getKey(), childRefEntry.getValue()));
- }
-
- //
- context.createChildren(object.getId());
-
- //
- for (AddChild addedChildUpdate : addedChildrenUpdates)
- {
- addedChildUpdate.execute(context);
- }
-
- //
- for (RemoveChild removedChildUpdate : removedChildrenUpdates)
- {
- removedChildUpdate.execute(context);
- }
-
- //
- for (UpdateObject updateChildUpdate : updateChildrenUpdates)
- {
- updateChildUpdate.execute(context);
- }
- }
- }
- }
-
- public static class RemoveObject extends ObjectUpdate
- {
-
- /** . */
- final String objectId;
-
- /** . */
- private final List<RemoveObject> removedChildrenUpdates;
-
- /** . */
- private final AddChild addChildUpdate;
-
- public RemoveObject(String objectId, List<RemoveObject> removedChildrenUpdates, AddChild addChildUpdate)
- {
- this.objectId = objectId;
- this.removedChildrenUpdates = removedChildrenUpdates;
- this.addChildUpdate = addChildUpdate;
- }
-
- public void execute(ViewPortContext context)
- {
- for (RemoveObject removedChildUpdate : removedChildrenUpdates)
- {
- context.removeChild(objectId, removedChildUpdate.objectId);
-
- //
- removedChildUpdate.execute(context);
- }
-
- //
- context.removeObject(objectId);
-
- //
- if (addChildUpdate != null)
- {
- addChildUpdate.execute(context);
- }
- }
- }
-
- public static class AddChild extends ObjectUpdate
- {
-
- /** . */
- private final String parentId;
-
- /** . */
- private final AddObject addedObjectUpdate;
-
- public AddChild(String parentId, AddObject addedObjectUpdate)
- {
- this.parentId = parentId;
- this.addedObjectUpdate = addedObjectUpdate;
- }
-
- public void execute(ViewPortContext context)
- {
- addedObjectUpdate.execute(context);
-
- //
- context.addChild(parentId, addedObjectUpdate.object.getId());
- }
- }
-
- public static class RemoveChild extends ObjectUpdate
- {
-
- /** . */
- private final String parentId;
-
- /** . */
- final RemoveObject removedObjectUpdate;
-
- public RemoveChild(String parentId, RemoveObject removedObjectUpdate)
- {
- this.parentId = parentId;
- this.removedObjectUpdate = removedObjectUpdate;
- }
-
- public void execute(ViewPortContext context)
- {
- context.removeChild(parentId, removedObjectUpdate.objectId);
-
- //
- removedObjectUpdate.execute(context);
- }
- }
-}
Deleted: modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/ObjectVisit.java
===================================================================
--- modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/ObjectVisit.java 2008-07-07 06:23:05 UTC (rev 11309)
+++ modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/ObjectVisit.java 2008-07-07 12:25:32 UTC (rev 11310)
@@ -1,339 +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.impl.model;
-
-import org.jboss.portal.presentation.impl.model.ui.UIObjectImpl;
-
-import java.util.Set;
-import java.util.Map;
-import java.util.Collection;
-import java.io.Serializable;
-
-/**
- * @author <a href="mailto:julien@jboss-portal.org">Julien Viet</a>
- * @version $Revision: 630 $
- */
-public abstract class ObjectVisit
-{
-
- static ObjectVisit.Evict createEvict(UIObjectImpl object, Collection<Evict> evictedChildren)
- {
- return new Evict(object, evictedChildren);
- }
-
- static RecursiveLoad createRecursiveLoad(UIObjectImpl object, Collection<ObjectVisit> addedChildren)
- {
- return new RecursiveLoad(object, addedChildren);
- }
-
- static ObjectVisit createLoad(UIObjectImpl object)
- {
- return new Load(object);
- }
-
- static ObjectVisit createSkip(UIObjectImpl object)
- {
- return new Skip(object);
- }
-
- static SingleUpdate createSingleUpdate(
- UIObjectImpl object,
- Set<String> removedProperties,
- Map<String, Serializable> updatedProperties,
- Map<String, Serializable> addedProperties,
- Collection<Evict> evictedChildren)
- {
- return new SingleUpdate(object, removedProperties, updatedProperties, addedProperties, evictedChildren);
- }
-
- static RecursiveUpdate createRecursiveUpdate(
- UIObjectImpl object,
- Set<String> removedProperties,
- Map<String, Serializable> updatedProperties,
- Map<String, Serializable> addedProperties,
- Collection<ObjectVisit> addedChildren,
- Collection<ObjectVisit> validChildren,
- Collection<ObjectVisit> staleChildren,
- Collection<ObjectVisit> removedChildren)
- {
- return new RecursiveUpdate(
- object,
- removedProperties,
- updatedProperties,
- addedProperties,
- addedChildren,
- validChildren,
- staleChildren,
- removedChildren);
- }
-
- /** . */
- private final UIObjectImpl object;
-
- private ObjectVisit(UIObjectImpl object)
- {
- if (object == null)
- {
- throw new IllegalArgumentException();
- }
-
- //
- this.object = object;
- }
-
- public String getObjectId()
- {
- return object.getId();
- }
-
- public UIObjectImpl getObject()
- {
- return object;
- }
-
- public static class Skip extends ObjectVisit
- {
- private Skip(UIObjectImpl object)
- {
- super(object);
- }
- }
-
- public static class Load extends ObjectVisit
- {
-
- private Load(UIObjectImpl object)
- {
- super(object);
- }
- }
-
- public static class RecursiveLoad extends Load
- {
-
- /** . */
- private final Collection<ObjectVisit> addedChildren;
-
- private RecursiveLoad(
- UIObjectImpl object,
- Collection<ObjectVisit> addedChildren)
- {
- super(object);
-
- //
- if (addedChildren == null)
- {
- throw new IllegalArgumentException();
- }
-
- //
- for (ObjectVisit addedChild : addedChildren)
- {
- if (!(addedChild instanceof Skip || addedChild instanceof Load))
- {
- throw new AssertionError("Cannot accept added child " + addedChild);
- }
- }
-
- //
- this.addedChildren = addedChildren;
- }
-
- public Collection<ObjectVisit> getAddedChildren()
- {
- return addedChildren;
- }
- }
-
- public static class RecursiveUpdate extends Update
- {
-
- /** . */
- private final Collection<ObjectVisit> addedChildren;
-
- /** . */
- private final Collection<ObjectVisit> validChildren;
-
- /** . */
- private final Collection<ObjectVisit> staleChildren;
-
- /** . */
- private final Collection<ObjectVisit> removedChildren;
-
- private RecursiveUpdate(
- UIObjectImpl object,
- Set<String> removedProperties,
- Map<String, Serializable> updatedProperties,
- Map<String, Serializable> addedProperties,
- Collection<ObjectVisit> addedChildren,
- Collection<ObjectVisit> validChildren,
- Collection<ObjectVisit> staleChildren,
- Collection<ObjectVisit> removedChildren)
- {
- super(
- object,
- removedProperties,
- updatedProperties,
- addedProperties);
-
- //
- if (addedChildren == null)
- {
- throw new IllegalArgumentException();
- }
- if (validChildren == null)
- {
- throw new IllegalArgumentException();
- }
- if (staleChildren == null)
- {
- throw new IllegalArgumentException();
- }
- if (removedChildren == null)
- {
- throw new IllegalArgumentException();
- }
-
- //
- for (ObjectVisit addedChild : addedChildren)
- {
- if (!(addedChild instanceof Evict || addedChild instanceof Load))
- {
- throw new AssertionError();
- }
- }
-
- //
- this.addedChildren = addedChildren;
- this.validChildren = validChildren;
- this.staleChildren = staleChildren;
- this.removedChildren = removedChildren;
- }
-
- public Collection<ObjectVisit> getAddedChildren()
- {
- return addedChildren;
- }
-
- public Collection<ObjectVisit> getValidChildren()
- {
- return validChildren;
- }
-
- public Collection<ObjectVisit> getStaleChildren()
- {
- return staleChildren;
- }
-
- public Collection<ObjectVisit> getRemovedChildren()
- {
- return removedChildren;
- }
- }
-
- public static class SingleUpdate extends Update
- {
-
- /** . */
- private final Collection<Evict> evictedChildren;
-
- public SingleUpdate(
- UIObjectImpl object,
- Set<String> removedProperties,
- Map<String, Serializable> updatedProperties,
- Map<String, Serializable> addedProperties,
- Collection<Evict> evictedChildren)
- {
- super(
- object,
- removedProperties,
- updatedProperties,
- addedProperties);
-
- //
- this.evictedChildren = evictedChildren;
- }
-
- public Collection<Evict> getEvictedChildren()
- {
- return evictedChildren;
- }
- }
-
- public static class Update extends ObjectVisit
- {
-
- /** . */
- private final Set<String> removedProperties;
-
- /** . */
- private final Map<String, Serializable> updatedProperties;
-
- /** . */
- private final Map<String, Serializable> addedProperties;
-
- private Update(
- UIObjectImpl object,
- Set<String> removedProperties,
- Map<String, Serializable> updatedProperties,
- Map<String, Serializable> addedProperties)
- {
- super(object);
-
- //
- this.removedProperties = removedProperties;
- this.updatedProperties = updatedProperties;
- this.addedProperties = addedProperties;
- }
-
- public Set<String> getRemovedProperties()
- {
- return removedProperties;
- }
-
- public Map<String, Serializable> getUpdatedProperties()
- {
- return updatedProperties;
- }
-
- public Map<String, Serializable> getAddedProperties()
- {
- return addedProperties;
- }
- }
-
- public static class Evict extends ObjectVisit
- {
-
- /** . */
- final Collection<Evict> evictedChildren;
-
- public Evict(UIObjectImpl object, Collection<Evict> evictedChildren)
- {
- super(object);
-
- //
- this.evictedChildren = evictedChildren;
- }
- }
-}
Added: modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/UpdatePhase.java
===================================================================
--- modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/UpdatePhase.java (rev 0)
+++ modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/UpdatePhase.java 2008-07-07 12:25:32 UTC (rev 11310)
@@ -0,0 +1,207 @@
+/******************************************************************************
+ * 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.impl.model;
+
+import org.jboss.portal.presentation.model.ViewPortContext;
+import org.jboss.portal.presentation.impl.model.ui.UIObjectImpl;
+
+import java.util.Collection;
+import java.util.HashMap;
+
+/**
+ * @author <a href="mailto:julien@jboss-portal.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+public class UpdatePhase
+{
+
+ /** . */
+ private final ViewPortContext context;
+
+ /** . */
+ private final ObjectDiff rootDiff;
+
+ public UpdatePhase(ViewPortContext context, ObjectDiff rootDiff)
+ {
+ this.context = context;
+ this.rootDiff = rootDiff;
+ }
+
+ public void perform()
+ {
+ perform1stPhase();
+ perform2ndPhase();
+ }
+
+ private void perform1stPhase()
+ {
+ perform1stPhase(rootDiff);
+ }
+
+ private void perform1stPhase(ObjectDiff diff)
+ {
+ if (diff instanceof ObjectDiff.Evict)
+ {
+ ObjectDiff.Evict evict = (ObjectDiff.Evict)diff;
+
+ //
+ if (evict.getEvictedChildren() != null)
+ {
+ perform1stPhase(diff.getObject(), evict.getEvictedChildren());
+
+ //
+ context.destroyChildren(diff.getObjectId());
+ }
+
+ //
+ context.removeObject(evict.getObjectId());
+ }
+ else if (diff instanceof ObjectDiff.Update)
+ {
+ if (diff instanceof ObjectDiff.RecursiveUpdate)
+ {
+ ObjectDiff.RecursiveUpdate recursiveUpdate = (ObjectDiff.RecursiveUpdate)diff;
+
+ //
+ perform1stPhase(diff.getObject(), recursiveUpdate.getAddedChildren());
+ perform1stPhase(diff.getObject(), recursiveUpdate.getStaleChildren());
+ perform1stPhase(diff.getObject(), recursiveUpdate.getValidChildren());
+ perform1stPhase(diff.getObject(), recursiveUpdate.getRemovedChildren());
+ }
+ else
+ {
+ ObjectDiff.SingleUpdate singleUpdate = (ObjectDiff.SingleUpdate)diff;
+
+ //
+ if (singleUpdate.getEvictedChildren() != null)
+ {
+ perform1stPhase(diff.getObject(), singleUpdate.getEvictedChildren());
+
+ //
+ context.destroyChildren(diff.getObjectId());
+ }
+ }
+ }
+ }
+
+ private void perform1stPhase(UIObjectImpl parent, Collection<? extends ObjectDiff> diffs)
+ {
+ for (ObjectDiff diff : diffs)
+ {
+ if (diff instanceof ObjectDiff.Evict)
+ {
+ String childId = diff.getObjectId();
+
+ //
+ context.removeChild(parent.getId(), childId);
+
+ //
+ InternalObjectContext parentContext = (InternalObjectContext)parent.getContext();
+
+ //
+ parentContext.childRefs.remove(childId);
+ }
+
+ //
+ perform1stPhase(diff);
+ }
+ }
+
+ private void perform2ndPhase()
+ {
+ perform2ndPhase(rootDiff);
+ }
+
+ private void perform2ndPhase(ObjectDiff diff)
+ {
+ UIObjectImpl object = diff.getObject();
+
+ //
+ InternalObjectContext objectContext = (InternalObjectContext)object.getContext();
+
+ //
+ if (diff instanceof ObjectDiff.Load)
+ {
+ context.addObject(object);
+
+ //
+ if (diff instanceof ObjectDiff.RecursiveLoad)
+ {
+ objectContext.childRefs = new HashMap<String, UIObjectRef>();
+
+ //
+ context.createChildren(object.getId());
+
+ //
+ perform2ndPhase(diff.getObject(), ((ObjectDiff.RecursiveLoad)diff).getAddedChildren());
+ }
+ }
+ else if (diff instanceof ObjectDiff.Update)
+ {
+ if (diff instanceof ObjectDiff.RecursiveUpdate)
+ {
+ ObjectDiff.RecursiveUpdate recursiveUpdate = (ObjectDiff.RecursiveUpdate)diff;
+
+ //
+ if (recursiveUpdate.getCreateChildren())
+ {
+ objectContext.childRefs = new HashMap<String, UIObjectRef>();
+
+ //
+ context.createChildren(object.getId());
+ }
+
+ //
+ perform2ndPhase(diff.getObject(), recursiveUpdate.getAddedChildren());
+ perform2ndPhase(diff.getObject(), recursiveUpdate.getValidChildren());
+ perform2ndPhase(diff.getObject(), recursiveUpdate.getStaleChildren());
+ }
+ }
+ }
+
+ private void perform2ndPhase(UIObjectImpl parent, Collection<ObjectDiff> diffs)
+ {
+ InternalObjectContext objectContext = (InternalObjectContext)parent.getContext();
+
+ //
+ for (ObjectDiff diff : diffs)
+ {
+ perform2ndPhase(diff);
+
+ //
+ if (diff instanceof ObjectDiff.Load)
+ {
+ objectContext.childRefs.put(diff.getObjectId(), new UIObjectRef(diff.getObjectId(), true));
+ context.addChild(parent.getId(), diff.getObjectId());
+ }
+ else if (diff instanceof ObjectDiff.Update)
+ {
+ // Nothing ?
+ }
+ else if (diff instanceof ObjectDiff.Skip)
+ {
+ objectContext.childRefs.put(diff.getObjectId(), new UIObjectRef(diff.getObjectId(), false));
+ }
+ }
+ }
+}
Modified: modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/ViewPortImpl.java
===================================================================
--- modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/ViewPortImpl.java 2008-07-07 06:23:05 UTC (rev 11309)
+++ modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model/ViewPortImpl.java 2008-07-07 12:25:32 UTC (rev 11310)
@@ -59,17 +59,10 @@
//
ObjectDiff rootDiff = createDiffPhase.getRootVisit();
- //
- CreateUpdatePhase createUpdatePhase = new CreateUpdatePhase(context, rootDiff);
+ UpdatePhase phase = new UpdatePhase(context, rootDiff);
//
- createUpdatePhase.perform();
-
- //
- ObjectUpdate rootUpdate = createUpdatePhase.getRootUpdate();
-
- //
- rootUpdate.execute(context);
+ phase.perform();
}
public ViewPortContext getContext()
16 years