FileDocCategorySizeDatePackage
InitConfFileBean.javaAPI DocGlassfish v2 API10632Fri May 04 22:33:16 BST 2007com.sun.enterprise.admin.common

InitConfFileBean

public class InitConfFileBean extends Object

Fields Summary
public static final String
INITCONF_SECURITY_ATTRIBUTE
public static final String
INITCONF_VALUE_ON
public static final String
INITCONF_VALUE_OFF
private List
storage
private List
init_storage
private int
position
private int
init_position
private Hashtable
index
private Hashtable
init_index
private String
mag_file
private static com.sun.enterprise.admin.util.SOMLocalStringsManager
localizedStrMgr
Constructors Summary
public InitConfFileBean()

    
     
    
        storage = Collections.synchronizedList( new LinkedList());
        init_storage = Collections.synchronizedList( new LinkedList());
        index = new Hashtable();
        init_index = new Hashtable();
        position=0;
        init_position = 0;
    
Methods Summary
public voiddump()

        writeConfig(mag_file);
    
public java.lang.Stringget_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 voidinitialise(java.lang.String instanceName, boolean bBackupFile)

        InstanceEnvironment environ = new InstanceEnvironment(instanceName);
        String confFile;
        confFile = environ.getInitFilePath();
        initialize(confFile);
    
private voidinitialize(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.StringisSelected(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 voidmain(java.lang.String[] args)

    /*
    MagObj testObj = new MagObj();
    testObj.readConfig("magnus.conf", "sRoot");
    testObj.set_mag_var("Security","On");
    testObj.writeConfig("magnus.conf");
     */
    
public voidreadConfig(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 voidremake_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 intsearchIndex(java.lang.String varName)

        int indexHash = -1;
        
        Object o = index.get(varName);
        if (o != null)
            indexHash = (( Integer)(index.get(varName))).intValue();
        return indexHash;
    
public voidset_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 voidsyncIndex(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 voidwriteConfig(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();