org.sape.carbon.core.config.type
Class TokenReplacer

java.lang.Object
  |
  +--org.sape.carbon.core.config.type.TokenReplacer

class TokenReplacer
extends Object

This class provides tokenization and value linking for configuration values in order to minimize the duplication of data. It supports two types of value replacement, document property and deployment property.

The Document Property has a form of {document-name$attribute-name}. This would search for a document named document-name and then look for an attribute named attribute-name.

The Deployment Property lookup has a form of {deployment-property}. This would retrieve the Deployment Property deployment-property from the BootStrapper. This mechanism should not be used for normal configurations and is specially provided for instances where deployment values can not or do not want to be known ahead of time (such as the base file-system directory of config or a database password).

Since:
carbon 1.0
Version:
$Revision: 1.19 $($Author: dvoet $ / $Date: 2003/05/05 21:21:20 $)
Author:
Douglas Voet, April 2002
See Also:
Copyright 2002 Sapient

Field Summary
private static String ALL_DELIMETERS
          Delimiters to tokenize on.
private static String ATTRIBUTE_DELIMETER
          The delimeter used for seperating a config document name from the value that is required from it.
private static String BEGIN_DELIMETER
          The delimiter that begins a replaceable config value
private  String data
          The data to be tokenized, mapped and replaced necessary.
private static String END_DELIMETER
          The end delimter that declares the end of a replaceable config value
private static String ESCAPE_DELIMETER
          The character set used to escape other delimeters so that they can be used as real values.
private  org.apache.commons.logging.Log log
          Provides a handle to Apache-commons logger
private  String replacedValue
          The replaced value of the data.
 
Constructor Summary
TokenReplacer(String data)
          Creates a new token replacer for the specified configuration value.
 
Method Summary
 boolean containsTokens()
          Tests if the data contains tokens.
private  String lookupConfigurationValue(String configName, String attributeName)
          Looks up a Configuration value from the Config using token replacement.
 String replaceTokens()
          Replaces tokens within configuration attributes with values from other configurations.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

private org.apache.commons.logging.Log log
Provides a handle to Apache-commons logger


BEGIN_DELIMETER

private static final String BEGIN_DELIMETER
The delimiter that begins a replaceable config value

See Also:
Constant Field Values

END_DELIMETER

private static final String END_DELIMETER
The end delimter that declares the end of a replaceable config value

See Also:
Constant Field Values

ATTRIBUTE_DELIMETER

private static final String ATTRIBUTE_DELIMETER
The delimeter used for seperating a config document name from the value that is required from it.

See Also:
Constant Field Values

ESCAPE_DELIMETER

private static final String ESCAPE_DELIMETER
The character set used to escape other delimeters so that they can be used as real values.

See Also:
Constant Field Values

ALL_DELIMETERS

private static final String ALL_DELIMETERS
Delimiters to tokenize on.

See Also:
Constant Field Values

data

private String data
The data to be tokenized, mapped and replaced necessary.


replacedValue

private String replacedValue
The replaced value of the data.

Constructor Detail

TokenReplacer

public TokenReplacer(String data)
Creates a new token replacer for the specified configuration value.

Parameters:
data - the data to run the replacer on
Method Detail

containsTokens

public boolean containsTokens()
Tests if the data contains tokens.

Returns:
if the data contains tokens

replaceTokens

public String replaceTokens()
                     throws ConfigurationTypeException
Replaces tokens within configuration attributes with values from other configurations. Tokens are in the form of {configuration name$attribute name}. If either '{', '}' or '$' are required in the actual value, escape them with a '\'.

Returns:
String the String to tokenize and replace
Throws:
ConfigurationTypeException - thrown when unable to retrieve a referenced value or in case there is a failure parse the reference.

lookupConfigurationValue

private String lookupConfigurationValue(String configName,
                                        String attributeName)
                                 throws TokenReplacementException
Looks up a Configuration value from the Config using token replacement.

Parameters:
configName - name of the configuration to lookup
attributeName - name of the attribute to retreive from config
Returns:
the String value of the configuration
Throws:
TokenReplacementException - indicates an error retreiving the value from the configuration


Copyright 1999-2003 Sapient Corporation. All Rights Reserved.