Beispiel #1
0
  static {
    /** Configure BeanUtilsBean to use our converters and resolver. */
    ConvertUtilsBean convertUtils = new ConvertUtilsBean();

    // Register bean type converters
    convertUtils.register(
        new Converter() {
          @SuppressWarnings("rawtypes")
          @Override
          public Object convert(Class type, Object value) {
            if (value instanceof StringType) {
              return AwayState.forValue(value.toString());
            } else {
              return null;
            }
          }
        },
        AwayState.class);
    convertUtils.register(
        new Converter() {
          @SuppressWarnings("rawtypes")
          @Override
          public Object convert(Class type, Object value) {
            if (value instanceof StringType) {
              return HvacMode.forValue(value.toString());
            } else {
              return null;
            }
          }
        },
        HvacMode.class);
    convertUtils.register(
        new Converter() {
          @SuppressWarnings("rawtypes")
          @Override
          public Object convert(Class type, Object value) {
            if (value instanceof StringType) {
              return BatteryHealth.forValue(value.toString());
            } else {
              return null;
            }
          }
        },
        BatteryHealth.class);
    convertUtils.register(
        new Converter() {
          @SuppressWarnings("rawtypes")
          @Override
          public Object convert(Class type, Object value) {
            if (value instanceof StringType) {
              return AlarmState.forValue(value.toString());
            } else {
              return null;
            }
          }
        },
        AlarmState.class);
    convertUtils.register(
        new Converter() {
          @SuppressWarnings("rawtypes")
          @Override
          public Object convert(Class type, Object value) {
            if (value instanceof StringType) {
              return ColorState.forValue(value.toString());
            } else {
              return null;
            }
          }
        },
        ColorState.class);
    convertUtils.register(
        new Converter() {
          @SuppressWarnings("rawtypes")
          @Override
          public Object convert(Class type, Object value) {
            if (value instanceof DecimalType) {
              return ((DecimalType) value).intValue();
            } else {
              return null;
            }
          }
        },
        Integer.class);
    convertUtils.register(
        new Converter() {
          @SuppressWarnings("rawtypes")
          @Override
          public Object convert(Class type, Object value) {
            if (value instanceof OnOffType) {
              return ((OnOffType) value) == OnOffType.ON;
            } else {
              return null;
            }
          }
        },
        Boolean.class);
    convertUtils.register(
        new Converter() {
          @SuppressWarnings("rawtypes")
          @Override
          public Object convert(Class type, Object value) {
            return value.toString();
          }
        },
        String.class);

    propertyUtils = new PropertyUtilsBean();
    propertyUtils.setResolver(new DataModelPropertyResolver());
    beanUtils = new BeanUtilsBean(convertUtils, propertyUtils);
  }