List of usage examples for org.apache.commons.beanutils PropertyUtils getSimpleProperty
public static Object getSimpleProperty(Object bean, String name) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException
Return the value of the specified simple property of the specified bean, with no type conversions.
For more details see PropertyUtilsBean
.
From source file:org.ambraproject.rhino.view.JsonWrapper.java
@Override public JsonElement serialize(JsonSerializationContext context) { JsonObject serialized = new JsonObject(); for (String property : propertiesToInclude) { String value;//w ww .j a va 2 s. c om try { value = (String) PropertyUtils.getSimpleProperty(target, property); } catch (IllegalAccessException iae) { throw new RuntimeException(iae); } catch (InvocationTargetException ite) { throw new RuntimeException(ite); } catch (NoSuchMethodException nsme) { throw new RuntimeException(nsme); } serialized.addProperty(property, value); } return serialized; }
From source file:org.apache.bval.util.PropertyAccess.java
private static Object getPublicProperty(Object bean, String property) throws InvocationTargetException, NoSuchMethodException, IllegalAccessException { if (bean instanceof Map<?, ?>) { return ((Map<?, ?>) bean).get(property); } else { // supports DynaBean and standard Objects return PropertyUtils.getSimpleProperty(bean, property); }/*from w ww.ja v a2 s . co m*/ }
From source file:org.apache.camel.component.gora.utils.GoraUtils.java
/** * Utility method to check if a value exist in the configuration class * * <b>NOTE:</>//from w ww. j a v a2 s . c o m * Checks only if is not null * * @param attr * @param conf * @return * @throws IllegalAccessException * @throws NoSuchMethodException * @throws InvocationTargetException */ protected static boolean configurationExist(final GoraAttribute attr, final GoraConfiguration conf) throws IllegalAccessException, NoSuchMethodException, InvocationTargetException { return PropertyUtils.getSimpleProperty(conf, attr.value) != null; }
From source file:org.apache.camel.component.gora.utils.GoraUtils.java
/** * Utility method to extract value from configuration * * @param attr/*from www . j a v a 2 s . c o m*/ * @param conf * @return * @throws IllegalAccessException * @throws NoSuchMethodException * @throws InvocationTargetException */ protected static Object getAttribute(final GoraAttribute attr, final GoraConfiguration conf) throws IllegalAccessException, NoSuchMethodException, InvocationTargetException { return PropertyUtils.getSimpleProperty(conf, attr.value); }
From source file:org.apache.forrest.forrestbot.webapp.action.ExecuteAction.java
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { super.execute(mapping, form, request, response); ActionErrors errors = new ActionErrors(); String project = (String) PropertyUtils.getSimpleProperty(form, "project"); String build = (String) PropertyUtils.getSimpleProperty(form, "build"); String deploy = (String) PropertyUtils.getSimpleProperty(form, "deploy"); request.setAttribute("project", project); if (!checkAuthorized(request, response)) return mapping.findForward(Constants.FORWARD_NAME_SUCCESS); if (!Project.exists(project)) { log.warn("project doesn't exist: " + project); errors.add("execute", new ActionError("error.project.notfound", project)); saveErrors(request, errors);/*from ww w . ja va 2 s.c om*/ return mapping.findForward(Constants.FORWARD_NAME_SUCCESS); } Project p = new Project(); p.asDTO().setName(project); p.loadData(); p.loadSecurity((String) request.getSession(true).getAttribute("username")); if (p.asDTO().getStatus() == Constants.STATUS_RUNNING) { log.warn("can't execute " + project + " while still running"); errors.add("execute", new ActionError("error.project.stillrunning", project)); saveErrors(request, errors); return mapping.findForward(Constants.FORWARD_NAME_SUCCESS); } if (build != null && !build.equals("")) { if (p.asDTO().isBuildable()) { try { Executor.build(project); } catch (Exception e) { log.warn("couldn't build " + project, e); errors.add("execute", new ActionError("error.build", project)); } } else { errors.add("execute", new ActionError("error.authorization")); } } else if (deploy != null && !deploy.equals("")) { if (p.asDTO().isDeployable()) { try { Executor.deploy(project); } catch (Exception e) { log.warn("couldn't deploy " + project, e); errors.add("execute", new ActionError("error.deploy", project)); } } else { errors.add("execute", new ActionError("error.authorization")); } } saveErrors(request, errors); return mapping.findForward(Constants.FORWARD_NAME_SUCCESS); }
From source file:org.apache.forrest.forrestbot.webapp.action.ViewSummaryAction.java
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { super.execute(mapping, form, request, response); if (form != null && !PropertyUtils.getSimpleProperty(form, "submit").equals("unsubmitted")) { ActionErrors errors = form.validate(mapping, request); String username = (String) PropertyUtils.getSimpleProperty(form, "username"); String password = (String) PropertyUtils.getSimpleProperty(form, "password"); request.setAttribute("username", username); UserManager userManager = UserManager.getInstance(); boolean validPassword = false; try {/*from w ww .j av a 2 s . c o m*/ validPassword = userManager.getUser(username).authenticate(password); } catch (EntityNotFoundException e) { validPassword = false; } if (!validPassword) { log.debug("bad password"); errors.add("password", new ActionError("error.authentication")); saveErrors(request, errors); } else { log.debug("authenticated"); request.getSession(true).setAttribute("auth", Boolean.TRUE); request.getSession(true).setAttribute("username", username); } } request.setAttribute("serverTime", new Date()); if (checkAuthorized(request, response, false)) { // set access for each project String currentUser = (String) request.getSession(true).getAttribute("username"); Collection projects = Project.getAllProjects(); for (Iterator i = projects.iterator(); i.hasNext();) { ProjectDTO projectDTO = (ProjectDTO) i.next(); (new Project(projectDTO)).loadSecurity(currentUser); } request.setAttribute("projects", projects); return mapping.findForward(Constants.FORWARD_NAME_AUTHORIZED); } request.setAttribute("projects", Project.getAllProjects()); return mapping.findForward(Constants.FORWARD_NAME_SUCCESS); }
From source file:org.apache.hadoop.gateway.config.impl.BeanConfigurationAdapter.java
@Override public Object getConfigurationValue(String name) throws ConfigurationException { try {//from www.ja v a 2 s . c om return PropertyUtils.getSimpleProperty(bean, name); } catch (Exception e) { throw new ConfigurationException(String.format(""), e); } }
From source file:org.apache.qpid.server.jmx.mbeans.MBeanTestUtils.java
public static void assertMBeanAttribute(DefaultManagedObject managedObject, String jmxAttributeName, Object expectedValue) throws Exception { Object actualValue = PropertyUtils.getSimpleProperty(managedObject, jmxAttributeName); TestCase.assertEquals("Attribute " + jmxAttributeName + " has unexpected value", expectedValue, actualValue);// w ww . ja v a 2 s .c o m }
From source file:org.apache.struts.actions.LocaleAction.java
/** * <p>/*from w w w . j a va 2 s. c o m*/ * Change the user's {@link java.util.Locale} based on {@link ActionForm} * properties. * </p> * <p> * This <code>Action</code> looks for <code>language</code> and * <code>country</code> properties on the given form, constructs an * appropriate Locale object, and sets it as the Struts Locale for this * user's session. * Any <code>ActionForm</code>, including a * {@link org.apache.struts.action.DynaActionForm}, may be used. * </p> * <p> * If a <code>page</code> property is also provided, then after * setting the Locale, control is forwarded to that URI path. * Otherwise, control is forwarded to "success". * </p> * * @param mapping The ActionMapping used to select this instance * @param form The optional ActionForm bean for this request (if any) * @param request The HTTP request we are processing * @param response The HTTP response we are creating * * @return Action to forward to * @exception java.lang.Exception if an input/output error or servlet exception occurs */ public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { // Extract attributes we will need HttpSession session = request.getSession(); Locale locale = getLocale(request); String language = null; String country = null; String page = null; try { language = (String) PropertyUtils.getSimpleProperty(form, "language"); country = (String) PropertyUtils.getSimpleProperty(form, "country"); page = (String) PropertyUtils.getSimpleProperty(form, "page"); } catch (Exception e) { log.error(e.getMessage(), e); } boolean isLanguage = (language != null && language.length() > 0); boolean isCountry = (country != null && country.length() > 0); if ((isLanguage) && (isCountry)) { locale = new java.util.Locale(language, country); } else if (isLanguage) { locale = new java.util.Locale(language, ""); } session.setAttribute(Globals.LOCALE_KEY, locale); if (null == page) return mapping.findForward("success"); else return new ActionForward(page); }
From source file:org.apache.struts.apps.mailreader.actions.BaseAction.java
/** * <p>//from w ww .j av a 2s.com * Helper method to fetch a String property from a DynaActionForm. * </p> * <p> * Values are returned trimmed of leading and trailing whitespace. * Zero-length strings are returned as null. * </p> * * @param form Our DynaActionForm * @param property The name of the property * @return The value or null if an error occurs */ protected String doGet(ActionForm form, String property) { String initial; try { initial = (String) PropertyUtils.getSimpleProperty(form, property); } catch (Throwable t) { initial = null; } String value = null; if ((initial != null) && (initial.length() > 0)) { value = initial.trim(); if (value.length() == 0) { value = null; } } return value; }