= Policies =

A policy is a set of named parameters that can be used to configure
the internal data and behavior of an object within an application.  An
important feature the Policy objects is that the parameters can be
loaded in from a file.  Thus, it allows applications fine grained
control of objects even if much of the configuration parameters they
provide are normally set to defaults and otherwise do not change.

Policy objects are built around DataProperty objects, although the
types allowed value types are restricted (to unsure a simple
serialization format).  In particular, Policy parameters can be
hierarchical, just like DataProperties.  That is, a Policy can contain
a parameter whose type itself is a Policy.  This feature can be used to
configure a whole hierarchy of objects, even if the object classes (and
their associated policy parameters) have developed by different
people.  

The UML design allows for a special parameter value called a
PolicyRule.  This allows for the actual value to be determined
according to a a rule that interprets the values of other parameters
or other runtime conditions.  Implementation of this class is not
planned for inclusion in DC2.  

== Configuring an Object using a Policy ==

A developer that wishes to support a configuration via a Policy will
normally do so by providing a constructor that takes a Policy object
as an argument.  Then, within the implementation, the constructor is
coded to look for specific names (of its devloper's choosing) that the
paramaters saved under.  (Documentation of these names are provided
via a Dictionary; see below.)  In particular, the class will want to
access the configuration via these names without concern for name
collisions (other objects looking for different Policy parameters
under that same name) not knowledge of how the class being configured
is being used.  That is, encapsulization of information is preserved.    

It is expected that one object may in turn need to configure other
objects it manages.  For example, an Image Subtraction Stage object
may need to internally configure a Kernel object.  The support for
hierarchical parameters means that the outer object (Image Subtraction
Stage) can pull out all of the policy data for a Kernel instance under
a single name and pass it to the Kernel object.  In this way, the
Kernel policy names won't conflict with the Image Subtraction Stage
policy names.  It is not required that a developer make use this
hierarchal method; however if he/she does not, it will require
collatoration with the design of all the other objects that may draw
from the same level policy data.
necessary 

== Parameter Types == 

The Policy interface restricts that types of values that can be loaded
and retrieved:
  * integer
  * double
  * string
  * Policy
  * arrays of the above types

== File Formats ==

The standard format for serializing Policy data will use XML.  This
will allow us to leverage a number of off-the-shelf tools for
manipulating metadata.  Further, the expressiveness XML enables will
be useful for encoding conditions associated with PolicyRules.  An
example of a Policy file can be found here.  The main disadvantage of
XML is that its verboseness makes it not so convenient for authoring
documents manually and, thus, can be prone to error.  For this reason,
two additional formats are being considered an alternative.  The
purpose of the alternative is to provide a format that easier for a
developer to create with an editor.  This alternate format will be
completely convertable into the XML form for automated processing by
LSST middleware.  (On the other hand, it is not yet guaranteed that
the XML format, with its extra syntax for PolicyRule conditions, will
always be convertable back into the alternate format.)

One format in consideration as an alternative format is the JavaScript
Object Notation (JSON, pronounced jason, www.json.org).  This is a
very simple object serializtion format used widely in web, AJAX-type
applications as a lighter-weight alternative to XML.  It supports the
basic types mentioned above, and there are large number of existing
libraries for parsing JSON.  As a format, it is less verbose than XML,
and many argue it is more readable.  The above mentioned XML example
would be look like this in JSON.

While the JSON format is quite simple, its syntax is dependent on
controlled use of curly and square braces.  A format that combined the
simplicity of data properties (as used in DC1) with the better type
support of JSON might be ideal; thus, a new format that attempts to make
this combination is proposed.  An example of such a format can be
seen here.  I refer to this format as the policy authoring format
(paf).  The biggest disadvantage of this format is that, as a new
format developed specifically for this purpose, there are no existing
libraries to support it (though parts of a JSON library may be
useful).  

The choice of format will be based on how quickly a parser can be
developed and preferences from the team.  

== Dictionaries ==

It will be necessary for developers to document the policy parameters
an class implementation will look for to configure itself.  I propose
the creation of parameter dictionaries based on the same format used
for the policy files themselves.  A Dictionary will be able to record
for a class's Policy each parameter name, its types, default value and
other syntactic information.  This can be used to validate a
particular policy file or be used as a default when none is
available.  An example of a dictionary is here in JSON and PAF
formats.  



