Author: chris.laprun(a)jboss.com
Date: 2008-09-03 08:15:06 -0400 (Wed, 03 Sep 2008)
New Revision: 11795
Modified:
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/impl/model/portal/AbstractPortalObjectContainer.java
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/model/portal/PortalObjectContainer.java
Log:
- Added getObject(id, expectedClass) method for convenience.
Modified:
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/impl/model/portal/AbstractPortalObjectContainer.java
===================================================================
---
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/impl/model/portal/AbstractPortalObjectContainer.java 2008-09-03
09:46:26 UTC (rev 11794)
+++
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/impl/model/portal/AbstractPortalObjectContainer.java 2008-09-03
12:15:06 UTC (rev 11795)
@@ -22,6 +22,7 @@
******************************************************************************/
package org.jboss.portal.core.impl.model.portal;
+import org.jboss.portal.common.util.ParameterValidation;
import org.jboss.portal.core.model.content.ContentType;
import org.jboss.portal.core.model.content.spi.ContentProvider;
import org.jboss.portal.core.model.content.spi.ContentProviderRegistry;
@@ -82,14 +83,25 @@
public PortalObject getObject(PortalObjectId id) throws IllegalArgumentException
{
- if (id == null)
- {
- throw new IllegalArgumentException("No null id accepted");
- }
+ ParameterValidation.throwIllegalArgExceptionIfNull(id, "id");
ObjectNode node = getObjectNode(id);
return node == null ? null : node.getObject();
}
+ public <T extends PortalObject> T getObject(PortalObjectId id, Class<T>
expectedType) throws IllegalArgumentException
+ {
+ ParameterValidation.throwIllegalArgExceptionIfNull(expectedType, "expected
type");
+ PortalObject object = getObject(id);
+
+ // only return the object if it matches the expected class
+ if(expectedType.isInstance(object))
+ {
+ return expectedType.cast(object);
+ }
+
+ return null;
+ }
+
public Context getContext(String namespace)
{
if (namespace == null)
Modified:
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/model/portal/PortalObjectContainer.java
===================================================================
---
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/model/portal/PortalObjectContainer.java 2008-09-03
09:46:26 UTC (rev 11794)
+++
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/model/portal/PortalObjectContainer.java 2008-09-03
12:15:06 UTC (rev 11795)
@@ -42,6 +42,19 @@
PortalObject getObject(PortalObjectId id) throws IllegalArgumentException;
/**
+ * Returns the portal object of the specified type identified with the specified
identified or <code>null</code> if
+ * it cannot be found.
+ *
+ * @param id the portal object identifier
+ * @param expectedType the expected type of the object to be retrieved
+ * @param <T> a class extending PortalObject
+ * @return the PortalObject identified by the specified id or
<code>null</code> if it cannot be found
+ * @throws IllegalArgumentException if the specified id or the specified class is
<code>null</code>
+ * @since 2.7
+ */
+ <T extends PortalObject> T getObject(PortalObjectId id, Class<T>
expectedType) throws IllegalArgumentException;
+
+ /**
* Returns the default root object.
*
* @return a root object
Show replies by date