Class XMLConfiguration

java.lang.Object
org.eclipse.net4j.util.XMLConfiguration

public final class XMLConfiguration extends Object
A finalized, immutable snapshot of an XML document. Set parameters before calling prepare(File) or prepare(Reader). Preparation uses a namespace-aware, secure parser, preprocesses conditional elements, expands retained element attributes, and records metadata on the resulting DOM nodes. The prepared document is fixed: later parameter or converter changes do not alter its values.

Parameter keys are replaced literally wherever they occur in attribute values. The standard keys are @user, @state, and @config; callers may add or replace keys before preparation. Values are expanded with StringUtil.replace(String, Map) and then passed through registered StringConverters. Conditions are evaluated before ordinary attribute expansion. See XMLUtil.preprocessConditions(org.w3c.dom.Document, Map) for condition syntax.

getDocument() returns a defensive DOM copy. Its expanded-state metadata is copied with the nodes so that downstream processors can distinguish finalized values from values in an unprocessed document. This allows multiple consumers to inspect the same snapshot without sharing mutable DOM nodes. File-backed configurations retain their source file; Reader-backed configurations do not have a source file.

Parsing rejects DTD declarations and disables external entities, XInclude, and entity expansion. Namespace-free XML documents remain valid. For example:

<configuration>
  <service endpoint="@endpoint" enabled="true"/>
</configuration>
Since:
3.31
Author:
Eike Stepper
  • Constructor Details

    • XMLConfiguration

      public XMLConfiguration(IManagedContainer container)
      Creates a configuration preparation context.
      Parameters:
      container - the container used to resolve StringConverter expressions; it may be null
  • Method Details

    • setParameter

      public String setParameter(String name, String value)
      Adds or replaces a preparation parameter.
      Parameters:
      name - the parameter name
      value - its value; null removes the parameter
      Returns:
      the previous value
      Throws:
      IllegalStateException - if preparation has completed
    • setParameters

      public void setParameters(Map<String,String> values)
      Adds or replaces preparation parameters.
      Parameters:
      values - the values to copy
      Throws:
      IllegalStateException - if preparation has completed
    • replaceParameters

      public void replaceParameters(Map<String,String> values)
      Replaces all preparation parameters with an exact supplied snapshot, including removing any default parameter that is absent from the snapshot.
      Parameters:
      values - the complete parameter snapshot to copy
      Throws:
      IllegalStateException - if preparation has completed
      Since:
      3.31
    • prepare

      Parses and prepares a file-backed configuration.
      Parameters:
      file - the XML source
      Returns:
      this prepared configuration
      Throws:
      ParserConfigurationException - if a secure parser cannot be created
      SAXException - if XML is malformed or unsafe
      IOException - if the file cannot be read
    • prepare

      Parses and prepares a reader-backed configuration.
      Parameters:
      reader - the XML source
      Returns:
      this prepared configuration
      Throws:
      ParserConfigurationException - if a secure parser cannot be created
      SAXException - if XML is malformed or unsafe
      IOException - if the reader cannot be read
    • getDocument

      public Document getDocument()
      Returns a defensive copy of the prepared document.
      Returns:
      an independent DOM copy
      Throws:
      IllegalStateException - if preparation has not completed
    • getSourceFile

      public File getSourceFile()
      Returns the original file, if the configuration was prepared from one.
      Returns:
      source file or null
    • isPrepared

      public boolean isPrepared()
      Indicates whether preparation has completed.
      Returns:
      true after successful preparation
    • getParameters

      public Map<String,String> getParameters()
      Returns an immutable copy of parameters used for preparation.
      Returns:
      immutable parameter snapshot
    • isExpanded

      public static boolean isExpanded(Node node)
      Indicates whether a DOM node belongs to a configuration whose attributes were fully expanded during preparation. The marker is attached to the document, elements, and attributes, and is preserved by getDocument().
      Parameters:
      node - the DOM node to inspect
      Returns:
      true when the node carries finalized expansion metadata
      Since:
      3.31