From 005c7fa7efde7d2ff9d74d9185b803a62711467d Mon Sep 17 00:00:00 2001 From: Josef Rokos Date: Sun, 6 Jul 2014 11:48:26 +0200 Subject: [PATCH] =?UTF-8?q?P=C5=99idan=C3=A1=20statick=C3=A1=20metoda,=20k?= =?UTF-8?q?ter=C3=A1=20vrac=C3=AD=20kolekci=20properties=20objektu.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bukova/isspst/sort/ReflectionTools.java | 32 +++++++++++++++++++ .../isspst/ui/reporting/ColSelectVM.java | 24 +++----------- 2 files changed, 36 insertions(+), 20 deletions(-) diff --git a/src/main/java/info/bukova/isspst/sort/ReflectionTools.java b/src/main/java/info/bukova/isspst/sort/ReflectionTools.java index 5a2902e6..ed363745 100644 --- a/src/main/java/info/bukova/isspst/sort/ReflectionTools.java +++ b/src/main/java/info/bukova/isspst/sort/ReflectionTools.java @@ -1,6 +1,12 @@ package info.bukova.isspst.sort; +import java.beans.BeanInfo; +import java.beans.IntrospectionException; +import java.beans.Introspector; +import java.beans.PropertyDescriptor; import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.List; public class ReflectionTools { @@ -46,4 +52,30 @@ public class ReflectionTools { throw new IllegalArgumentException("Not getter method found for '" + propertyName + "', bean: " + bean); } + + public static List getEntityFields(Class clazz) { + BeanInfo beanInfo; + try { + beanInfo = Introspector.getBeanInfo(clazz); + } catch (IntrospectionException e) { + return null; + } + PropertyDescriptor[] pds = beanInfo.getPropertyDescriptors(); + List properties = new ArrayList(); + for (PropertyDescriptor pd : pds) { + if (!(pd.getName().equals("password") || pd.getName().equals("class") || pd.getName().equals("id") || pd.getName().equals("valid"))) { + properties.add(pd.getName()); + } + } + + return properties; + } + + public static List getEntityFields(Object entity) { + if (entity == null) { + return null; + } + + return getEntityFields(entity.getClass()); + } } diff --git a/src/main/java/info/bukova/isspst/ui/reporting/ColSelectVM.java b/src/main/java/info/bukova/isspst/ui/reporting/ColSelectVM.java index 6036514c..f22bd68b 100644 --- a/src/main/java/info/bukova/isspst/ui/reporting/ColSelectVM.java +++ b/src/main/java/info/bukova/isspst/ui/reporting/ColSelectVM.java @@ -1,18 +1,14 @@ package info.bukova.isspst.ui.reporting; -import java.beans.BeanInfo; -import java.beans.IntrospectionException; -import java.beans.Introspector; -import java.beans.PropertyDescriptor; -import java.util.ArrayList; -import java.util.List; - import info.bukova.isspst.reporting.Report; import info.bukova.isspst.reporting.ReportDefinition; import info.bukova.isspst.reporting.ReportType; +import info.bukova.isspst.sort.ReflectionTools; import info.bukova.isspst.ui.ListChecks; import info.bukova.isspst.ui.LocaleConverter; +import java.util.List; + import org.zkoss.bind.annotation.Init; import org.zkoss.zk.ui.select.annotation.WireVariable; @@ -38,19 +34,7 @@ public class ColSelectVM { return null; } - BeanInfo beanInfo; - try { - beanInfo = Introspector.getBeanInfo(data.get(0).getClass()); - } catch (IntrospectionException e) { - return null; - } - PropertyDescriptor[] pds = beanInfo.getPropertyDescriptors(); - List properties = new ArrayList(); - for (PropertyDescriptor pd : pds) { - if (!(pd.getName().equals("password") || pd.getName().equals("class") || pd.getName().equals("id") || pd.getName().equals("valid"))) { - properties.add(pd.getName()); - } - } + List properties = ReflectionTools.getEntityFields(data.get(0)); ListChecks columns = new ListChecks(reportDefinition.getFieldsToPrint(), properties); return columns;