本文整理汇总了Java中net.sf.cglib.beans.BeanMap类的典型用法代码示例。如果您正苦于以下问题:Java BeanMap类的具体用法?Java BeanMap怎么用?Java BeanMap使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BeanMap类属于net.sf.cglib.beans包,在下文中一共展示了BeanMap类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: render
import net.sf.cglib.beans.BeanMap; //导入依赖的package包/类
@Override
public void render(HttpRequest request, HttpResponse response, BeanMap beanMap, SpiderBean bean, Field field) {
ProductList jd = (ProductList)bean;
StringBuffer sb = new StringBuffer();
/*for(String code : jd.getCodes()) {
sb.append("J_").append(code).append(",");
}*/
String skuIds = sb.toString();
try {
skuIds = URLEncoder.encode(skuIds, "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
String url = "http://p.3.cn/prices/mgets?skuIds="+skuIds;
HttpRequest subRequest = request.subRequest(url);
try {
HttpResponse subReponse = DownloaderContext.download(subRequest);
String json = subReponse.getContent();
List<JDPrice> prices = JSON.parseArray(json, JDPrice.class);
beanMap.put(field.getName(), prices);
} catch(Exception ex) {
ex.printStackTrace();
}
}
示例2: render
import net.sf.cglib.beans.BeanMap; //导入依赖的package包/类
@Override
@SuppressWarnings({ "unchecked" })
public void render(HttpRequest request, HttpResponse response, BeanMap beanMap, SpiderBean bean) {
Map<String, Object> fieldMap = new HashMap<String, Object>();
Set<Field> jsonPathFields = ReflectionUtils.getAllFields(bean.getClass(), ReflectionUtils.withAnnotation(JSONPath.class));
String jsonStr = response.getContent();
jsonStr = jsonp2Json(jsonStr);
if (jsonStr == null) {
return;
}
try {
Object json = JSON.parse(jsonStr);
for (Field field : jsonPathFields) {
Object value = injectJsonField(request, field, json);
if(value != null) {
fieldMap.put(field.getName(), value);
}
}
} catch(JSONException ex) {
//throw new RenderException(ex.getMessage(), bean.getClass());
RenderException.log("json parse error : " + request.getUrl(), bean.getClass(), ex);
}
beanMap.putAll(fieldMap);
}
示例3: injectImageField
import net.sf.cglib.beans.BeanMap; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private Object injectImageField(HttpRequest request, BeanMap beanMap, SpiderBean bean, Field field) {
Object value = beanMap.get(field.getName());
if(value == null) {
return null;
}
if(value instanceof Collection) {
Collection<Object> collection = (Collection<Object>)value;
for(Object item : collection) {
String imgUrl = downloadImage(request, field, item.toString());
item = imgUrl;
}
return collection;
} else {
return downloadImage(request, field, value.toString());
}
}
示例4: decode
import net.sf.cglib.beans.BeanMap; //导入依赖的package包/类
public void decode(BitBuffer bitBuffer, BeanMap beanMap, Field field, Annotation annotation) throws Exception {
DateTime dateTime = (DateTime) annotation;
byte[] buf = bitBuffer.readBytes(new byte[6]);
if(dateTime.isBCDCode())
beanMap.put(field.getName(), ByteBufferUtil.bcdbuf2Date(buf));
else
beanMap.put(field.getName(), ByteBufferUtil.buf2Date(buf));
}
示例5: encode
import net.sf.cglib.beans.BeanMap; //导入依赖的package包/类
public void encode(BitBuffer bitBuffer, BeanMap beanMap, Field field, Annotation annotation) throws Exception {
DateTime dateTime = (DateTime) annotation;
long millSec = (Long) beanMap.get(field.getName());
if(dateTime.isBCDCode())
bitBuffer.write(ByteBufferUtil.date2bcdbuf(millSec));
else
bitBuffer.write(ByteBufferUtil.date2buf(millSec));
}
示例6: toPrettyHexString
import net.sf.cglib.beans.BeanMap; //导入依赖的package包/类
@Override
public String toPrettyHexString(BitBuffer bitBuffer, BeanMap beanMap, Field field, Annotation annotation) throws Exception {
DateTime dateTime = (DateTime) annotation;
long millSec = (Long) beanMap.get(field.getName());
if(dateTime.isBCDCode()) {
return String.format(FIELD_TEMPLATE, HexStringUtil.toHexString(ByteBufferUtil.date2bcdbuf(millSec)), field.getName(), millSec);
} else {
return String.format(FIELD_TEMPLATE, HexStringUtil.toHexString(ByteBufferUtil.date2buf(millSec)), field.getName(), millSec);
}
}
示例7: toPrettyHexString
import net.sf.cglib.beans.BeanMap; //导入依赖的package包/类
@Override
public String toPrettyHexString(BitBuffer bitBuffer, BeanMap beanMap, Field field, Annotation annotation) throws Exception {
bitBuffer.reset();
encode(bitBuffer, beanMap, field, annotation);
byte[] array = bitBuffer.toByteArray();
bitBuffer.reset();
return String.format(FIELD_TEMPLATE, HexStringUtil.toHexString(array), field.getName(), beanMap.get(field.getName()));
}
示例8: decode
import net.sf.cglib.beans.BeanMap; //导入依赖的package包/类
public void decode(BitBuffer bitBuffer, BeanMap beanMap, Field field, Annotation annotation) throws Exception {
AsciiString anno = (AsciiString) annotation;
int length = CoderHelper.caculateArrayLength(beanMap.getBean(), anno.length());
if (length > 0) {
byte[] buf = bitBuffer.readBytes(new byte[length]);
beanMap.put(field.getName(), new String(buf, anno.charsetName()));
}
}
示例9: encode
import net.sf.cglib.beans.BeanMap; //导入依赖的package包/类
public void encode(BitBuffer bitBuffer, BeanMap beanMap, Field field, Annotation annotation) throws Exception {
AsciiString arrayAnnocation = (AsciiString) annotation;
int length = CoderHelper.caculateArrayLength(beanMap.getBean(), arrayAnnocation.length());
String value = (String) beanMap.get(field.getName());
byte[] buf = value.getBytes(arrayAnnocation.charsetName());
if(length != buf.length)
throw new Exception(field.getName() + " length is not equal to " + length);
if (buf != null && buf.length > 0) {
bitBuffer.write(buf);
}
}
示例10: 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("}");
}
示例11: 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");
}
示例12: 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("}");
}
示例13: 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");
}
示例14: 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);
}
}
示例15: 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);
}
}