This project has retired. For details please refer to its Attic page.
UrlDefinitionsFactory (Tiles 2 2.0.7 API)

org.apache.tiles.definition
Class UrlDefinitionsFactory

Package class diagram package UrlDefinitionsFactory
java.lang.Object
  extended by org.apache.tiles.definition.UrlDefinitionsFactory
All Implemented Interfaces:
DefinitionsFactory, ReloadableDefinitionsFactory

public class UrlDefinitionsFactory
extends Object
implements DefinitionsFactory, ReloadableDefinitionsFactory

DefinitionsFactory implementation that manages Definitions configuration data from URLs.

The Definition objects are read from the DigesterDefinitionsReader class unless another implementation is specified.

Version:
$Rev: 680308 $ $Date: 2008-07-28 12:03:41 +0200 (Mon, 28 Jul 2008) $

Field Summary
protected  Map<String,Long> lastModifiedDates
          Contains the dates that the URL sources were last modified.
protected  DefinitionsReader reader
          Reader used to get definitions from the sources.
protected  List<Object> sources
          Contains the URL objects identifying where configuration data is found.
 
Fields inherited from interface org.apache.tiles.definition.DefinitionsFactory
LOCALE_RESOLVER_IMPL_PROPERTY, READER_IMPL_PROPERTY
 
Constructor Summary
UrlDefinitionsFactory()
          Creates a new instance of UrlDefinitionsFactory.
 
Method Summary
protected  void addDefinitions(Definitions definitions, TilesRequestContext tilesContext)
          Appends locale-specific Definition objects to an existing Definitions set by reading locale-specific versions of the applied sources.
 void addSource(Object source)
          Adds a source where Definition objects are stored.
protected static List<String> calculatePostfixes(Locale locale)
          Calculate the postfixes along the search path from the base bundle to the bundle specified by baseName and locale.
protected  String concatPostfix(String name, String postfix)
          Concat postfix to the name.
protected  Definitions createDefinitions()
          Creates a new instance of Definitions.
 Definition getDefinition(String name, TilesRequestContext tilesContext)
          Returns a Definition object that matches the given name and Tiles context.
protected  Definitions getDefinitions()
          Returns the definitions holder object.
 void init(Map<String,String> params)
          Initializes the DefinitionsFactory and its subcomponents.
protected  boolean isContextProcessed(TilesRequestContext tilesContext)
          Indicates whether a given context has been processed or not.
 Definitions readDefinitions()
          Creates and returns a Definitions set by reading configuration data from the applied sources.
 void refresh()
          Refreshes the stored definitions, reloading them.
 boolean refreshRequired()
          Indicates whether the DefinitionsFactory is out of date and needs to be reloaded.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

sources

protected List<Object> sources
Contains the URL objects identifying where configuration data is found.


reader

protected DefinitionsReader reader
Reader used to get definitions from the sources.


lastModifiedDates

protected Map<String,Long> lastModifiedDates
Contains the dates that the URL sources were last modified.

Constructor Detail

UrlDefinitionsFactory

public UrlDefinitionsFactory()
Creates a new instance of UrlDefinitionsFactory.

Method Detail

init

public void init(Map<String,String> params)
          throws TilesException
Initializes the DefinitionsFactory and its subcomponents.

Implementations may support configuration properties to be passed in via the params Map.

Specified by:
init in interface DefinitionsFactory
Parameters:
params - The Map of configuration properties.
Throws:
TilesException - if an initialization error occurs.

getDefinitions

protected Definitions getDefinitions()
                              throws DefinitionsFactoryException
Returns the definitions holder object.

Returns:
The definitions holder.
Throws:
DefinitionsFactoryException - If something goes wrong during reading definitions.

getDefinition

public Definition getDefinition(String name,
                                TilesRequestContext tilesContext)
                         throws DefinitionsFactoryException
Returns a Definition object that matches the given name and Tiles context.

Specified by:
getDefinition in interface DefinitionsFactory
Parameters:
name - The name of the Definition to return.
tilesContext - The Tiles context to use to resolve the definition.
Returns:
the Definition matching the given name or null if none is found.
Throws:
DefinitionsFactoryException - if an error occurs reading definitions.

addSource

public void addSource(Object source)
               throws DefinitionsFactoryException
Adds a source where Definition objects are stored.

Implementations should publish what type of source object they expect. The source should contain enough information to resolve a configuration source containing definitions. The source should be a "base" source for configurations. Internationalization and Localization properties will be applied by implementations to discriminate the correct data sources based on locale.

Specified by:
addSource in interface DefinitionsFactory
Parameters:
source - The configuration source for definitions.
Throws:
DefinitionsFactoryException - if an invalid source is passed in or an error occurs resolving the source to an actual data store.

addDefinitions

protected void addDefinitions(Definitions definitions,
                              TilesRequestContext tilesContext)
                       throws DefinitionsFactoryException
Appends locale-specific Definition objects to an existing Definitions set by reading locale-specific versions of the applied sources.

Parameters:
definitions - The Definitions object to append to.
tilesContext - The requested locale.
Throws:
DefinitionsFactoryException - if an error occurs reading definitions.

readDefinitions

public Definitions readDefinitions()
                            throws DefinitionsFactoryException
Creates and returns a Definitions set by reading configuration data from the applied sources.

Specified by:
readDefinitions in interface DefinitionsFactory
Returns:
The definitions holder object, filled with base definitions.
Throws:
DefinitionsFactoryException - if an error occurs reading the sources.

isContextProcessed

protected boolean isContextProcessed(TilesRequestContext tilesContext)
Indicates whether a given context has been processed or not.

This method can be used to avoid unnecessary synchronization of the DefinitionsFactory in multi-threaded situations. Check the return of isContextProcessed before synchronizing the object and reading locale-specific definitions.

Parameters:
tilesContext - The Tiles context to check.
Returns:
true if the given context has been processed and false otherwise.

createDefinitions

protected Definitions createDefinitions()
Creates a new instance of Definitions. Override this method to provide your custom instance of Definitions.

Returns:
A new instance of Definitions.

concatPostfix

protected String concatPostfix(String name,
                               String postfix)
Concat postfix to the name. Take care of existing filename extension. Transform the given name "name.ext" to have "name" + "postfix" + "ext". If there is no ext, return "name" + "postfix".

Parameters:
name - Filename.
postfix - Postfix to add.
Returns:
Concatenated filename.

calculatePostfixes

protected static List<String> calculatePostfixes(Locale locale)
Calculate the postfixes along the search path from the base bundle to the bundle specified by baseName and locale. Method copied from java.util.ResourceBundle

Parameters:
locale - the locale
Returns:
a list of

refresh

public void refresh()
             throws DefinitionsFactoryException
Refreshes the stored definitions, reloading them.

Specified by:
refresh in interface ReloadableDefinitionsFactory
Throws:
DefinitionsFactoryException - If something goes wrong during refresh.

refreshRequired

public boolean refreshRequired()
Indicates whether the DefinitionsFactory is out of date and needs to be reloaded.

Specified by:
refreshRequired in interface ReloadableDefinitionsFactory
Returns:
If the factory needs refresh.


Copyright © 2001-2008 Apache Software Foundation. All Rights Reserved.