Class FileConfig


  • public class FileConfig
    extends java.lang.Object
    This class parses configurations from .inf files. The parsed configurations are being accumulated in the state of the FileConfig object. (Some time ago, this class was used to load TDI configurations (configurations were stored in .inf format rather than in XML). That is why some of the features (such as encryption) exist.) The configurations are represented by TreeMap objects and are organized into a hierarchy. The hierarchy is composed by embedding TreeMap objects as values inside other TreeMap objects. Navigation through the configuration hierarchy is performed via the key names. Several keys can be combined to form a compound key, which identifies a configuration (i.e. TreeMap object) in the hierarchy. The individual parts of a compound key are delimited by a forward slash : '/'. For example: "connectors/ibmdi.URLConnector/connectorConfig". There are some predefined keys for objects in the configuration hierarchy. These predefined keys are used to logically organize configurations into categories such as Connectors, Parsers, Forms, ... The predefined keys are available as String constants (C_CONNECTOR, C_PARSER, C_FORMDEF, ...) in the FileConfig class.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String C_CONNECTOR
      Connector configurations are stored under this key.
      static java.lang.String C_FORMDEF
      Form configurations are stored under this key.
      static java.lang.String C_INCLUDE
      Includes configurations are stored under this key.
      static java.lang.String C_INCLUDEFILES
      Includes configurations are stored under this key.
      static java.lang.String C_JAVALIBRARIES
      Java libraries configurations are stored under this key.
      static java.lang.String C_JAVAPROPERTIES
      Java properties configurations are stored under this key.
      static java.lang.String C_LIBRARIES
      Library configurations are stored under this key.
      static java.lang.String C_LISTENER
      Listener configurations are stored under this key.
      static java.lang.String C_MBUS
      Message bus configurations are stored under this key.
      static java.lang.String C_PARSER
      ParserTypes configurations are stored under this key.
      static java.lang.String C_PROPERTIES
      Properties configurations are stored under this key.
      static java.lang.String C_SCRIPTS
      Script configurations are stored under this key.
      static java.lang.String C_SECURITY
      Security configurations are stored under this key.
      static java.lang.String C_SHAREDCONN
      Shared Connector configurations are stored under this key.
      static java.lang.String C_TASK
      AssemblyLine configurations are stored under this key.
      static java.lang.String C_TRIGGER
      Trigger configurations are stored under this key.
      boolean dontOverwriteConfig
      Whether newly read configurations are allowed to overwrite previously stored configurations.
      java.util.Vector includedFiles
      All include configuration files (the absolute file system paths).
      boolean isInclude
      Whether the configuration currently being parsed is read from an include configuration file.
      java.lang.String password
      Password (key) for decrypting the configuration input stream/file.
    • Constructor Summary

      Constructors 
      Constructor Description
      FileConfig​(java.lang.String path)
      Constructor for the FileConfig object
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addAttribute​(java.util.TreeMap h, java.lang.String name)
      Reads attribute values from the configuration stream which is currently open for reading.
      void addMap​(java.util.TreeMap h, java.lang.String name)
      Adds an empty TreeMap to the specified TreeMap under the specified key name.
      void addSection​(java.util.TreeMap config, java.lang.String name)
      Parses a configuration section (TreeMap) from the configuration stream which is currently open for reading.
      void addVector​(java.util.TreeMap h, java.lang.String name)
      Reads a configuration Vector from the configuration stream which is currenlty open for reading.
      boolean fireError​(java.lang.Exception error)
      The method tells whether a specified error should be raised or is internally handled.
      java.util.TreeMap getConfig​(java.lang.String key)
      Gets the config attribute of the FileConfig object
      java.lang.String getConfigPath()
      Gets the configPath attribute of the FileConfig object
      java.util.TreeMap getConnector​(java.lang.String name)
      Gets the connector attribute of the FileConfig object
      java.util.TreeMap getForm​(java.lang.String name)
      Gets the form attribute of the FileConfig object
      java.util.TreeMap getInclude​(java.lang.String name)
      Gets the include attribute of the FileConfig object
      java.util.Vector getIncludes()
      Gets the includes attribute of the FileConfig object
      java.lang.Object getKey​(java.util.TreeMap map, java.lang.String key)
      Gets the key attribute of the FileConfig object
      java.util.TreeMap getLibrary​(java.lang.String name)
      Gets the library attribute of the FileConfig object
      java.lang.String getLine()
      Gets the line attribute of the FileConfig object
      java.util.TreeMap getListener​(java.lang.String name)
      Gets the listener attribute of the FileConfig object
      java.util.TreeMap getParser​(java.lang.String name)
      Gets the parser attribute of the FileConfig object
      java.util.TreeMap getProperty​(java.lang.String type)
      Gets the property attribute of the FileConfig object
      java.util.TreeMap getScript​(java.lang.String name)
      Gets the script attribute of the FileConfig object
      java.util.TreeMap getTables()
      Gets the tables attribute of the FileConfig object
      java.util.TreeMap getTask​(java.lang.String name)
      Gets the task attribute of the FileConfig object
      java.lang.String getVersion()
      Returns the version string.
      void includeFile​(java.lang.String path, boolean overwrite)
      Parses the configurations from the specified include file.
      void includeFiles​(boolean first)
      Parses the configurations from the include files, which are currently accumulated for reading.
      java.util.TreeMap loadConfig()
      Parses the currently set configuration file.
      java.util.TreeMap loadConfig​(byte[] data)
      Parses the specified configuration data.
      java.util.TreeMap loadConfig​(java.io.BufferedReader input)
      Parses the specified configuration input stream.
      java.util.TreeMap loadConfig​(java.lang.String urlPath)
      Parses the specified configuration file.
      java.util.TreeMap loadConfig2​(java.lang.String urlPath)
      Parses the specified configuration data.
      java.util.TreeMap loadConfig3()
      Parses the configuration stream, which is currently open for reading.
      void loadEncrypted()
      A NOOP method.
      void openInputFile​(java.lang.String path)
      Opens the specified configuration file for reading.
      void removeIncludedComponents()
      Removes included components from our tables.
      void saveArray​(java.io.BufferedWriter out, java.lang.String prefix, java.util.TreeMap cf)
      Writes the contents of the specified configuration TreeMap into the specified output stream.
      void saveConfig()
      Writes the internally accumulated configurations to the currently set configuration file.
      void saveConfig​(java.io.BufferedWriter out)
      Writes the internally accumulated configurations to the specified output stream.
      void saveConfig​(java.io.BufferedWriter out, java.lang.String type, java.util.TreeMap cf)
      Writes the configurations from the specified TreeMap into the specified output stream.
      void saveConfig​(java.io.OutputStream output)
      Saves the configuration to an output stream.
      void saveConfig​(java.util.TreeMap config)
      Overwrites the currently set configuration file with the configurations from the specified TreeMap.
      void saveConfig​(java.util.TreeMap config, java.lang.String path)
      Overwrites the specified file with the configurations from the specified TreeMap.
      void saveVector​(java.io.BufferedWriter out, java.lang.String prefix, java.util.Vector v)
      Writes the specified Vector with configurations to the specified output stream.
      void setConfig​(java.lang.String key, java.lang.Object data)
      Sets the config attribute of the FileConfig object
      void setConfigPath​(java.lang.String path)
      Sets the configPath attribute of the FileConfig object
      void setErrorListener​(ErrorListener listener)
      Sets the errorListener attribute of the FileConfig object
      void setImport​(java.util.Vector v)
      Sets the import attribute of the FileConfig object
      void setPassword​(java.lang.String pwd)
      Sets the password attribute of the FileConfig object
      void setTables​(java.util.TreeMap tables)
      Sets the tables attribute of the FileConfig object
      void setVersion​(java.lang.String version)
      Sets the version string.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • C_TASK

        public static final java.lang.String C_TASK
        AssemblyLine configurations are stored under this key.
        See Also:
        Constant Field Values
      • C_CONNECTOR

        public static final java.lang.String C_CONNECTOR
        Connector configurations are stored under this key.
        See Also:
        Constant Field Values
      • C_TRIGGER

        public static final java.lang.String C_TRIGGER
        Trigger configurations are stored under this key.
        See Also:
        Constant Field Values
      • C_LISTENER

        public static final java.lang.String C_LISTENER
        Listener configurations are stored under this key.
        See Also:
        Constant Field Values
      • C_LIBRARIES

        public static final java.lang.String C_LIBRARIES
        Library configurations are stored under this key.
        See Also:
        Constant Field Values
      • C_PROPERTIES

        public static final java.lang.String C_PROPERTIES
        Properties configurations are stored under this key.
        See Also:
        Constant Field Values
      • C_PARSER

        public static final java.lang.String C_PARSER
        ParserTypes configurations are stored under this key.
        See Also:
        Constant Field Values
      • C_SCRIPTS

        public static final java.lang.String C_SCRIPTS
        Script configurations are stored under this key.
        See Also:
        Constant Field Values
      • C_FORMDEF

        public static final java.lang.String C_FORMDEF
        Form configurations are stored under this key.
        See Also:
        Constant Field Values
      • C_JAVAPROPERTIES

        public static final java.lang.String C_JAVAPROPERTIES
        Java properties configurations are stored under this key.
        See Also:
        Constant Field Values
      • C_JAVALIBRARIES

        public static final java.lang.String C_JAVALIBRARIES
        Java libraries configurations are stored under this key.
        See Also:
        Constant Field Values
      • C_MBUS

        public static final java.lang.String C_MBUS
        Message bus configurations are stored under this key.
        See Also:
        Constant Field Values
      • C_INCLUDE

        public static final java.lang.String C_INCLUDE
        Includes configurations are stored under this key.
        See Also:
        Constant Field Values
      • C_SECURITY

        public static final java.lang.String C_SECURITY
        Security configurations are stored under this key.
        See Also:
        Constant Field Values
      • C_SHAREDCONN

        public static final java.lang.String C_SHAREDCONN
        Shared Connector configurations are stored under this key.
        See Also:
        Constant Field Values
      • C_INCLUDEFILES

        public static final java.lang.String C_INCLUDEFILES
        Includes configurations are stored under this key.
        See Also:
        Constant Field Values
      • password

        public java.lang.String password
        Password (key) for decrypting the configuration input stream/file. Must be null if the stream is not encrypted.
      • dontOverwriteConfig

        public boolean dontOverwriteConfig
        Whether newly read configurations are allowed to overwrite previously stored configurations.
      • isInclude

        public boolean isInclude
        Whether the configuration currently being parsed is read from an include configuration file.
      • includedFiles

        public java.util.Vector includedFiles
        All include configuration files (the absolute file system paths).
    • Constructor Detail

      • FileConfig

        public FileConfig​(java.lang.String path)
                   throws java.io.IOException
        Constructor for the FileConfig object
        Parameters:
        path - the file system path or URL for the configuration file (the file is not actually parsed at this time)
        Throws:
        java.io.IOException - a problem while constructing the object
    • Method Detail

      • getVersion

        public java.lang.String getVersion()
        Returns the version string.
        Returns:
        a string representing the version
      • setVersion

        public void setVersion​(java.lang.String version)
        Sets the version string.
        Parameters:
        version - a new version string to be set
      • setPassword

        public void setPassword​(java.lang.String pwd)
        Sets the password attribute of the FileConfig object
        Parameters:
        pwd - The new password value
      • setErrorListener

        public void setErrorListener​(ErrorListener listener)
        Sets the errorListener attribute of the FileConfig object
        Parameters:
        listener - The new errorListener value
      • setConfig

        public void setConfig​(java.lang.String key,
                              java.lang.Object data)
        Sets the config attribute of the FileConfig object
        Parameters:
        key - The new config value
        data - The new config value
      • setConfigPath

        public void setConfigPath​(java.lang.String path)
        Sets the configPath attribute of the FileConfig object
        Parameters:
        path - The new configPath value
      • setTables

        public void setTables​(java.util.TreeMap tables)
        Sets the tables attribute of the FileConfig object
        Parameters:
        tables - The new tables value
      • setImport

        public void setImport​(java.util.Vector v)
        Sets the import attribute of the FileConfig object
        Parameters:
        v - The new import value
      • getConfig

        public java.util.TreeMap getConfig​(java.lang.String key)
        Gets the config attribute of the FileConfig object
        Parameters:
        key - compound key, which identifies an object in the configuration hierarchy
        Returns:
        The config value
      • getConfigPath

        public java.lang.String getConfigPath()
        Gets the configPath attribute of the FileConfig object
        Returns:
        The configPath value
      • getTables

        public java.util.TreeMap getTables()
        Gets the tables attribute of the FileConfig object
        Returns:
        The tables value
      • getLine

        public java.lang.String getLine()
                                 throws java.io.IOException
        Gets the line attribute of the FileConfig object
        Returns:
        The line value
        Throws:
        java.io.IOException - problem while reading the current line from the configuration file
      • getTask

        public java.util.TreeMap getTask​(java.lang.String name)
        Gets the task attribute of the FileConfig object
        Parameters:
        name - the key (simple key, not a compound one) of the desired AssemblyLine configuration object
        Returns:
        The task value
      • getIncludes

        public java.util.Vector getIncludes()
        Gets the includes attribute of the FileConfig object
        Returns:
        The includes value
      • getConnector

        public java.util.TreeMap getConnector​(java.lang.String name)
        Gets the connector attribute of the FileConfig object
        Parameters:
        name - the key (simple key, not a compound one) of the desired Connector configuration object
        Returns:
        The connector value
      • getParser

        public java.util.TreeMap getParser​(java.lang.String name)
        Gets the parser attribute of the FileConfig object
        Parameters:
        name - the key (simple key, not a compound one) of the desired Parser configuration object
        Returns:
        The parser value
      • getLibrary

        public java.util.TreeMap getLibrary​(java.lang.String name)
        Gets the library attribute of the FileConfig object
        Parameters:
        name - the key (simple key, not a compound one) of the desired Library configuration object
        Returns:
        The library value
      • getListener

        public java.util.TreeMap getListener​(java.lang.String name)
        Gets the listener attribute of the FileConfig object
        Parameters:
        name - the key (simple key, not a compound one) of the desired Listener configuration object
        Returns:
        The listener value
      • getScript

        public java.util.TreeMap getScript​(java.lang.String name)
        Gets the script attribute of the FileConfig object
        Parameters:
        name - the key (simple key, not a compound one) of the desired Script configuration object
        Returns:
        The script value
      • getProperty

        public java.util.TreeMap getProperty​(java.lang.String type)
        Gets the property attribute of the FileConfig object
        Parameters:
        type - the key (simple key, not a compound one) of the desired Properties configuration object
        Returns:
        The property value
      • getForm

        public java.util.TreeMap getForm​(java.lang.String name)
        Gets the form attribute of the FileConfig object
        Parameters:
        name - the key (simple key, not a compound one) of the desired Form configuration object
        Returns:
        The form value
      • getInclude

        public java.util.TreeMap getInclude​(java.lang.String name)
        Gets the include attribute of the FileConfig object
        Parameters:
        name - the key (simple key, not a compound one) of the desired Includes configuration object
        Returns:
        The include value
      • getKey

        public java.lang.Object getKey​(java.util.TreeMap map,
                                       java.lang.String key)
        Gets the key attribute of the FileConfig object
        Parameters:
        map - the root configuration object of the configuration hierarchy
        key - a compound key, which identifies the searched configuration object in the hierarchy
        Returns:
        The key value
      • loadConfig

        public java.util.TreeMap loadConfig()
                                     throws java.lang.Exception
        Parses the currently set configuration file. The configurations are accumulated in the state of the FileConfig object.
        Returns:
        the accumulated configurations in the state of the FileConfig object
        Throws:
        java.lang.Exception - problem while parsing the configuration file
      • openInputFile

        public void openInputFile​(java.lang.String path)
                           throws java.lang.Exception
        Opens the specified configuration file for reading. If the file is encrypted, the password must be already set.
        Parameters:
        path - file system path or URL for the configuration file; if the parameter is set to " ", the configuration will be read from the standard input
        Throws:
        java.lang.Exception - problem while opening the configuration file for reading
      • loadConfig

        public java.util.TreeMap loadConfig​(java.lang.String urlPath)
                                     throws java.lang.Exception
        Parses the specified configuration file. Configurations are accumulated in the state of the FileConfig object.
        Parameters:
        urlPath - file system path or URL for the configuration file if the parameter is set to " ", the configuration will be read from the standard input
        Returns:
        the accumulated configurations in the state of the FileConfig object
        Throws:
        java.lang.Exception - problem while parsing the configuration file
      • loadConfig

        public java.util.TreeMap loadConfig​(java.io.BufferedReader input)
                                     throws java.lang.Exception
        Parses the specified configuration input stream. Configurations are accumulated in the state of the FileConfig object.
        Parameters:
        input - the configuration input stream
        Returns:
        the accumulated configurations in the state of the FileConfig object
        Throws:
        java.lang.Exception - problem while parsing the configuration input stream
      • loadConfig

        public java.util.TreeMap loadConfig​(byte[] data)
                                     throws java.lang.Exception
        Parses the specified configuration data. Configurations are accumulated in the state of the FileConfig object.
        Parameters:
        data - the configuration data
        Returns:
        the accumulated configurations in the state of the FileConfig object
        Throws:
        java.lang.Exception - problem while parsing the configuration data
      • loadConfig2

        public java.util.TreeMap loadConfig2​(java.lang.String urlPath)
                                      throws java.lang.Exception
        Parses the specified configuration data. Configurations are accumulated in the state of the FileConfig object.
        Parameters:
        urlPath - file system path or URL for the configuration file; if the parameter is set to " ", the configuration will be read from the standard input
        Returns:
        the accumulated configurations in the state of the FileConfig object
        Throws:
        java.lang.Exception - problem while parsing the configuration file
      • loadConfig3

        public java.util.TreeMap loadConfig3()
                                      throws java.lang.Exception
        Parses the configuration stream, which is currently open for reading. Configurations are accumulated in the state of the FileConfig object.
        Returns:
        the accumulated configurations in the state of the FileConfig object
        Throws:
        java.lang.Exception - problem while parsing the configuration file
      • includeFiles

        public void includeFiles​(boolean first)
                          throws java.lang.Exception
        Parses the configurations from the include files, which are currently accumulated for reading. Configurations are accumulated in the state of the FileConfig object.
        Parameters:
        first - whether this is the first include file for the currently parsed configuration stream
        Throws:
        java.lang.Exception - problem while parsing the configurations
      • includeFile

        public void includeFile​(java.lang.String path,
                                boolean overwrite)
                         throws java.lang.Exception
        Parses the configurations from the specified include file. Configurations are accumulated in the state of the FileConfig object.
        Parameters:
        path - the include configuration file
        overwrite - whether to overwrite existing configurations
        Throws:
        java.lang.Exception - problem while parsing the configurations
      • addSection

        public void addSection​(java.util.TreeMap config,
                               java.lang.String name)
                        throws java.io.IOException
        Parses a configuration section (TreeMap) from the configuration stream which is currently open for reading. The read configuration section is added in the specified TreeMap under the specified key name.
        Parameters:
        config - the TreeMap where the parsed section will be added
        name - key name for the parsed section
        Throws:
        java.io.IOException - problem while parsing the configurations
      • addVector

        public void addVector​(java.util.TreeMap h,
                              java.lang.String name)
                       throws java.io.IOException
        Reads a configuration Vector from the configuration stream which is currenlty open for reading. The read Vector with configuration objects is added to the specified TreeMap under the specified key name.
        Parameters:
        h - the TreeMap configuration object, where the parsed Vector with configurations will be added
        name - the key name for the configurations Vector
        Throws:
        java.io.IOException - problem while parsing the configurations
      • addMap

        public void addMap​(java.util.TreeMap h,
                           java.lang.String name)
                    throws java.io.IOException
        Adds an empty TreeMap to the specified TreeMap under the specified key name.
        Parameters:
        h - the TreeMap where where the addition will happen
        name - the key name
        Throws:
        java.io.IOException - problem
      • addAttribute

        public void addAttribute​(java.util.TreeMap h,
                                 java.lang.String name)
                          throws java.io.IOException
        Reads attribute values from the configuration stream which is currently open for reading. The read values are placed in a Vector and added to the specified TreeMap under the specified key name (the name of the attribute).
        Parameters:
        h - the TreeMap where the attrbute will be added
        name - the name of the attribute
        Throws:
        java.io.IOException - problem while parsing the configurations
      • saveConfig

        public void saveConfig()
                        throws java.lang.Exception
        Writes the internally accumulated configurations to the currently set configuration file.
        Throws:
        java.lang.Exception - if a problem occurs
      • saveConfig

        public void saveConfig​(java.io.OutputStream output)
                        throws java.io.IOException
        Saves the configuration to an output stream. An EOF marker is also written. This method is used by the guiRunner in the miadmin tool.
        Parameters:
        output - the output stream
        Throws:
        java.io.IOException - problem while writing the configurations
      • saveConfig

        public void saveConfig​(java.util.TreeMap config,
                               java.lang.String path)
                        throws java.io.IOException
        Overwrites the specified file with the configurations from the specified TreeMap.
        Parameters:
        config - the configuration TreeMap
        path - the file path
        Throws:
        java.io.IOException - problem while writing the configurations
      • saveConfig

        public void saveConfig​(java.io.BufferedWriter out)
                        throws java.io.IOException
        Writes the internally accumulated configurations to the specified output stream.
        Parameters:
        out - the output stream
        Throws:
        java.io.IOException - problem while writing the configurations
      • saveConfig

        public void saveConfig​(java.util.TreeMap config)
                        throws java.io.IOException
        Overwrites the currently set configuration file with the configurations from the specified TreeMap.
        Parameters:
        config - the configuration TreeMap
        Throws:
        java.io.IOException - problem while writing the configurations
      • saveConfig

        public void saveConfig​(java.io.BufferedWriter out,
                               java.lang.String type,
                               java.util.TreeMap cf)
                        throws java.io.IOException
        Writes the configurations from the specified TreeMap into the specified output stream. The specified TreeMap is supposed be a top-most container which hold configurations for a single category (AssemblyLines, Connectors, Forms,...).
        Parameters:
        out - the output stream
        type - the name of the category
        cf - the configurations TreeMap
        Throws:
        java.io.IOException - problem while writing the configurations
      • saveVector

        public void saveVector​(java.io.BufferedWriter out,
                               java.lang.String prefix,
                               java.util.Vector v)
                        throws java.io.IOException
        Writes the specified Vector with configurations to the specified output stream.
        Parameters:
        out - the output stream
        prefix - indentation prefix
        v - the configuration Vector
        Throws:
        java.io.IOException - problem while writing the configurations
      • saveArray

        public void saveArray​(java.io.BufferedWriter out,
                              java.lang.String prefix,
                              java.util.TreeMap cf)
                       throws java.io.IOException
        Writes the contents of the specified configuration TreeMap into the specified output stream. The specified TreeMap is not supposed to be a top-most container for configurations from a category (AssemblyLines, Connectors, Forms,...).
        Parameters:
        out - the output stream
        prefix - indentation prefix
        cf - the configuration TreeMap
        Throws:
        java.io.IOException - problem while writing the configurations
      • loadEncrypted

        public void loadEncrypted()
                           throws java.io.IOException
        A NOOP method.
        Throws:
        java.io.IOException - problem
      • fireError

        public boolean fireError​(java.lang.Exception error)
                          throws java.lang.Exception
        The method tells whether a specified error should be raised or is internally handled.
        Parameters:
        error - the error object
        Returns:
        true if the error should not be raised
        Throws:
        java.lang.Exception - problem
      • removeIncludedComponents

        public void removeIncludedComponents()
        Removes included components from our tables.