List of usage examples for org.apache.commons.beanutils PropertyUtilsBean PropertyUtilsBean
public PropertyUtilsBean()
From source file:name.ikysil.beanpathdsl.sandbox.describe.Main.java
/** * @param args the command line arguments *//*ww w .j a va2 s .c o m*/ public static void main(String[] args) { PropertyUtilsBean propertyUtilsBean = new PropertyUtilsBean(); Reflections reflections = new Reflections(TestBean.class, new SubTypesScanner(false)); Set<Class<?>> classes = reflections.getSubTypesOf(Object.class); for (Class<?> clazz : classes) { System.out.println(String.format("Class name: %s", clazz.getName())); System.out.println(String.format("Class simple name: %s", clazz.getSimpleName())); System.out.println(String.format("Class canonical name: %s", clazz.getCanonicalName())); PropertyDescriptor[] pds = propertyUtilsBean.getPropertyDescriptors(clazz); for (PropertyDescriptor pd : pds) { System.out.println(String.format(" Property name: %s", pd.getName())); Class<?> pc = pd.getPropertyType(); System.out.println(String.format(" Class name: %s", pc.getName())); System.out.println(String.format(" Class simple name: %s", pc.getSimpleName())); System.out.println(String.format(" Class canonical name: %s", pc.getCanonicalName())); } } }
From source file:BeanUtilsExampleV4.java
public static void main(String args[]) throws Exception { BeanUtilsExampleV4 diff = new BeanUtilsExampleV4(); Actor actor = diff.prepareData();// ww w. j a v a 2s .c o m ConvertUtilsBean convertUtilsBean = new ConvertUtilsBean(); convertUtilsBean.deregister(String.class); convertUtilsBean.register(new MyStringConverter(), String.class); convertUtilsBean.deregister(Long.class); convertUtilsBean.register(new MyLongConverter(), Long.class); convertUtilsBean.register(new MyLongConverter(), Long.TYPE); BeanUtilsBean beanUtilsBean = new BeanUtilsBean(convertUtilsBean, new PropertyUtilsBean()); System.err.println("==== Values before calling describe ==== "); System.err.println("By PropertyUtils: " + PropertyUtils.getProperty(actor, "name")); System.err.println("By BeanUtils: " + beanUtilsBean.getProperty(actor, "name")); System.err.println(beanUtilsBean.getProperty(actor, "worth")); Map describedData = beanUtilsBean.describe(actor); // check the map System.err.println("==== Values in Map ==== "); System.err.println(describedData.get("name")); System.err.println(describedData.get("worth")); // create a new Actor Bean Actor newActor = new Actor(); beanUtilsBean.populate(newActor, describedData); System.err.println("==== Values after calling populate ==== "); System.err.println(beanUtilsBean.getProperty(newActor, "name")); System.err.println(beanUtilsBean.getProperty(newActor, "worth")); }
From source file:com.eryansky.core.excelTools.ExcelUtils.java
/** * JavaBeanMap// w w w . j av a 2 s . c o m * @param obj * @return */ public static Map<String, Object> beanToMap(Object obj) { Map<String, Object> params = new HashMap<String, Object>(0); try { PropertyUtilsBean propertyUtilsBean = new PropertyUtilsBean(); PropertyDescriptor[] descriptors = propertyUtilsBean.getPropertyDescriptors(obj); for (int i = 0; i < descriptors.length; i++) { String name = descriptors[i].getName(); if (!StringUtils.equals(name, "class")) { params.put(name, propertyUtilsBean.getNestedProperty(obj, name)); } } } catch (Exception e) { e.printStackTrace(); } return params; }
From source file:com.teamsun.framework.util.BeanUtils.java
public BeanUtils() { super(new ConvertUtilsBean(), new PropertyUtilsBean()); }
From source file:com.rundeck.plugin.resources.puppetdb.Mapper.java
public Mapper() { this.propertyUtilsBean = new PropertyUtilsBean(); }
From source file:com.alibaba.cobar.manager.web.screen.EditClusterPage.java
@SuppressWarnings("unchecked") @Override//from www. jav a 2 s. c o m protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { long clusterId = 0; try { clusterId = Long.parseLong(request.getParameter("clusterId").trim()); } catch (Exception e) { throw new IllegalArgumentException( "parameter 'clusterId' is invalid:" + request.getParameter("clusterId")); } ClusterDO cluster = xmlAccesser.getClusterDAO().getClusterById(clusterId); Map<String, Object> clusterMap = new PropertyUtilsBean().describe(cluster); clusterMap.remove("class"); clusterMap.remove("name"); clusterMap.remove("deployDesc"); clusterMap.put("name", CobarStringUtil.htmlEscapedString(cluster.getName())); clusterMap.put("deployDesc", CobarStringUtil.htmlEscapedString(cluster.getDeployDesc())); return new ModelAndView("m_editCluster", new FluenceHashMap<String, Object>().putKeyValue("cluster", clusterMap)); }
From source file:com.alibaba.cobar.manager.web.screen.EditCobarPage.java
@SuppressWarnings("unchecked") @Override/*w ww . java 2 s.c o m*/ protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { long cobarId = 0; try { cobarId = Long.parseLong(request.getParameter("cobarId").trim()); } catch (Exception e) { throw new IllegalArgumentException("parameter 'cobarId' is invalid:" + request.getParameter("cobarId")); } CobarDO cobar = xmlAccesser.getCobarDAO().getCobarById(cobarId); Map<String, Object> cobarMap = new PropertyUtilsBean().describe(cobar); cobarMap.remove("class"); cobarMap.remove("name"); cobarMap.put("name", CobarStringUtil.htmlEscapedString(cobar.getName())); List<ClusterDO> cList = xmlAccesser.getClusterDAO().listAllCluster(); List<Map<String, Object>> clusterList = new ArrayList<Map<String, Object>>(); 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); } return new ModelAndView("m_editCobar", new FluenceHashMap<String, Object>() .putKeyValue("cluList", clusterList).putKeyValue("cobar", cobarMap)); }
From source file:com.alibaba.cobar.manager.web.screen.MClusterListScreen.java
@SuppressWarnings("unchecked") @Override//from ww w . ja va 2s .c om protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { UserDO user = (UserDO) request.getSession().getAttribute("user"); List<ClusterDO> list = xmlAccesser.getClusterDAO().listAllCluster(); List<Map<String, Object>> clusterList = new ArrayList<Map<String, Object>>(); ListSortUtil.sortClusterBySortId(list); PropertyUtilsBean util = new PropertyUtilsBean(); for (ClusterDO e : list) { int count = xmlAccesser.getCobarDAO().getCobarList(e.getId(), ConstantDefine.ACTIVE).size(); count += xmlAccesser.getCobarDAO().getCobarList(e.getId(), ConstantDefine.IN_ACTIVE).size(); Map<String, Object> map; try { map = util.describe(e); } catch (Exception ex) { throw new RuntimeException(ex); } map.remove("class"); map.remove("name"); map.remove("deployDesc"); map.put("name", CobarStringUtil.htmlEscapedString(e.getName())); map.put("deployContact", CobarStringUtil.htmlEscapedString(e.getDeployContact())); map.put("cobarNum", count); clusterList.add(map); } return new ModelAndView("m_clusterList", new FluenceHashMap<String, Object>() .putKeyValue("clusterList", clusterList).putKeyValue("user", user)); }
From source file:gr.abiss.calipso.jpasearch.json.serializer.FormSchemaSerializer.java
@Override public void serialize(FormSchema schema, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonGenerationException { try {//w w w . ja v a2 s. c o m Class domainClass = schema.getDomainClass(); if (null == domainClass) { throw new RuntimeException("formSchema has no domain class set"); } else { jgen.writeStartObject(); PropertyDescriptor[] descriptors = new PropertyUtilsBean().getPropertyDescriptors(domainClass); for (int i = 0; i < descriptors.length; i++) { PropertyDescriptor descriptor = descriptors[i]; String name = descriptor.getName(); if (!ignoredFieldNames.contains(name)) { jgen.writeFieldName(name); jgen.writeStartObject(); // String fieldValue = getFormFieldConfig(domainClass, name); if (StringUtils.isNotBlank(fieldValue)) { jgen.writeRaw(fieldValue); } jgen.writeEndObject(); } } jgen.writeEndObject(); } } catch (Exception e) { LOGGER.error("Failed serializing form schema", e); } }
From source file:com.alibaba.cobar.manager.web.screen.MCobarListScreen.java
@SuppressWarnings({ "unchecked" })
@Override/*w ww . ja v a 2 s .c o m*/
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response)
throws Exception {
UserDO user = (UserDO) request.getSession().getAttribute("user");
long clusterId = Long.parseLong(request.getParameter("clusterId"));
ClusterDO cluster = xmlAccesser.getClusterDAO().getClusterById(clusterId);
List<CobarDO> cobarList = xmlAccesser.getCobarDAO().getCobarList(clusterId);
List<Map<String, Object>> cobarViewList = null;
if (null != cobarList) {
ListSortUtil.sortCobarByName(cobarList);
cobarViewList = new ArrayList<Map<String, Object>>();
PropertyUtilsBean util = new PropertyUtilsBean();
for (CobarDO c : cobarList) {
Map<String, Object> map = util.describe(c);
map.remove("class");
map.remove("name");
map.put("name", CobarStringUtil.htmlEscapedString(c.getName()));
cobarViewList.add(map);
}
}
Map<String, Object> clusterView = new HashMap<String, Object>();
clusterView.put("id", cluster.getId());
clusterView.put("name", CobarStringUtil.htmlEscapedString(cluster.getName()));
return new ModelAndView("m_cobarList",
new FluenceHashMap<String, Object>().putKeyValue("cobarList", cobarViewList)
.putKeyValue("user", user).putKeyValue("cluster", clusterView));
}