org.springframework.cglib.beans.BeanMap Java Examples
The following examples show how to use
org.springframework.cglib.beans.BeanMap.
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: DynamicEntityHolder.java From we-cmdb with Apache License 2.0 | 7 votes |
/** * Clone given ci data attribute to new one include default fields * * @param entityMeta * @param fromCiBean * @return */ public static DynamicEntityHolder cloneDynamicEntityBean(DynamicEntityMeta entityMeta, Object fromCiBean) { org.apache.commons.beanutils.BeanMap fromBeanMap = new org.apache.commons.beanutils.BeanMap(fromCiBean); DynamicEntityHolder entityHolder = new DynamicEntityHolder(entityMeta); for (String attr : entityHolder.getEntityMeta().getAttrs()) { FieldNode fieldNode = entityHolder.getEntityMeta().getFieldNode(attr); if (fieldNode.isId()) { continue; } /* * if(DynamicEntityType.MultiReference.equals(fieldNode.getEntityType())){ * continue; } */ entityHolder.put(attr, fromBeanMap.get(attr)); } return entityHolder; }
Example #2
Source File: BeanMapUtils.java From Lottor with MIT License | 7 votes |
/** * 将List<Map<String,Object>>转换为List<T> * * @param maps * @param clazz * @return * @throws InstantiationException * @throws IllegalAccessException */ public static <T> List<T> listToBean(List<Object> maps, Class<T> clazz) throws InstantiationException, IllegalAccessException { List<T> list = Lists.newArrayList(); if (maps != null && maps.size() > 0) { Object map; T bean; for (int i = 0, size = maps.size(); i < size; i++) { map = maps.get(i); bean = clazz.newInstance(); BeanMap beanMap = BeanMap.create(bean); list.add(bean); } } return list; }
Example #3
Source File: BasedBindSnsHandler.java From super-cloudops with Apache License 2.0 | 6 votes |
@SuppressWarnings({ "rawtypes", "unchecked" }) @Override protected String doHandleOAuth2Callback(String provider, String code, OAuth2ApiBinding connect, Map<String, String> connectParams, HttpServletRequest request) { // Access token Oauth2AccessToken ast = connect.getAccessToken(code); // User openId Oauth2OpenId openId = connect.getUserOpenId(ast); // User info Oauth2UserProfile profile = connect.getUserInfo(ast.accessToken(), openId.openId()); // Binding principal id String principal = connectParams.get(config.getParam().getPrincipalName()); // To social connection info SocialConnectInfo info = new SocialConnectInfo(provider, principal, openId.openId(), openId.unionId()); // Extra info info.setClientIp(WebUtils2.getHttpRemoteAddr(request)); info.setReferer(request.getHeader("Referer")); info.setUserAgent(request.getHeader("User-Agent")); info.setUserProfile(BeanMap.create(profile)); // User info // Binding or UnBinding process postBindingProcess(info); return null; }
Example #4
Source File: BeanConvertUtil.java From MicroCommunity with Apache License 2.0 | 6 votes |
/** * 对象A转为对象B * 这个也支持map转bean * * @param orgBean 原始对象 * @param dstBean 目标对象类 * @param <T1> 原始对象 * @param <T2> 目标对象 * @return 目标对象 */ public static <T1, T2> T2 covertBean(T1 orgBean, T2 dstBean) { try { //BeanUtils.copyProperties(dstBean, orgBean); if (orgBean instanceof Map) { BeanMap beanMap = BeanMap.create(dstBean); //beanMap.putAll((Map)orgBean); objectFieldsPutMap(dstBean, beanMap, (Map) orgBean); return dstBean; } final BeanCopier beanCopier = BeanCopier.create(orgBean.getClass(), dstBean.getClass(), true); beanCopier.copy(orgBean, dstBean, new Java110Converter()); } catch (Exception e) { e.printStackTrace(); throw new RuntimeException("bean转换bean失败", e); } return dstBean; }
Example #5
Source File: BeanConvertUtil.java From MicroCommunity with Apache License 2.0 | 6 votes |
private static void objectFieldsPutMap(Object dstBean, BeanMap beanMap, Map orgMap) { //Field[] fields = dstBean.getClass().getDeclaredFields(); Field[] fields = FieldUtils.getAllFields(dstBean.getClass()); for (Field field : fields) { if (!orgMap.containsKey(field.getName())) { continue; } Class dstClass = field.getType(); //System.out.println("字段类型" + dstClass); Object value = orgMap.get(field.getName()); //String 转date Object tmpValue = Java110Converter.getValue(value, dstClass); beanMap.put(field.getName(), tmpValue); } }
Example #6
Source File: DynamicDTO.java From jea with Apache License 2.0 | 5 votes |
public DynamicDTO(BaseModel model){ generator = new BeanGenerator(); valueMap = new TreeMap<String, Object>(); beanObject = model; beanMap = BeanMap.create(model); valueMap.putAll(beanMap); }
Example #7
Source File: BeanUtil.java From BlogManagePlatform with Apache License 2.0 | 5 votes |
/** * map转bean * @author Frodez * @throws InvocationTargetException * @date 2019-02-08 */ @SneakyThrows public static <T> T as(Map<String, Object> map, Supplier<T> supplier) { Assert.notNull(map, "map must not be null"); T bean = supplier.get(); try { BeanMap.create(bean).putAll(map); } catch (Exception e) { log.error("map转bean出现异常,采用安全方式继续...异常消息:{}", e.getMessage()); //如果出错则采用安全但较慢的方式 safeAs(map, bean); } return bean; }
Example #8
Source File: AbstractSnsHandler.java From super-cloudops with Apache License 2.0 | 5 votes |
/** * After SNS callback handling.<br/> * * @param provider * @param code * @param api * @param connectParams * @param request * @return */ @SuppressWarnings({ "rawtypes", "unchecked" }) protected String doHandleOAuth2Callback(String provider, String code, OAuth2ApiBinding api, Map<String, String> connectParams, HttpServletRequest request) { // Access token Oauth2AccessToken at = api.getAccessToken(code); // User openId Oauth2OpenId openId = api.getUserOpenId(at); // User info Map<String, Object> userProfile = emptyMap(); try { Oauth2UserProfile profile = api.getUserInfo(at.accessToken(), openId.openId()); userProfile = BeanMap.create(profile); } catch (SnsApiBindingException e) { // Ignore? log.warn("Could't get OAuth2 userInfo, provider: %s, accessToken: %s, openId: %s, caused by: %s", provider, at.accessToken(), openId.openId(), getRootCausesString(e)); } /* * Caching social callback user openId information.(Applicable only to * which=login/client_auth)<br/> * See:xx.realm.Oauth2SnsAuthorizingRealm#doAuthenticationInfo() */ SocialAuthorizeInfo authInfo = new SocialAuthorizeInfo(provider, openId.openId(), openId.unionId(), userProfile); String callbackId = generateCallbackId(); cacheManager.getIamCache(CACHE_SNSAUTH).put(new CacheKey(getOAuth2CallbackKey(callbackId), 30), authInfo); return callbackId; }
Example #9
Source File: BeanUtil.java From BlogManagePlatform with Apache License 2.0 | 5 votes |
/** * map转bean * @author Frodez * @throws InvocationTargetException * @date 2019-02-08 */ @SneakyThrows public static <T> T as(Map<String, Object> map, Class<T> klass) { Assert.notNull(map, "map must not be null"); T bean = ReflectUtil.instance(klass); try { BeanMap.create(bean).putAll(map); } catch (Exception e) { log.error("map转bean出现异常,采用安全方式继续...异常消息:{}", e.getMessage()); //如果出错则采用安全但较慢的方式 safeAs(map, bean); } return bean; }
Example #10
Source File: Utils.java From faster-framework-project with Apache License 2.0 | 5 votes |
/** * bean转map * * @param bean 原始bean * @param <T> 泛型 * @return map */ public static <T> Map<String, Object> beanToMap(T bean) { Map<String, Object> map = new HashMap<>(); if (bean != null) { BeanMap beanMap = BeanMap.create(bean); for (Object key : beanMap.keySet()) { map.put(key + "", beanMap.get(key)); } } return map; }
Example #11
Source File: BeanConvertUtil.java From MicroCommunity with Apache License 2.0 | 5 votes |
/** * bean转换为map对象 * * @param orgBean 原始bean * @return map对象 */ public static Map beanCovertMap(Object orgBean) { Map<String, Object> map = new HashMap(); try { BeanMap beanMap = BeanMap.create(orgBean); for (Object key : beanMap.keySet()) { map.put(key + "", beanMap.get(key)); } } catch (Exception e) { throw new RuntimeException("bean转换Map失败", e); } return map; }
Example #12
Source File: BeanMapUtils.java From Lottor with MIT License | 5 votes |
/** * 将对象装换为map * * @param bean * @return */ public static <T> Map<String, Object> beanToMap(T bean) { Map<String, Object> map = Maps.newHashMap(); if (bean != null) { BeanMap beanMap = BeanMap.create(bean); for (Object key : beanMap.keySet()) { if (Objects.nonNull(beanMap.get(key))) { map.put(key + "", beanMap.get(key)); } } } return map; }
Example #13
Source File: AbstractContextProvider.java From bdf3 with Apache License 2.0 | 5 votes |
protected Object getRealContext(Object obj, String dataPath) { if (StringUtils.isEmpty(dataPath)) { return obj; } String[] path = dataPath.split("\\."); Object target = obj; BeanMap beanMap = BeanMap.create(target); for (String property : path) { target = beanMap.get(property); } return target; }
Example #14
Source File: SoapClient.java From jea with Apache License 2.0 | 5 votes |
private Object copytoSoapObject(Object param, Class<?> soapClass) throws Exception { Object soapObject = soapClass.newInstance(); if (soapObject instanceof java.lang.String) { soapObject = param.toString(); } else { BeanMap beanMap = BeanMap.create(soapObject); DynamicDTO dto = (DynamicDTO) param; for (String key : dto.properties()) { beanMap.put(key, dto.getValue(key)); } } return soapObject; }
Example #15
Source File: BeanUtil.java From flash-waimai with MIT License | 5 votes |
/** * 将对象装换为map * @param bean * @return */ public static <T> Map<String, Object> beanToMap(T bean) { Map<String, Object> map = Maps.newHashMap(); if (bean != null) { BeanMap beanMap = BeanMap.create(bean); for (Object key : beanMap.keySet()) { map.put(key+"", beanMap.get(key)); } } return map; }
Example #16
Source File: BeanUtil.java From web-flash with MIT License | 5 votes |
/** * 将对象装换为map * @param bean * @return */ public static <T> Map<String, Object> beanToMap(T bean) { Map<String, Object> map = Maps.newHashMap(); if (bean != null) { BeanMap beanMap = BeanMap.create(bean); for (Object key : beanMap.keySet()) { map.put(key+"", beanMap.get(key)); } } return map; }
Example #17
Source File: AuditUtil.java From pmq with Apache License 2.0 | 5 votes |
public static Map<String, String> convertMap(Object source) { if (source== null) { return new HashMap<>(); } BeanMap sourceBeanMap = BeanMap.create(source); Map<String, String> sourceFieldMap = new HashMap<>(); for (Object key: sourceBeanMap.keySet()) { sourceFieldMap.put(key.toString(), JsonUtil.toJson(sourceBeanMap.get(key))); } return sourceFieldMap; }
Example #18
Source File: WarningHelper.java From seppb with MIT License | 5 votes |
default Map<String, Object> beanToMap(@NonNull T t) { Map<String, Object> defectMap = Maps.newHashMap(); BeanMap beanMap = BeanMap.create(t); for (Object key : beanMap.keySet()) { Object value = valueToDouble(null == beanMap.get(key) ? 0.0001 : beanMap.get(key)); defectMap.put(String.valueOf(key), value); } return defectMap; }
Example #19
Source File: ObjectUtil.java From SENS with GNU General Public License v3.0 | 5 votes |
public static <T> Map<String, Object> beanToMap(T bean) { Map<String, Object> map = Maps.newHashMap(); if (bean != null) { BeanMap beanMap = BeanMap.create(bean); for (Object key : beanMap.keySet()) { map.put(key+"", beanMap.get(key)); } } return map; }
Example #20
Source File: DynamicEntityGeneratorTest.java From we-cmdb with Apache License 2.0 | 5 votes |
@Test @Ignore public void operateAdmMenuThenSuccessfully() throws Exception { List<FieldNode> fields = Arrays.asList(new FieldNode(DynamicEntityType.CI, 1, "idAdmMenu", Integer.class, "id_adm_menu", true), new FieldNode(DynamicEntityType.CI, 1, "classPath", String.class, "class_path"), new FieldNode(DynamicEntityType.CI, 1, "isActive", Integer.class, "is_active"), new FieldNode(DynamicEntityType.CI, 1, "name", String.class, "name"), new FieldNode(DynamicEntityType.CI, 1, "otherName", String.class, "other_name"), new FieldNode(DynamicEntityType.CI, 1, "parentIdAdmMenu", Integer.class, "parent_id_adm_menu"), new FieldNode(DynamicEntityType.CI, 1, "remark", String.class, "remark"), new FieldNode(DynamicEntityType.CI, 1, "seqNo", Integer.class, "seq_no"), new FieldNode(DynamicEntityType.CI, 1, "url", String.class, "url")); byte[] domainBuf = DynamicEntityGenerator.generate("test.domain.AdmMenu", "adm_menu", fields); Class clzz = entityCL.getClass(domainBuf); HibernateJpaEntityManagerFactory ciManagerFactory = new HibernateJpaEntityManagerFactory(Arrays.asList(clzz), dataSource, entityCL, datasourceProperties.getSchema()); EntityManager ciEntityManager = ciManagerFactory.getEntityManagerFactory() .createEntityManager(); Object entity = clzz.newInstance(); BeanMap beanMap = BeanMap.create(entity); beanMap.put("name", "test menu"); beanMap.put("remark", "test remark"); beanMap.put("seqNo", 99); beanMap.put("idAdmMenu", 100); EntityTransaction transaction = ciEntityManager.getTransaction(); transaction.begin(); Object updatedEntity = ciEntityManager.merge(entity); System.out.println("id:" + BeanMap.create(updatedEntity) .get("idAdmMenu")); transaction.commit(); }
Example #21
Source File: domainTest.java From we-cmdb with Apache License 2.0 | 5 votes |
public void testDomain() throws Exception { // byte[] domainBuf = AdmMenuDump.generateClzz(); List<FieldNode> fields = Arrays.asList(new FieldNode(DynamicEntityType.CI, 1, "idAdmMenu", Integer.class, "id_adm_menu", true), new FieldNode(DynamicEntityType.CI, 1, "classPath", String.class, "class_path"), new FieldNode(DynamicEntityType.CI, 1, "isActive", Integer.class, "is_active"), new FieldNode(DynamicEntityType.CI, 1, "name", String.class, "name"), new FieldNode(DynamicEntityType.CI, 1, "otherName", String.class, "other_name"), new FieldNode(DynamicEntityType.CI, 1, "parentIdAdmMenu", Integer.class, "parent_id_adm_menu"), new FieldNode(DynamicEntityType.CI, 1, "remark", String.class, "remark"), new FieldNode(DynamicEntityType.CI, 1, "seqNo", Integer.class, "seq_no"), new FieldNode(DynamicEntityType.CI, 1, "url", String.class, "url")); byte[] domainBuf = DynamicEntityGenerator.generate("test/domain/AdmMenu", "adm_menu", fields); Class clzz = entityCL.getClass(domainBuf); HibernateJpaEntityManagerFactory ciManagerFactory = new HibernateJpaEntityManagerFactory(Arrays.asList(clzz), dataSource, entityCL, datasourceProperties.getSchema()); EntityManager ciEntityManager = ciManagerFactory.getEntityManagerFactory() .createEntityManager(); Object entity = clzz.newInstance(); BeanMap beanMap = BeanMap.create(entity); beanMap.put("name", "test menu"); beanMap.put("remark", "test remark"); beanMap.put("seqNo", 99); EntityTransaction transaction = ciEntityManager.getTransaction(); transaction.begin(); Object updatedEntity = ciEntityManager.merge(entity); System.out.println("id:" + BeanMap.create(updatedEntity) .get("idAdmMenu")); transaction.commit(); }
Example #22
Source File: BeanMapUtils.java From we-cmdb with Apache License 2.0 | 5 votes |
public static <T> Map<String, Object> convertBeanToMap(T bean) { Map<String, Object> map = Maps.newHashMap(); if (bean != null) { BeanMap beanMap = BeanMap.create(bean); for (Object key : beanMap.keySet()) { if (beanMap.get(key) != null) { map.put(key.toString(), beanMap.get(key)); } } } return map; }
Example #23
Source File: DynamicDTO.java From jea with Apache License 2.0 | 5 votes |
/** * 建议用于SOAP对象的转换,一般的JavaBean请继承BaseDTO或BasePO * @param obj */ public DynamicDTO(Object obj){ generator = new BeanGenerator(); valueMap = new TreeMap<String, Object>(); beanObject = obj; beanMap = BeanMap.create(obj); valueMap.putAll(beanMap); }
Example #24
Source File: DynamicDTO.java From jea with Apache License 2.0 | 5 votes |
public Object getCloneBean() { try { Object tmpObject = generator.create(); BeanMap tmpMap = BeanMap.create(tmpObject); tmpMap.putAll(valueMap); return tmpObject; } catch (Exception e) { return null; } }
Example #25
Source File: DynamicDTO.java From jea with Apache License 2.0 | 5 votes |
/** * 转换器,设置DynamicDTO的属性值到对应的Model对象 * * @param target */ @SuppressWarnings("unchecked") public void convert(BaseModel target) { BeanMap tmp = BeanMap.create(target); Iterator<String> keys = tmp.keySet().iterator(); String key = null; while(keys.hasNext()){ key = keys.next(); if(beanMap.containsKey(key)){ StringConverter converter = new StringConverter(); TypeConverterManager.register(String.class, converter); tmp.put(key, TypeConverterManager.convertType(beanMap.get(key), tmp.getPropertyType(key))); } } }
Example #26
Source File: DynamicEntityHolder.java From we-cmdb with Apache License 2.0 | 5 votes |
private DynamicEntityHolder(DynamicEntityMeta entityMeta) { this.entityMeta = entityMeta; try { Constructor<?> entityConst = entityMeta.getEntityClazz().getConstructor(); entityObj = entityConst.newInstance(); entityBeanMap = BeanMap.create(entityObj); } catch (Exception e) { throw new ServiceException(String.format("Failed to create CI entity bean for CI type (%s)", entityMeta.getQulifiedName())); } }
Example #27
Source File: DynamicDTO.java From jea with Apache License 2.0 | 4 votes |
private void generateBean() throws Exception { beanObject = generator.create(); beanMap = BeanMap.create(beanObject); beanMap.putAll(valueMap); }
Example #28
Source File: MicaBeanMap.java From mica with GNU Lesser General Public License v3.0 | 4 votes |
@Override protected Object firstInstance(Class type) { return ((BeanMap)ReflectUtils.newInstance(type)).newInstance(bean); }
Example #29
Source File: MicaBeanMap.java From mica with GNU Lesser General Public License v3.0 | 4 votes |
@Override protected Object nextInstance(Object instance) { return ((BeanMap)instance).newInstance(bean); }
Example #30
Source File: DynamicEntityHolder.java From we-cmdb with Apache License 2.0 | 4 votes |
public DynamicEntityHolder(DynamicEntityMeta entityMeta, Object entityObj) { this.entityMeta = entityMeta; this.entityObj = entityObj; entityBeanMap = BeanMap.create(entityObj); }