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

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

Introduction

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

Prototype

public static void setProperty(Object bean, String name, Object value)
        throws IllegalAccessException, InvocationTargetException, NoSuchMethodException 

Source Link

Document

Set 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:org.photovault.swingui.color.PhotoInfoViewAdapter.java

public void setField(PhotoInfoFields field, Object newValue) {
    String propertyName = field.getName();
    try {// w  ww . j  av  a2  s.c  o  m
        PropertyUtils.setProperty(this, propertyName, newValue);
    } catch (NoSuchMethodException ex) {
        log.error("Cannot set property " + propertyName);
        ex.printStackTrace();
    } catch (IllegalAccessException ex) {
        log.error(ex.getMessage());
    } catch (InvocationTargetException ex) {
        log.error(ex.getMessage());
    }
}

From source file:org.photovault.swingui.color.PhotoInfoViewAdapter.java

public void setFieldMultivalued(PhotoInfoFields field, boolean isMultivalued) {
    String propertyName = field.getName() + "Multivalued";
    try {//  w  ww.j av  a  2s  .c  o  m
        PropertyUtils.setProperty(this, propertyName, isMultivalued);
    } catch (NoSuchMethodException ex) {
        log.error("Cannot set property " + propertyName);
        ex.printStackTrace();
    } catch (IllegalAccessException ex) {
        log.error(ex.getMessage());
    } catch (InvocationTargetException ex) {
        log.error(ex.getMessage());
    }
}

From source file:org.photovault.swingui.PhotoInfoEditor.java

public void setField(PhotoInfoFields field, Object newValue) {
    StringBuffer debugMsg = new StringBuffer();
    debugMsg.append("setField ").append(field).append(": ").append(newValue);
    log.debug(debugMsg.toString());//from   w  ww  .j  av a2s  .  co  m
    String propertyName = field.getName();
    try {
        PropertyUtils.setProperty(this, propertyName, newValue);
    } catch (NoSuchMethodException ex) {
        log.error("Cannot set property " + propertyName);
        ex.printStackTrace();
    } catch (IllegalAccessException ex) {
        log.error(ex.getMessage());
    } catch (InvocationTargetException ex) {
        log.error(ex.getMessage());
    }
}

From source file:org.photovault.swingui.PhotoInfoEditor.java

/**     
 Set the multivalued state of given field
 @param field Field to set//from  w ww .  j  a  va 2s . c  o  m
 @param isMultivalued If <code>null, set the field to multivalued state. If not, set
 it to normal state 
 */
public void setFieldMultivalued(PhotoInfoFields field, boolean isMultivalued) {
    String propertyName = field.getName() + "Multivalued";
    try {
        PropertyUtils.setProperty(this, propertyName, isMultivalued);
    } catch (NoSuchMethodException ex) {
        log.error("Cannot set property " + propertyName);
        ex.printStackTrace();
    } catch (IllegalAccessException ex) {
        log.error(ex.getMessage());
    } catch (InvocationTargetException ex) {
        log.error(ex.getMessage());
    }
}

From source file:org.projectforge.excel.ExcelImport.java

/**
 * convert a single row to an object./*from w  w  w  . ja  v a 2 s .c  om*/
 * 
 * @param row the row containing the values.
 * @param columnNames the row containing the column-names.
 * @param rowNum the current rownum
 * @return a new created object populated with the values.
 * @throws InstantiationException if the object creation fails.
 * @throws IllegalAccessException if the object creation fails or the invoked setter is not public.
 * @throws InvocationTargetException if the object creation fails with an exception or the setter threw an exception.
 * @throws NoSuchMethodException if the setter for the property name is not existant.
 */
private T convertToBean(final HSSFRow row, final HSSFRow columnNames, final int rowNum)
        throws InstantiationException, IllegalAccessException, InvocationTargetException,
        NoSuchMethodException {
    if (row == null) {
        log.debug("created no bean for row#" + rowNum);
        return null;
    }
    final T o = clazzFactory.newInstance(row);
    if (columnNames == null) {
        return null;
    }
    for (int column = 0; column < columnNames.getPhysicalNumberOfCells(); column++) {
        if (columnNames.getCell(column) == null) {
            continue;
        }
        String columnName = columnNames.getCell(column).getStringCellValue();
        if (columnName != null) {
            columnName = columnName.trim();
        }
        String propName = columnName;
        if (columnToPropertyMap != null) {
            final String mapName = columnToPropertyMap.get(columnName);
            if (mapName != null) {
                propName = mapName.trim();
            }
        }
        try {
            final Class<?> destClazz = PropertyUtils.getPropertyType(o, propName);
            if (propName == null || destClazz == null) {
                log.debug("Skipping column " + columnName);
                continue;
            }
            final Object value = toNativeType(row.getCell(column), destClazz);
            log.debug("Setting property=" + propName + " to " + value + " class="
                    + ClassUtils.getShortClassName(value, "null"));
            PropertyUtils.setProperty(o, propName, value);
        } catch (final ConversionException e) {
            log.warn(e);
            throw new ExcelImportException("Falscher Datentyp beim Excelimport", new Integer(row.getRowNum()),
                    columnName);
        } catch (final Exception e) {
            log.warn(e);
            throw new ExcelImportException("Falscher Datentyp beim Excelimport", new Integer(row.getRowNum()),
                    columnName);
        }
    }
    if (log.isDebugEnabled() == true) {
        log.debug("created bean " + o + " for row#" + rowNum);
    }
    return o;
}

From source file:org.rti.zcore.dar.remote.ReportHelper.java

/**
 * Update report value and saves report to an Excel file.
 * @param identifier//w w w .j  av  a 2 s. c  o m
 * @param reportName
 * @param value
 * @param isFacilityReport
 * @return
 */
public static String updateReport(String identifier, String reportName, String value, Boolean isFacilityReport)
        throws FileNotFoundException {
    String result = "";
    WebContext exec = WebContextFactory.get();
    String username = null;
    SessionUtil zeprs_session = null;
    Site site = null;
    String siteAbbrev = null;
    try {
        username = exec.getHttpServletRequest().getUserPrincipal().getName();
    } catch (NullPointerException e) {
        // unit testing - it's ok...
        username = "demo";
    }
    HttpSession session = exec.getSession();
    try {
        zeprs_session = (SessionUtil) session.getAttribute("zeprs_session");
    } catch (Exception e) {
        // unit testing - it's ok...
    }
    try {
        ClientSettings clientSettings = zeprs_session.getClientSettings();
        site = clientSettings.getSite();
        siteAbbrev = site.getAbbreviation();
    } catch (SessionUtil.AttributeNotFoundException e) {
        log.error(e);
    } catch (NullPointerException e) {
        // it's ok - unit testing
        siteAbbrev = "test";
    }

    String parentField = null;
    String childField = null;

    if (identifier.equals("Save") || identifier.equals("SaveNext")) {

    } else {
        String[] identArray = identifier.split("\\.");
        parentField = identArray[0];
        childField = identArray[1];
    }

    Register report = null;
    String className = "org.rti.zcore.dar.report." + StringManipulation.fixClassname(reportName);
    Class clazz = null;
    try {
        clazz = Class.forName(className);
    } catch (ClassNotFoundException e) {
        log.error(e);
    }
    try {
        report = (Register) clazz.newInstance();
    } catch (InstantiationException e) {
        log.error(e);
    } catch (IllegalAccessException e) {
        log.error(e);
    }

    if (identifier.equals("Save") || identifier.equals("SaveNext") || value != null) {
        Integer valueInt = null;
        report = SessionUtil.getInstance(session).getReports().get(reportName);
        String totalIdent = "";
        String reportFileName = report.getReportFileName();
        String pathXml = Constants.ARCHIVE_PATH + site.getAbbreviation() + "/reports/" + reportFileName
                + ".xml";
        String pathExcel = Constants.ARCHIVE_PATH + site.getAbbreviation() + "/reports/" + reportFileName
                + ".xls";
        String bdate = report.getBeginDate().toString();
        String edate = report.getEndDate().toString();
        String siteId = String.valueOf(report.getSiteId());
        String jsessionId = session.getId();
        String[] identifierArray = identifier.split("\\.");
        int len = identifierArray.length;
        String keyForMap = null;
        try {
            if (identifier.equals("Save")) {
                result = "Report saved at " + pathExcel;
            } else if (identifier.equals("SaveNext")) {
                String reportId = null;
                if (reportName.equals("CDRRArtReport")) {
                    if ((isFacilityReport != null) && (isFacilityReport == Boolean.TRUE)) {
                        reportId = "7";
                        result = "/dar/ChooseReportAction.do;jsessionid=" + jsessionId + "?bdate=" + bdate
                                + "&edate=" + edate + "&siteId=" + siteId + "&report=" + reportId
                                + "&isCombinedReport=1&isFacilityReport=1";
                    } else {
                        // Skipping CDRROIReport
                        reportId = "6";
                        result = "/dar/ChooseReportAction.do;jsessionid=" + jsessionId + "?bdate=" + bdate
                                + "&edate=" + edate + "&siteId=" + siteId + "&report=" + reportId
                                + "&isCombinedReport=1";
                    }
                } else if (reportName.equals("CDRROIReport")) {
                    reportId = "6";
                    result = "/dar/ChooseReportAction.do;jsessionid=" + jsessionId + "?bdate=" + bdate
                            + "&edate=" + edate + "&siteId=" + siteId + "&report=" + reportId
                            + "&isCombinedReport=1&isFacilityReport=1";
                } else {
                    if ((isFacilityReport != null) && (isFacilityReport == Boolean.TRUE)) {
                        result = "/dar/reports/combined/gen.do;jsessionid=" + jsessionId
                                + "?isFacilityReport=1";
                    } else {
                        result = "/dar/reports/combined/gen.do;jsessionid=" + jsessionId;
                    }
                }
            } else {
                try {
                    valueInt = Integer.valueOf(value);
                } catch (NumberFormatException e) {
                    try {
                        throw new PersistenceException(
                                "This input field requires an integer value (e.g.: 55). You entered : " + value,
                                e, false);
                    } catch (PersistenceException e1) {
                        return result = identifier + "=" + "Error:" + e1.getMessage();
                    }
                }

                if (identifier.contains("regimenReportMap")) {
                    keyForMap = identifierArray[len - 1];
                    // should be newEstimatedArtPatients.
                    String parentObjectName = identifier
                            .replace("." + identifierArray[len - 2] + "." + keyForMap, "");
                    try {
                        Object parent = null;
                        parent = PropertyUtils.getNestedProperty(report, parentObjectName);
                        PropertyUtils.setMappedProperty(parent, "regimenReportMap", keyForMap, valueInt);
                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                } else if (identifier.contains("stockReportMap")) {
                    keyForMap = identifierArray[len - 2];
                    //String propertyName = identifierArray[len-1];
                    // parentObjectName should be stockReportMap
                    //String parentObjectName = identifier.replace("." +  keyForMap + "." + childField, "");
                    try {
                        PropertyUtils.setNestedProperty(report, identifier, valueInt);
                        //Object parent = PropertyUtils.getNestedProperty(report, parentObjectName);
                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                } else {
                    PropertyUtils.setProperty(report, identifier, valueInt);
                }
                //valueInt = (Integer) PropertyUtils.getProperty(report, identifier);
                /*HashMap<String, Integer> regimenReportMap = report.get
                regimenReportMap.put(key, amount);*/

                // CDRR (Stock) Reports
                if (parentField.equals("stockReportMap")) {
                    String propertyField = identifierArray[2];
                    if (propertyField.equals("quantityRequiredNewPatients")) {
                        String quantityRequiredResupplyIdent = identifier.replace(propertyField,
                                "quantityRequiredResupply");
                        Integer quantityRequiredResupply = 0;
                        if (PropertyUtils.getNestedProperty(report, quantityRequiredResupplyIdent) != null) {
                            quantityRequiredResupply = (Integer) PropertyUtils.getNestedProperty(report,
                                    quantityRequiredResupplyIdent);
                        }
                        Integer totalQuantityRequired = quantityRequiredResupply + valueInt;
                        String totalQuantityRequiredIdent = identifier.replace(propertyField,
                                "totalQuantityRequired");
                        try {
                            PropertyUtils.setNestedProperty(report, totalQuantityRequiredIdent, valueInt);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                        result = identifier + "=" + valueInt + ";" + totalQuantityRequiredIdent + "="
                                + totalQuantityRequired;
                    } else {
                        result = "0=0;" + identifier + "=" + valueInt;
                    }
                    // Regimen report
                } else if (parentField.equals("newEstimatedArtPatients")) {
                    //String quantityRequiredResupplyIdent = "artRegimenReport." + childField;
                    Integer quantityRequiredResupply = 0;
                    /*if (PropertyUtils.getProperty(report, quantityRequiredResupplyIdent) != null) {
                       quantityRequiredResupply = (Integer) PropertyUtils.getProperty(report, quantityRequiredResupplyIdent);
                    }*/

                    if (PropertyUtils.getMappedProperty(report, "regimenReportMap", keyForMap) != null) {
                        //value = regimenReportMap.get("regimen" + regimenCode);
                        quantityRequiredResupply = (Integer) PropertyUtils.getMappedProperty(report,
                                "regimenReportMap", keyForMap);
                    }

                    totalIdent = "totalEstimatedArtPatients." + childField + "." + keyForMap;
                    Integer totalQuantityRequired = quantityRequiredResupply + valueInt;

                    //String parentObjectName = identifier.replace("." +  identifierArray[len-2] + "." + keyForMap, "");
                    //Object parent = PropertyUtils.getNestedProperty(report, parentObjectName);

                    Object parent = PropertyUtils.getNestedProperty(report, "totalEstimatedArtPatients");
                    PropertyUtils.setMappedProperty(parent, "regimenReportMap", keyForMap,
                            totalQuantityRequired);
                    //PropertyUtils.setProperty(report, totalIdent, totalQuantityRequired);
                    result = identifier + "=" + valueInt + ";" + totalIdent + "=" + totalQuantityRequired;
                } else if (parentField.equals("totalQuantityRequired")) {
                    result = "0=0;" + identifier + "=" + valueInt;
                }
            }
            try {
                ReportOutput.outputReport(reportName, report, clazz, pathXml, pathExcel, null);
            } catch (FileNotFoundException e) {
                result = identifier + "=" + valueInt + ";" + totalIdent + "="
                        + "Error: the Excel file for this report is open. Please close.";
            } catch (IOException e) {
                log.debug(e);
            } catch (WrappedRuntimeException e) {
                log.error(e);
                //e.printStackTrace();
            } catch (TransformerException e) {
                log.error(e);
            }
        } catch (IllegalAccessException e) {
            log.debug(e);
        } catch (InvocationTargetException e) {
            log.debug(e);
        } catch (NoSuchMethodException e) {
            log.debug(e);
        }
        //BeanUtils.setProperty(parent, childField, value);
    } else {
        result = identifier + "=" + "Error: No value entered.";
    }
    return result;
}

From source file:org.rti.zcore.dar.remote.ReportHelper.java

/**
 * Updates values in dynamic report and outputs to file.
 * @param identifier/*w w  w . j  a  va2  s . c om*/
 * @param reportName
 * @param value
 * @return
 * @throws FileNotFoundException
 */
public static String updateDynamicReport(String identifier, String reportName, String value)
        throws FileNotFoundException {
    String result = "";
    WebContext exec = WebContextFactory.get();
    String username = null;
    SessionUtil zeprs_session = null;
    Site site = null;
    String siteAbbrev = null;
    try {
        username = exec.getHttpServletRequest().getUserPrincipal().getName();
    } catch (NullPointerException e) {
        // unit testing - it's ok...
        username = "demo";
    }
    HttpSession session = exec.getSession();
    try {
        zeprs_session = (SessionUtil) session.getAttribute("zeprs_session");
    } catch (Exception e) {
        // unit testing - it's ok...
    }
    try {
        ClientSettings clientSettings = zeprs_session.getClientSettings();
        site = clientSettings.getSite();
        siteAbbrev = site.getAbbreviation();
    } catch (SessionUtil.AttributeNotFoundException e) {
        log.error(e);
    } catch (NullPointerException e) {
        // it's ok - unit testing
        siteAbbrev = "test";
    }

    String parentField = null;
    String childField = null;

    if (identifier.equals("Save") || identifier.equals("SaveNext")) {

    } else {
        String[] identArray = identifier.split("\\.");
        parentField = identArray[0];
        childField = identArray[1];
    }

    Register report = null;
    String className = "org.rti.zcore.dar.report." + StringManipulation.fixClassname(reportName);
    Class clazz = null;
    try {
        clazz = Class.forName(className);
    } catch (ClassNotFoundException e) {
        log.error(e);
    }
    try {
        report = (Register) clazz.newInstance();
    } catch (InstantiationException e) {
        log.error(e);
    } catch (IllegalAccessException e) {
        log.error(e);
    }

    if (identifier.equals("Save") || identifier.equals("SaveNext") || value != null) {
        Integer valueInt = null;
        report = SessionUtil.getInstance(session).getReports().get(reportName);
        String totalIdent = "";
        String reportFileName = report.getReportFileName();
        String pathXml = Constants.ARCHIVE_PATH + site.getAbbreviation() + "/reports/" + reportFileName
                + ".xml";
        String pathExcel = Constants.ARCHIVE_PATH + site.getAbbreviation() + "/reports/" + reportFileName
                + ".xls";
        String xslFile = Constants.REPORTS_XSL_PATH + Constants.pathSep + reportName + "-dynamic.xsl";
        String bdate = report.getBeginDate().toString();
        String edate = report.getEndDate().toString();
        String siteId = String.valueOf(report.getSiteId());
        String jsessionId = session.getId();
        try {
            if (identifier.equals("Save")) {
                result = "Report saved at " + pathExcel;
            } else if (identifier.equals("SaveNext")) {
                String reportId = null;
                if (reportName.equals("CDRRArtReport")) {
                    reportId = "7";
                    result = "/dar/ChooseReportAction.do;jsessionid=" + jsessionId + "?bdate=" + bdate
                            + "&edate=" + edate + "&siteId=" + siteId + "&report=" + reportId
                            + "&isCombinedReport=1&dynamicReport=1";
                } else if (reportName.equals("CDRROIReport")) {
                    reportId = "6";
                    result = "/dar/ChooseReportAction.do;jsessionid=" + jsessionId + "?bdate=" + bdate
                            + "&edate=" + edate + "&siteId=" + siteId + "&report=" + reportId
                            + "&isCombinedReport=1&dynamicReport=1";
                } else {
                    result = "/dar/reports/combined/gen.do;jsessionid=" + jsessionId + "?dynamicReport=1";
                }
            } else {
                try {
                    valueInt = Integer.valueOf(value);
                } catch (NumberFormatException e) {
                    try {
                        throw new PersistenceException(
                                "This input field requires an integer value (e.g.: 55). You entered : " + value,
                                e, false);
                    } catch (PersistenceException e1) {
                        return result = identifier + "=" + "Error:" + e1.getMessage();
                    }
                }

                if (reportName.equals("MonthlyArtReport")) {
                    MonthlyArtReport dynamicReport = (MonthlyArtReport) report;
                    ArrayList<RegimenReport> regimenList = dynamicReport.getRegimenList();
                    String code = childField.replace("regimen", "");
                    totalIdent = "totalEstimatedArtPatients." + childField;
                    Integer totalEstimatedArtPatients = 0;
                    for (RegimenReport regimenReport : regimenList) {
                        String regimenCode = regimenReport.getCode();
                        if (regimenCode.equals(code)) {
                            regimenReport.setNewEstimatedArtPatients(valueInt);
                            int countInt = regimenReport.getCountInt();
                            totalEstimatedArtPatients = countInt + valueInt;
                            regimenReport.setTotalEstimatedArtPatients(totalEstimatedArtPatients);
                            break;
                        }
                    }
                    result = identifier + "=" + valueInt + ";" + totalIdent + "=" + totalEstimatedArtPatients;
                } else if (reportName.equals("CDRRArtReport")) {
                    CDRRArtReport dynamicReport = (CDRRArtReport) report;
                    // CDRR Reports
                    if (parentField.equals("quantityRequiredNewPatients")) {
                        ArrayList<DrugReport> drugReportList = dynamicReport.getDrugReportList();
                        String itemId = childField.replace("drug", "");
                        //String quantityRequiredResupplyIdent = "quantityRequiredResupply." + childField;
                        Integer quantityRequiredResupply = 0;
                        for (DrugReport drugReport : drugReportList) {
                            String idStr = drugReport.getId().toString();
                            if (idStr.equals(itemId)) {
                                drugReport.setQuantityRequiredNewPatients(valueInt);
                                totalIdent = "totalQuantityRequired." + childField;
                                if (drugReport.getQuantityRequiredResupply() != null) {
                                    quantityRequiredResupply = drugReport.getQuantityRequiredResupply();
                                }
                                Integer totalQuantityRequired = quantityRequiredResupply + valueInt;
                                //PropertyUtils.setProperty(report, totalIdent, totalQuantityRequired);
                                result = identifier + "=" + valueInt + ";" + totalIdent + "="
                                        + totalQuantityRequired;
                                drugReport.setTotalQuantityRequired(totalQuantityRequired);
                                break;
                            }
                        }
                        /*if (PropertyUtils.getProperty(report, quantityRequiredResupplyIdent) != null) {
                           quantityRequiredResupply = (Integer) PropertyUtils.getProperty(report, quantityRequiredResupplyIdent);
                        }*/

                    } else if (parentField.equals("newEstimatedArtPatients")) {
                        String quantityRequiredResupplyIdent = "artRegimenReport." + childField;
                        Integer quantityRequiredResupply = 0;
                        if (PropertyUtils.getProperty(report, quantityRequiredResupplyIdent) != null) {
                            quantityRequiredResupply = (Integer) PropertyUtils.getProperty(report,
                                    quantityRequiredResupplyIdent);
                        }
                        totalIdent = "totalEstimatedArtPatients." + childField;
                        Integer totalQuantityRequired = quantityRequiredResupply + valueInt;
                        PropertyUtils.setProperty(report, totalIdent, totalQuantityRequired);
                        result = identifier + "=" + valueInt + ";" + totalIdent + "=" + totalQuantityRequired;
                    } else if (parentField.equals("totalQuantityRequired")) {
                        ArrayList<DrugReport> drugReportList = dynamicReport.getDrugReportList();
                        String itemId = childField.replace("drug", "");
                        for (DrugReport drugReport : drugReportList) {
                            String idStr = drugReport.getId().toString();
                            if (idStr.equals(itemId)) {
                                drugReport.setTotalQuantityRequired(valueInt);
                                result = "0=0;" + identifier + "=" + valueInt;
                                break;
                            }
                        }
                    }
                }
            }
            try {
                ReportOutput.outputReport(reportName, report, clazz, pathXml, pathExcel, xslFile);
            } catch (FileNotFoundException e) {
                result = identifier + "=" + valueInt + ";" + totalIdent + "="
                        + "Error: the Excel file for this report is open. Please close.";
            } catch (IOException e) {
                log.debug(e);
            } catch (WrappedRuntimeException e) {
                log.error(e);
                //e.printStackTrace();
            } catch (TransformerException e) {
                log.error(e);
            }
        } catch (IllegalAccessException e) {
            log.debug(e);
        } catch (InvocationTargetException e) {
            log.debug(e);
        } catch (NoSuchMethodException e) {
            log.debug(e);
        }
        //BeanUtils.setProperty(parent, childField, value);
    } else {
        result = identifier + "=" + "Error: No value entered.";
    }
    return result;
}

From source file:org.sakaiproject.component.common.manager.PersistableHelper.java

public void modifyPersistableFields(Persistable persistable) {
    Date now = new Date(); // time sensitive
    if (LOG.isDebugEnabled()) {
        LOG.debug("modifyPersistableFields(Persistable " + persistable + ")");
    }//from w ww.j  a va  2 s .  c o m
    if (persistable == null)
        throw new IllegalArgumentException("Illegal persistable argument passed!");

    try {
        String actor = getActor();

        PropertyUtils.setProperty(persistable, LASTMODIFIEDBY, actor);
        PropertyUtils.setProperty(persistable, LASTMODIFIEDDATE, now);
    } catch (NoSuchMethodException e) {
        LOG.error(e);
        throw new RuntimeException(e);
    } catch (IllegalAccessException e) {
        LOG.error(e);
        throw new RuntimeException(e);
    } catch (InvocationTargetException e) {
        LOG.error(e);
        throw new RuntimeException(e);
    }
}

From source file:org.sakaiproject.component.common.manager.PersistableHelper.java

public void createPersistableFields(Persistable persistable) {
    Date now = new Date(); // time sensitive
    if (LOG.isDebugEnabled()) {
        LOG.debug("modifyPersistableFields(Persistable " + persistable + ")");
    }/*from ww  w  .  java2s.c o m*/
    if (persistable == null)
        throw new IllegalArgumentException("Illegal persistable argument passed!");

    try {
        String actor = getActor();

        PropertyUtils.setProperty(persistable, LASTMODIFIEDBY, actor);
        PropertyUtils.setProperty(persistable, LASTMODIFIEDDATE, now);
        PropertyUtils.setProperty(persistable, CREATEDBY, actor);
        PropertyUtils.setProperty(persistable, CREATEDDATE, now);
    } catch (NoSuchMethodException e) {
        LOG.error(e);
        throw new RuntimeException(e);
    } catch (IllegalAccessException e) {
        LOG.error(e);
        throw new RuntimeException(e);
    } catch (InvocationTargetException e) {
        LOG.error(e);
        throw new RuntimeException(e);
    }
}

From source file:org.seasar.mayaa.impl.util.ObjectUtil.java

/**
 * ????//  w ww  .  j a v  a  2 s  . c  o m
 *
 * @param bean ??
 * @param propertyName ???
 * @param value ?
 */
public static void setProperty(Object bean, String propertyName, Object value) {
    try {
        Class propertyClass = getPropertyClass(bean, propertyName);
        if (propertyClass == null) {
            throw new NoSuchPropertyException(bean.getClass(), propertyName);
        }
        value = convert(propertyClass, value);
        PropertyUtils.setProperty(bean, propertyName, value);
    } catch (IllegalAccessException e) {
        LOG.warn(StringUtil.getMessage(ObjectUtil.class, 3, propertyName, getClassName(bean),
                getClassName(value)), e);
        throw new RuntimeException(e);
    } catch (InvocationTargetException e) {
        LOG.warn(StringUtil.getMessage(ObjectUtil.class, 3, propertyName, getClassName(bean),
                getClassName(value)), e);
        throw new RuntimeException(e.getTargetException());
    } catch (NoSuchMethodException e) {
        LOG.warn(StringUtil.getMessage(ObjectUtil.class, 3, propertyName, getClassName(bean),
                getClassName(value)), e);
        throw new RuntimeException(e);
    }
}