Top Description Inners Fields Constructors Methods
org.apache.tools.ant

public Class PropertyHelper

extends Object
implements GetProperty
Class Inheritance
All Implemented Interfaces
org.apache.tools.ant.property.GetProperty
Imports
java.util.ArrayList, .Collection, .Collections, .HashSet, .Hashtable, .List, .Map, .Set, .Vector, org.apache.tools.ant.property.GetProperty, .NullReturn, .ParseProperties, .PropertyExpander

Deals with properties - substitution, dynamic properties, etc.

This code has been heavily restructured for Ant 1.8.0. It is expected that custom PropertyHelper implementation that used the older chaining mechanism of Ant 1.6 won't work in all cases, and its usage is deprecated. The preferred way to customize Ant's property handling is by adding delegates of the appropriate subinterface and have this implementation use them.

When expanding a string that may contain properties this class will delegate the actual parsing to parseProperties inside the ParseProperties class which in turn uses the PropertyExpander delegates to find properties inside the string and this class to expand the property names found into the corresponding values.

When looking up a property value this class will first consult all PropertyEvaluator delegates and fall back to an internal map of "project properties" if no evaluator matched the property name.

When setting a property value this class will first consult all PropertySetter delegates and fall back to an internal map of "project properties" if no setter matched the property name.

Since
Ant 1.6

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface
PropertyHelper.Delegate

Marker interface for a PropertyHelper delegate.

public static interface
PropertyHelper.PropertyEnumerator

Obtains the names of all known properties.

public static interface
PropertyHelper.PropertyEvaluator

Looks up a property's value based on its name.

public static interface
PropertyHelper.PropertySetter

Sets or overrides a property.

Field Summary

Modifier and TypeField and Description
private static final PropertyExpander
private final Hashtable<Class<? extends PropertyHelper.Delegate>, List<PropertyHelper.Delegate>>
private static final PropertyHelper.PropertyEvaluator
private final Hashtable<String, Object>
inheritedProperties

Map of inherited "user" properties - that are those "user" properties that have been created by tasks and not been set from the command line or a GUI tool.

private PropertyHelper
private Project
private final Hashtable<String, Object>
properties

Project properties map (usually String to String).

private static final PropertyExpander
private static final PropertyHelper.PropertyEvaluator
private final Hashtable<String, Object>
userProperties

Map of "user" properties (as created in the Ant task, for example).

Constructor Summary

AccessConstructor and Description
protected
PropertyHelper()

Default constructor.

Method Summary

Modifier and TypeMethod and Description
public void
add(PropertyHelper.Delegate
the delegate to add.
delegate
)

Add the specified delegate object to this PropertyHelper.

public boolean

Returns:

true if value contains property notation.
containsProperties
(String
the String to check.
value
)

Learn whether a String contains replaceable properties.

public void
copyInheritedProperties(Project
the project to copy the properties to. Must not be null.
other
)

Copies all user properties that have not been set on the command line or a GUI tool from this instance to the Project instance given as the argument.

public void
copyUserProperties(Project
the project to copy the properties to. Must not be null.
other
)

Copies all user properties that have been set on the command line or a GUI tool from this instance to the Project instance given as the argument.

private boolean

Returns:

boolean
evalAsBooleanOrPropertyName
(Object
Object
value
)

Returns true if the value can be interpreted as a true value or cannot be interpreted as a false value and a property of the value's name exists.

protected static Set<Class<? extends PropertyHelper.Delegate>>

Returns:

Set<Class>
getDelegateInterfaces
(PropertyHelper.Delegate
the Delegate to inspect.
d
)

Get all Delegate interfaces (excluding Delegate itself) from the specified Delegate.

protected <
desired type.
D extends PropertyHelper.Delegate
>
List<D>

Returns:

Collection.
getDelegates
(Class<D>
delegate type.
type
)

Get the Collection of delegates of the specified type.

public Collection<PropertyExpander>

Returns:

the expanders.
getExpanders
()

Get the expanders.

public Hashtable<String, Object>

Returns:

a hashtable containing just the inherited properties
getInheritedProperties
()

Returns a copy of the inherited property hashtable

Does not contain properties held by implementations of delegates (like local properties).

protected Hashtable<String, Object>

Returns:

the live hashtable inherited properties
getInternalInheritedProperties
()

special back door for subclasses, internal access to the hashtables

protected Hashtable<String, Object>

Returns:

the live hashtable of all properties
getInternalProperties
()

special back door for subclasses, internal access to the hashtables

protected Hashtable<String, Object>

Returns:

the live hashtable of user properties
getInternalUserProperties
()

special back door for subclasses, internal access to the hashtables

public PropertyHelper

Returns:

the next property helper.
getNext
()

Deprecated use the delegate mechanism instead
Get the next property helper in the chain.
public Project

Returns:

Project
getProject
()

Get this PropertyHelper's Project.

public Hashtable<String, Object>

Returns:

a hashtable containing all properties (including user properties).
getProperties
()

Returns a copy of the properties table.

public static Object

Returns:

the value of the property if present, null otherwise.
getProperty
(Project
the project in question.
project
,
String
the property name
name
)

A helper static method to get a property from a particular project.

public Object

Returns:

the property value, or null for no match or if a null name is provided.
getProperty
(String
The namespace for the property (currently not used).
ns
,
String
The name of the property. May be null, in which case the return value is also null.
name
)

Deprecated namespaces are unnecessary.
Returns the value of a property, if it is set.
public Object

Returns:

the property value, or null for no match or if a null name is provided.
getProperty
(String
The name of the property. May be null, in which case the return value is also null.
name
)

Implements org.apache.tools.ant.property.GetProperty.getProperty.

Returns the value of a property, if it is set.
public static synchronized PropertyHelper

Returns:

the project's property helper.
getPropertyHelper
(Project
the project for which the property helper is required.
project
)

Factory method to create a property processor.

public Object

Returns:

The property, if returned by a hook, or null if none.
getPropertyHook
(String
namespace of the sought property.
ns
,
String
name of the sought property.
name
,
boolean
True if this is a user property.
user
)

Deprecated PropertyHelper chaining is deprecated.
Get a property.
public Set<String>

Returns:

the names of all known properties.
getPropertyNames
()

Returns the names of all known properties.

public Hashtable<String, Object>

Returns:

a hashtable containing just the user properties
getUserProperties
()

Returns a copy of the user property hashtable

Does not contain properties held by implementations of delegates (like local properties).

public Object

Returns:

the property value, or null for no match or if a null name is provided.
getUserProperty
(String
The namespace for the property (currently not used).
ns
,
String
The name of the property. May be null, in which case the return value is also null.
name
)

Deprecated namespaces are unnecessary.
Returns the value of a user property, if it is set.
public Object

Returns:

the property value, or null for no match or if a null name is provided.
getUserProperty
(String
The name of the property. May be null, in which case the return value is also null.
name
)

Returns the value of a user property, if it is set.

private static boolean

Returns:

boolean
nullOrEmpty
(Object
Object
value
)

Returns true if the object is null or an empty string.

public Object

Returns:

the original string with the properties replaced, or null if the original string is null.
parseProperties
(String
The string to be scanned for property references. May be null, in which case this method returns immediately with no effect.
value
)

Decode properties from a String representation.

public void
parsePropertyString(String
Text to parse. Must not be null.
value
,
Vector<String>
List to add text fragments to. Must not be null.
fragments
,
Vector<String>
List to add property names to. Must not be null.
propertyRefs
)

Deprecated use the other mechanisms of this class instead
Parses a string containing ${xxx} style property references into two lists.
pack-priv static void
parsePropertyStringDefault(String value, Vector<String> fragments, Vector<String> propertyRefs)

Default parsing method.

public String

Returns:

the original string with the properties replaced, or null if the original string is null.
replaceProperties
(String
The namespace for the property.
ns
,
String
The string to be scanned for property references. May be null, in which case this method returns immediately with no effect.
value
,
Hashtable<String, Object>
Mapping (String to Object) of property names to their values. If null, only project properties will be used.
keys
)

Replaces ${xxx} style constructions in the given value with the string value of the corresponding data types.

public String

Returns:

the original string with the properties replaced, or null if the original string is null.
replaceProperties
(String
The string to be scanned for property references. May be null, in which case this method returns immediately with no effect.
value
)

Replaces ${xxx} style constructions in the given value with the string value of the corresponding data types.

public void
setInheritedProperty(String
The namespace for the property (currently not used).
ns
,
String
The name of property to set. Must not be null.
name
,
Object
The new value of the property. Must not be null.
value
)

Deprecated namespaces are unnecessary.
Sets an inherited user property, which cannot be overwritten by set/unset property calls.
public void
setInheritedProperty(String
The name of property to set. Must not be null.
name
,
Object
The new value of the property. Must not be null.
value
)

Sets an inherited user property, which cannot be overwritten by set/unset property calls.

public static void
setNewProperty(Project
the project in question.
project
,
String
the property name
name
,
Object
the value to use.
value
)

A helper static method to set a new property from a particular project.

public void
setNewProperty(String
The namespace for the property (currently not used).
ns
,
String
The name of property to set. Must not be null.
name
,
Object
The new value of the property. Must not be null.
value
)

Deprecated namespaces are unnecessary.
Sets a property if no value currently exists.
public void
setNewProperty(String
The name of property to set. Must not be null.
name
,
Object
The new value of the property. Must not be null.
value
)

Sets a property if no value currently exists.

public void
setNext(PropertyHelper
the next property helper in the chain.
next
)

Deprecated use the delegate mechanism instead
Prior to Ant 1.8.0 there have been 2 ways to hook into property handling: - you can replace the main PropertyHelper.
public void
setProject(Project
the project instance.
p
)

Set the project for which this helper is performing property resolution.

public static void
setProperty(Project
the project in question.
project
,
String
the property name
name
,
Object
the value to use.
value
)

A helper static method to set a property from a particular project.

public boolean

Returns:

true if the property is set.
setProperty
(String
The namespace for the property (currently not used).
ns
,
String
The name of the property.
name
,
Object
The value to set the property to.
value
,
boolean
If this is true output extra log messages.
verbose
)

Deprecated namespaces are unnecessary.
Default implementation of setProperty.
public boolean

Returns:

true if the property is set.
setProperty
(String
The name of the property.
name
,
Object
The value to set the property to.
value
,
boolean
If this is true output extra log messages.
verbose
)

Default implementation of setProperty.

public boolean

Returns:

true if this helper has stored the property, false if it couldn't. Each helper should delegate to the next one (unless it has a good reason not to).
setPropertyHook
(String
The namespace that the property is in (currently not used.
ns
,
String
The name of property to set. Must not be null.
name
,
Object
The new value of the property. Must not be null.
value
,
boolean
True if this property is inherited (an [sub]ant[call] property).
inherited
,
boolean
True if this property is a user property.
user
,
boolean
True is this is a new property.
isNew
)

Deprecated PropertyHelper chaining is deprecated.
Sets a property.
public void
setUserProperty(String
The namespace for the property (currently not used).
ns
,
String
The name of property to set. Must not be null.
name
,
Object
The new value of the property. Must not be null.
value
)

Deprecated namespaces are unnecessary.
Sets a user property, which cannot be overwritten by set/unset property calls.
public void
setUserProperty(String
The name of property to set. Must not be null.
name
,
Object
The new value of the property. Must not be null.
value
)

Sets a user property, which cannot be overwritten by set/unset property calls.

public boolean

Returns:

boolean
testIfCondition
(Object
Object
value
)

Returns true if the value is null or an empty string, can be interpreted as a true value or cannot be interpreted as a false value and a property of the value's name exists.

public boolean

Returns:

boolean
testUnlessCondition
(Object
Object
value
)

Returns true if the value is null or an empty string, can be interpreted as a false value or cannot be interpreted as a true value and a property of the value's name doesn't exist.

public static Boolean

Returns:

Boolean
toBoolean
(Object
Object
value
)

If the given object can be interpreted as a true/false value, turn it into a matching Boolean - otherwise return null.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait