mro.util.properties
Class Properties

java.lang.Object
  extended by mro.util.properties.Properties

public class Properties
extends java.lang.Object

This class works a bit like java.util.Properties. The main difference is that each value is stored as a Property-object, which may have a description attached to it. The Property-objects also may have PropertyValueDescription:s. These store a description of the meaning of a certain value of the Property. Further the Property:s may be grouped together in PropertyGroup:s.

Each Properties is tied to a owner object. That object is remembered with a UniqueIdentifier. The Properties may also have several related identifiers, also UniqueIdentifiers.

When using Properties as a instance field, let the class implement the HasProperties-interface. Set the properties owner to the instance using the setOwnerIdentifier(mro.util.UniqueIdentifier) method.

A Properties-object is conveniently saved/loaded to/from a XML-file. Using the identifiers a datastructure of different objects may be rebuilt.

See Also:
Property, PropertyValueDescription, PropertyGroup, UniqueIdentifier

Field Summary
private  java.lang.String description
          Info about the Properties (and its owning class).
private  java.util.HashMap<java.lang.String,PropertyGroup> namePropertyGroupMap
          PropertyGroup:s.
private  java.util.HashMap<java.lang.String,Property> namePropertyMap
          All Property:s.
private  UniqueIdentifier ownerIdentifier
          This identifier identifies the owning object.
private  java.lang.String propertiesName
          The name of the Properties.
private  java.util.Vector<Property> propertyVector
          The vector in the order the user wants it.
private  java.util.Vector<UniqueIdentifier> relatedIdentifiers
          The related identifiers.
 
Constructor Summary
  Properties(Properties ps)
          Copy constructor.
protected Properties(java.lang.String name)
          A constructor.
  Properties(java.lang.String name, java.lang.Object o)
          A constructor that creates a UniqueIdentifier from the object that is passed along and lets it be the owner identifier.
  Properties(java.lang.String name, java.lang.String ownerClassName)
          A constructor that creates a UniqueIdentifier with the specified owner class name.
  Properties(java.lang.String name, UniqueIdentifier ownerIdentifier)
          A constructor.
 
Method Summary
 void addProperty(Property p)
          Adds a Property (or a PropertyGroup) to the Properties.
 void addRelatedIdentifier(UniqueIdentifier relatedIdentifier)
          Add a UniqueIdentifier as a related identifier.
 boolean equals(Properties properties2)
          Returns true if: 1) the Properties:s have the same name, 2) all Property:s (including PropertyGroup:s) have the same name and are in the same order, and the Property:s have the same values.
private  java.lang.String fixFileName(java.lang.String name)
          IO
 java.lang.String getAppropriateValueDescription(java.lang.String name)
           
 java.lang.String getOwnerClassName()
           
 UniqueIdentifier getOwnerIdentifier()
          Returns the owner identifier (a UniqueIdentifier).
 java.lang.String getPropertiesName()
           
 Property getProperty(java.lang.String name)
          Returns a Property with the specified name.
 PropertyGroup getPropertyGroup(java.lang.String propertyGroupName)
          Returns a PropertyGroup with the specified name.
 java.lang.Object getPropertyValue(java.lang.String name)
           
 java.util.Vector<Property> getPropertyVector()
           
 java.util.Vector<UniqueIdentifier> getRelatedIdentifiers()
          Returns all related identifiers, a Vector of UniqueIdentifier:s.
static Properties load(java.io.File file)
          Loads a Properties-object from the specified file.
static Properties load(java.lang.String fileName)
          Loads a Properties-object from a file with the specified file name.
static Properties loadXML(org.xml.sax.InputSource source)
          Loads a Properties-object from an java.io.InputSource.
static void printDTD(java.io.PrintWriter pw)
          Prints the complete DTD of a Properties-XML-file to a PrintWriter.
static void printPartDTD(java.io.PrintWriter pw)
          Prints the DTD of a Properties-XML-file to a PrintWriter.
 void printPartXML(java.io.PrintWriter pw)
           
static void printPropertiesXSLReference(java.io.PrintWriter pw)
          Prints a reference to the Properties-XSL-file to a PrintWriter.
 void printXML(java.io.PrintWriter pw)
          Prints the Properties to a PrintWriter.
 void printXSL(java.io.PrintWriter pw)
          Prints a basic XSL-file for Properties XML-files to a PrintWriter.
private  void recursivelyAddPropertiesInPropertyVector(java.util.Vector properties)
          Used by the addProperty(mro.util.properties.Property)-method.
 void removeProperty(java.lang.String propertyName)
          Removes the Property with the specified name.
private  void removePropertyRecursively(java.lang.String propertyName, java.util.Vector<Property> propertyVector)
           
 boolean sameOwnerIdentifier(Properties ps)
          Returns true if this and ps has the same owner-object as decided by their owner identifier, an UniqueIdentifier.
 boolean sameProperties(Properties properties)
          Returns true if all Property:s (including PropertyGroup:s) have the same name and are in the same order, false otherwise.
 boolean sameRelatedIdentifiers(Properties ps)
          Returns true if this and ps has the same related identifiers (UniqueIdentifier-objects).
 void save(java.io.File file)
          Saves a Properties-object to the specified file.
 void save(java.lang.String fileName)
          Saves a Properties-object to a file with the specified file name.
 void saveToDirectory(java.lang.String directoryName)
          Saves a Properties-object to the directory with specified file name.
 void setOwnerIdentifier(UniqueIdentifier ownerIdentifier)
          Set the owner identifier to the specified UniqueIdentifier.
 void setPropertiesInPropertyVector(java.util.Vector<Property> propertyVector)
          Uses #setProperty().
 void setProperty(java.lang.String name, java.lang.Object value)
          Sets a Property with the given name to the given value.
 int size()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ownerIdentifier

private UniqueIdentifier ownerIdentifier
This identifier identifies the owning object. A Properties is not in it self identifiable. It should always be tied to one other object.


relatedIdentifiers

private java.util.Vector<UniqueIdentifier> relatedIdentifiers
The related identifiers.


propertiesName

private java.lang.String propertiesName
The name of the Properties.


namePropertyMap

private java.util.HashMap<java.lang.String,Property> namePropertyMap
All Property:s. No PropertyGroup:s.


namePropertyGroupMap

private java.util.HashMap<java.lang.String,PropertyGroup> namePropertyGroupMap
PropertyGroup:s. Only top-level PropertyGroups.


propertyVector

private java.util.Vector<Property> propertyVector
The vector in the order the user wants it. Only top-level Property:s and PropertyGroup:s.


description

private java.lang.String description
Info about the Properties (and its owning class). Not used yet.

Constructor Detail

Properties

protected Properties(java.lang.String name)
A constructor. The other fields need to be set using the methods.


Properties

public Properties(java.lang.String name,
                  java.lang.String ownerClassName)
A constructor that creates a UniqueIdentifier with the specified owner class name.


Properties

public Properties(java.lang.String name,
                  java.lang.Object o)
A constructor that creates a UniqueIdentifier from the object that is passed along and lets it be the owner identifier.


Properties

public Properties(java.lang.String name,
                  UniqueIdentifier ownerIdentifier)
A constructor. The other fields need to be set using the methods.


Properties

public Properties(Properties ps)
           throws PropertyNameConflictException
Copy constructor.

Throws:
PropertyNameConflictException
Method Detail

addProperty

public void addProperty(Property p)
                 throws PropertyNameConflictException
Adds a Property (or a PropertyGroup) to the Properties.

Throws:
PropertyNameConflictException

recursivelyAddPropertiesInPropertyVector

private void recursivelyAddPropertiesInPropertyVector(java.util.Vector properties)
                                               throws PropertyNameConflictException
Used by the addProperty(mro.util.properties.Property)-method.

Throws:
PropertyNameConflictException

getPropertyGroup

public PropertyGroup getPropertyGroup(java.lang.String propertyGroupName)
Returns a PropertyGroup with the specified name. null if it doesn't exist.


getProperty

public Property getProperty(java.lang.String name)
Returns a Property with the specified name. null if it doesn't exist.


getPropertyValue

public java.lang.Object getPropertyValue(java.lang.String name)

getAppropriateValueDescription

public java.lang.String getAppropriateValueDescription(java.lang.String name)

getPropertyVector

public java.util.Vector<Property> getPropertyVector()

sameProperties

public boolean sameProperties(Properties properties)
Returns true if all Property:s (including PropertyGroup:s) have the same name and are in the same order, false otherwise. The values does not have to be the same.


equals

public boolean equals(Properties properties2)
Returns true if: 1) the Properties:s have the same name, 2) all Property:s (including PropertyGroup:s) have the same name and are in the same order, and the Property:s have the same values. Uses Property.equals()


setProperty

public void setProperty(java.lang.String name,
                        java.lang.Object value)
                 throws PropertyNotFoundException
Sets a Property with the given name to the given value. If the Property is not in the Properties a PropertyNotFoundException is thrown.

Throws:
PropertyNotFoundException

setPropertiesInPropertyVector

public void setPropertiesInPropertyVector(java.util.Vector<Property> propertyVector)
                                   throws PropertyNotFoundException
Uses #setProperty().

Throws:
PropertyNotFoundException

removeProperty

public void removeProperty(java.lang.String propertyName)
Removes the Property with the specified name. Use with caution: if a class depends on the Property it may fail. Does not report on wether the Property exists. Uses #removePropertyRecursively().


removePropertyRecursively

private void removePropertyRecursively(java.lang.String propertyName,
                                       java.util.Vector<Property> propertyVector)

getOwnerIdentifier

public UniqueIdentifier getOwnerIdentifier()
Returns the owner identifier (a UniqueIdentifier).


setOwnerIdentifier

public void setOwnerIdentifier(UniqueIdentifier ownerIdentifier)
Set the owner identifier to the specified UniqueIdentifier.


addRelatedIdentifier

public void addRelatedIdentifier(UniqueIdentifier relatedIdentifier)
Add a UniqueIdentifier as a related identifier.


getRelatedIdentifiers

public java.util.Vector<UniqueIdentifier> getRelatedIdentifiers()
Returns all related identifiers, a Vector of UniqueIdentifier:s.


getOwnerClassName

public java.lang.String getOwnerClassName()

getPropertiesName

public java.lang.String getPropertiesName()

size

public int size()

sameOwnerIdentifier

public boolean sameOwnerIdentifier(Properties ps)
Returns true if this and ps has the same owner-object as decided by their owner identifier, an UniqueIdentifier. False otherwise.


sameRelatedIdentifiers

public boolean sameRelatedIdentifiers(Properties ps)
Returns true if this and ps has the same related identifiers (UniqueIdentifier-objects). False otherwise. If both Properties has no related identifiers true is returned.


fixFileName

private java.lang.String fixFileName(java.lang.String name)
IO


saveToDirectory

public void saveToDirectory(java.lang.String directoryName)
                     throws java.io.IOException
Saves a Properties-object to the directory with specified file name.

Throws:
java.io.IOException

save

public void save(java.lang.String fileName)
          throws java.io.IOException
Saves a Properties-object to a file with the specified file name.

Throws:
java.io.IOException

save

public void save(java.io.File file)
          throws java.io.IOException
Saves a Properties-object to the specified file.

Throws:
java.io.IOException

printDTD

public static void printDTD(java.io.PrintWriter pw)
                     throws java.io.IOException
Prints the complete DTD of a Properties-XML-file to a PrintWriter.

Throws:
java.io.IOException

printPartDTD

public static void printPartDTD(java.io.PrintWriter pw)
                         throws java.io.IOException
Prints the DTD of a Properties-XML-file to a PrintWriter. Only the elements. This method may be used when the Properties-XML should be part of a larger XML.

Throws:
java.io.IOException

printPropertiesXSLReference

public static void printPropertiesXSLReference(java.io.PrintWriter pw)
                                        throws java.io.IOException
Prints a reference to the Properties-XSL-file to a PrintWriter.

Throws:
java.io.IOException

printXML

public void printXML(java.io.PrintWriter pw)
              throws java.io.IOException
Prints the Properties to a PrintWriter.

Throws:
java.io.IOException

printPartXML

public void printPartXML(java.io.PrintWriter pw)
                  throws java.io.IOException
Throws:
java.io.IOException

printXSL

public void printXSL(java.io.PrintWriter pw)
              throws java.io.IOException
Prints a basic XSL-file for Properties XML-files to a PrintWriter.

Throws:
java.io.IOException

load

public static Properties load(java.lang.String fileName)
                       throws java.io.IOException,
                              org.xml.sax.SAXException
Loads a Properties-object from a file with the specified file name.

Throws:
java.io.IOException
org.xml.sax.SAXException

load

public static Properties load(java.io.File file)
                       throws java.io.IOException,
                              org.xml.sax.SAXException
Loads a Properties-object from the specified file.

Throws:
java.io.IOException
org.xml.sax.SAXException

loadXML

public static Properties loadXML(org.xml.sax.InputSource source)
                          throws java.io.IOException,
                                 org.xml.sax.SAXException
Loads a Properties-object from an java.io.InputSource.

Throws:
java.io.IOException
org.xml.sax.SAXException