List of usage examples for java.lang.reflect InvocationTargetException InvocationTargetException
public InvocationTargetException(Throwable target, String s)
From source file:org.locationtech.udig.processingtoolbox.tools.MergeFeaturesDialog.java
@Override public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { monitor.beginTask(String.format(Messages.Task_Executing, windowTitle), 5); try {/*ww w .ja v a2 s .co m*/ monitor.worked(increment); List<SimpleFeatureCollection> fcList = new ArrayList<SimpleFeatureCollection>(); for (TableItem item : inputTable.getItems()) { if (item.getChecked()) { fcList.add(MapUtils.getFeatures((ILayer) item.getData())); } } String outputName = FilenameUtils.getBaseName(locationView.getFile()); MergeOp op = new MergeOp(outputName); op.setOutputDataStore(locationView.getDataStore()); SimpleFeatureSource sfs = op.merge(fcList, templateFc, monitor); if (sfs != null) { MapUtils.addFeaturesToMap(map, new File(locationView.getFile()), outputName); } else { ToolboxPlugin.log(windowTitle + " : Failed to merge : " + outputName); //$NON-NLS-1$ } monitor.worked(increment); } catch (Exception e) { ToolboxPlugin.log(e.getMessage()); throw new InvocationTargetException(e.getCause(), e.getMessage()); } finally { monitor.done(); } }
From source file:org.locationtech.udig.processingtoolbox.tools.TextfileToPointDialog.java
@Override public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { monitor.beginTask(Messages.Task_Running, 100); try {/*www. ja v a 2 s . co m*/ monitor.setTaskName(String.format(Messages.Task_Executing, windowTitle)); monitor.worked(increment); boolean headerFirst = chkHeader.getSelection(); List<TextColumn> schema = getTextColumns(); CoordinateReferenceSystem sourceCRS = null; CoordinateReferenceSystem targetCRS = null; if (txtSourceCrs.getData() != null) { sourceCRS = (CoordinateReferenceSystem) txtSourceCrs.getData(); } if (txtTargetCrs.getData() != null) { targetCRS = (CoordinateReferenceSystem) txtTargetCrs.getData(); } String outputName = FilenameUtils.removeExtension(FilenameUtils.getName(locationView.getFile())); monitor.subTask(String.format(Messages.Task_Executing, windowTitle)); TextfileToPointOperation process = new TextfileToPointOperation(); ShapeExportOperation exportOp = new ShapeExportOperation(); exportOp.setOutputDataStore(locationView.getDataStore()); exportOp.setOutputTypeName(outputName); SimpleFeatureCollection features = exportOp.execute( process.execute(textFile, charset, delimiter, headerFirst, schema, sourceCRS, targetCRS)) .getFeatures(); error = process.getError(); monitor.worked(increment); if (features != null) { monitor.setTaskName(Messages.Task_AddingLayer); addFeaturesToMap(map, locationView.getFile(), outputName); monitor.worked(increment); } } catch (Exception e) { ToolboxPlugin.log(e.getMessage()); throw new InvocationTargetException(e.getCause(), e.getMessage()); } finally { ToolboxPlugin.log(String.format(Messages.Task_Completed, windowTitle)); monitor.done(); } }
From source file:org.pentaho.di.ui.repository.dialog.RepositoryExportProgressDialog.java
public boolean open() { boolean retval = true; final List<ExportFeedback> list = new ArrayList<ExportFeedback>(); IRepositoryExporter tmpExporter = null; try {/*from ww w . j a v a 2 s . co m*/ tmpExporter = rep.getExporter(); } catch (KettleException e) { log.logError(RepositoryExportProgressDialog.class.toString(), "Error creating repository: " + e.toString()); log.logError(Const.getStackTracker(e)); new ErrorDialog(shell, BaseMessages.getString(PKG, "RepositoryExportDialog.ErrorExport.Title"), BaseMessages.getString(PKG, "RepositoryExportDialog.ErrorExport.Message"), e); return false; } final IRepositoryExporter exporter = tmpExporter; // this hack is only to support dog-nail build process for <...> // and keep base interfaces without changes - getExporter should // directly return IRepositoryExporterFeedback. final boolean isFeedback = (exporter instanceof IRepositoryExporterFeedback) ? true : false; IRunnableWithProgress op = new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { try { exporter.setImportRulesToValidate(importRules); ProgressMonitorAdapter pMonitor = new ProgressMonitorAdapter(monitor); if (isFeedback) { IRepositoryExporterFeedback fExporter = IRepositoryExporterFeedback.class.cast(exporter); List<ExportFeedback> ret = fExporter.exportAllObjectsWithFeedback(pMonitor, filename, dir, "all"); list.addAll(ret); } else { exporter.exportAllObjects(pMonitor, filename, dir, "all"); } } catch (KettleException e) { throw new InvocationTargetException(e, BaseMessages.getString(PKG, "RepositoryExportDialog.Error.CreateUpdate", Const.getStackTracker(e))); } } }; try { ProgressMonitorDialog pmd = new ProgressMonitorDialog(shell); pmd.run(true, true, op); if (!pmd.getProgressMonitor().isCanceled() && isFeedback) { // show some results here. IRepositoryExporterFeedback fExporter = IRepositoryExporterFeedback.class.cast(exporter); showExportResultStatus(list, fExporter.isRulesViolation()); } } catch (InvocationTargetException e) { log.logError(RepositoryExportProgressDialog.class.toString(), "Error creating repository: " + e.toString()); log.logError(Const.getStackTracker(e)); new ErrorDialog(shell, BaseMessages.getString(PKG, "RepositoryExportDialog.ErrorExport.Title"), BaseMessages.getString(PKG, "RepositoryExportDialog.ErrorExport.Message"), e); retval = false; } catch (InterruptedException e) { log.logError(RepositoryExportProgressDialog.class.toString(), "Error creating repository: " + e.toString()); log.logError(Const.getStackTracker(e)); new ErrorDialog(shell, BaseMessages.getString(PKG, "RepositoryExportDialog.ErrorExport.Title"), BaseMessages.getString(PKG, "RepositoryExportDialog.ErrorExport.Message"), e); retval = false; } return retval; }
From source file:utils.beanUtils.JIMBeanUtilsBean.java
/** * //ww w. j a v a 2s .c o m * ------ * MODIFIED METHOD, THIS JAVADOC IS NOT COMPLETE * ------ * * <p>Copy the specified property value to the specified destination bean, * performing any type conversion that is required. If the specified * bean does not have a property of the specified name, or the property * is read only on the destination bean, return without * doing anything. If you have custom destination property types, register * {@link Converter}s for them by calling the <code>register()</code> * method of {@link ConvertUtils}.</p> * * <p><strong>IMPLEMENTATION RESTRICTIONS</strong>:</p> * <ul> * <li>Does not support destination properties that are indexed, * but only an indexed setter (as opposed to an array setter) * is available.</li> * <li>Does not support destination properties that are mapped, * but only a keyed setter (as opposed to a Map setter) * is available.</li> * <li>The desired property type of a mapped setter cannot be * determined (since Maps support any data type), so no conversion * will be performed.</li> * </ul> * * @param bean Bean on which setting is to be performed * @param name Property name (can be nested/indexed/mapped/combo) * @param value Value to be set * * @exception IllegalAccessException if the caller does not have * access to the property accessor method * @exception InvocationTargetException if the property accessor method * throws an exception */ protected void copyProperty(Object bean, String name, Object value) throws IllegalAccessException, InvocationTargetException { // Trace logging (if enabled) if (log.isTraceEnabled()) { StringBuffer sb = new StringBuffer(" copyProperty("); sb.append(bean); sb.append(", "); sb.append(name); sb.append(", "); if (value == null) { sb.append("<NULL>"); } else if (value instanceof String) { sb.append((String) value); } else if (value instanceof String[]) { String values[] = (String[]) value; sb.append('['); for (int i = 0; i < values.length; i++) { if (i > 0) { sb.append(','); } sb.append(values[i]); } sb.append(']'); } else { sb.append(value.toString()); } sb.append(')'); log.trace(sb.toString()); } //TODO: form here to next 'TODO' the code has not been revised // Resolve any nested expression to get the actual target bean Object target = bean; int delim = name.lastIndexOf(PropertyUtils.NESTED_DELIM); if (delim >= 0) { try { target = getPropertyUtils().getProperty(bean, name.substring(0, delim)); } catch (NoSuchMethodException e) { return; // Skip this property setter } name = name.substring(delim + 1); if (log.isTraceEnabled()) { log.trace(" Target bean = " + target); log.trace(" Target name = " + name); } } // Declare local variables we will require String propName = null; // Simple name of target property Class type = null; // Java type of target property int index = -1; // Indexed subscript value (if any) String key = null; // Mapped key value (if any) // Calculate the target property name, index, and key values propName = name; int i = propName.indexOf(PropertyUtils.INDEXED_DELIM); if (i >= 0) { int k = propName.indexOf(PropertyUtils.INDEXED_DELIM2); try { index = Integer.parseInt(propName.substring(i + 1, k)); } catch (NumberFormatException e) { ; } propName = propName.substring(0, i); } int j = propName.indexOf(PropertyUtils.MAPPED_DELIM); if (j >= 0) { int k = propName.indexOf(PropertyUtils.MAPPED_DELIM2); try { key = propName.substring(j + 1, k); } catch (IndexOutOfBoundsException e) { ; } propName = propName.substring(0, j); } //TODO: until here (from last 'TODO') the code has not been revised // Calculate the target property type if (target instanceof DynaBean) { throw new IllegalArgumentException("this method can not work with DynaBean"); } else { PropertyDescriptor descriptor = null; try { descriptor = getPropertyUtils().getPropertyDescriptor(target, name); if (descriptor == null) { return; // Skip this property setter } } catch (NoSuchMethodException e) { return; // Skip this property setter } type = descriptor.getPropertyType(); if (type == null) { // Most likely an indexed setter on a POJB only if (log.isTraceEnabled()) { log.trace(" target type for property '" + propName + "' is null, so skipping ths setter"); } return; } } if (log.isTraceEnabled()) { log.trace(" target propName=" + propName + ", type=" + type + ", index=" + index + ", key=" + key); } //TODO: form here to next 'TODO' the code has not been revised // Convert the specified value to the required type and store it if (index >= 0) { // Destination must be indexed Converter converter = getConvertUtils().lookup(type.getComponentType()); if (converter != null) { log.trace(" USING CONVERTER " + converter); value = converter.convert(type, value); } try { getPropertyUtils().setIndexedProperty(target, propName, index, value); } catch (NoSuchMethodException e) { throw new InvocationTargetException(e, "Cannot set " + propName); } } else if (key != null) { // Destination must be mapped // Maps do not know what the preferred data type is, // so perform no conversions at all // FIXME - should we create or support a TypedMap? try { getPropertyUtils().setMappedProperty(target, propName, key, value); } catch (NoSuchMethodException e) { throw new InvocationTargetException(e, "Cannot set " + propName); } // TODO: until here (from last 'TODO') the code has not been revised } else { if (isFromPojoCopy() && !Persistent.class.isInstance(value) && !NonPersistent.class.isInstance(value)) { try { Object oldValue = getPropertyUtils().getProperty(target, propName); if (!(oldValue == null || (String.class.isInstance(oldValue) && ((String) oldValue).equalsIgnoreCase("")))) { // log.error("****** (1) comprobar si hay que quitar estas lneas de cdigo, ver diagnet *****"); return; } } catch (NoSuchMethodException e2) { } } // Destination must be simple Converter converter = getConvertUtils().lookup(type); if (converter != null) { log.trace(" USING CONVERTER " + converter); if (propName.equals("year")) { //chapuza para que los aos no salgan formateados value = value.toString(); } else { value = converter.convert(type, value); } } try { getPropertyUtils().setSimpleProperty(target, propName, value); } catch (Exception e) { try { //it is not a simple property, so it should be recursivelly copied Object originalValue = getPropertyUtils().getProperty(target, propName); if (originalValue == null) { //if it is null it should be created Class clazz = getPropertyUtils().getPropertyType(target, propName); originalValue = clazz.newInstance(); getPropertyUtils().setProperty(target, propName, originalValue); } if (target instanceof bussineslogic.objects.Personal) { if (name.equals("country") && (originalValue instanceof bussineslogic.objects.Country) && (value instanceof presentation.formbeans.objects.Country_IDForm)) { bussineslogic.objects.Country newCountry = new bussineslogic.objects.Country(); newCountry.setCode( ((presentation.formbeans.objects.Country_IDForm) value).getCountrycode()); ((bussineslogic.objects.Personal) target).setCountry(newCountry); } else if (name.equals("birth_country") && (originalValue instanceof bussineslogic.objects.Country) && (value instanceof presentation.formbeans.objects.Country_IDForm)) { bussineslogic.objects.Country newCountry = new bussineslogic.objects.Country(); newCountry.setCode( ((presentation.formbeans.objects.Country_IDForm) value).getCountrycode()); ((bussineslogic.objects.Personal) target).setBirth_country(newCountry); } else if (name.equals("end_of_contract_country") && (originalValue instanceof bussineslogic.objects.Country) && (value instanceof presentation.formbeans.objects.Country_IDForm)) { bussineslogic.objects.Country newCountry = new bussineslogic.objects.Country(); newCountry.setCode( ((presentation.formbeans.objects.Country_IDForm) value).getCountrycode()); ((bussineslogic.objects.Personal) target).setEnd_of_contract_country(newCountry); } else if (name.equals("nationality") && (originalValue instanceof bussineslogic.objects.Nationality) && (value instanceof presentation.formbeans.objects.Nationality_IDForm)) { bussineslogic.objects.Nationality newNationality = new bussineslogic.objects.Nationality(); newNationality.setCode(((presentation.formbeans.objects.Nationality_IDForm) value) .getNationalitycode()); ((bussineslogic.objects.Personal) target).setNationality(newNationality); } else if (name.equals("nationality_2") && (originalValue instanceof bussineslogic.objects.Nationality) && (value instanceof presentation.formbeans.objects.Nationality_IDForm)) { bussineslogic.objects.Nationality newNationality = new bussineslogic.objects.Nationality(); newNationality.setCode(((presentation.formbeans.objects.Nationality_IDForm) value) .getNationalitycode()); ((bussineslogic.objects.Personal) target).setNationality_2(newNationality); } else { copyProperties(originalValue, value); } } else if (target instanceof bussineslogic.objects.Alumni_personal) { if (name.equals("nationality") && (originalValue instanceof bussineslogic.objects.Nationality) && (value instanceof presentation.formbeans.objects.Nationality_IDForm)) { bussineslogic.objects.Nationality newNationality = new bussineslogic.objects.Nationality(); newNationality.setCode(((presentation.formbeans.objects.Nationality_IDForm) value) .getNationalitycode()); ((bussineslogic.objects.Alumni_personal) target).setNationality(newNationality); } else if (name.equals("nationality_2") && (originalValue instanceof bussineslogic.objects.Nationality) && (value instanceof presentation.formbeans.objects.Nationality_IDForm)) { bussineslogic.objects.Nationality newNationality = new bussineslogic.objects.Nationality(); newNationality.setCode(((presentation.formbeans.objects.Nationality_IDForm) value) .getNationalitycode()); ((bussineslogic.objects.Alumni_personal) target).setNationality_2(newNationality); } else { copyProperties(originalValue, value); } } else if (target instanceof bussineslogic.objects.Professional) { if (name.equals("payroll_institution") && (originalValue instanceof bussineslogic.objects.Payroll_institution) && (value instanceof presentation.formbeans.objects.Payroll_institution_IDForm)) { bussineslogic.objects.Payroll_institution newInstitution = new bussineslogic.objects.Payroll_institution(); newInstitution .setCode(((presentation.formbeans.objects.Payroll_institution_IDForm) value) .getPayroll_institutioncode()); ((bussineslogic.objects.Professional) target).setPayroll_institution(newInstitution); } else if (name.equals("payroll_institution_2") && (originalValue instanceof bussineslogic.objects.Payroll_institution) && (value instanceof presentation.formbeans.objects.Payroll_institution_IDForm)) { bussineslogic.objects.Payroll_institution newInstitution = new bussineslogic.objects.Payroll_institution(); newInstitution .setCode(((presentation.formbeans.objects.Payroll_institution_IDForm) value) .getPayroll_institutioncode()); ((bussineslogic.objects.Professional) target).setPayroll_institution_2(newInstitution); } else if (name.equals("professional_unit") && (originalValue instanceof bussineslogic.objects.Unit) && (value instanceof presentation.formbeans.objects.Unit_IDForm)) { bussineslogic.objects.Unit newUnit = new bussineslogic.objects.Unit(); newUnit.setCode(((presentation.formbeans.objects.Unit_IDForm) value).getUnitcode()); ((bussineslogic.objects.Professional) target).setProfessional_unit(newUnit); } else if (name.equals("professional_unit_3") && (originalValue instanceof bussineslogic.objects.Unit) && (value instanceof presentation.formbeans.objects.Unit_IDForm)) { bussineslogic.objects.Unit newUnit = new bussineslogic.objects.Unit(); newUnit.setCode(((presentation.formbeans.objects.Unit_IDForm) value).getUnitcode()); ((bussineslogic.objects.Professional) target).setProfessional_unit_3(newUnit); } else if (name.equals("professional_unit_4") && (originalValue instanceof bussineslogic.objects.Unit) && (value instanceof presentation.formbeans.objects.Unit_IDForm)) { bussineslogic.objects.Unit newUnit = new bussineslogic.objects.Unit(); newUnit.setCode(((presentation.formbeans.objects.Unit_IDForm) value).getUnitcode()); ((bussineslogic.objects.Professional) target).setProfessional_unit_4(newUnit); } else if (name.equals("research_group") && (originalValue instanceof bussineslogic.objects.Research_group) && (value instanceof presentation.formbeans.objects.Research_group_IDForm)) { bussineslogic.objects.Research_group newResearchGroup = new bussineslogic.objects.Research_group(); newResearchGroup.setCode(((presentation.formbeans.objects.Research_group_IDForm) value) .getResearch_groupcode()); ((bussineslogic.objects.Professional) target).setResearch_group(newResearchGroup); } else if (name.equals("research_group_2") && (originalValue instanceof bussineslogic.objects.Research_group) && (value instanceof presentation.formbeans.objects.Research_group_IDForm)) { bussineslogic.objects.Research_group newResearchGroup = new bussineslogic.objects.Research_group(); newResearchGroup.setCode(((presentation.formbeans.objects.Research_group_IDForm) value) .getResearch_groupcode()); ((bussineslogic.objects.Professional) target).setResearch_group_2(newResearchGroup); } else if (name.equals("research_group_3") && (originalValue instanceof bussineslogic.objects.Research_group) && (value instanceof presentation.formbeans.objects.Research_group_IDForm)) { bussineslogic.objects.Research_group newResearchGroup = new bussineslogic.objects.Research_group(); newResearchGroup.setCode(((presentation.formbeans.objects.Research_group_IDForm) value) .getResearch_groupcode()); ((bussineslogic.objects.Professional) target).setResearch_group_3(newResearchGroup); } else if (name.equals("research_group_4") && (originalValue instanceof bussineslogic.objects.Research_group) && (value instanceof presentation.formbeans.objects.Research_group_IDForm)) { bussineslogic.objects.Research_group newResearchGroup = new bussineslogic.objects.Research_group(); newResearchGroup.setCode(((presentation.formbeans.objects.Research_group_IDForm) value) .getResearch_groupcode()); ((bussineslogic.objects.Professional) target).setResearch_group_4(newResearchGroup); } else { copyProperties(originalValue, value); } } else { copyProperties(originalValue, value); } } catch (Exception e1) { throw new InvocationTargetException(e, "Cannot get " + propName + " of " + target); } } } }
From source file:utils.beanUtils.JIMBeanUtilsBean.java
/** * <p>Set the specified property value, performing type conversions as * required to conform to the type of the destination property.</p> * * <p>If the property is read only then the method returns * without throwing an exception.</p> * * <p>If <code>null</code> is passed into a property expecting a primitive value, * then this will be converted as if it were a <code>null</code> string.</p> * * <p><strong>WARNING</strong> - The logic of this method is customized * to meet the needs of <code>populate()</code>, and is probably not what * you want for general property copying with type conversion. For that * purpose, check out the <code>copyProperty()</code> method instead.</p> * * <p><strong>WARNING</strong> - PLEASE do not modify the behavior of this * method without consulting with the Struts developer community. There * are some subtleties to its functionality that are not documented in the * Javadoc description above, yet are vital to the way that Struts utilizes * this method.</p>/*from w ww . j a v a 2 s .c o m*/ * * @param bean Bean on which setting is to be performed * @param name Property name (can be nested/indexed/mapped/combo) * @param value Value to be set * * @exception IllegalAccessException if the caller does not have * access to the property accessor method * @exception InvocationTargetException if the property accessor method * throws an exception */ protected void setProperty(Object bean, String name, Object value) throws IllegalAccessException, InvocationTargetException { // Trace logging (if enabled) if (log.isTraceEnabled()) { StringBuffer sb = new StringBuffer(" setProperty("); sb.append(bean); sb.append(", "); sb.append(name); sb.append(", "); if (value == null) { sb.append("<NULL>"); } else if (value instanceof String) { sb.append((String) value); } else if (value instanceof String[]) { String values[] = (String[]) value; sb.append('['); for (int i = 0; i < values.length; i++) { if (i > 0) { sb.append(','); } sb.append(values[i]); } sb.append(']'); } else { sb.append(value.toString()); } sb.append(')'); log.trace(sb.toString()); } // Resolve any nested expression to get the actual target bean Object target = bean; int delim = findLastNestedIndex(name); if (delim >= 0) { try { target = getPropertyUtils().getProperty(bean, name.substring(0, delim)); } catch (NoSuchMethodException e) { return; // Skip this property setter } name = name.substring(delim + 1); if (log.isTraceEnabled()) { log.trace(" Target bean = " + target); log.trace(" Target name = " + name); } } // Declare local variables we will require String propName = null; // Simple name of target property Class type = null; // Java type of target property int index = -1; // Indexed subscript value (if any) String key = null; // Mapped key value (if any) // Calculate the property name, index, and key values propName = name; int i = propName.indexOf(PropertyUtils.INDEXED_DELIM); if (i >= 0) { int k = propName.indexOf(PropertyUtils.INDEXED_DELIM2); try { index = Integer.parseInt(propName.substring(i + 1, k)); } catch (NumberFormatException e) { ; } propName = propName.substring(0, i); } int j = propName.indexOf(PropertyUtils.MAPPED_DELIM); if (j >= 0) { int k = propName.indexOf(PropertyUtils.MAPPED_DELIM2); try { key = propName.substring(j + 1, k); } catch (IndexOutOfBoundsException e) { ; } propName = propName.substring(0, j); } // Calculate the property type if (target instanceof DynaBean) { DynaClass dynaClass = ((DynaBean) target).getDynaClass(); DynaProperty dynaProperty = dynaClass.getDynaProperty(propName); if (dynaProperty == null) { return; // Skip this property setter } type = dynaProperty.getType(); } else { PropertyDescriptor descriptor = null; try { descriptor = getPropertyUtils().getPropertyDescriptor(target, name); if (descriptor == null) { return; // Skip this property setter } } catch (NoSuchMethodException e) { return; // Skip this property setter } if (descriptor instanceof MappedPropertyDescriptor) { if (((MappedPropertyDescriptor) descriptor).getMappedWriteMethod() == null) { if (log.isDebugEnabled()) { log.debug("Skipping read-only property"); } return; // Read-only, skip this property setter } type = ((MappedPropertyDescriptor) descriptor).getMappedPropertyType(); } else if (descriptor instanceof IndexedPropertyDescriptor) { if (((IndexedPropertyDescriptor) descriptor).getIndexedWriteMethod() == null) { if (log.isDebugEnabled()) { log.debug("Skipping read-only property"); } return; // Read-only, skip this property setter } type = ((IndexedPropertyDescriptor) descriptor).getIndexedPropertyType(); } else { if (descriptor.getWriteMethod() == null) { if (log.isDebugEnabled()) { log.debug("Skipping read-only property"); } return; // Read-only, skip this property setter } type = descriptor.getPropertyType(); } } // Convert the specified value to the required type Object newValue = null; if (type.isArray() && (index < 0)) { // Scalar value into array if (value == null) { String values[] = new String[1]; values[0] = (String) value; newValue = getConvertUtils().convert((String[]) values, type); } else if (value instanceof String) { String values[] = new String[1]; values[0] = (String) value; newValue = getConvertUtils().convert((String[]) values, type); } else if (value instanceof String[]) { newValue = getConvertUtils().convert((String[]) value, type); } else { newValue = value; } } else if (type.isArray()) { // Indexed value into array if (value instanceof String) { newValue = getConvertUtils().convert((String) value, type.getComponentType()); } else if (value instanceof String[]) { newValue = getConvertUtils().convert(((String[]) value)[0], type.getComponentType()); } else { newValue = value; } } else { // Value into scalar if ((value instanceof String) || (value == null)) { newValue = getConvertUtils().convert((String) value, type); } else if (value instanceof String[]) { newValue = getConvertUtils().convert(((String[]) value)[0], type); } else if (getConvertUtils().lookup(value.getClass()) != null) { newValue = getConvertUtils().convert(value.toString(), type); } else { newValue = value; } } // Invoke the setter method try { if (index >= 0) { getPropertyUtils().setIndexedProperty(target, propName, index, newValue); } else if (key != null) { getPropertyUtils().setMappedProperty(target, propName, key, newValue); } else { getPropertyUtils().setProperty(target, propName, newValue); } } catch (NoSuchMethodException e) { throw new InvocationTargetException(e, "Cannot set " + propName); } }