本文整理汇总了Java中net.sf.cglib.beans.BeanMap.create方法的典型用法代码示例。如果您正苦于以下问题:Java BeanMap.create方法的具体用法?Java BeanMap.create怎么用?Java BeanMap.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.sf.cglib.beans.BeanMap
的用法示例。
在下文中一共展示了BeanMap.create方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doPrettyHexString
import net.sf.cglib.beans.BeanMap; //导入方法依赖的package包/类
/**
* Begin to print pretty string
*
* @param obj The JavaBean
* @param prettyStringBuilder The prettystring builder
* @throws Exception error
*/
private void doPrettyHexString(Object obj, StringBuilder prettyStringBuilder) throws Exception {
prettyStringBuilder.append(obj.getClass().getSimpleName() + "={");
Field[] fields = pool.getFields(obj.getClass());
BeanMap beanMap = BeanMap.create(obj);
int length = fields.length;
for (int i = 0; i < length; i++) {
Field field = fields[i];
Annotation[] annotations = pool.getAnnotations(field);
if (annotations != null && annotations.length > 0) {
if (annotations[0] instanceof Element) {
Element anno = (Element) annotations[0];
int arraySize = CoderHelper.caculateArrayLength(obj, anno.length());
if (arraySize == 1) {
prettyStringBuilder.append(field.getName() + "={");
doPrettyHexString(beanMap.get(field.getName()), prettyStringBuilder);
prettyStringBuilder.append("},");
} else {
Object[] objs = (Object[]) beanMap.get(field.getName());
for (Object ob : objs) {
prettyStringBuilder.append(field.getName() + "={");
doPrettyHexString(ob, prettyStringBuilder);
prettyStringBuilder.append("},");
}
}
} else {
String line = coderFactory.toPrettyHexString(bitBuffer.get(), beanMap, field, annotations[0]);
if (i == (length - 1)) {
line = line.replace(",", "");
}
prettyStringBuilder.append(line);
}
}
}
prettyStringBuilder.append("}");
}
示例2: test
import net.sf.cglib.beans.BeanMap; //导入方法依赖的package包/类
@Test
public void test() {
TestDouble testDouble = new TestDouble();
testDouble.setV1(12.35f);
testDouble.setV2(12.35f);
testDouble.setV3(12.35d);
testDouble.setV4(12.35d);
BeanMap beanMap = BeanMap.create(testDouble);
double v = (float)beanMap.get("v1");
v = (Float)beanMap.get("v2");
v = (Double)beanMap.get("v3");
v = (Double)beanMap.get("v4");
}
示例3: doPrettyHexString
import net.sf.cglib.beans.BeanMap; //导入方法依赖的package包/类
/**
*
* @param obj
* @param prettyStringBuilder
* @throws Exception
*/
private void doPrettyHexString(Object obj, StringBuilder prettyStringBuilder) throws Exception {
prettyStringBuilder.append(obj.getClass().getSimpleName() + "={");
Field[] fields = pool.getFields(obj.getClass());
BeanMap beanMap = BeanMap.create(obj);
int length = fields.length;
for (int i = 0; i < length; i++) {
Field field = fields[i];
Annotation[] annotations = pool.getAnnotations(field);
if(annotations != null && annotations.length > 0) {
if (annotations[0] instanceof Element) {
Element anno = (Element) annotations[0];
int arraySize = CoderHelper.caculateArrayLength(obj, anno.length());
if(arraySize == 1) {
prettyStringBuilder.append(field.getName() + "={");
doPrettyHexString(beanMap.get(field.getName()), prettyStringBuilder);
prettyStringBuilder.append("},");
} else {
Object[] objs = (Object[]) beanMap.get(field.getName());
for (Object ob : objs) {
prettyStringBuilder.append(field.getName() + "={");
doPrettyHexString(ob, prettyStringBuilder);
prettyStringBuilder.append("},");
}
}
} else {
String line = coderFactory.toPrettyHexString(bitBuffer, beanMap, field, annotations[0]);
if(i == (length - 1)) {
line = line.replace(",", "");
}
prettyStringBuilder.append(line);
}
}
}
prettyStringBuilder.append("}");
}
示例4: test
import net.sf.cglib.beans.BeanMap; //导入方法依赖的package包/类
@Test
public void test() {
TestDouble testDouble = new TestDouble();
testDouble.setV1(12.35f);
testDouble.setV2(12.35f);
testDouble.setV3(12.35d);
testDouble.setV4(12.35d);
BeanMap beanMap = BeanMap.create(testDouble);
double v = (double)beanMap.get("v1");
v = (double)beanMap.get("v2");
v = (Double)beanMap.get("v3");
v = (Double)beanMap.get("v4");
}
示例5: copy
import net.sf.cglib.beans.BeanMap; //导入方法依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public Map<String, Object> copy(F bean) {
checkNull(bean, "source bean cannot be null!");
try {
BeanMap beanMap = BeanMap.create(bean);
return new HashMap<>(beanMap);
} catch (Exception e) {
throw new RuntimeException("create object fail, class: " + bean.getClass().getName(), e);
}
}
示例6: copy
import net.sf.cglib.beans.BeanMap; //导入方法依赖的package包/类
@Override
public T copy(Map<String, Object> map) {
checkNull(map, "map cannot be null!");
checkNull(targetClass, "target class cannot be null!");
try {
T bean = ReflectionUtil.newInstance(targetClass);
BeanMap beanMap = BeanMap.create(bean);
beanMap.putAll(map);
return bean;
} catch (Exception e) {
throw new RuntimeException("create object fail, class: " + targetClass.getName(), e);
}
}
示例7: restore
import net.sf.cglib.beans.BeanMap; //导入方法依赖的package包/类
/**
* 还原CGLIB对象
* @param object
* @return
*/
@SuppressWarnings("unchecked")
public Object restore(Object object){
if(object == null){
return null;
}
try {
Map<String,Object> map = BeanMap.create(object);
Map<String,Object> newmap = new HashMap<String,Object>();
for(Map.Entry<String,Object> entry : map.entrySet()){
if(entry.getValue() == null){
continue;
}
if(entry.getValue() instanceof Entity && isCglib(entry.getValue().getClass())){
Object newObject = entry.getValue().getClass().getSuperclass().newInstance();
JavaBeanUtil.beanCopy(entry.getValue(), newObject);
newmap.put(entry.getKey(), newObject);
restore(newObject);
}
// if(entry.getValue() instanceof List){
// List<Object> list = (List<Object>)entry.getValue();
// List<Object> newlist = new ArrayList<Object>();
// for(Object ob : list){
// if(isCglib(ob.getClass())){
// Object newObject = ob.getClass().getSuperclass().newInstance();
// JavaBeanUtil.beanCopy(ob, newObject);
// newlist.add(newObject);
// }
// }
// newmap.put(entry.getKey(), newlist);
// restore(entry.getValue());
// }
}
map.putAll(newmap);
} catch (Exception e) {
e.printStackTrace();
}
return changeSelf(object);
}
示例8: CglibBeanUtil
import net.sf.cglib.beans.BeanMap; //导入方法依赖的package包/类
public CglibBeanUtil(Map<String, Class<?>> propertyMap) {
this.object = generateBean(propertyMap);
this.beanMap = BeanMap.create(this.object);
}
示例9: bean2Map
import net.sf.cglib.beans.BeanMap; //导入方法依赖的package包/类
/**
* bean to map
* @param bean 转换的bean对象
* @param map
* @return map 如果bean为null 返回null
* @author huangxin
*/
@SuppressWarnings("unchecked")
public static Map<String,Object> bean2Map(Map<String,Object> map, Object bean){
if(bean == null){
return null;
}
if(map == null){
map = new HashMap<String,Object>();
}
//判断是否是cglib代理对象
if(CglibUitl.getInstance().isCglib(bean.getClass())){
Map<String,Object> maps = BeanMap.create(bean);
for(Entry<String,Object> entry : maps.entrySet()){
if(entry.getValue() == null){
continue;
}
if(entry.getKey().contains("callbacks")){
continue;
}
if(entry.getKey().contains("bstate")){
continue;
}
map.put(entry.getKey(), entry.getValue());
}
return map;
}
Method[] methods = bean.getClass().getMethods();
for (Method method : methods){
try
{
if (method.getName().startsWith("get"))
{
String field = method.getName();
field = field.substring(field.indexOf("get") + 3);
field = field.toLowerCase().charAt(0) + field.substring(1);
Object o = method.invoke(bean, (Object[])null);
if(o == null){
continue;
}
if(o instanceof Date){
SimpleDateFormat sdf = new SimpleDateFormat(DateUtil.DEFAULT_DATETIME_PATTERN);
map.put(field,sdf.format(o));
}else if(o instanceof String){
String str = (String)o;
// if(Pattern.compile("[<>]+").matcher(str).find()){
// str = str.replaceAll("<", "<").replaceAll(">", ">");
// }
map.put(field,str);
}else{
map.put(field,o);
}
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
return map;
}
示例10: DynamicBean
import net.sf.cglib.beans.BeanMap; //导入方法依赖的package包/类
public DynamicBean(Map<String, Class> map) {
if (map == null || map.size() == 0) {
return;
}
BeanGenerator beanGenerator = new BeanGenerator();
for (Map.Entry<String, Class> entry : map.entrySet()) {
beanGenerator.addProperty(entry.getKey(), entry.getValue());
}
object = beanGenerator.create();
this.beanMap = BeanMap.create(object);
}
示例11: toMap
import net.sf.cglib.beans.BeanMap; //导入方法依赖的package包/类
/**
* 对象转为map
*
* @param obj
* @return
*/
public Map<String, Object> toMap(Object obj) {
return BeanMap.create(obj);
}