Property 클래스 추가

master
mjkhan21 2 months ago
parent d88985f7ee
commit 1b996ac057

@ -0,0 +1,113 @@
package cokr.xit.foundation.data;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.beanutils.PropertyUtils;
import cokr.xit.foundation.AbstractComponent;
/**
* @author mjkhan
*/
public class Property extends AbstractComponent {
private static Property instance;
private static Property get() {
if (instance == null)
instance = new Property();
return instance;
}
/** .
* @param obj
* @param name
* @return
*/
public static boolean readable(Object obj, String name) {
return get().isReadable(obj, name);
}
/** .
* @param obj
* @param name
* @return
*/
public static boolean writeable(Object obj, String name) {
return get().isWritable(obj, name);
}
/** .
* @param obj
* @param name
* @return
*/
public static String read(Object obj, String name) {
return get().get(obj, name);
}
/** .
* @param obj
* @param name
* @param val
*/
public static void write(Object obj, String name, Object val) {
get().set(obj, name, val);
}
/** .
* @param obj
* @param name
* @return
*/
public boolean isReadable(Object obj, String name) {
if (isEmpty(obj))
return false;
try {
return PropertyUtils.isReadable(obj, name);
} catch (Exception e) {
return false;
}
}
/** .
* @param obj
* @param name
* @return
*/
public boolean isWritable(Object obj, String name) {
if (isEmpty(obj))
return false;
try {
return PropertyUtils.isWriteable(obj, name);
} catch (Exception e) {
return false;
}
}
/** .
* @param obj
* @param name
* @return
*/
public String get(Object obj, String name) {
try {
return BeanUtils.getProperty(obj, name);
} catch (Exception e) {
throw runtimeException(e);
}
}
/** .
* @param obj
* @param name
* @param val
*/
public void set(Object obj, String name, Object val) {
try {
BeanUtils.setProperty(obj, name, val);
} catch (Exception e) {
throw runtimeException(e);
}
}
}
Loading…
Cancel
Save