Example #1
0
  private void appendOperations(SyncmlBody syncmlBody) throws WindowsOperationException {
    Get getElement = new Get();
    List<Item> itemsGet = new ArrayList<Item>();

    Exec execElement = new Exec();
    List<Item> itemsExec = new ArrayList<Item>();

    Atomic atomicElement = new Atomic();
    List<Add> addsAtomic = new ArrayList<Add>();

    if (operations != null) {
      for (int x = 0; x < operations.size(); x++) {
        Operation operation = operations.get(x);
        Operation.Type type = operation.getType();
        switch (type) {
          case CONFIG:
            List<Add> addConfig = appendAddConfiguration(operation);
            for (Add addConfiguration : addConfig) {
              addsAtomic.add(addConfiguration);
            }
            break;
          case MESSAGE:;
            break;
          case INFO:
            Item itemGet = appendGetInfo(operation);
            itemsGet.add(itemGet);
            break;
          case COMMAND:
            Item itemExec = appendExecInfo(operation);
            itemsExec.add(itemExec);
            break;
          default:
            throw new WindowsOperationException("Operation with no type found");
        }
      }
    }

    if (!itemsGet.isEmpty()) {
      getElement.setCommandId(75);
      getElement.setItems(itemsGet);
    }

    if (!itemsExec.isEmpty()) {
      execElement.setCommandId(5);
      execElement.setItems(itemsExec);
    }

    if (!addsAtomic.isEmpty()) {
      atomicElement.setCommandId(300);
      atomicElement.setAdds(addsAtomic);
    }

    syncmlBody.setGet(getElement);
    syncmlBody.setExec(execElement);
  }
Example #2
0
  private SyncmlBody generateStatuses() {
    SyncmlBody sourceSyncmlBody = syncmlDocument.getBody();
    SyncmlHeader sourceHeader = syncmlDocument.getHeader();
    SyncmlBody syncmlBodyReply = new SyncmlBody();
    List<Status> status = new ArrayList<Status>();
    Status headerStatus =
        new Status(
            HEADER_COMMAND_REFERENCE_ID,
            sourceHeader.getMsgID(),
            HEADER_STATUS_ID,
            HEADER_COMMAND_TEXT,
            sourceHeader.getSource().getLocURI(),
            String.valueOf(Constants.SyncMLResponseCodes.AUTHENTICATION_ACCEPTED));
    status.add(headerStatus);
    if (sourceSyncmlBody.getAlert() != null) {
      Status alertStatus =
          new Status(
              sourceSyncmlBody.getAlert().getCommandId(),
              HEADER_COMMAND_REFERENCE_ID,
              sourceSyncmlBody.getAlert().getCommandId(),
              ALERT_COMMAND_TEXT,
              null,
              String.valueOf(Constants.SyncMLResponseCodes.ACCEPTED));
      status.add(alertStatus);
    }
    if (sourceSyncmlBody.getReplace() != null) {
      Status replaceStatus =
          new Status(
              sourceSyncmlBody.getReplace().getCommandId(),
              HEADER_COMMAND_REFERENCE_ID,
              sourceSyncmlBody.getReplace().getCommandId(),
              REPLACE_COMMAND_TEXT,
              null,
              String.valueOf(Constants.SyncMLResponseCodes.ACCEPTED));
      status.add(replaceStatus);
    }
    if (sourceSyncmlBody.getExec() != null) {
      Status replaceStatus =
          new Status(
              sourceSyncmlBody.getExec().getCommandId(),
              HEADER_COMMAND_REFERENCE_ID,
              sourceSyncmlBody.getExec().getCommandId(),
              GET_COMMAND_TEXT,
              null,
              String.valueOf(Constants.SyncMLResponseCodes.ACCEPTED));
      status.add(replaceStatus);
    }
    if (sourceSyncmlBody.getGet() != null) {
      Status execStatus =
          new Status(
              sourceSyncmlBody.getGet().getCommandId(),
              HEADER_COMMAND_REFERENCE_ID,
              sourceSyncmlBody.getGet().getCommandId(),
              EXEC_COMMAND_TEXT,
              null,
              String.valueOf(Constants.SyncMLResponseCodes.ACCEPTED));
      status.add(execStatus);
    }

    syncmlBodyReply.setStatus(status);
    return syncmlBodyReply;
  }