net.dpml.library.impl
Class DefaultLibrary

java.lang.Object
  extended bynet.dpml.library.impl.DefaultDictionary
      extended bynet.dpml.library.impl.DefaultLibrary
All Implemented Interfaces:
Dictionary, Library

public final class DefaultLibrary
extends DefaultDictionary
implements Library

Utility class used for construction of a module model from an XML source.

Version:
1.0.0
Author:
The Digital Product Meta Library

Field Summary
 
Fields inherited from interface net.dpml.library.Library
INDEX_FILENAME
 
Constructor Summary
DefaultLibrary(Logger logger)
          Creation of a new library.
DefaultLibrary(Logger logger, File source)
          Creation of a new library.
 
Method Summary
 Module[] getAllModules()
          Return a array of all modules in the library.
 Module getModule(String ref)
          Return a named module.
 Module[] getModules()
          Return an array of the top-level modules within the library.
 String getProperty(String key)
          Return a property value.
 String getProperty(String key, String value)
          Return a property value.
 String[] getPropertyNames()
          Return the property names associated with the dictionary.
 Resource getResource(String ref)
          Recursively lookup a resource using a fully qualified reference.
 Resource locate(File base)
          Locate a resource relative to a base directory.
 Resource[] select(File base)
          Select all local projects with a basedir equal to or deeper than the supplied directory.
 Resource[] select(File base, boolean self)
          Select all local projects relative to the supplied basedir.
 Resource[] select(String criteria, boolean sort)
          Select a set of resource matching a supplied a resource selection constraint.
 Resource[] select(String criteria, boolean local, boolean sort)
          Select a set of resource matching a supplied a resource selection constraint.
 Resource[] sort(Resource[] resources)
          Utility operation to sort a collection of resources.
 
Methods inherited from class net.dpml.library.impl.DefaultDictionary
getBooleanProperty, getIntegerProperty, getLocalPropertyNames, resolve
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultLibrary

public DefaultLibrary(Logger logger)
               throws Exception
Creation of a new library. The definition of the indexwill be resolved by search up the file system for a file named index.xml.

Parameters:
logger - the assigned logging channel
Throws:
Exception - if an error occurs during defintion loading

DefaultLibrary

public DefaultLibrary(Logger logger,
                      File source)
               throws Exception
Creation of a new library.

Parameters:
logger - the assigned logging channel
source - the index source defintion
Throws:
Exception - if an error occurs during defintion loading
Method Detail

sort

public Resource[] sort(Resource[] resources)
Utility operation to sort a collection of resources.

Specified by:
sort in interface Library
Parameters:
resources - the resources to sort
Returns:
the sorted resource array

getModules

public Module[] getModules()
Return an array of the top-level modules within the library.

Specified by:
getModules in interface Library
Returns:
module array

getAllModules

public Module[] getAllModules()
Return a array of all modules in the library.

Specified by:
getAllModules in interface Library
Returns:
module array

getModule

public Module getModule(String ref)
                 throws ModuleNotFoundException
Return a named module.

Specified by:
getModule in interface Library
Parameters:
ref - the fully qualified module name
Returns:
the module
Throws:
ModuleNotFoundException - if the module cannot be found

getResource

public Resource getResource(String ref)
                     throws ResourceNotFoundException
Recursively lookup a resource using a fully qualified reference.

Specified by:
getResource in interface Library
Parameters:
ref - the fully qualified resource name
Returns:
the resource instance
Throws:
ResourceNotFoundException - if the resource cannot be found

select

public Resource[] select(String criteria,
                         boolean sort)

Select a set of resource matching a supplied a resource selection constraint. The constraint may contain the wildcards '**' and '*'.

Specified by:
select in interface Library
Parameters:
criteria - the selection criteria
sort - if true the returned array will be sorted relative to dependencies otherwise the array will be sorted alphanumerically with respect to the resource path
Returns:
an array of resources matching the selction criteria

select

public Resource[] select(String criteria,
                         boolean local,
                         boolean sort)

Select a set of resource matching a supplied a resource selection constraint. The constraint may contain the wildcards '**' and '*'.

Specified by:
select in interface Library
Parameters:
criteria - the selection criteria
local - if true restrict selection to local projects
sort - if true the returned array will be sorted relative to dependencies otherwise the array will be sorted alphanumerically with respect to the resource path
Returns:
an array of resources matching the selction criteria

select

public Resource[] select(File base)
Select all local projects with a basedir equal to or deeper than the supplied directory.

Specified by:
select in interface Library
Parameters:
base - the reference basedir
Returns:
an array of projects within or lower than the supplied basedir

select

public Resource[] select(File base,
                         boolean self)
Select all local projects relative to the supplied basedir.

Specified by:
select in interface Library
Parameters:
base - the reference basedir
self - if true and the basedir resolves to a project then include the project otherwise the project will be expluded from selection
Returns:
an array of projects relative to the basedir

locate

public Resource locate(File base)
                throws ResourceNotFoundException
Locate a resource relative to a base directory.

Specified by:
locate in interface Library
Parameters:
base - the base directory
Returns:
a resource with a matching basedir
Throws:
ResourceNotFoundException - if resource match relative to the supplied base

getPropertyNames

public String[] getPropertyNames()
Return the property names associated with the dictionary.

Specified by:
getPropertyNames in interface Dictionary
Overrides:
getPropertyNames in class DefaultDictionary
Returns:
the array of property names

getProperty

public String getProperty(String key)
Return a property value.

Specified by:
getProperty in interface Dictionary
Overrides:
getProperty in class DefaultDictionary
Parameters:
key - the property key
Returns:
the property value

getProperty

public String getProperty(String key,
                          String value)
Return a property value.

Specified by:
getProperty in interface Dictionary
Overrides:
getProperty in class DefaultDictionary
Parameters:
key - the property key
value - the default value
Returns:
the property value