Persistent Properties support


TEA APIs

See also TEA Editor Installation and Description

In this section we'll see how to realize a simple method to perform Persistent Properties support. The code exposed is taken from the Source Codes of the TETRACTYS Enhanced Apis and is extensively used by the TEA Editor.

Class and Methods

Two are the classes:

  1. Class tea.util.PropertiesManager

    This class that can create objects that manage a Properties File. It's passed as an argument to the PropertiesOwners that share the same Properties File.

  2. Class tea.util.PropertiesOwner

    This is a class that holds Properties and refers to a main PropertiesManager.

How PropertiesManager works

PropertiesManager loads and saves Properties from a file.

	public void load(String fileName) {
	  file = fileName;
	  try {
	    FileInputStream f = new FileInputStream(file);
	    properties.load(f);
	    f.close();
	  } catch(IOException exc) {
	    properties.clear();
	  }
	}

	public void save() {
	  try {
	    FileOutputStream f = new FileOutputStream(file);
	    properties.save(f,null);
	    f.close();
	  } catch(IOException exc) {
	  }
	}

How PropertiesOwner works

PropertiesOwner is associated to a PropertiesManager through the setPropertiesManager() method and has some methods to read Properties properly (e.g, getInteger()).

	public void setPropertiesManager(PropertiesManager pm) {
	  propertiesManager = pm;
	  properties = pm.getProperties();
	}

	public int getInteger(String prop) {
	  return Integer.parseInt(properties.getProperty(prop));
	}

You can find the complete source code in the TEA APIs page. Write directly to TETRACTYS Freeware for any question or suggestion.


TETRACTYS Freeware Main Page

In the next Issue Java Tutorials will be

AWT: International Languages Support

GeoCities