Methods Summary |
---|
public void | dump()
writeConfig(mag_file);
|
public java.lang.String | get_mag_var(java.lang.String varName)
int iterIndex = this.searchIndex(varName);
String retVal= "";
if (iterIndex != -1)
synchronized(storage)
{
retVal =( String ) (( Hashtable) (storage.get(iterIndex))).get(varName);
}
return retVal;
|
public void | initialise(java.lang.String instanceName, boolean bBackupFile)
InstanceEnvironment environ = new InstanceEnvironment(instanceName);
String confFile;
confFile = environ.getInitFilePath();
initialize(confFile);
|
private void | initialize(java.lang.String confFile)
mag_file = confFile;
storage = Collections.synchronizedList( new LinkedList());
index = new Hashtable();
position=0;
init_storage = Collections.synchronizedList( new LinkedList());
init_index = new Hashtable();
init_position=0;
readConfig(confFile);
|
public java.lang.String | isSelected(java.lang.String varName, java.lang.String val)
String value = this.get_mag_var(varName);
if (value.equals(val))
return "SELECTED";
else
return "";
|
public static void | main(java.lang.String[] args)
/*
MagObj testObj = new MagObj();
testObj.readConfig("magnus.conf", "sRoot");
testObj.set_mag_var("Security","On");
testObj.writeConfig("magnus.conf");
*/
|
public void | readConfig(java.lang.String fileName)
File inputFile = new File(fileName) ;
BufferedReader in = new BufferedReader( new FileReader(inputFile));
String inLine = null;
int spaceIndex=0;
while ( (inLine = in.readLine() )!= null )
{
if ( inLine.length() > 2 )
{
spaceIndex = inLine.indexOf(" ");
if ((spaceIndex == -1) && !(inLine.startsWith("Init"))) {
String msg = localizedStrMgr.getString( "admin.common.wrong_filename_format" );
throw new IOException( msg );
}
String key;
if (!inLine.startsWith("Init"))
key=inLine.substring(0,spaceIndex);
else
key="Init";
if (!key.equals("Init"))
{
Hashtable temp = new Hashtable();
temp.put(key, inLine.substring(spaceIndex +1 ));
synchronized(storage)
{
storage.add(temp);
}
index.put(key,new Integer(position));
position++;
}
else
{
String tempString = "" ;
if (spaceIndex != -1)
tempString = inLine.substring(spaceIndex + 1);
Hashtable temp = new Hashtable();
while (inLine != null)
{
in.mark(500);
inLine = in.readLine();
if (inLine != null)
{
if ((inLine.startsWith("\t")) ||
(inLine.startsWith(" ")))
{
tempString += inLine;
}
else
{
in.reset();
break;
}
}
}
temp.put(key, tempString);
synchronized(init_storage)
{
init_storage.add(temp);
}
init_index.put(key,new Integer(position));
init_position++;
}
}
}
|
private synchronized void | remake_index(java.util.Hashtable table)
int in_size = 0;
Enumeration e = table.keys();
while(e.hasMoreElements() )
{
table.put(e.nextElement(),new Integer(in_size));
in_size++;
}
|
private int | searchIndex(java.lang.String varName)
int indexHash = -1;
Object o = index.get(varName);
if (o != null)
indexHash = (( Integer)(index.get(varName))).intValue();
return indexHash;
|
public void | set_mag_var(java.lang.String varName, java.lang.String value)
int iterIndex = this.searchIndex(varName);
Hashtable temp = new Hashtable();
temp.put(varName,value);
if (iterIndex != -1)
{
synchronized(storage)
{
storage.set(iterIndex,temp);
}
}
else
synchronized(storage)
{
storage.add(temp);
this.syncIndex(varName , 1);
}
|
private synchronized void | syncIndex(java.lang.String varName, int mode)
switch (mode )
{
case 0 :
if ( index.containsKey(varName ) )
{
index.remove(varName);
this.remake_index(index);
}
break;
default :
if ( !index.containsKey(varName ) )
{
index.put(varName,new Integer(storage.size() - 1));
}
break;
}
|
public void | writeConfig(java.lang.String fileName)
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(fileName)));
synchronized( storage)
{
ListIterator storageIter = storage.listIterator(0);
while(storageIter.hasNext() )
{
Hashtable temp_store = ( Hashtable) (storageIter.next());
Enumeration e = temp_store.keys();
while ( e.hasMoreElements() )
{
String temp_key =(String ) e.nextElement();
String temp_val = ( String ) temp_store.get(temp_key) ;
String temp_value= temp_key+" "+temp_val;
if (temp_val != null && !temp_val.trim().equals(""))
out.println(temp_value);
}
out.flush();
}
out.println();
}
synchronized( init_storage)
{
ListIterator storageIter = init_storage.listIterator(0);
while(storageIter.hasNext() )
{
Hashtable temp_store = ( Hashtable) (storageIter.next());
Enumeration e = temp_store.keys();
while ( e.hasMoreElements() )
{
String temp_key =(String ) e.nextElement();
String temp_val = (String ) temp_store.get(temp_key) ;
String temp_value= temp_key+" "+temp_val;
if (temp_val != null && !temp_val.trim().equals(""))
out.println(temp_value);
//out.println(temp_val);
}
out.flush();
}
}
out.close();
|