verinec.importer.parser.ethernet
Class ConfigFile

java.lang.Object
  extended by verinec.importer.parser.ethernet.ConfigFile

public class ConfigFile
extends Object

A ConfigFile object represents a configuration file of the /etc/sysconfig/network-scripts directory. These files are ini-style files containing only one section. A section in a ini-style file consists of option lines:


option name = value

To parse the file the package ch.ubique.inieditor is used.

ConfigFile provides methods to return the values to an option name, and to construct a VeriNeC <nw> XML element with the data of the configuration file.

Author:
geraldine.antener at unifr.ch

Field Summary
private  ch.ubique.inieditor.IniEditor.Section confData
           
private  ImporterEnvironment config
           
private  File file
           
(package private)  Logger log
           
private  List optionlist
           
private  List unhandled
           
 
Constructor Summary
ConfigFile(File file, ImporterEnvironment config)
          Construct a new ConfigFile by reading the File file.
 
Method Summary
private  Element generateDns(String DNS)
          Create a VeriNeC <dns> element with the specifications of the file.
private  Element generateDyn()
          Create a VeriNeC <dyn> XML element with the specifications of the file.
 String getValue(String var)
          Get the value of a option defined in the file.
 boolean hasVariable(String var)
          Check if a option is defined in the file.
 Element nw()
          Create a VeriNec <nw> XML element with the specifications of the file.
 List options()
          Get the list of all options of the file.
private  ch.ubique.inieditor.IniEditor.Section readFile()
          Read the file specified in the constructor and return it as a IniEditor.Section value.
 void removeOption(String opt)
          Remove the option name opt from the list unhandled.
 List unhandledOptions()
          Get the list of all options of the file that are not handled while creating the VeriNec <nw> XML element.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

Logger log

config

private ImporterEnvironment config

optionlist

private List optionlist

unhandled

private List unhandled

file

private File file

confData

private ch.ubique.inieditor.IniEditor.Section confData
Constructor Detail

ConfigFile

public ConfigFile(File file,
                  ImporterEnvironment config)
           throws VerinecImporterException
Construct a new ConfigFile by reading the File file.

Parameters:
file - The inistyle file to construct a ConfigFile object. Must exist.
config - The environment.
Throws:
VerinecImporterException - If anything goes wrong.
Method Detail

readFile

private ch.ubique.inieditor.IniEditor.Section readFile()
                                                throws VerinecImporterException
Read the file specified in the constructor and return it as a IniEditor.Section value.

Returns:
A config section for the confData section.
Throws:
VerinecImporterException - If the file can not be read.

nw

public Element nw()
Create a VeriNec <nw> XML element with the specifications of the file.
These items of the configuration file:
are analysed and translated.

Returns:
the VeriNeC <nw> XML element

options

public List options()
Get the list of all options of the file.

Returns:
all options of the file as a List value

unhandledOptions

public List unhandledOptions()
Get the list of all options of the file that are not handled while creating the VeriNec <nw> XML element. Only usefull after calling the nw() method.

Returns:
these options as a List value

removeOption

public void removeOption(String opt)
Remove the option name opt from the list unhandled.

Parameters:
opt - The name of the option.

getValue

public String getValue(String var)
Get the value of a option defined in the file. If the option is not defined in the file return blank.

Parameters:
var - the name of the option.
Returns:
the value of the option var as a String value, or empty string if the option is not defined in the file.

hasVariable

public boolean hasVariable(String var)
Check if a option is defined in the file.

Parameters:
var - The name of the option to look for.
Returns:
true if the option is defined in the file.

generateDyn

private Element generateDyn()
Create a VeriNeC <dyn> XML element with the specifications of the file. These items of the configuration file:
are analysed and translated.

Returns:
Generated dyn element.

generateDns

private Element generateDns(String DNS)
Create a VeriNeC <dns> element with the specifications of the file. These items of the configuration file:
are analysed and translated.

Parameters:
DNS - The dns server name
Returns:
The generated dns element.

Copyright © 2005 Verinec, DIUF