Java Code Examples for org.apache.commons.beanutils.BeanMap#containsKey()

The following examples show how to use org.apache.commons.beanutils.BeanMap#containsKey() . 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: StramToNodeGetPropertyRequest.java    From Bats with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example 2
Source File: StramToNodeGetPropertyRequest.java    From attic-apex-core with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example 3
Source File: ServiceActions.java    From sailfish-core with Apache License 2.0 5 votes vote down vote up
@CommonColumns(@CommonColumn(value = Column.ServiceName, required = true))
@ActionMethod
   public void initService(IActionContext actionContext, HashMap<?, ?> message) throws IllegalAccessException, InvocationTargetException, InterruptedException, IOException {
	ServiceName serviceName = ServiceName.parse(actionContext.getServiceName());
	IActionServiceManager serviceManager = actionContext.getServiceManager();

	try {
           IServiceSettings serviceSettings = serviceManager.getServiceSettings(serviceName);
		BeanMap beanMap = new BeanMap(serviceSettings);
		Set<String> editedProperty = new HashSet<>();
		Set<String> incorrectProperty = new HashSet<>();
		for (Entry<?, ?> entry : message.entrySet()) {
			String property = convertProperty(entry.getKey().toString());
			if (beanMap.containsKey(property)){
				BeanUtils.setProperty(serviceSettings, property, converter.get().convert((Object)unwrapFilters(entry.getValue()), beanMap.getType(property)));
                   editedProperty.add(property);
			} else {
				incorrectProperty.add(property);
			}
		}

		if (!incorrectProperty.isEmpty()) {
			throw new EPSCommonException(serviceSettings.getClass().getName() + " does not contain properties: " + incorrectProperty);
		}

           serviceManager.updateService(serviceName, serviceSettings, null).get();

		try (FileOutputStream out = new FileOutputStream(actionContext.getReport().createFile(StatusType.NA, servicesFolder, changingSettingFolder, serviceName + FORMATTER.format(DateTimeUtility.nowLocalDateTime()) + servicesFileExpression))) {
               actionContext.getServiceManager().serializeServiceSettings(serviceName, out);
           }
       } catch (ExecutionException e) {
           ExceptionUtils.rethrow(ObjectUtils.defaultIfNull(e.getCause(), e));
       }
}
 
Example 4
Source File: Output.java    From red5-io with Apache License 2.0 4 votes vote down vote up
/** {@inheritDoc} */
@SuppressWarnings({ "rawtypes" })
@Override
public void writeObject(Object object) {
    if (!checkWriteReference(object)) {
        storeReference(object);
        // create new map out of bean properties
        BeanMap beanMap = new BeanMap(object);
        // set of bean attributes
        Set attrs = beanMap.keySet();
        log.trace("Bean map keys: {}", attrs);
        if (attrs.size() == 0 || (attrs.size() == 1 && beanMap.containsKey("class"))) {
            // beanMap is empty or can only access "class" attribute, skip it
            writeArbitraryObject(object);
            return;
        }
        // write out either start of object marker for class name or "empty" start of object marker
        Class<?> objectClass = object.getClass();
        if (!objectClass.isAnnotationPresent(Anonymous.class)) {
            buf.put(AMF.TYPE_CLASS_OBJECT);
            putString(buf, Serializer.getClassName(objectClass));
        } else {
            buf.put(AMF.TYPE_OBJECT);
        }
        if (object instanceof ICustomSerializable) {
            ((ICustomSerializable) object).serialize(this);
            buf.put(AMF.END_OF_OBJECT_SEQUENCE);
            return;
        }
        // Iterate thru entries and write out property names with separators
        for (Object key : attrs) {
            String fieldName = key.toString();
            log.debug("Field name: {} class: {}", fieldName, objectClass);
            Field field = getField(objectClass, fieldName);
            Method getter = getGetter(objectClass, beanMap, fieldName);
            // Check if the Field corresponding to the getter/setter pair is transient
            if (!serializeField(objectClass, fieldName, field, getter)) {
                continue;
            }
            putString(buf, fieldName);
            Serializer.serialize(this, field, getter, object, beanMap.get(key));
        }
        // write out end of object mark
        buf.put(AMF.END_OF_OBJECT_SEQUENCE);
    }
}