コード例 #1
0
 public void notifyObservers(Activity activity) {
   for (ActionCommand<?> observer : getObservers()) {
     observer.update(activity);
   }
 }
コード例 #2
0
  @Override
  protected ActionCommand<?> createEntity(JSONArray args) {
    try {
      ActionCommand<?> result = null;

      int counter = 0;

      String actionType = args.getString(counter++);

      String idStr = args.getString(counter++);

      String name = args.getString(counter++);
      String description = args.getString(counter++);

      if ("CONFIGURATION".equals(actionType)) {
        Configuration configuration = new Configuration();

        String settingStr = args.getString(counter++);
        Double setting = Double.parseDouble(settingStr);
        configuration.setSetting(setting);

        String settingType = args.getString(counter++);

        ConfigurationType type = ConfigurationType.valueOf(settingType);

        configuration.setType(type);

        switch (type) {
          case SCREEN:
            result = new ScreenConfigurationCommand(configuration);
            break;

          case VOLUME:
            result = new VolumeConfigurationCommand(configuration);
            break;

          default:
            break;
        }
      } else {
        Notification notification = new Notification();

        String sendTo = args.getString(counter++);
        notification.setSendTo(sendTo);

        String notificationTypeStr = args.getString(counter++);

        NotificationType type = NotificationType.valueOf(notificationTypeStr);
        notification.setType(type);

        String message = args.getString(counter++);
        notification.setMessage(message);

        switch (type) {
          case SMS:
            result = new SmsNotificationCommand(notification);
            break;

          case EMAIL:
            result = new EmailNotificationCommand(notification);
            break;

          case ALERT:
            result = new AlertNotificationCommand(notification);
            break;

          default:
            break;
        }
      }

      if (idStr != null && !(idStr.trim().length() == 0)) {
        Integer id = Integer.parseInt(idStr);
        result.setId(id);
      }

      result.setName(name);
      result.setDescription(description);

      return result;
    } catch (JSONException e) {
      throw new RuntimeException(e);
    }
  }