コード例 #1
0
ファイル: SimpleCommand.java プロジェクト: iamthechad/frame2
  @Override
  void set(PropertyMapping mapping, Object value) throws BeanException {
    PropertyDescriptor descriptor = getDescriptor(mapping.getBean(), mapping.getKey());

    if (descriptor != null) {
      Method setMethod = descriptor.getWriteMethod();
      Class<?> type = descriptor.getPropertyType();

      try {
        Object convertedValue = null;
        Class<?> arrayRef = type.getComponentType();
        if (value instanceof Object[]) {
          Object[] values = (Object[]) value;
          if (arrayRef == null) {
            convertedValue = Converter.convertValueToType(values[0], type);
          } else {
            for (int i = 0; i < values.length; i++) {
              values[i] = Converter.convertValueToType(values[i], type);
            }
            convertedValue = values;
          }
        } else {
          if (arrayRef == null) {
            convertedValue = Converter.convertValueToType(value, type);
          } else {
            convertedValue = Converter.convertValueToArrayType(value, type);
          }
        }

        setMethod.invoke(mapping.getBean(), new Object[] {convertedValue});
      } catch (Exception e) {
        throw new MappingException(
            "Unable to set property",
            mapping, //$NON-NLS-1$
            value,
            e);
      }
    } else {
      LOGGER.info(
          "Unable to locate descriptor for property " //$NON-NLS-1$
              + mapping.getKey());
    }
  }
コード例 #2
0
ファイル: SimpleCommand.java プロジェクト: iamthechad/frame2
  @Override
  Object get(PropertyMapping mapping) throws BeanException {
    PropertyDescriptor descriptor = getDescriptor(mapping.getBean(), mapping.getKey());

    if (descriptor != null) {
      try {
        Method getMethod = descriptor.getReadMethod();

        return getMethod.invoke(mapping.getBean(), (Object[]) null);
      } catch (Exception e) {
        throw new MappingException("Unable to get property", mapping, e); // $NON-NLS-1$
      }
    }

    LOGGER.info(
        "Unable to locate descriptor for property " //$NON-NLS-1$
            + mapping.getKey());
    return null;
  }