edu.usc.cse.desi.properties
Class PropertyInitializer

java.lang.Object
  extended byedu.usc.cse.desi.properties.PropertyInitializer
All Implemented Interfaces:
java.io.Serializable

public class PropertyInitializer
extends java.lang.Object
implements java.io.Serializable

Author:
nbeckman Started on Jul 16, 2004 The property initializer is necessary for the process of loading properties and assigning them to model objects. This class may be removed or signifigantly changed when we begin to read properties from xADL.
See Also:
Serialized Form

Field Summary
private  java.lang.String myFileName
           
private  java.util.List myObjectTypes
           
private  java.util.HashMap myPropertiesHashMaps
           
 
Constructor Summary
PropertyInitializer(java.lang.String file_name)
           
 
Method Summary
private  void addObjectType(java.lang.String obj_type)
          This method adds a object type to the myObjectTypes list signifying that the given object type can have properties.
private  void addProperty(java.lang.String type_name, Property prop)
          Adds a new property to the given type.
private  java.util.HashMap finalizePropertyMappings(java.util.HashMap htable_of_htables)
          This method examines the given HashMap, which should be a HashMap of HashMaps, and combines any tables of subclasses for which there are superclasses.
 java.util.List getMyObjectTypes()
          This method, after the property file has been parsed, will return a list of all the object types that have properties.
 java.util.Map getMyProperties(java.lang.String class_name)
          This method is to be called by model objects when they need to get mappings of their properties.
private  boolean hasProperties(java.lang.String obj_type)
          Given an object type, this method will tell you if that type has properties.
 boolean parsePropertyFile()
          Parses the property file.
private  Property propertyLine(java.lang.String line)
          Given a line from the property file in the form: property id display name default type it will return a property.
private  java.util.Map recursivePropertyFinder(java.lang.String prop_name, java.util.HashMap htable_of_htables)
          This method is a recursive method that navigates up the heirarchy tree, returning the property mappings of all the superclasses of the first class that it is called on.
 void setMyFileName(java.lang.String myFileName)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

myObjectTypes

private java.util.List myObjectTypes

myPropertiesHashMaps

private java.util.HashMap myPropertiesHashMaps

myFileName

private java.lang.String myFileName
Constructor Detail

PropertyInitializer

public PropertyInitializer(java.lang.String file_name)
Method Detail

setMyFileName

public void setMyFileName(java.lang.String myFileName)
Parameters:
myFileName - The myFileName to set.

getMyProperties

public java.util.Map getMyProperties(java.lang.String class_name)
This method is to be called by model objects when they need to get mappings of their properties. Given the name of a class type, this method will return a mapping of that class' properties.

Parameters:
class_name - String - The name of the class whose properties you want to get.
Returns:
Map - The mapping of the given object's properties or null if object has no properties.

getMyObjectTypes

public java.util.List getMyObjectTypes()
This method, after the property file has been parsed, will return a list of all the object types that have properties. Before that point it just returns an empty list.

Returns:
List - A list of strings.

parsePropertyFile

public boolean parsePropertyFile()
Parses the property file. Returns false if there are missing fields or in general if file could not be parsed. If this method returns false, then none of its work can be regarded as having completed successfully.

Returns:
false - If any fields are missing or format is improper.

addObjectType

private void addObjectType(java.lang.String obj_type)
This method adds a object type to the myObjectTypes list signifying that the given object type can have properties.

Parameters:
obj_type - String - The name of the object that can have a type.

addProperty

private void addProperty(java.lang.String type_name,
                         Property prop)
Adds a new property to the given type. If HashMap for the type does not yet exist, create it.

Parameters:
type_name - String - The name of the object that this property should be added to.
prop - Property - The property to add.

propertyLine

private Property propertyLine(java.lang.String line)
                       throws java.util.NoSuchElementException
Given a line from the property file in the form: property id display name default type it will return a property.

Parameters:
line - The string line that contains info on one property.
Returns:
The newly created property.
Throws:
java.util.NoSuchElementException - Thrown if the line has an invalid format.

hasProperties

private boolean hasProperties(java.lang.String obj_type)
Given an object type, this method will tell you if that type has properties. It does this by seeing if the object name is in myObjectTypes.

Parameters:
obj_type - String - The name of the object type.
Returns:
boolean - true if the object type has properties, false otherwise.

finalizePropertyMappings

private java.util.HashMap finalizePropertyMappings(java.util.HashMap htable_of_htables)
This method examines the given HashMap, which should be a HashMap of HashMaps, and combines any tables of subclasses for which there are superclasses. This method should probably be called after the file has been parsed. It will look through the given map for any entries whose superclass has properties that it needs to inherit.

Parameters:
htable_of_htables - A HashMap of HashMaps that contains the mappings of all object properties.
Returns:
HashMap - A new and complete copy of the hashmap of hashmaps.

recursivePropertyFinder

private java.util.Map recursivePropertyFinder(java.lang.String prop_name,
                                              java.util.HashMap htable_of_htables)
This method is a recursive method that navigates up the heirarchy tree, returning the property mappings of all the superclasses of the first class that it is called on.

Parameters:
prop_name - String - The name of a class you know has properties.
htable_of_htables - HashMap - The complete hashMap of hashMaps that this method can use to lookup classes.
Returns:
Map - A mapping of all the properties of the given class and its superclasses.