Platypus

org.pz.platypus
Class PropertyFile

java.lang.Object
  extended by org.pz.platypus.PropertyFile
Direct Known Subclasses:
Literals

public class PropertyFile
extends java.lang.Object

Reads a properties file and parses it into a Map. The Java library has routines for doing this, but they have some constraints, such as naming, that are not found here.


Field Summary
private  java.util.HashMap<java.lang.String,java.lang.String> contents
          the Map of key value pairs taken from the property file
private  java.lang.String filename
          the filename of the property file
protected  GDD gdd
           
private  java.io.BufferedReader inReader
          input reader for file
 
Constructor Summary
PropertyFile()
          This constructor is used only when extending PropertyFile for testing purposes.
PropertyFile(java.lang.String propertyFilename, GDD Gdd)
           
 
Method Summary
 java.util.Map<java.lang.String,java.lang.String> getContents()
           
 int getSize()
           
 java.util.Set<java.lang.String> keySet()
           
 int load()
          read the file into a map.
 void loadLine(java.lang.String line)
          Find the lines with properties; break them into key-value pairs, load them into hash map
 java.lang.String lookup(java.lang.String key)
          Look up a property based on a search key
(package private)  int open()
          open the property file
 void setFilename(java.lang.String newFilename)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

filename

private java.lang.String filename
the filename of the property file


contents

private final java.util.HashMap<java.lang.String,java.lang.String> contents
the Map of key value pairs taken from the property file


inReader

private java.io.BufferedReader inReader
input reader for file


gdd

protected final GDD gdd
Constructor Detail

PropertyFile

public PropertyFile(java.lang.String propertyFilename,
                    GDD Gdd)

PropertyFile

public PropertyFile()
This constructor is used only when extending PropertyFile for testing purposes.

Method Detail

load

public int load()
read the file into a map. Involves reading the file, trimming the entries, removing the comments, and splitting the lines into key,value pairs at the first = sign

Returns:
Status.OK, if all went well; else Status.IO_ERR

loadLine

public void loadLine(java.lang.String line)
Find the lines with properties; break them into key-value pairs, load them into hash map

Parameters:
line - input lines from the property file

open

int open()
open the property file

Returns:
Status.OK, if all went well; Status.FILE_NOT_FOUND_ERR if file not found.

lookup

public java.lang.String lookup(java.lang.String key)
Look up a property based on a search key

Parameters:
key - the key used to look up the property
Returns:
the property if found; otherwise, null

getContents

public java.util.Map<java.lang.String,java.lang.String> getContents()

setFilename

public void setFilename(java.lang.String newFilename)

keySet

public java.util.Set<java.lang.String> keySet()

getSize

public int getSize()

Platypus

Copyright © 2006-10 Pacific Data Works LLC. (platypus.pz.org)