[portal-commits] JBoss Portal SVN: r11824 - in branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal: core/impl/coordination and 1 other directories.

portal-commits at lists.jboss.org portal-commits at lists.jboss.org
Sat Sep 6 07:51:06 EDT 2008


Author: chris.laprun at jboss.com
Date: 2008-09-06 07:51:06 -0400 (Sat, 06 Sep 2008)
New Revision: 11824

Modified:
   branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/controller/coordination/CoordinationConfigurator.java
   branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/impl/coordination/CoordinationService.java
   branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/test/core/model/portal/coordination/CoordinationServiceTestCase.java
Log:
- Added removeWindowBinding(page, name), renameWindowBinding(page, old name, new name) and getWindowBindingInfo(page, name) methods
- Fixed an issue with PREFIX_PARAMETER_ALIAS_LENGTH which wasn't correct.
- get*(page, name) should return null when the coordination element is not found instead of failing.
- Improved tests and coverage.

Modified: branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/controller/coordination/CoordinationConfigurator.java
===================================================================
--- branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/controller/coordination/CoordinationConfigurator.java	2008-09-06 09:50:22 UTC (rev 11823)
+++ branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/controller/coordination/CoordinationConfigurator.java	2008-09-06 11:51:06 UTC (rev 11824)
@@ -165,6 +165,12 @@
    void removeWindowBinding(WindowBindingInfo parameterBinding) throws IllegalCoordinationException;
 
    /**
+    * @param page
+    * @param name
+    */
+   void removeWindowBinding(Page page, String name);
+
+   /**
     * Renames the specified window binding to the new name
     *
     * @param windowBinding the window binding to be renamed
@@ -174,6 +180,34 @@
    void renameWindowBinding(WindowBindingInfo windowBinding, String newName) throws IllegalCoordinationException;
 
    /**
+    * @param page
+    * @param bindingName
+    * @param newName
+    * @throws IllegalCoordinationException
+    */
+   void renameWindowBinding(Page page, String bindingName, String newName) throws IllegalCoordinationException;
+
+   /**
+    * @param page
+    * @return window bindings define in the scope of a given page
+    */
+   Collection<? extends WindowBindingInfo> getWindowBindings(Page page);
+
+   /**
+    * @param window
+    * @return window bindings where given window is involved
+    */
+   Collection<? extends WindowBindingInfo> getWindowBindings(Window window);
+
+   /**
+    * @param page
+    * @param name
+    * @return
+    * @throws IllegalCoordinationException
+    */
+   WindowBindingInfo getWindowBindingInfo(Page page, String name) throws IllegalCoordinationException;
+
+   /**
     * Set parameter binding implicit mode for a given page container. This will be inherited recursively by all children
     * page containers
     *
@@ -239,16 +273,4 @@
     * @return window bindings for a given parameter qname
     */
    Collection<? extends WindowBindingInfo> getWindowBindings(Page page, QName parameterQName);
-
-   /**
-    * @param page
-    * @return window bindings define in the scope of a given page
-    */
-   Collection<? extends WindowBindingInfo> getWindowBindings(Page page);
-
-   /**
-    * @param window
-    * @return window bindings where given window is involved
-    */
-   Collection<? extends WindowBindingInfo> getWindowBindings(Window window);
 }

Modified: branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/impl/coordination/CoordinationService.java
===================================================================
--- branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/impl/coordination/CoordinationService.java	2008-09-06 09:50:22 UTC (rev 11823)
+++ branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/impl/coordination/CoordinationService.java	2008-09-06 11:51:06 UTC (rev 11824)
@@ -78,7 +78,7 @@
 
    public static final String PREFIX_PARAMETER_ALIAS = PREFIX_PARAMETER + ".alias";
    public static final String PREFIX_PARAMETER_ALIAS_NAME = PREFIX_PARAMETER_ALIAS + ".name.";
-   private static final int PREFIX_PARAMETER_ALIAS_LENGTH = PREFIX_PARAMETER_ALIAS.length();
+   private static final int PREFIX_PARAMETER_ALIAS_LENGTH = PREFIX_PARAMETER_ALIAS_NAME.length();
 
    public static final Boolean DEFAULT_IMPLICIT_MODE = true;
    protected EventConverter eventConverter = new SimpleEventConverter();
@@ -393,12 +393,20 @@
          }
       }
 
-      if (sources.isEmpty() || destinations.isEmpty())
+      boolean emptySources = sources.isEmpty();
+      boolean emptyDestinations = destinations.isEmpty();
+      if (emptySources && emptyDestinations)
       {
+         return null;
+      }
+      else if ((emptySources && !emptyDestinations) || emptyDestinations)
+      {
          throw new IllegalCoordinationException("Couldn't find sources or destinations for event '" + name + "'");
       }
-
-      return new EventInfoPOJO(name, page, sources, destinations);
+      else
+      {
+         return new EventInfoPOJO(name, page, sources, destinations);
+      }
    }
 
    public Collection<EventWiringInfo> getEventWirings(Page page)
@@ -536,11 +544,18 @@
    {
       ParameterValidation.throwIllegalArgExceptionIfNull(info, "WindowBindingInfo");
 
-      // Remove all entries
-      String prop_wiring = PREFIX_PARAMETER_BINDING + "." + info.getName();
-      for (Window window : info.getWindows().keySet())
+      removeWindowBinding(info.getPage(), info.getName());
+   }
+
+   public void removeWindowBinding(Page page, String name)
+   {
+      ParameterValidation.throwIllegalArgExceptionIfNull(name, "window binding name");
+      ParameterValidation.throwIllegalArgExceptionIfNull(page, "Page");
+
+      String nameProp = PREFIX_PARAMETER_BINDING + name;
+      for (PortalObject window : page.getChildren(PortalObject.WINDOW_MASK))
       {
-         window.setDeclaredProperty(prop_wiring, null);
+         window.setDeclaredProperty(nameProp, null);
       }
    }
 
@@ -550,6 +565,44 @@
       setWindowBinding(newName, windowBinding.getWindows());
    }
 
+   public void renameWindowBinding(Page page, String bindingName, String newName) throws IllegalCoordinationException
+   {
+      WindowBindingInfo info = getWindowBindingInfo(page, bindingName);
+      removeWindowBinding(page, bindingName);
+      setWindowBinding(newName, info.getWindows());
+   }
+
+   public WindowBindingInfo getWindowBindingInfo(Page page, String name) throws IllegalCoordinationException
+   {
+      ParameterValidation.throwIllegalArgExceptionIfNull(page, "Page");
+      ParameterValidation.throwIllegalArgExceptionIfNull(name, "window binding name");
+
+      String nameProp = PREFIX_PARAMETER_BINDING + name;
+
+      // Examine window properties and create page parameters
+      Collection<PortalObject> children = page.getChildren(PortalObject.WINDOW_MASK);
+      Map<Window, QName> windows = new HashMap<Window, QName>(children.size());
+      for (PortalObject window : children)
+      {
+         String bindingName = window.getDeclaredProperty(nameProp);
+
+         if (bindingName != null)
+         {
+            QName qname = decodeQName(bindingName);
+            windows.put((Window)window, qname);
+         }
+      }
+
+      if (windows.isEmpty())
+      {
+         return null;
+      }
+      else
+      {
+         return new WindowInfoPOJO(name, page, windows);
+      }
+   }
+
    public Boolean isParameterBindingImplicitModeEnabled(PageContainer pageContainer)
    {
       ParameterValidation.throwIllegalArgExceptionIfNull(pageContainer, "PageContainer");
@@ -884,13 +937,18 @@
       private final Map<Window, QName> windows;
       private final Page page;
 
-      private WindowInfoPOJO(String name, Page page)
+      private WindowInfoPOJO(String name, Page page, Map<Window, QName> windows)
       {
          this.name = name;
-         this.windows = new HashMap<Window, QName>();
+         this.windows = windows;
          this.page = page;
       }
 
+      private WindowInfoPOJO(String name, Page page)
+      {
+         this(name, page, new HashMap<Window, QName>());
+      }
+
       public String getName()
       {
          return name;

Modified: branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/test/core/model/portal/coordination/CoordinationServiceTestCase.java
===================================================================
--- branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/test/core/model/portal/coordination/CoordinationServiceTestCase.java	2008-09-06 09:50:22 UTC (rev 11823)
+++ branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/test/core/model/portal/coordination/CoordinationServiceTestCase.java	2008-09-06 11:51:06 UTC (rev 11824)
@@ -299,6 +299,90 @@
       TransactionAssert.commitTransaction();
    }
 
+   public void testGetWindowBinding() throws Exception
+   {
+      TransactionAssert.beginTransaction();
+
+      Page page1 = getPage1();
+
+      Window w1 = page1.getWindow("Window_1");
+      Window w2 = page1.getWindow("Window_2");
+      Window w4 = page1.getWindow("Window_4");
+
+
+      Map<Window, QName> ws = new HashMap<Window, QName>();
+      QName qName11 = new QName("ns1", "1");
+      QName qName12 = new QName("ns1", "2");
+      ws.put(w1, qName11);
+      ws.put(w2, qName12);
+      cos.setWindowBinding("binding1", ws);
+
+      QName qName21 = new QName("ns2", "foo3");
+      ws.clear();
+      ws.put(w4, qName21);
+      cos.setWindowBinding("binding2", ws);
+
+      WindowBindingInfo info = cos.getWindowBindingInfo(page1, "binding1");
+      assertNotNull(info);
+      assertEquals("binding1", info.getName());
+      assertEquals(page1, info.getPage());
+      Map<Window, QName> windows = info.getWindows();
+      assertNotNull(windows);
+      assertEquals(2, windows.size());
+      assertTrue(windows.containsKey(w1));
+      assertTrue(windows.containsKey(w2));
+      assertEquals(qName11, windows.get(w1));
+      assertEquals(qName12, windows.get(w2));
+
+      info = cos.getWindowBindingInfo(page1, "binding2");
+      assertNotNull(info);
+      assertEquals("binding2", info.getName());
+      assertEquals(page1, info.getPage());
+      windows = info.getWindows();
+      assertNotNull(windows);
+      assertEquals(1, windows.size());
+      assertTrue(windows.containsKey(w4));
+      assertEquals(qName21, windows.get(w4));
+
+      TransactionAssert.commitTransaction();
+   }
+
+   public void testRemoveWindowBinding() throws Exception
+   {
+      TransactionAssert.beginTransaction();
+
+      Page page1 = getPage1();
+
+      Window w1 = page1.getWindow("Window_1");
+      Window w2 = page1.getWindow("Window_2");
+      Window w4 = page1.getWindow("Window_4");
+
+      Map<Window, QName> ws = new HashMap<Window, QName>();
+      QName qName11 = new QName("ns1", "1");
+      QName qName12 = new QName("ns1", "2");
+      ws.put(w1, qName11);
+      ws.put(w2, qName12);
+      cos.setWindowBinding("binding1", ws);
+
+      QName qName21 = new QName("ns2", "foo3");
+      ws.clear();
+      ws.put(w4, qName21);
+      cos.setWindowBinding("binding2", ws);
+
+      Collection<? extends WindowBindingInfo> infos = cos.getWindowBindings(page1);
+      assertNotNull(infos);
+      assertEquals(2, infos.size());
+
+      cos.removeWindowBinding(page1, "binding2");
+      infos = cos.getWindowBindings(page1);
+      assertNotNull(infos);
+      assertEquals(1, infos.size());
+      assertNotNull(cos.getWindowBindingInfo(page1, "binding1"));
+      assertNull(cos.getWindowBindingInfo(page1, "binding2"));
+
+      TransactionAssert.commitTransaction();
+   }
+
    public void testAliasBinding() throws Exception
    {
       TransactionAssert.beginTransaction();
@@ -455,7 +539,7 @@
       TransactionAssert.commitTransaction();
    }
 
-   public void testAddMultipleEventWirings() throws IllegalCoordinationException
+   public void testRemoveEventWiring() throws IllegalCoordinationException
    {
       TransactionAssert.beginTransaction();
 
@@ -477,6 +561,12 @@
       assertNotNull(events);
       assertEquals(2, events.size());
 
+      cos.removeEventWiring(page1, "event1");
+      events = cos.getEventWirings(page1);
+      assertEquals(1, events.size());
+      assertNull(cos.getEventWiring(page1, "event1"));
+      assertNotNull(cos.getEventWiring(page1, "event2"));
+
       TransactionAssert.commitTransaction();
    }
 
@@ -570,6 +660,11 @@
       info = bindings.iterator().next();
       assertEquals("new", info.getName());
 
+      cos.renameWindowBinding(page1, "new", "newer");
+
+      info = cos.getWindowBindingInfo(page1, "newer");
+      assertNotNull(info);
+
       TransactionAssert.commitTransaction();
    }
 




More information about the portal-commits mailing list