Java Code Examples for net.sf.cglib.beans.BeanMap#putAll()
The following examples show how to use
net.sf.cglib.beans.BeanMap#putAll() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JsonFieldRender.java From gecco with MIT License | 6 votes |
@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); }
Example 2
Source File: MapToBeanCopier.java From Copiers with Apache License 2.0 | 5 votes |
@Override public T copy(Map<String, Object> source) { checkNotNull(source, "source map cannot be null!"); try { T bean = ReflectionUtil.newInstance(targetClass); BeanMap beanMap = BeanMap.create(bean); beanMap.putAll(source); return bean; } catch (Exception e) { throw new CopierException("create object fail, class: " + targetClass.getName(), e); } }
Example 3
Source File: MapToBeanCopier.java From Copiers with Apache License 2.0 | 5 votes |
@Override public void copy(Map<String, Object> source, T bean) { checkNotNull(source, "source map cannot be null!"); checkNotNull(bean, "target bean cannot be null!"); try { BeanMap beanMap = BeanMap.create(bean); beanMap.putAll(source); } catch (Exception e) { throw new CopierException("create object fail, class: " + bean.getClass().getName(), e); } }
Example 4
Source File: HtmlFieldRender.java From gecco with MIT License | 5 votes |
@Override public void render(HttpRequest request, HttpResponse response, BeanMap beanMap, SpiderBean bean) { Map<String, Object> fieldMap = new HashMap<String, Object>(); Set<Field> htmlFields = ReflectionUtils.getAllFields(bean.getClass(), ReflectionUtils.withAnnotation(HtmlField.class)); for (Field htmlField : htmlFields) { Object value = injectHtmlField(request, response, htmlField, bean.getClass()); if(value != null) { fieldMap.put(htmlField.getName(), value); } } beanMap.putAll(fieldMap); }
Example 5
Source File: ImageFieldRender.java From gecco with MIT License | 5 votes |
@Override @SuppressWarnings("unchecked") public void render(HttpRequest request, HttpResponse response, BeanMap beanMap, SpiderBean bean) { Map<String, Object> fieldMap = new HashMap<String, Object>(); Set<Field> imageFields = ReflectionUtils.getAllFields(bean.getClass(), ReflectionUtils.withAnnotation(Image.class)); for (Field imageField : imageFields) { Object value = injectImageField(request, beanMap, bean, imageField); if(value != null) { fieldMap.put(imageField.getName(), value); } } beanMap.putAll(fieldMap); }
Example 6
Source File: JSVarFieldRender.java From gecco with MIT License | 5 votes |
@Override @SuppressWarnings({ "unchecked" }) public void render(HttpRequest request, HttpResponse response, BeanMap beanMap, SpiderBean bean) { Context cx = Context.enter(); ScriptableObject scope = cx.initSafeStandardObjects(); String windowScript = "var window = {};var document = {};"; cx.evaluateString(scope, windowScript, "window", 1, null); HtmlParser parser = new HtmlParser(request.getUrl(), response.getContent()); for (Element ele : parser.$("script")) { String sc = ele.html(); if (StringUtils.isNotEmpty(sc)) { try { cx.evaluateString(scope, sc, "", 1, null); } catch (Exception ex) { // ex.printStackTrace(); } } } Map<String, Object> fieldMap = new HashMap<String, Object>(); Set<Field> jsVarFields = ReflectionUtils.getAllFields(bean.getClass(), ReflectionUtils.withAnnotation(JSVar.class)); for (Field jsVarField : jsVarFields) { Object value = injectJsVarField(request, beanMap, jsVarField, cx, scope); if(value != null) { fieldMap.put(jsVarField.getName(), value); } } beanMap.putAll(fieldMap); Context.exit(); }
Example 7
Source File: AjaxFieldRender.java From gecco with MIT License | 5 votes |
@Override @SuppressWarnings("unchecked") public void render(HttpRequest request, HttpResponse response, BeanMap beanMap, SpiderBean bean) { Map<String, Object> fieldMap = new HashMap<String, Object>(); Set<Field> ajaxFields = ReflectionUtils.getAllFields(bean.getClass(), ReflectionUtils.withAnnotation(Ajax.class)); for (Field ajaxField : ajaxFields) { Object value = injectAjaxField(request, beanMap, ajaxField); if(value != null) { fieldMap.put(ajaxField.getName(), value); } } beanMap.putAll(fieldMap); }
Example 8
Source File: MapUtils.java From nuls-v2 with MIT License | 2 votes |
/** * 将map装换为javabean对象 * * @param map * @param bean * @return */ public static <T> T mapToBean(Map<String, Object> map, T bean) { BeanMap beanMap = BeanMap.create(bean); beanMap.putAll(map); return bean; }