List of usage examples for org.apache.commons.beanutils ConvertUtils convert
public static Object convert(String values[], Class clazz)
Convert an array of specified values to an array of objects of the specified class (if possible).
For more details see ConvertUtilsBean
.
From source file:com.funtl.framework.smoke.core.modules.act.utils.Variable.java
@JsonIgnore public Map<String, Object> getVariableMap() { ConvertUtils.register(new DateConverter(), java.util.Date.class); if (StringUtils.isBlank(keys)) { return map; }// w ww . j a v a2s . com String[] arrayKey = keys.split(","); String[] arrayValue = values.split(","); String[] arrayType = types.split(","); for (int i = 0; i < arrayKey.length; i++) { String key = arrayKey[i]; String value = arrayValue[i]; String type = arrayType[i]; Class<?> targetType = Enum.valueOf(PropertyType.class, type).getValue(); Object objectValue = ConvertUtils.convert(value, targetType); map.put(key, objectValue); } return map; }
From source file:com.siberhus.tdfl.excel.DefaultExcelRowReader.java
private String getCellValueAsString(Cell cell) { Object value = getCellValue(cell); if (value == null) { return null; } else if (value instanceof Number) { return ObjectUtils.toString(value); } else if (value instanceof Date) { return ObjectUtils.toString(ConvertUtils.convert(value, String.class)); } else {//www . j av a 2 s . c o m return value.toString(); } }
From source file:com.khubla.cbean.serializer.impl.json.JSONArrayFieldSerializer.java
@Override public void deserialize(Object o, Field field, String value) throws SerializerException { try {//from w w w . ja v a 2 s. c o m final JSONArray jsonArray = new JSONArray(value); final Object od = Array.newInstance(field.getType().getComponentType(), jsonArray.length()); PropertyUtils.setProperty(o, field.getName(), od); final Class<?> componentType = field.getType().getComponentType(); if (componentType.isPrimitive()) { for (int i = 0; i < jsonArray.length(); i++) { final String v = jsonArray.getString(i); PropertyUtils.setIndexedProperty(o, field.getName(), i, ConvertUtils.convert(v, field.getType().getComponentType())); } } else { final CBean<Object> cBean = CBeanServer.getInstance().getCBean(componentType); for (int i = 0; i < jsonArray.length(); i++) { final Object co = cBean.load(new CBeanKey(jsonArray.getString(i))); PropertyUtils.setIndexedProperty(o, field.getName(), i, ConvertUtils.convert(co, field.getType().getComponentType())); } } } catch (final Exception e) { throw new SerializerException(e); } }
From source file:com.creactiviti.piper.core.MapObject.java
@Override public <T> List<T> getList(Object aKey, Class<T> aElementType) { List list = get(aKey, List.class); if (list == null) { return null; }/*w ww. j av a 2 s. c om*/ List<T> typedList = new ArrayList<>(); for (Object item : list) { if (aElementType.equals(Accessor.class) || aElementType.equals(MapObject.class)) { typedList.add((T) new MapObject((Map<String, Object>) item)); } else { typedList.add((T) ConvertUtils.convert(item, aElementType)); } } return Collections.unmodifiableList(typedList); }
From source file:com.ebiz.modules.persistence.repository.support.MyRepositoryImpl.java
@Override @Transactional//from w w w . j av a2 s . c o m public void delete(T entity) { logger.trace("----->MyRepositoryImpl.delete(T entity)"); Assert.notNull(entity, "The entity must not be null!"); Class<?> clazz = entity.getClass(); if (clazz.isAnnotationPresent(LogicallyDelete.class)) { LogicallyDelete logicallyDelete = clazz.getAnnotation(LogicallyDelete.class); Object value = ConvertUtils.convert(logicallyDelete.value(), logicallyDelete.type().getClazz()); Field field = ReflectionUtils.findField(entity.getClass(), logicallyDelete.name()); ReflectionUtils.makeAccessible(field); ReflectionUtils.setField(field, entity, value); save(entity); } else { super.delete(entity); } }
From source file:edu.scripps.fl.curves.plot.GCurvePlot.java
public void addCurve(Curve curve, FitFunction function) { double[] yValues = (double[]) ConvertUtils.convert(curve.getResponses(), double[].class); double curveMinY = NumberUtils.min(yValues); double curveMaxY = NumberUtils.max(yValues); this.minY = Math.min(minY, curveMinY); this.maxY = Math.min(maxY, curveMaxY); Data yData = DataUtil.scaleWithinRange(curveMinY, curveMaxY, yValues); double[] xValues = (double[]) ConvertUtils.convert(curve.getConcentrations(), double[].class); for (int ii = 0; ii < xValues.length; ii++) { double x = Math.log10(xValues[ii]); xValues[ii] = x;/*from w w w . ja v a 2s. com*/ } double curveMinX = NumberUtils.min(xValues); double curveMaxX = NumberUtils.max(xValues); this.minX = Math.min(minX, curveMinX); this.maxX = Math.min(maxX, curveMaxX); Data xData = DataUtil.scaleWithinRange(NumberUtils.min(xValues), NumberUtils.max(xValues), xValues); String hexColor = Integer .toHexString(((java.awt.Color) drawingSupplier.getNextPaint()).getRGB() & 0x00ffffff); StringBuffer sb = new StringBuffer(); sb.append(hexColor); while (sb.length() < 6) sb.insert(0, "0"); Color color = Color.newColor(sb.toString()); XYLine line1 = Plots.newXYLine(xData, yData, getBackgroundColor(), ""); // line1.setLineStyle(LineStyle.newLineStyle(3, 1, 0)); line1.addShapeMarkers(Shape.CIRCLE, color, 5); XYLine fittedLine = sampleFunctionToLine(curve, function, curveMinX, curveMaxX, 100); // fittedLine.setLineStyle(LineStyle.newLineStyle(3, 1, 0)); fittedLine.setColor(color); lines.add(line1); lines.add(fittedLine); }
From source file:com.fantasia.snakerflow.web.FlowController.java
@RequestMapping(value = "process") public String process(HttpServletRequest request) { Map<String, Object> params = new HashMap<String, Object>(); Enumeration<String> paraNames = request.getParameterNames(); while (paraNames.hasMoreElements()) { String element = paraNames.nextElement(); int index = element.indexOf("_"); String paraValue = request.getParameter(element); if (index == -1) { params.put(element, paraValue); } else {/*from ww w . j a v a2 s .c om*/ char type = element.charAt(0); String name = element.substring(index + 1); Object value = null; switch (type) { case 'S': value = paraValue; break; case 'I': value = ConvertUtils.convert(paraValue, Integer.class); break; case 'L': value = ConvertUtils.convert(paraValue, Long.class); break; case 'B': value = ConvertUtils.convert(paraValue, Boolean.class); break; case 'D': value = ConvertUtils.convert(paraValue, Date.class); break; case 'N': value = ConvertUtils.convert(paraValue, Double.class); break; default: value = paraValue; break; } params.put(name, value); } } String processId = request.getParameter("processId"); String orderId = request.getParameter("orderId"); String taskId = request.getParameter("taskId"); String nextOperator = request.getParameter(""); kpiWorkFlow.process(request); if (StringUtils.isEmpty(orderId) && StringUtils.isEmpty(taskId)) { facets.startAndExecute(processId, DbcContext.getUser().getUserName(), params); } else { String methodStr = request.getParameter("method"); int method; try { method = Integer.parseInt(methodStr); } catch (Exception e) { method = 0; } switch (method) { case 0:// facets.execute(taskId, DbcContext.getUser().getUserName(), params); break; case -1://?? facets.executeAndJump(taskId, DbcContext.getUser().getUserName(), params, request.getParameter("nodeName")); break; case 1:// if (StringUtils.isNotEmpty(nextOperator)) { facets.transferMajor(taskId, DbcContext.getUser().getUserName(), nextOperator.split(",")); } break; case 2://?? if (StringUtils.isNotEmpty(nextOperator)) { facets.transferAidant(taskId, DbcContext.getUser().getUserName(), nextOperator.split(",")); } break; default: facets.execute(taskId, DbcContext.getUser().getUserName(), params); break; } } String ccOperator = request.getParameter("ccoperator"); if (StringUtils.isNotEmpty(ccOperator)) { facets.getEngine().order().createCCOrder(orderId, ccOperator.split(",")); } return "redirect:/snaker/task/active"; }
From source file:net.erdfelt.android.sdkfido.configer.ConfigCmdLineParser.java
public void parse(String[] args) throws CmdLineParseException { LinkedList<String> arglist = new LinkedList<String>(); arglist.addAll(Arrays.asList(args)); // Quick Help if (arglist.contains("--" + OPT_HELP)) { usage();// ww w . j a v a 2 s.co m return; } // Configuration File Option int idx = arglist.indexOf("--" + OPT_CONFIG); if (idx >= 0) { if (idx + 1 > arglist.size()) { throw new CmdLineParseException("Expected <File> parameter for option: --" + OPT_CONFIG); } String value = arglist.get(idx + 1); File file = (File) ConvertUtils.convert(value, File.class); this.configer.setPersistFile(file); arglist.remove(idx + 1); arglist.remove(idx); } // Save Options Option boolean saveOptions = false; idx = arglist.indexOf("--" + OPT_SAVE); if (idx >= 0) { saveOptions = true; arglist.remove(idx); } // Restore from persist first. try { configer.restore(); } catch (IOException e) { throw new CmdLineParseException("Unable to load configuration: " + e.getMessage(), e); } // Set values from command line now. String value; ListIterator<String> iter = arglist.listIterator(); while (iter.hasNext()) { String arg = iter.next(); if (arg.startsWith("--")) { // Its an option. String optname = arg.substring(2); Configurable cfgrbl = configer.getConfigurable(optname); if (cfgrbl == null) { throw new CmdLineParseException("Invalid Option: " + arg); } if (!iter.hasNext()) { throw new CmdLineParseException( "Expected <" + cfgrbl.getType() + "> parameter for option: " + arg); } value = iter.next(); configer.setValue(optname, value); continue; // process next arg } // All others are considered args. addToRawArgs(arg); } // Save options (if specified) if (saveOptions) { try { configer.persist(); } catch (IOException e) { throw new CmdLineParseException("Unable to save configuration: " + e.getMessage(), e); } } }
From source file:com.greenline.hrs.admin.cache.redis.util.RedisInfoParser.java
/** * RedisInfoMapT?RedisInfoMapRedis?/* w ww.ja v a2s . c o m*/ * RedisServerInfoPO * * @param instanceType class * @param redisInfoMap Map * @param <T> * @return instanceTypeinfomapnullinfoMap?instancenullRedisServerInfoPO */ public static <T> T parserRedisInfo(Class<T> instanceType, Map<String, String> redisInfoMap) { if (instanceType == null || redisInfoMap == null || redisInfoMap.isEmpty()) { return null; } T instance = null; try { instance = instanceType.newInstance(); } catch (Exception e) { LOG.error("Instance:" + instanceType.getName(), e); return null; } Field[] fields = instanceType.getDeclaredFields(); String inputName = null; for (Field field : fields) { ParserField parserField = field.getAnnotation(ParserField.class); if (parserField != null) { inputName = parserField.inputName(); } else { inputName = field.getName(); } if (redisInfoMap.containsKey(inputName)) { field.setAccessible(true); try { field.set(instance, ConvertUtils.convert(redisInfoMap.get(inputName), field.getType())); } catch (Exception e) { LOG.error("Field:" + field.getName() + "\t|\t value:" + redisInfoMap.get(inputName), e); } } } return instance; }
From source file:com.projity.field.FieldConverter.java
public static Object fromString(String value, Class clazz) { return ConvertUtils.convert(value, clazz); }