FileDocCategorySizeDatePackage
ConfigurationImpl.javaAPI DocGlassfish v2 API8588Fri May 04 22:35:10 BST 2007com.sun.enterprise.repository

ConfigurationImpl

public class ConfigurationImpl extends Object implements Configuration
A Configuration object stores all the properties that are needed by various components within the EJB server.
author
Harish Prabandham

Fields Summary
private static Logger
_logger
private static String
OBJECT_STORE_DIR
private static final String
OBJECT_FILE_EXT
IASRI 4672501 -- remove ri directory private static String SERVER_CONFIG_DIR = "repository" + File.separator + Utility.getLocalHost() + File.separator;
private Hashtable
table
private Repository
defaultRepository
Constructors Summary
public ConfigurationImpl()
Creates a new instance of a Configuration object.

param
readwrite => true or false

    
	               	 
	  
        /** IASRI 4672501 -- remove ri directory
	    File dir = new File(FileUtil.getAbsolutePath(OBJECT_STORE_DIR));
	    if(!dir.exists()) {
		dir.mkdirs();
	    }
        **/

	    table = new Hashtable();
	    defaultRepository = getRepository("default");
        /** IASRI 4672501 -- remove ri directory
	    getServerRepository();
        **/
	
Methods Summary
private java.lang.StringgetEffectiveKey(java.lang.String key)

	    // Everything after the first .
	    int index = key.indexOf(".");
	    
	    if(index < 0)
		return key;

	    return key.substring(index + 1);
	
private java.lang.StringgetIndex(java.lang.String key)

	    // Everything before the first .
	    int index = key.indexOf(".");
	    
	    if(index < 0)
		return "default";
	    
	    return key.substring(0, index);
	
public java.lang.String[]getKeys(java.lang.String index)
This method returns all the keys for the given index.

		Repository rep = getRepository(index);

		return rep.keys();
	
public java.lang.ObjectgetObject(java.lang.String key)

		String fname = getProperty(key);
		Object obj = null;

		// Use this fname to deserialize...
		if(fname != null) {
		    try{
		        FileInputStream fstream = new FileInputStream(fname);
		        ObjectInputStream objstream = 
			    new ObjectInputStream(fstream);
		        obj = objstream.readObject();
		        fstream.close();
		    }catch(Exception e){
//IASRI 4660742			e.printStackTrace(System.out);
// START OF IASRI 4660742
			_logger.log(Level.SEVERE,"enterprise.file_exception",e);
// END OF IASRI 4660742
		    }
		}

		return obj;
	
public java.lang.StringgetProperty(java.lang.String key)
This method gets a property value associated with the given key.

return
A property value corresponding to the key

		String index = getIndex(key);
		String newKey = getEffectiveKey(key);

		Repository rep = getRepository(index);

		String val = null;
		
		if(rep.getName().equals(index)){
			val = rep.find(newKey);
		} else {
			val = rep.find(key);
		}


		return val;	
	
private RepositorygetRepository(java.lang.String repName)

	    Repository rep = (Repository) table.get(repName);
	    if(rep == null) {
		rep = new Repository(repName);
		if(rep.getName().equals(repName)) {
		    table.put(repName, rep);
		} else
		    rep = defaultRepository;
	    }

	    return rep;
	
public voidremoveObject(java.lang.String key)

		String fname = getProperty(key);

		// Use this fname & delete the file first..
		if(fname != null) {
		    try{
		    File file = new File(fname);
			if(file.exists())
				file.delete();
			removeProperty(key);
		    }catch(Exception e){
//IASRI 4660742			e.printStackTrace(System.out);
// START OF IASRI 4660742
			_logger.log(Level.SEVERE,"enterprise.file_exception",e);
// END OF IASRI 4660742
		    }
		}
	
public voidremoveProperty(java.lang.String key)
This method removes a property value given the key.

		String index = getIndex(key);
		String newKey = getEffectiveKey(key);
		Repository rep = getRepository(index);

		if(rep.getName().equals(index)){
			rep.remove(newKey);
		} else {
			rep.remove(key);
		}
	
public voidsetObject(java.lang.String key, java.lang.Object obj)
This method associates an Object with the given key.

		String className = obj.getClass().getName();
		String instanceId = String.valueOf(obj.hashCode());
		String fname =  OBJECT_STORE_DIR + className + instanceId + 
						OBJECT_FILE_EXT;

		// serialize obj and store it in the file .....

		try{
		String absFileName = FileUtil.getAbsolutePath(fname);
		FileOutputStream fstream = new FileOutputStream(absFileName);
		ObjectOutputStream objstream = new ObjectOutputStream(fstream);
		objstream.writeObject(obj);
		objstream.flush();
		fstream.close();
		setProperty(key, absFileName);
		}catch(Exception e){
//IASRI 4660742			e.printStackTrace(System.out);
// START OF IASRI 4660742
			_logger.log(Level.SEVERE,"enterprise.file_exception",e);
// END OF IASRI 4660742
		}
	
public voidsetProperty(java.lang.String key, java.lang.String value)
This method associates a property value with the given key.

		String index = getIndex(key);
		String newKey = getEffectiveKey(key);
		Repository rep = getRepository(index);

		if(rep.getName().equals(index)){
			rep.add(newKey, value);
		} else {
			rep.add(key, value);
		}