Example usage for org.apache.commons.beanutils PropertyUtils getProperty

List of usage examples for org.apache.commons.beanutils PropertyUtils getProperty

Introduction

In this page you can find the example usage for org.apache.commons.beanutils PropertyUtils getProperty.

Prototype

public static Object getProperty(Object bean, String name)
        throws IllegalAccessException, InvocationTargetException, NoSuchMethodException 

Source Link

Document

Return the value of the specified property of the specified bean, no matter which property reference format is used, with no type conversions.

For more details see PropertyUtilsBean.

Usage

From source file:com.wavemaker.json.BeanUtilsTest.java

public void testNested() throws Exception {

    SampleNestingClass snc = new SampleNestingClass();
    assertEquals(snc.getSc().getSingleString(), PropertyUtils.getProperty(snc, "sc.singleString"));
    assertEquals(snc.getSc().getStrings().get(1), PropertyUtils.getProperty(snc, "sc.strings[1]"));
}

From source file:com.googlecode.psiprobe.tools.logging.DefaultAccessor.java

protected Object getProperty(Object o, String name, Object defaultValue) {
    try {/*w w w.  ja  va2s .  c o  m*/
        return PropertyUtils.isReadable(o, name) ? PropertyUtils.getProperty(o, name) : defaultValue;
    } catch (Exception e) {
        log.debug("Could not access property \"" + name + "\" of object " + o, e);
        return defaultValue;
    }
}

From source file:com.pasteur.ci.action.type_gene_toxicite.EnregistreModifTypeGeneToxiciteAction.java

/**
 * This is the action called from the Struts framework.
 *
 * @param mapping The ActionMapping used to select this instance.
 * @param form The optional ActionForm bean for this request.
 * @param request The HTTP Request we are processing.
 * @param response The HTTP Response we are processing.
 * @throws java.lang.Exception//w  w w  .  j av  a2s. c om
 * @return
 */
@Override
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    int idtyp_gene_toxicite = (Integer) PropertyUtils.getProperty(form, "idtyp_gene_toxicite");
    String design_typ_gene_toxicite = (String) PropertyUtils.getProperty(form, "design_typ_gene_toxicite");
    double conc_typ_gene_toxicite = (Double) PropertyUtils.getProperty(form, "conc_typ_gene_toxicite");
    boolean visible = (Boolean) PropertyUtils.getProperty(form, "visible");
    TypeGeneToxicite gene_toxicite = new TypeGeneToxicite();
    gene_toxicite.setIdtyp_gene_toxicite(idtyp_gene_toxicite);
    gene_toxicite.setDesign_typ_gene_toxicite(design_typ_gene_toxicite);

    gene_toxicite.setVisible(visible);
    TypeGeneToxiciteDAOImplement gdaoi = new TypeGeneToxiciteDAOImplement(DAOFactory.getInstance());
    gdaoi.update(gene_toxicite);
    return mapping.findForward(SUCCESS);
}

From source file:net.sf.taverna.t2.workbench.models.graph.GraphColorManager.java

/**
 * Returns the colour associated with the Activity.
 *
 * For unknown activities Color.WHITE is returned.
 *
 * For {@link LocalworkerActivity} which have been user configured use the
 * BeanshellActivity colour//from w  ww  . ja va 2 s. c o  m
 *
 * @return the colour associated with the Activity
 */
public static Color getFillColor(Activity activity, ColourManager colourManager) {
    try {
        if (activity.getType().equals(LOCALWORKER)) {
            // To avoid compile time dependency - read isAltered property as bean
            if (Boolean.TRUE.equals(PropertyUtils.getProperty(activity, "altered"))) {
                Color colour = colourManager.getPreferredColour(BEANSHELL);
                return colour;
            }
        }
    } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
    }
    Color colour = colourManager.getPreferredColour(activity.getType().toASCIIString());
    return colour;
}

From source file:com.pasteur.ci.action.creation.ajaxNumEchantAction.java

/**
 * This is the action called from the Struts framework.
 *
 * @param mapping The ActionMapping used to select this instance.
 * @param form The optional ActionForm bean for this request.
 * @param request The HTTP Request we are processing.
 * @param response The HTTP Response we are processing.
 * @throws java.lang.Exception//from   ww  w.  j a v a  2  s.c  o  m
 * @return
 */
@Override
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    String numero = (String) PropertyUtils.getProperty(form, "num_echan");
    System.out.println("numero" + numero);

    Echantillon echantillon = new Echantillon();
    echantillon.setNum_echantillon(numero.trim());
    EchantillonDAOImplement echantillonDAOImplement = new EchantillonDAOImplement(DAOFactory.getInstance());

    echantillon = (Echantillon) echantillonDAOImplement.findS(echantillon);

    String num_echantillon = "";
    if (echantillon.getNum_echantillon() != null) {
        num_echantillon = echantillon.getNum_echantillon();
    }

    HashMap hm = new HashMap();
    hm.put("num_echantillon", num_echantillon);
    JSONObject jsono = JSONObject.fromObject(hm);
    response.setHeader("X-JSON", jsono.toString());

    return null;
}

From source file:com.eviware.soapui.model.propertyexpansion.MutablePropertyExpansionImpl.java

public void update() throws Exception {
    String rep = toString();//from   ww w.  ja v a2  s. co m

    // not changed
    if (stringRep.equals(rep))
        return;

    Object obj = PropertyUtils.getProperty(container, propertyName);
    if (obj == null)
        throw new Exception("property value is null");

    String str = obj.toString();
    int ix = str.indexOf(stringRep);
    if (ix == -1)
        throw new Exception("property expansion [" + stringRep + "] not found for update");

    while (ix != -1) {
        str = str.substring(0, ix) + rep + str.substring(ix + stringRep.length());
        ix = str.indexOf(stringRep, ix + rep.length());
    }

    PropertyUtils.setProperty(container, propertyName, str);

    stringRep = rep;
}

From source file:com.mycollab.validator.constraints.DateComparisionValidator.java

@Override
public boolean isValid(Object value, ConstraintValidatorContext context) {
    try {//from   ww  w. ja  v  a 2 s.  co  m
        Date firstValue = (Date) PropertyUtils.getProperty(value, firstDateField);
        Date lastValue = (Date) PropertyUtils.getProperty(value, lastDateField);
        if (firstValue != null && lastValue != null) {
            LocalDate firstDate = new LocalDate(PropertyUtils.getProperty(value, firstDateField));
            LocalDate lastDate = new LocalDate(PropertyUtils.getProperty(value, lastDateField));
            return firstDate.compareTo(lastDate) <= 0;
        }
        return true;
    } catch (Exception ex) {
        return true;
    }
}

From source file:de.erdesignerng.dialect.ModelItemProperties.java

public void copyTo(T aObject) {

    ModelProperties theProperties = aObject.getProperties();

    try {// w w w  . ja v a 2s .  c om
        for (PropertyDescriptor theDescriptor : PropertyUtils.getPropertyDescriptors(this)) {
            if (theDescriptor.getReadMethod() != null && theDescriptor.getWriteMethod() != null) {
                Object theValue = PropertyUtils.getProperty(this, theDescriptor.getName());
                if (theValue != null) {
                    theProperties.setProperty(theDescriptor.getName(), theValue.toString());
                } else {
                    theProperties.setProperty(theDescriptor.getName(), null);
                }
            }
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:com.pasteur.ci.action.gene.GestionModifGeneCyanoAction.java

/**
 * This is the action called from the Struts framework.
 *
 * @param mapping The ActionMapping used to select this instance.
 * @param form The optional ActionForm bean for this request.
 * @param request The HTTP Request we are processing.
 * @param response The HTTP Response we are processing.
 * @throws java.lang.Exception/*from w  ww .  ja v a2 s  .co  m*/
 * @return
 */
@Override
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    int comId = (Integer) PropertyUtils.getProperty(form, "idgene_cyano");

    GeneCyano gene_cyano = new GeneCyano();

    gene_cyano.setIdgene_cyano(comId);
    GeneCyanoDAOImplement cdaoi = new GeneCyanoDAOImplement(DAOFactory.getInstance());

    gene_cyano = (GeneCyano) cdaoi.find(gene_cyano);

    request.setAttribute("geneCyan_trouve", gene_cyano);
    return mapping.findForward(SUCCESS);
}

From source file:cn.hope.platform.persistence.params.ReflectionParameterResolver.java

public Object resolveProperty(Object base, String property) {
    try {/* www . j  a v a  2  s. co m*/
        return PropertyUtils.getProperty(base, property);
    } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {

    }
    return null;
}