当前位置: 首页>>代码示例>>Java>>正文


Java BeanMap类代码示例

本文整理汇总了Java中org.apache.commons.beanutils.BeanMap的典型用法代码示例。如果您正苦于以下问题:Java BeanMap类的具体用法?Java BeanMap怎么用?Java BeanMap使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


BeanMap类属于org.apache.commons.beanutils包,在下文中一共展示了BeanMap类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getBeanMap

import org.apache.commons.beanutils.BeanMap; //导入依赖的package包/类
@SuppressWarnings({"rawtypes", "unchecked"})
private Map<Object, Object> getBeanMap(Object obj) throws Exception {
    Map oMap = new BeanMap(obj);
    Map rMap = new HashMap();
    if (MapUtils.isEmpty(oMap)) {
        throw new Exception("实体类没有可用属性");
    } else {
        // 去除class属性
        for (Object key : oMap.keySet()) {
            if (!"class".equals(key)) {
                rMap.put(key, oMap.get(key));
            }
        }
    }
    return rMap;
}
 
开发者ID:phoenix-varus,项目名称:jeeWe,代码行数:17,代码来源:BaseProvider.java

示例2: represent

import org.apache.commons.beanutils.BeanMap; //导入依赖的package包/类
@Override
public YamlMapping represent() {
    YamlMappingBuilder builder = new RtYamlMappingBuilder();
    Set<Map.Entry<Object, Object>> entries = new BeanMap(this.obj)
        .entrySet();
    for (final Map.Entry<Object, Object> entry : entries) {
        String key = (String) entry.getKey();
        if(!"class".equals(key)) {
            Object value = entry.getValue();
            if(super.leafProperty(value)) {
                builder = builder
                    .add((String) entry.getKey(), value.toString());
            } else {
                builder = builder
                    .add((String) entry.getKey(), this.yamlNode(value));
            }
        }
    }
    return builder.build();
}
 
开发者ID:decorators-squad,项目名称:camel,代码行数:21,代码来源:YamlObjectDump.java

示例3: setBeanProperties

import org.apache.commons.beanutils.BeanMap; //导入依赖的package包/类
/** Sets members of a bean according to the properties defined in the given properties object 
 * Implicitly converts some types that could otherwise not be initialized in a config file: <br>
 * <ul>
 * <li> org.eclipse.swt.graphics.Color objects are parsed from a vector of RGB values, e.g. (255, 120, 30), [200, 300, 100] ... </li>
 * </ul>
 * Prints out an error message, if any attribute could not be set e.g. due to String to Type conversion errors
 * **/
public static void setBeanProperties(Object bean, Properties properties) /*throw IllegalAccessException, InvocationTargetException, NoSuchMethodException*/ {
	BeanMap beanmap = new BeanMap(bean);
			
	for (Map.Entry<Object, Object> e : properties.entrySet()) {
		if (e.getKey() instanceof String && beanmap.containsKey(e.getKey())) {
			String key = (String) e.getKey();
			String value = e.getValue().toString().trim();
			Class<?> type = beanmap.getType(key);
			if (type == null) // no such property!
				continue;
			
			logger.debug("setting property '"+key+"' of bean '"+bean.getClass().getSimpleName()+"' to '"+value+"'"+ " type = "+beanmap.getType(key));
			
			try {
				Object valueObject = getValue(beanmap.getType(key), value);
				BeanUtils.setProperty(bean, key, valueObject);
			}
			catch (Exception ex) {
				logger.warn("Could not set value of config attribute "+key+" to "+value+", error: "+ex.getMessage());
			}
		}
	}
}
 
开发者ID:Transkribus,项目名称:TranskribusSwtGui,代码行数:31,代码来源:Utils.java

示例4: getOperatorProperties

import org.apache.commons.beanutils.BeanMap; //导入依赖的package包/类
@GET
@Path(PATH_LOGICAL_PLAN_OPERATORS + "/{operatorName}/properties")
@Produces(MediaType.APPLICATION_JSON)
public JSONObject getOperatorProperties(@PathParam("operatorName") String operatorName, @QueryParam("propertyName") String propertyName) throws IOException, JSONException
{
  init();
  OperatorMeta logicalOperator = dagManager.getLogicalPlan().getOperatorMeta(operatorName);
  BeanMap operatorProperties = null;
  if (logicalOperator == null) {
    ModuleMeta logicalModule = dagManager.getModuleMeta(operatorName);
    if (logicalModule == null) {
      throw new NotFoundException();
    }
    operatorProperties = LogicalPlanConfiguration.getObjectProperties(logicalModule.getOperator());
  } else {
    operatorProperties = LogicalPlanConfiguration.getObjectProperties(logicalOperator.getOperator());
  }

  Map<String, Object> m = getPropertiesAsMap(propertyName, operatorProperties);
  return new JSONObject(objectMapper.writeValueAsString(m));
}
 
开发者ID:apache,项目名称:apex-core,代码行数:22,代码来源:StramWebServices.java

示例5: getPropertiesAsMap

import org.apache.commons.beanutils.BeanMap; //导入依赖的package包/类
private Map<String, Object> getPropertiesAsMap(@QueryParam("propertyName") String propertyName, BeanMap operatorProperties)
{
  Map<String, Object> m = new HashMap<>();
  @SuppressWarnings("rawtypes")
  Iterator entryIterator = operatorProperties.entryIterator();
  while (entryIterator.hasNext()) {
    try {
      @SuppressWarnings("unchecked")
      Map.Entry<String, Object> entry = (Map.Entry<String, Object>)entryIterator.next();
      if (propertyName == null) {
        m.put(entry.getKey(), entry.getValue());
      } else if (propertyName.equals(entry.getKey())) {
        m.put(entry.getKey(), entry.getValue());
        break;
      }
    } catch (Exception ex) {
      LOG.warn("Caught exception", ex);
    }
  }
  return m;
}
 
开发者ID:apache,项目名称:apex-core,代码行数:22,代码来源:StramWebServices.java

示例6: execute

import org.apache.commons.beanutils.BeanMap; //导入依赖的package包/类
@Override
public StatsListener.OperatorResponse execute(Operator operator, int operatorId, long windowId) throws IOException
{
  BeanMap beanMap = new BeanMap(operator);
  Map<String, Object> propertyValue = new HashMap<>();
  if (propertyName != null) {
    if (beanMap.containsKey(propertyName)) {
      propertyValue.put(propertyName, beanMap.get(propertyName));
    }
  } else {
    Iterator entryIterator = beanMap.entryIterator();
    while (entryIterator.hasNext()) {
      Map.Entry<String, Object> entry = (Map.Entry<String, Object>)entryIterator.next();
      propertyValue.put(entry.getKey(), entry.getValue());
    }
  }
  logger.debug("Getting property {} on operator {}", propertyValue, operator);
  OperatorResponse response = new OperatorResponse(requestId, propertyValue);
  return response;
}
 
开发者ID:apache,项目名称:apex-core,代码行数:21,代码来源:StramToNodeGetPropertyRequest.java

示例7: obtainHistorySummary

import org.apache.commons.beanutils.BeanMap; //导入依赖的package包/类
/**
 * JAVADOC Method Level Comments
 *
 * @param id
 *            JAVADOC.
 * @param applicationType
 *            JAVADOC.
 *
 * @return JAVADOC.
 */
@Override
@Transactional(readOnly = true)
public List<Map<Object, Object>> obtainHistorySummary(Serializable id, String applicationType) {
    Assert.notNull(id, "id must be provided!");
    Assert.hasText(applicationType, "applicationType is required!");

    List<Map<Object, Object>> results = new LinkedList<Map<Object, Object>>();
    List<HistoryRecord> hres = historyRecordRepository.findByIdAndApplicationType(id,
            applicationType);

    for (HistoryRecord historyRecord : hres) {
        Map<Object, Object> bm = new BeanMap(historyRecord);

        results.add(bm);
    }

    return results;
}
 
开发者ID:cucina,项目名称:opencucina,代码行数:29,代码来源:ProcessSupportServiceImpl.java

示例8: getGetter

import org.apache.commons.beanutils.BeanMap; //导入依赖的package包/类
@SuppressWarnings("unchecked")
protected Method getGetter(Class<?> objectClass, BeanMap beanMap, String keyName) {
	//check element to prevent null pointer
	Element element = getGetterCache().get(objectClass);
	Map<String, Method> getterMap = (element == null ? null : (Map<String, Method>) element.getObjectValue());
	if (getterMap == null) {
		getterMap = new HashMap<String, Method>();
		getGetterCache().put(new Element(objectClass, getterMap));
	}
	Method getter;
	if (getterMap.containsKey(keyName)) {
		getter = getterMap.get(keyName);
	} else {
		getter = beanMap.getReadMethod(keyName);
		getterMap.put(keyName, getter);
	}
	return getter;
}
 
开发者ID:Kyunghwa-Yoo,项目名称:StitchRTSP,代码行数:19,代码来源:Output.java

示例9: writeObject

import org.apache.commons.beanutils.BeanMap; //导入依赖的package包/类
/** {@inheritDoc} */
public void writeObject(Map<Object, Object> map) {
	if (checkWriteReference(map)) {
		return;
	}
	storeReference(map);
	buf.put(AMF.TYPE_OBJECT);
	boolean isBeanMap = (map instanceof BeanMap);
	for (Map.Entry<Object, Object> entry : map.entrySet()) {
		if (isBeanMap && "class".equals(entry.getKey())) {
			continue;
		}
		putString(entry.getKey().toString());
		Serializer.serialize(this, entry.getValue());
	}
	buf.put((byte) 0x00);
	buf.put((byte) 0x00);
	buf.put(AMF.TYPE_END_OF_OBJECT);
}
 
开发者ID:Kyunghwa-Yoo,项目名称:StitchRTSP,代码行数:20,代码来源:Output.java

示例10: fillBeanDefaults

import org.apache.commons.beanutils.BeanMap; //导入依赖的package包/类
/**
     * Fills the bean with the default values, by calling all the getters and setting the returned value.
     * @param bean
     * @return
     * @throws IllegalAccessException
     * @throws NoSuchMethodException
     * @throws InvocationTargetException
     */
    public static DiffableBean fillBeanDefaults(DiffableBean bean) throws IllegalAccessException, NoSuchMethodException, InvocationTargetException {
        BeanMap map = new BeanMap(bean);
        PropertyUtilsBean propUtils = new PropertyUtilsBean();

        for (Object propNameObject : map.keySet()) {
            String propertyName = (String) propNameObject;
            Object property1 = propUtils.getProperty(bean, propertyName);
            if(property1 == null || !DiffableBean.class.isAssignableFrom(property1.getClass())) {
                if(property1 != null) {
//					System.out.println(propertyName + ": " + property1.toString());
                    org.apache.commons.beanutils.BeanUtils.setProperty(bean, propertyName, property1);
                }
            } else {
//				System.out.println("RECURSIVE: " + propertyName);
                property1 = fillBeanDefaults((DiffableBean) property1);
                org.apache.commons.beanutils.BeanUtils.setProperty(bean, propertyName, property1);
            }
        }
        return bean;
    }
 
开发者ID:miguel-porto,项目名称:flora-on-server,代码行数:29,代码来源:BeanUtils.java

示例11: updateBean

import org.apache.commons.beanutils.BeanMap; //导入依赖的package包/类
/**
 * Updates a oldBean with all non-null values in the newBean.
 * @param cls
 * @param ignoreProperties
 * @param oldBean
 * @param newBean
 * @param <T>
 * @return
 * @throws IllegalAccessException
 * @throws InvocationTargetException
 * @throws NoSuchMethodException
 * @throws FloraOnException
 * @throws InstantiationException
 */
public static <T extends DiffableBean> T updateBean(Class<T> cls, Collection<String> ignoreProperties, T oldBean, T newBean) throws IllegalAccessException
        , InvocationTargetException, NoSuchMethodException, FloraOnException, InstantiationException {
    BeanMap propertyMap = new BeanMap(oldBean);    // we assume beans are the same class! so we take the first as a model
    PropertyUtilsBean propUtils = new PropertyUtilsBean();
    BeanUtilsBean bub = createBeanUtilsNull();

    T out = cls.newInstance();

    for (Object propNameObject : propertyMap.keySet()) {
        String propertyName = (String) propNameObject;
        if(ignoreProperties != null && ignoreProperties.contains(propertyName)) continue;
        System.out.println("PROP: " + propertyName);
        Object newProperty;

        newProperty = propUtils.getProperty(newBean, propertyName);

        if(newProperty == null)
            bub.setProperty(out, propertyName, propUtils.getProperty(oldBean, propertyName));
        else
            bub.setProperty(out, propertyName, newProperty);
        // TODO: nested beans
    }
    return out;
}
 
开发者ID:miguel-porto,项目名称:flora-on-server,代码行数:39,代码来源:BeanUtils.java

示例12: mapFromDomainObject

import org.apache.commons.beanutils.BeanMap; //导入依赖的package包/类
/**
 * Maps the given instance of the domain class to an instance of the {@code CaseXml} class.
 *
 * @param careCase  the instance of the domain class
 * @return the created instance of the {@link CaseXml} class
 */
public CaseXml mapFromDomainObject(T careCase) {
    CaseXml ccCase = new CaseXml();

    try {
        BeanUtils.copyProperties(ccCase, careCase);
    } catch (IllegalAccessException | InvocationTargetException e) {
        throw new IllegalStateException("Unable to map case XML from a domain object", e);
    }

    BeanMap beanMap = new BeanMap(careCase);
    removeStaticProperties(beanMap);

    Map<String, String> valueMap = new HashMap<>();
    while (beanMap.keyIterator().hasNext()) {
        valueMap.put(beanMap.keyIterator().next(), (String) beanMap.get(beanMap.keyIterator().next()));
    }
    ccCase.setFieldValues(valueMap);

    return ccCase;
}
 
开发者ID:motech,项目名称:modules,代码行数:27,代码来源:CaseMapper.java

示例13: simpleComponentConfigEntryWithOverride

import org.apache.commons.beanutils.BeanMap; //导入依赖的package包/类
/**
 * A utility methods to make it easier for components to configure themselves using the componentConfig
 * configuration and user overrides. It covers the most common case, where the configuration is a HashMap
 * that maps String to String and the override property is a string as well.
 * @param componentNode the key in the componentConfig hash for this component
 * @param key the key in the component node for the configuration item
 * @param overrideProperty the property name in the UserOverrides class. May be null. If not must exist.
 * @return the value, with the override applied if the override exists and is not blank
 * @throws InvalidArgumentException
 */
@Override
public String simpleComponentConfigEntryWithOverride(String componentNode, String key, String overrideProperty) throws InvalidArgumentException, InvalidStateException, IOException {
    String retval = null;
    try {
        HashMap componentConfig = (HashMap) getComponentConfigFor(componentNode);
        if (componentConfig != null) {
            retval = componentConfig.get(key).toString();
        }
        if (userOverrides != null && overrideProperty != null) {
            BeanMap overrides = new BeanMap(userOverrides);
            if (overrides.containsKey(overrideProperty)) {
                Object value = overrides.get(overrideProperty);
                String overrideValue = (value == null) ? null : value.toString();
                if (!StringUtils.isBlank(overrideValue)) {
                    retval = overrideValue;
                }
            }
        }
    } catch (ClassCastException e) {
        throw new InvalidArgumentException("Class cast problem in simpleComponentConfigEntryWithOverride() - most likely a mismatch between waht you expect the config or the overrides to contain and what they actually contain: " + e, e);
    }
    retval = interpolate(retval);
    return retval;
}
 
开发者ID:arnonmoscona,项目名称:iqfeed,代码行数:35,代码来源:IqFeedConfig.java

示例14: getGetter

import org.apache.commons.beanutils.BeanMap; //导入依赖的package包/类
@SuppressWarnings("unchecked")
protected Method getGetter(Class<?> objectClass, BeanMap beanMap, String keyName) {
    //check element to prevent null pointer
    Element element = getGetterCache().get(objectClass);
    Map<String, Method> getterMap = (element == null ? null : (Map<String, Method>) element.getObjectValue());
    if (getterMap == null) {
        getterMap = new HashMap<String, Method>();
        getGetterCache().put(new Element(objectClass, getterMap));
    }
    Method getter;
    if (getterMap.containsKey(keyName)) {
        getter = getterMap.get(keyName);
    } else {
        getter = beanMap.getReadMethod(keyName);
        getterMap.put(keyName, getter);
    }
    return getter;
}
 
开发者ID:Red5,项目名称:red5-io,代码行数:19,代码来源:Output.java

示例15: writeObject

import org.apache.commons.beanutils.BeanMap; //导入依赖的package包/类
/** {@inheritDoc} */
@Override
public void writeObject(Map<Object, Object> map) {
    if (!checkWriteReference(map)) {
        storeReference(map);
        buf.put(AMF.TYPE_OBJECT);
        boolean isBeanMap = (map instanceof BeanMap);
        for (Map.Entry<Object, Object> entry : map.entrySet()) {
            if (isBeanMap && "class".equals(entry.getKey())) {
                continue;
            }
            putString(entry.getKey().toString());
            Serializer.serialize(this, entry.getValue());
        }
        buf.put(AMF.END_OF_OBJECT_SEQUENCE);
    }
}
 
开发者ID:Red5,项目名称:red5-io,代码行数:18,代码来源:Output.java


注:本文中的org.apache.commons.beanutils.BeanMap类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。