[portal-commits] JBoss Portal SVN: r11816 - in branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core: model/portal and 1 other directory.

portal-commits at lists.jboss.org portal-commits at lists.jboss.org
Thu Sep 4 17:04:10 EDT 2008


Author: chris.laprun at jboss.com
Date: 2008-09-04 17:04:10 -0400 (Thu, 04 Sep 2008)
New Revision: 11816

Modified:
   branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/impl/model/portal/PortalObjectImpl.java
   branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/model/portal/PortalObject.java
Log:
- Added getChild(name, expectedType) convenience method.

Modified: branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/impl/model/portal/PortalObjectImpl.java
===================================================================
--- branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/impl/model/portal/PortalObjectImpl.java	2008-09-04 19:38:50 UTC (rev 11815)
+++ branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/impl/model/portal/PortalObjectImpl.java	2008-09-04 21:04:10 UTC (rev 11816)
@@ -22,6 +22,15 @@
  ******************************************************************************/
 package org.jboss.portal.core.impl.model.portal;
 
+import org.apache.log4j.Logger;
+import org.jboss.portal.common.NotYetImplemented;
+import org.jboss.portal.common.i18n.LocalizedString;
+import org.jboss.portal.common.util.ParameterValidation;
+import org.jboss.portal.core.model.portal.DuplicatePortalObjectException;
+import org.jboss.portal.core.model.portal.NoSuchPortalObjectException;
+import org.jboss.portal.core.model.portal.PortalObject;
+import org.jboss.portal.core.model.portal.PortalObjectId;
+
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
@@ -35,14 +44,6 @@
 import java.util.TreeMap;
 import java.util.TreeSet;
 
-import org.apache.log4j.Logger;
-import org.jboss.portal.common.NotYetImplemented;
-import org.jboss.portal.common.i18n.LocalizedString;
-import org.jboss.portal.core.model.portal.DuplicatePortalObjectException;
-import org.jboss.portal.core.model.portal.NoSuchPortalObjectException;
-import org.jboss.portal.core.model.portal.PortalObject;
-import org.jboss.portal.core.model.portal.PortalObjectId;
-
 /**
  * @author <a href="mailto:julien at jboss.org">Julien Viet</a>
  * @version $Revision$
@@ -420,10 +421,7 @@
 
    public PortalObject getChild(String name)
    {
-      if (name == null)
-      {
-         throw new IllegalArgumentException();
-      }
+      ParameterValidation.throwIllegalArgExceptionIfNull(name, "child name");
       ObjectNode childNode = (ObjectNode)objectNode.getChildren().get(name);
       if (childNode != null)
       {
@@ -441,6 +439,20 @@
       }
    }
 
+   public <T extends PortalObject> T getChild(String name, Class<T> expectedType)
+   {
+      ParameterValidation.throwIllegalArgExceptionIfNull(expectedType, "expected type");
+      PortalObject child = getChild(name);
+
+      // only return the child if it matches the expected class
+      if(expectedType.isInstance(child))
+      {
+         return expectedType.cast(child);
+      }
+
+      return null;
+   }
+
    private Set getAccessedChildren()
    {
       if (accessedChildren == null)

Modified: branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/model/portal/PortalObject.java
===================================================================
--- branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/model/portal/PortalObject.java	2008-09-04 19:38:50 UTC (rev 11815)
+++ branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/model/portal/PortalObject.java	2008-09-04 21:04:10 UTC (rev 11816)
@@ -22,11 +22,11 @@
  ******************************************************************************/
 package org.jboss.portal.core.model.portal;
 
+import org.jboss.portal.common.i18n.LocalizedString;
+
 import java.util.Collection;
 import java.util.Map;
 
-import org.jboss.portal.common.i18n.LocalizedString;
-
 /**
  * The base interface for all portal objects.
  *
@@ -97,7 +97,7 @@
    /**
     * Set the localized string used to represent that object.
     *
-    * @param the localized display name
+    * @param localizedString the localized display name
     */
    void setDisplayName(LocalizedString localizedString);
 
@@ -144,6 +144,18 @@
    PortalObject getChild(String name);
 
    /**
+    * Returns the child of the specified type and with the given name or <code>null</code> if it cannot be found.
+    *
+    * @param name           the child's name
+    * @param expectedType the expected type of the child to be retrieved
+    * @param <T>          a class extending PortalObject
+    * @return the named child or <code>null</code> if it cannot be found
+    * @throws IllegalArgumentException if the specified name or the specified class is <code>null</code>
+    * @since 2.7
+    */
+   <T extends PortalObject> T getChild(String name, Class<T> expectedType);
+
+   /**
     * Destroy an existing child.
     *
     * @param name the child name




More information about the portal-commits mailing list