From: Chad B. <cwb...@us...> - 2008-05-16 19:05:45
|
User: cwbrandon Date: 08/05/16 12:05:33 Modified: andromda-jsf2/src/main/resources/templates/jsf2/utils JsfUtils.java.vsl Log: add methods for getting and setting attributes on any kind of request, session, etc Revision Changes Path 1.5 +65 -0 cartridges/andromda-jsf2/src/main/resources/templates/jsf2/utils/JsfUtils.java.vsl Index: JsfUtils.java.vsl =================================================================== RCS file: /cvsroot/andromdaplugins/cartridges/andromda-jsf2/src/main/resources/templates/jsf2/utils/JsfUtils.java.vsl,v retrieving revision 1.4 retrieving revision 1.5 diff -u -w -r1.4 -r1.5 --- JsfUtils.java.vsl 8 Apr 2008 16:29:07 -0000 1.4 +++ JsfUtils.java.vsl 16 May 2008 19:05:33 -0000 1.5 @@ -192,6 +192,71 @@ } /** + * Gets the attribute from the given object. The object can be either a context, request + * or resposne (HttpServletContext/PortletContext, HttpServletRequest/PortletRequest, etc). + * + * @param object the object from which to retrieve the attribute. + * @param attributeName the attribute name. + * @return the value of the attribute if one is present. + */ + public static Object getAttribute(final Object object, final String attributeName) + { + try + { + Object attribute = null; + if (object != null) + { + try + { + final java.lang.reflect.Method method = object.getClass().getMethod("getAttribute", new Class[]{String.class}); + method.invoke(object, new Object[]{attributeName}); + } + catch (NoSuchMethodException exception) + { + } + } + return attribute; + } + catch (Exception exception) + { + throw new RuntimeException(exception); + } + } + + /** + * Sets the attribute on the given object. The object can be either a context, request + * or resposne (HttpServletContext/PortletContext, HttpServletRequest/PortletRequest, etc). + * + * @param object the object on which to set the attribute. + * @param attributeName the attribute name. + * @param attributeValue the value of the attribute to set. + * @return the value of the attribute if one is present. + */ + public static Object setAttribute(final Object object, final String attributeName, final Object attributeValue) + { + try + { + Object attribute = null; + if (object != null) + { + try + { + final java.lang.reflect.Method method = object.getClass().getMethod("setAttribute", new Class[]{String.class, Object.class}); + method.invoke(object, new Object[]{attributeName, attributeValue}); + } + catch (NoSuchMethodException exception) + { + } + } + return attribute; + } + catch (Exception exception) + { + throw new RuntimeException(exception); + } + } + + /** * Uses the converter identified by converterId to convert the value to a String. * @value the value to be converted * @converterId the id of the converter to be used |