BeanUtil.java
3.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
package com.bjivt.base.bean;
import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class BeanUtil
{
private static Log _log = LogFactory.getLog(BeanUtil.class);
public static boolean getBoolean(Object bean, String param)
{
return getBoolean(bean, param, false);
}
public static boolean getBoolean(Object bean, String param, boolean defaultValue)
{
Boolean beanValue = null;
if (bean != null) {
try {
beanValue = (Boolean)PropertyUtils.getSimpleProperty(bean, param);
}
catch (Exception e)
{
_log.error(e);
}
}
if (beanValue == null) {
return defaultValue;
}
return beanValue.booleanValue();
}
public static double getDouble(Object bean, String param)
{
return getDouble(bean, param, 0.0D);
}
public static double getDouble(Object bean, String param, double defaultValue)
{
Double beanValue = null;
if (bean != null) {
try {
beanValue = (Double)PropertyUtils.getSimpleProperty(bean, param);
}
catch (Exception e)
{
_log.error(e);
}
}
if (beanValue == null) {
return defaultValue;
}
return beanValue.doubleValue();
}
public static int getInteger(Object bean, String param)
{
return getInteger(bean, param, 0);
}
public static int getInteger(Object bean, String param, int defaultValue)
{
Integer beanValue = null;
if (bean != null) {
try {
beanValue = (Integer)PropertyUtils.getSimpleProperty(bean, param);
}
catch (Exception e)
{
_log.error(e);
}
}
if (beanValue == null) {
return defaultValue;
}
return beanValue.intValue();
}
public static long getLong(Object bean, String param)
{
return getLong(bean, param, 0L);
}
public static long getLong(Object bean, String param, long defaultValue)
{
Long beanValue = null;
if (bean != null) {
try {
beanValue = (Long)PropertyUtils.getSimpleProperty(bean, param);
}
catch (Exception e)
{
_log.error(e);
}
}
if (beanValue == null) {
return defaultValue;
}
return beanValue.longValue();
}
public static Object getObject(Object bean, String param)
{
Object beanValue = null;
if (bean != null) {
try {
beanValue = PropertyUtils.getSimpleProperty(bean, param);
}
catch (Exception e) {
_log.error(e);
}
}
return beanValue;
}
public static String getString(Object bean, String param) {
return getString(bean, param, "");
}
public static String getString(Object bean, String param, String defaultValue)
{
String beanValue = null;
if (bean != null) {
try {
beanValue = (String)PropertyUtils.getSimpleProperty(bean, param);
}
catch (Exception e)
{
_log.error(e);
}
}
if (beanValue == null) {
return defaultValue;
}
return beanValue;
}
}