Author: julien(a)jboss.com
Date: 2008-04-02 14:50:59 -0400 (Wed, 02 Apr 2008)
New Revision: 10486
Modified:
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model2/ui/UIObjectImpl.java
Log:
- use safeCast from org.jboss.portal.common
Modified:
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model2/ui/UIObjectImpl.java
===================================================================
---
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model2/ui/UIObjectImpl.java 2008-04-02
15:55:51 UTC (rev 10485)
+++
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/impl/model2/ui/UIObjectImpl.java 2008-04-02
18:50:59 UTC (rev 10486)
@@ -26,6 +26,7 @@
import org.jboss.portal.presentation.model2.state.StateException;
import org.jboss.portal.presentation.model2.state.structural.StructuralObject;
import org.jboss.portal.presentation.impl.model2.UIObjectRef;
+import org.jboss.portal.common.reflect.Reflection;
import java.util.Map;
import java.util.Set;
@@ -60,7 +61,7 @@
public <T> T getProperty(String propertyName, Class<T> propertyType)
throws IllegalArgumentException, StateException
{
- return safeCast(getProperty(propertyName), propertyType);
+ return Reflection.safeCast(getProperty(propertyName), propertyType);
}
public Set<String> getPropertyNames()
@@ -76,35 +77,4 @@
}
return structuralObject.getState().getProperties().get(propertyName);
}
-
- /**
- * Attempt to cast the value argument to the provided type argument. If the value
argument type is assignable
- * to the provided type, the value is returned, otherwise if it is not or the value is
null, null is returned.
- *
- * @param value the value to cast
- * @param type the type to downcast
- * @return the casted value or null
- */
- private <T> T safeCast(Object value, Class<T> type)
- {
- if (type == null)
- {
- throw new IllegalArgumentException();
- }
- if (value == null)
- {
- return null;
- }
- else
- {
- if (type.isAssignableFrom(value.getClass()))
- {
- return type.cast(value);
- }
- else
- {
- return null;
- }
- }
- }
}
\ No newline at end of file
Show replies by date