Class ParamReader

java.lang.Object
esa.opensf.osfi.ParamReader

public class ParamReader extends Object
ParamReader.
Constructs the list of parameters associated with a model stored in a XML configuration file.
Uses the DOM tree specification.
  • Constructor Details

    • ParamReader

      @Deprecated(since="3.5.0") public ParamReader(String xmlFile, String xsdFile) throws FileNotFoundException, XmlParseException
      Deprecated.
      Use the single argument version and call validateAgainst(String)
      Creates an instance of the ParamReader class, parses a given configuration XML file and stores every valid parameter.
      Parameters:
      xmlFile - Configuration XML file
      xsdFile - Configuration XSD schema. Validating against an XSD schema is optional
      Throws:
      XmlParseException - if error while parsing
      FileNotFoundException - if the XML file does not exist or cannot be read
    • ParamReader

      public ParamReader(String xmlFile) throws FileNotFoundException, XmlParseException
      Parses a given configuration XML file and stores the parameters read from it.
      Parameters:
      xmlFile - Configuration XML file
      Throws:
      XmlParseException - if any error occurs while parsing
      FileNotFoundException - if the XML file does not exist or cannot be read
    • ParamReader

      public ParamReader(Element el, String pathPrefix) throws XmlParseException
      Parses a given configuration XML subtree and stores the parameters read from it. This allows the user to read parameter objects from an OSFI-compliant fragment of a non-OSFI file.
      Parameters:
      el - Element that will be considered the root of the given tree. Note that this element is not parsed itself, only its children are. Thus, if a single parameter is to be parsed, it needs to be wrapped by an element.
      pathPrefix - Path up to and including el. If not null, paths of child parameters/groups will be prefixed with this string plus a period.
      Throws:
      XmlParseException - if error while parsing
  • Method Details

    • load

      public static LoadResult<ParamReader> load(LoadResult<Document> xml, boolean stopOnSingleParamError, Map<String,Parameter> map, Set<ParamReader.WarningType> suppWarns)
      Parse the contents of an XML document into OSFI parameters.
      Parameters:
      xml - Returned by calling one of the loader functions in XmlFiles
      stopOnSingleParamError - If true, an error loading a single parameter will stop the process. Otherwise, only a fatal error (e.g. a structural).
      map - Container that will be used to store the parameters read.
      suppWarns - The types of warnings that will be suppressed.
      Returns:
      Result object with the parsed parameters (if successful) and the list of warnings and errors ocurred during the parsing.
    • load

      public static LoadResult<ParamReader> load(LoadResult<Document> xml, boolean stopOnSingleParamError, Map<String,Parameter> map)
      Parse the contents of an XML document into OSFI parameters. Equivalent to calling load(LoadResult, boolean, Map, Set) with a a default set of suppressed warnings.
      Parameters:
      xml - Returned by calling one of the loader functions in XmlFiles
      stopOnSingleParamError - If true, an error loading a single parameter will stop the process. Otherwise, only a fatal error (e.g. a structural).
      map - Container that will be used to store the parameters read.
      Returns:
      Result object with the parsed parameters (if successful) and the list of warnings and errors ocurred during the parsing.
      See Also:
    • load

      public static LoadResult<ParamReader> load(LoadResult<Document> xml, boolean stopOnSingleParamError)
      Parse the contents of an XML document into OSFI parameters. Equivalent to calling the other overload with a new empty map as the third argument.
      Parameters:
      xml - Returned by calling one of the loader functions in XmlFiles
      stopOnSingleParamError - If true, an error loading a single parameter will stop the process. Otherwise, only a fatal error (e.g. a structural)
      Returns:
      Result object with the parsed parameters (if successful) and the list of warnings and errors ocurred during the parsing.
      See Also:
    • validateAgainst

      public boolean validateAgainst(String xsdFile)
      Validate the XML file read against the given XSD schema.
      Parameters:
      xsdFile - Path to a schema file which must exist
      Returns:
      true if the validation succeeds, false otherwise.
      Throws:
      IllegalArgumentException - if the schema cannot be loaded
    • validateAgainstInternalSchema

      public boolean validateAgainstInternalSchema()
      Validate the XML file read against the XSD schema referenced in the file itself.
      Returns:
      true if the validation succeeds, false otherwise.
    • getParameter

      public Parameter getParameter(String name)
      Retrieves the parameter object corresponding with given name in the configuration file.
      Parameters:
      name - Parameter full path.
      Returns:
      Parameter instance, or null if no parameter exists with that name.
    • getParameters

      public List<Parameter> getParameters(String groupName)
      Parameters:
      groupName - Full name of the group
      Returns:
      List of parameters under a certain group, including direct and indirect children.
    • getAllParameters

      public Map<String,Parameter> getAllParameters()
      Returns:
      A map containing all stored parameters.
    • existParameter

      public boolean existParameter(String name)

      Checks the existence of a parameter within a configuration file.

      Parameters:
      name - Parameter name (full path and name)
      Returns:
      boolean True if the parameter exists False otherwise.
    • setParameter

      public void setParameter(String paramName, Parameter value)
      Changes the stored value of a certain parameter. Shows an error if cannot find parameter.
      Parameters:
      paramName - - full name of the parameter
      value - - new value
      Throws:
      IllegalArgumentException - if parameter did not already exist
    • write

      public void write()

      Prints a textual representation of the list of Parameters on screen.

    • isStandardAttribute

      public static boolean isStandardAttribute(String key)
      Determines whether a given parameter attribute is E2E-ICD standard.
      Parameters:
      key - attribute name
      Returns:
      true if the parameter is interpreted by this class, false otherwise.
      See Also:
      • collectOtherAttributes(Element, Map, java.util.function.Supplier)