/** * Populates this <code>PathReportSectionData</code> from the data in the <code> * BtxHistoryAttributes</code> object. * * @param attributes a <code>BtxHistoryAttributes</code>. */ public void populate(BtxHistoryAttributes attributes) { if (attributes == null) { return; } else { try { Map map = (Map) attributes.asMap(); Iterator names = map.keySet().iterator(); PropertyUtilsBean bean = new PropertyUtilsBean(); while (names.hasNext()) { String name = (String) names.next(); if (bean.isWriteable(this, name)) { Class[] params = bean.getPropertyDescriptor(this, name).getWriteMethod().getParameterTypes(); if ("java.lang.String".equalsIgnoreCase(((Class) params[0]).getName())) { bean.setSimpleProperty(this, name, map.get(name)); } else if ("java.lang.Integer".equalsIgnoreCase(((Class) params[0]).getName())) { bean.setSimpleProperty(this, name, new Integer((String) map.get(name))); } else { throw new ApiException( "Unexpected class " + ((Class) params[0]).getName() + "encountered."); } } } } catch (Exception e) { throw new ApiException(e); } } }
static { /** Configure BeanUtilsBean to use our converters and resolver. */ ConvertUtilsBean convertUtils = new ConvertUtilsBean(); // Register bean type converters convertUtils.register( new Converter() { @SuppressWarnings("rawtypes") @Override public Object convert(Class type, Object value) { if (value instanceof StringType) { return AwayState.forValue(value.toString()); } else { return null; } } }, AwayState.class); convertUtils.register( new Converter() { @SuppressWarnings("rawtypes") @Override public Object convert(Class type, Object value) { if (value instanceof StringType) { return HvacMode.forValue(value.toString()); } else { return null; } } }, HvacMode.class); convertUtils.register( new Converter() { @SuppressWarnings("rawtypes") @Override public Object convert(Class type, Object value) { if (value instanceof StringType) { return BatteryHealth.forValue(value.toString()); } else { return null; } } }, BatteryHealth.class); convertUtils.register( new Converter() { @SuppressWarnings("rawtypes") @Override public Object convert(Class type, Object value) { if (value instanceof StringType) { return AlarmState.forValue(value.toString()); } else { return null; } } }, AlarmState.class); convertUtils.register( new Converter() { @SuppressWarnings("rawtypes") @Override public Object convert(Class type, Object value) { if (value instanceof StringType) { return ColorState.forValue(value.toString()); } else { return null; } } }, ColorState.class); convertUtils.register( new Converter() { @SuppressWarnings("rawtypes") @Override public Object convert(Class type, Object value) { if (value instanceof DecimalType) { return ((DecimalType) value).intValue(); } else { return null; } } }, Integer.class); convertUtils.register( new Converter() { @SuppressWarnings("rawtypes") @Override public Object convert(Class type, Object value) { if (value instanceof OnOffType) { return ((OnOffType) value) == OnOffType.ON; } else { return null; } } }, Boolean.class); convertUtils.register( new Converter() { @SuppressWarnings("rawtypes") @Override public Object convert(Class type, Object value) { return value.toString(); } }, String.class); propertyUtils = new PropertyUtilsBean(); propertyUtils.setResolver(new DataModelPropertyResolver()); beanUtils = new BeanUtilsBean(convertUtils, propertyUtils); }
/** * Return a JavaBean property by name. * * @param name the named property to return * @return the named property's value * @see PropertyUtils#getProperty() * @throws IllegalAccessException if the caller does not have access to the property accessor * method * @throws InvocationTargetException if the property accessor method throws an exception * @throws NoSuchMethodException if the accessor method for this property cannot be found */ public Object getProperty(String name) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException { return propertyUtils.getProperty(this, name); }
@SuppressWarnings("unchecked") @Override protected ModelAndView handleRequestInternal( HttpServletRequest request, HttpServletResponse response) throws Exception { UserDO user = (UserDO) request.getSession().getAttribute("user"); String id = request.getParameter("clusterId"); long clusterId = -1; if (null != id) { clusterId = Long.parseLong(id); } List<ClusterDO> cList = xmlAccesser.getClusterDAO().listAllCluster(); List<Map<String, Object>> clusterList = new ArrayList<Map<String, Object>>(); ListSortUtil.sortClusterByName(cList); for (ClusterDO e : cList) { Map<String, Object> map = new HashMap<String, Object>(); map.put("id", e.getId()); map.put("name", CobarStringUtil.htmlEscapedString(e.getName())); clusterList.add(map); } List<CobarDO> cobarList = null; if (null != cList && cList.size() > 0) { if (-1 == clusterId) { clusterId = cList.get(0).getId(); cobarList = xmlAccesser.getCobarDAO().getCobarList(clusterId); } else { cobarList = xmlAccesser.getCobarDAO().getCobarList(clusterId); } } List<Map<String, Object>> cobarListMap = new ArrayList<Map<String, Object>>(); PropertyUtilsBean util = new PropertyUtilsBean(); if (null != cobarList) { ListSortUtil.sortCobarByName(cobarList); for (CobarDO c : cobarList) { CobarAdapterDAO perf = cobarAccesser.getAccesser(c.getId()); Map<String, Object> map; try { map = util.describe(c); } catch (Exception ex) { throw new RuntimeException(ex); } map.remove("class"); map.remove("name"); map.put("name", CobarStringUtil.htmlEscapedString(c.getName())); if (ConstantDefine.ACTIVE.equals(c.getStatus())) { if (!perf.checkConnection()) { map.remove("status"); map.put("status", ConstantDefine.ERROR); map.put("reloadTime", ""); map.put("rollbackTime", ""); } else { ServerStatus ss = perf.getServerStatus(); String rollbackTime = "NO"; String reloadTime = FormatUtil.fromMilliseconds2String(ss.getReloadTime()); if (ss.getRollbackTime() != -1) { rollbackTime = FormatUtil.fromMilliseconds2String(ss.getRollbackTime()); } map.put("reloadTime", reloadTime); map.put("rollbackTime", rollbackTime); } } else { map.put("reloadTime", ""); map.put("rollbackTime", ""); } cobarListMap.add(map); } } return new ModelAndView( "c_propertyReload", new FluenceHashMap<String, Object>() .putKeyValue("cList", clusterList) .putKeyValue("cobarList", cobarListMap) .putKeyValue("clusterId", clusterId) .putKeyValue("user", user)); }