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.

Version:
061128
Author:
Magnus Rosell
See Also:
Property, PropertyValueDescription, PropertyGroup, UniqueIdentifier

Constructor Summary
Properties(Properties ps)
          Copy constructor.
Properties(java.lang.String name)
          A constructor.
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.
 java.lang.String getAppropriateValueDescription(java.lang.String name)
           
 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.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.
 void printEvaluationToWriter(java.io.Writer w)
          OLD
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.
 boolean sameOwnerIdentifier(Properties ps)
          Returns true if this and ps has the same owner-object as decided by their owner identifier, an UniqueIdentifier.
 boolean sameRelatedIdentifiers(Properties ps)
          Returns true if this and ps has the same related identifiers (UniqueIdentifier-objects).
 void save(java.lang.String fileName)
          Saves a Properties-object to a file with the specified file name.
 void setOwnerIdentifier(UniqueIdentifier ownerIdentifier)
          Set the owner identifier to the specified UniqueIdentifier.
 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
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Properties

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


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

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.


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

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()

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.


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.


save

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


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)
Loads a Properties-object from a file with the specified file name.


loadXML

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


printEvaluationToWriter

public void printEvaluationToWriter(java.io.Writer w)
                             throws java.io.IOException
OLD

Throws:
java.io.IOException