Exemplo n.º 1
0
  /**
   * Parses the given {@link de.xirp.profile.Robot robot} file and returns the resulting {@link
   * de.xirp.profile.Robot robot} bean. <br>
   * <br>
   * This method calls the {@link de.xirp.profile.ProfileParser#parseComSpec(String)} method for all
   * available {@link de.xirp.profile.CommunicationSpecification comm-spec} file names from the just
   * created {@link de.xirp.profile.Robot robot} object. At return time of the method the returned
   * {@link de.xirp.profile.Robot robot} is complete including the {@link
   * de.xirp.profile.CommunicationSpecification comm-specs}.
   *
   * @param fileName The XML robot file name (without postfix and path).
   * @param factory The factory which is used to load the XML schema definition used for validating
   *     the XML.
   * @return the parsed robot or <code>null</code> if an error occurred.
   * @see de.xirp.profile.Robot
   * @see de.xirp.profile.CommunicationSpecification
   */
  private static Robot parseRobot(String fileName, SchemaFactory factory) {
    if (!Util.isEmpty(fileName)) {
      try {
        JAXBContext jc = JAXBContext.newInstance(Robot.class);
        Unmarshaller um = jc.createUnmarshaller();

        try {
          Schema schema = factory.newSchema(new File(Constants.CONF_ROBOTS_XML_SCHEMA));
          um.setSchema(schema);
        } catch (SAXException e) {
          logClass.error(
              "Error: "
                  + e.getMessage()
                  + //$NON-NLS-1$
                  Constants.LINE_SEPARATOR,
              e);
        }

        Robot robot =
            (Robot)
                um.unmarshal(
                    new File(
                        Constants.CONF_ROBOTS_DIR
                            + File.separator
                            + fileName
                            + Constants.ROBOT_POSTFIX));

        String cmsFileName = robot.getCommSpecFileName();
        CommunicationSpecification comSpec = parseComSpec(cmsFileName, factory);
        if (comSpec.isComplete()) {
          robot.setCommunicationSpecification(comSpec);
        } else {
          logClass.warn(
              Constants.LINE_SEPARATOR
                  + I18n.getString(
                      "ProfileParser.log.comspecNotCompleted", //$NON-NLS-1$
                      Constants.LINE_SEPARATOR,
                      (cmsFileName + Constants.COMM_SPEC_POSTFIX))
                  + Constants.LINE_SEPARATOR);
        }

        robot.setBotFile(new File(Constants.CONF_ROBOTS_DIR, fileName));
        return robot;
      } catch (JAXBException e) {
        logClass.error("Error " + e.getMessage() + Constants.LINE_SEPARATOR, e);
        return null;
      }
    } else {
      return null;
    }
  }
Exemplo n.º 2
0
  /**
   * Parses the given {@link de.xirp.profile.CommunicationSpecification comm-spec} file and returns
   * the resulting {@link de.xirp.profile.CommunicationSpecification comm-spec} bean.
   *
   * @param fileName The XML comm-spec file name (without postfix and path).
   * @param factory The factory which is used to load the XML schema definition used for validating
   *     the XML.
   * @return the parsed communicationSpecification or <code>null</code> if an error occurred.
   */
  private static CommunicationSpecification parseComSpec(String fileName, SchemaFactory factory) {

    if (!Util.isEmpty(fileName)) {
      CommunicationSpecification comSpec;
      try {
        JAXBContext jc = JAXBContext.newInstance(CommunicationSpecification.class);
        Unmarshaller um = jc.createUnmarshaller();
        try {
          Schema schema = factory.newSchema(new File(Constants.CONF_COMMSPECS_XML_SCHEMA));
          um.setSchema(schema);
        } catch (SAXException e) {
          logClass.error(
              "Error: "
                  + e.getMessage()
                  + //$NON-NLS-1$
                  Constants.LINE_SEPARATOR,
              e);
        }
        comSpec =
            (CommunicationSpecification)
                um.unmarshal(
                    new File(
                        Constants.CONF_COMMSPECS_DIR
                            + File.separator
                            + fileName
                            + Constants.COMM_SPEC_POSTFIX));

        comSpec.setCmsFile(new File(Constants.CONF_COMMSPECS_DIR, fileName));
        return comSpec;
      } catch (JAXBException e) {
        logClass.error(
            "Error "
                + e.getMessage() // $NON-NLS-1$
                + Constants.LINE_SEPARATOR,
            e);
        return null;
      }
    } else {
      return null;
    }
  }