Exemplo n.º 1
0
  /** {@inheritDoc} */
  public Document encodeXML() throws InvalidLLRPMessageException {
    try {
      Namespace ns = Namespace.getNamespace("llrp", LLRPConstants.LLRPNAMESPACE);

      Element root = new Element("SET_READER_CONFIG", ns);
      //	Element root = new Element("SET_READER_CONFIG");
      root.addNamespaceDeclaration(Namespace.getNamespace("llrp", LLRPConstants.LLRPNAMESPACE));

      if (version == null) {
        throw new InvalidLLRPMessageException("Version not set");
      } else {
        root.setAttribute("Version", version.toInteger().toString());
      }

      if (messageID == null) {
        throw new InvalidLLRPMessageException("MessageID not set");
      } else {
        root.setAttribute("MessageID", messageID.toString(10));
      }

      if (resetToFactoryDefault == null) {
        LOGGER.warn(" resetToFactoryDefault not set");
        throw new MissingParameterException(" resetToFactoryDefault not set");
      } else {
        root.addContent(resetToFactoryDefault.encodeXML("ResetToFactoryDefault", ns));
      }

      // root.addContent(reserved0.encodeXML("reserved",ns));
      // parameters
      if (readerEventNotificationSpec == null) {
        LOGGER.info("readerEventNotificationSpec not set");
      } else {
        root.addContent(
            readerEventNotificationSpec.encodeXML(
                readerEventNotificationSpec.getClass().getSimpleName(), ns));
      }

      if (antennaPropertiesList == null) {
        LOGGER.info("antennaPropertiesList not set");
      } else {
        for (AntennaProperties field : antennaPropertiesList) {
          root.addContent(
              field.encodeXML(
                  field
                      .getClass()
                      .getName()
                      .replaceAll(field.getClass().getPackage().getName() + ".", ""),
                  ns));
        }
      }

      if (antennaConfigurationList == null) {
        LOGGER.info("antennaConfigurationList not set");
      } else {
        for (AntennaConfiguration field : antennaConfigurationList) {
          root.addContent(
              field.encodeXML(
                  field
                      .getClass()
                      .getName()
                      .replaceAll(field.getClass().getPackage().getName() + ".", ""),
                  ns));
        }
      }

      if (rOReportSpec == null) {
        LOGGER.info("rOReportSpec not set");
      } else {
        root.addContent(rOReportSpec.encodeXML(rOReportSpec.getClass().getSimpleName(), ns));
      }

      if (accessReportSpec == null) {
        LOGGER.info("accessReportSpec not set");
      } else {
        root.addContent(
            accessReportSpec.encodeXML(accessReportSpec.getClass().getSimpleName(), ns));
      }

      if (keepaliveSpec == null) {
        LOGGER.info("keepaliveSpec not set");
      } else {
        root.addContent(keepaliveSpec.encodeXML(keepaliveSpec.getClass().getSimpleName(), ns));
      }

      if (gPOWriteDataList == null) {
        LOGGER.info("gPOWriteDataList not set");
      } else {
        for (GPOWriteData field : gPOWriteDataList) {
          root.addContent(
              field.encodeXML(
                  field
                      .getClass()
                      .getName()
                      .replaceAll(field.getClass().getPackage().getName() + ".", ""),
                  ns));
        }
      }

      if (gPIPortCurrentStateList == null) {
        LOGGER.info("gPIPortCurrentStateList not set");
      } else {
        for (GPIPortCurrentState field : gPIPortCurrentStateList) {
          root.addContent(
              field.encodeXML(
                  field
                      .getClass()
                      .getName()
                      .replaceAll(field.getClass().getPackage().getName() + ".", ""),
                  ns));
        }
      }

      if (eventsAndReports == null) {
        LOGGER.info("eventsAndReports not set");
      } else {
        root.addContent(
            eventsAndReports.encodeXML(eventsAndReports.getClass().getSimpleName(), ns));
      }

      if (customList == null) {
        LOGGER.info("customList not set");
      } else {
        for (Custom field : customList) {
          root.addContent(
              field.encodeXML(
                  field
                      .getClass()
                      .getName()
                      .replaceAll(field.getClass().getPackage().getName() + ".", ""),
                  ns));
        }
      }

      Document doc = new Document(root);

      if (isValidXMLMessage(doc, LLRPConstants.LLRPMESSAGESCHEMAPATH)) {
        return doc;
      } else {
        return null;
      }
    } catch (IllegalArgumentException e) {
      throw new InvalidLLRPMessageException(e.getMessage());
    } catch (MissingParameterException e) {
      throw new InvalidLLRPMessageException(e.getMessage());
    }
  }