com.commsen.apropos.core
Class PropertyPackage

java.lang.Object
  extended by com.commsen.apropos.core.PropertyPackage
All Implemented Interfaces:
java.lang.Cloneable

public class PropertyPackage
extends java.lang.Object
implements java.lang.Cloneable

This class represents a package of properties. In APropOS a package is simply a container of Property objects. A package has name and may also have description, parent and child packages.

Author:
Milen Dyankov

Constructor Summary
PropertyPackage(java.lang.String name)
          Constructs new package
PropertyPackage(java.lang.String name, PropertyPackage parent)
          Constructs new package
PropertyPackage(java.lang.String name, java.lang.String description)
          Constructs new first level package (without parent)
PropertyPackage(java.lang.String name, java.lang.String description, PropertyPackage parent)
          Constructs new package
 
Method Summary
 Property addProperty(Property property)
          Adds new property to this package.
 java.util.Properties asProperties()
          Converts this package to Properties object.
 java.lang.Object clone()
          
 boolean containsChild(PropertyPackage propertyPackage)
          Checks if propertyPackage is a child package of this package.
 java.util.Map<java.lang.String,Property> getAllProperties()
          Returns a map of all properties from this package and all parent packages.
 java.util.List<PropertyPackage> getChildren()
           
 java.lang.String getDescription()
           
 java.lang.String getName()
           
 java.util.Map<java.lang.String,Property> getOverwritenProperties()
          Returns a map of all properties in this package which overwrite same properties from parent packages.
 PropertyPackage getParent()
           
 java.util.Map<java.lang.String,Property> getProperties()
           
 void importProperties(java.util.Properties externalProperties, boolean overwrite)
          Reads external Properties and adds them all to this package.
 Property removeProperty(Property property)
          Removes property from this package
 Property removeProperty(java.lang.String propertyName)
          Removes property called propertyName from this package
 void setDescription(java.lang.String description)
           
 void setParent(PropertyPackage parent)
           
 Property updateProperty(Property property)
          Updates a property in this package.
 Property updateProperty(java.lang.String oldName, Property property)
          Updates a property called oldName in this package with values from property.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PropertyPackage

public PropertyPackage(java.lang.String name,
                       java.lang.String description,
                       PropertyPackage parent)
Constructs new package

Parameters:
name - the name, this is required field
description - the description
parent - the parent package, if not provided it will become first level package
Throws:
java.lang.IllegalArgumentException - if name is null or blank

PropertyPackage

public PropertyPackage(java.lang.String name,
                       java.lang.String description)
Constructs new first level package (without parent)

Parameters:
name - the name, this is required field
description - the description

PropertyPackage

public PropertyPackage(java.lang.String name,
                       PropertyPackage parent)
Constructs new package

Parameters:
name - the name, this is required field
parent - the parent package, if not provided it will become first level package

PropertyPackage

public PropertyPackage(java.lang.String name)
Constructs new package

Parameters:
name - the name, this is required field
Method Detail

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException

Overrides:
clone in class java.lang.Object
Throws:
java.lang.CloneNotSupportedException

addProperty

public Property addProperty(Property property)
                     throws PropertiesException
Adds new property to this package.

Parameters:
property - the Property to be added. This is a required parameter
Returns:
reference do the added property
Throws:
PropertiesException - if property with such name already exists
java.lang.IllegalArgumentException - if property is null

updateProperty

public Property updateProperty(Property property)
                        throws PropertiesException
Updates a property in this package.

Parameters:
property - the Property to be updated. This is a required parameter
Returns:
reference do the added property
Throws:
PropertiesException - if no such property exists
java.lang.IllegalArgumentException - if property is null

updateProperty

public Property updateProperty(java.lang.String oldName,
                               Property property)
                        throws PropertiesException
Updates a property called oldName in this package with values from property. If oldName is null this method behaves exactly like updateProperty(Property)

Parameters:
oldName - the name of the property to be updated
property - the property to get values from
Returns:
reference do the added property
Throws:
PropertiesException - if no such property exists
java.lang.IllegalArgumentException - if property is null

removeProperty

public Property removeProperty(Property property)
Removes property from this package

Parameters:
property - the property to be removed
Returns:
reference to removed property

removeProperty

public Property removeProperty(java.lang.String propertyName)
Removes property called propertyName from this package

Parameters:
propertyName - the name of the property to be removed
Returns:
reference to removed property

importProperties

public void importProperties(java.util.Properties externalProperties,
                             boolean overwrite)
Reads external Properties and adds them all to this package.

Parameters:
externalProperties - the external properties to be added
overwrite - boolean flag indicating whether to overwrite existing properties
Throws:
java.lang.IllegalArgumentException - if externalProperties is null

asProperties

public java.util.Properties asProperties()
Converts this package to Properties object. The result object contains all properties from all parents as returned by getAllProperties().

Returns:
Properties object

getOverwritenProperties

public java.util.Map<java.lang.String,Property> getOverwritenProperties()
Returns a map of all properties in this package which overwrite same properties from parent packages.

Returns:
the properties a map of all properties in this package which overwrite same properties from parent packages.

getAllProperties

public java.util.Map<java.lang.String,Property> getAllProperties()
Returns a map of all properties from this package and all parent packages.

Returns:
a map of all properties from this package and all parent packages.

containsChild

public boolean containsChild(PropertyPackage propertyPackage)
Checks if propertyPackage is a child package of this package.

Parameters:
propertyPackage - 0 the package to be checked
Returns:
true if propertyPackage is a child package of this package, false otherwise.

getProperties

public java.util.Map<java.lang.String,Property> getProperties()
Returns:
the properties

getParent

public PropertyPackage getParent()
Returns:
the parent

setParent

public void setParent(PropertyPackage parent)
               throws PropertiesException
Parameters:
parent - the parent to set
Throws:
PropertiesException

getDescription

public java.lang.String getDescription()
Returns:
the description

setDescription

public void setDescription(java.lang.String description)
Parameters:
description - the description to set

getName

public java.lang.String getName()
Returns:
the name

getChildren

public java.util.List<PropertyPackage> getChildren()
Returns:
the children


Copyright © 2008 Commsen International. All Rights Reserved.