|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.sun.portal.providers.context.PropertiesFilter
This class is an abstract PropertiesFilter class. Every PropertiesFilter
implementation must extend this class.
A PropertiesFilter is used to describe an arbitrary filter
which is used to selectively look up properties with
certain criteria as well as when storing properties that are specific
to certain setting.
The PropertiesFilter itself does not compare any actual property values.
Rather, it determines if the qualifiers ('condition
' and
'value
') associated with the property match the filter
criteria supplied in the PropertiesFilter.
PropertiesFilters are instantiated using methods provided in
PropertiesFilterFactory
and are not to be constructed directly.
In addition, PropertiesFilter objects are meant to be immutable and
stateless. Once a PropertiesFilter is initialized, the value cannot
be modified.
Nevertheless, in some cases, having an access to stateful objects
such as ProviderContext within the PropertiesFilter, especially in
the match() method may become necessary. This can be achieved by
extending the PropertierFilter in such a way that the stateful object(s)
can be passed in the constructor and stored as a member variable.
Instantiating such a PropertiesFilter is done by directly constructing
the PropertiesFilter
, bypassing the PropertiesFilterFactory
.
Here is an example:
public class LoggingPropertiesFilter extends PropertiesFilter {
private ProviderContext pc = null;
public LoggingPropertiesFilter(ProviderContext pc, String value, boolean required) {
super();
this.pc = pc;
try {
init(value, required);
} catch (PropertiesFilterException pfe) {
pc.debugError("LoggingPropertiesFilter(): Failed to init." , pfe);
}
}
public String getCondition() {
return "loggingEnabled";
}
public boolean match(String condition, String value) throws PropertiesFilterException {
if (!condition.equals("loggingEnabled")) {
return false;
}
if (getValue().equals(value)) {
pc.debugMessage("LoggingPropertiesFilter(): matched loggingEnabled property. value=" value);
}
return true;
}
}
List pflist = new ArrayList();
pflist.add(new LoggingPropertiesFilter(getProviderContext(), "foo", true);
Note that bypassing PropertiesFilterFactory
may have a
performance impact. Also, PropertiesContext
has a life-span
of one session and should not be s
ProviderContext
.
ProviderContext
,
PropertiesFilterFactory
Constructor Summary | |
PropertiesFilter()
Constructor. |
Method Summary | |
abstract String |
getCondition()
Get the condition of the filter, such as "locale" and
"client" . |
String |
getValue()
Get the value of the filter that is associated with the condition of the filter. |
protected void |
init(String value,
boolean required)
Initialize PropertiesFilter with given values. |
boolean |
isRequired()
Is filter required? A conditional property lookup involves one or more property filters. |
abstract boolean |
match(String condition,
String value)
Does the given condition and value match the filter? |
String |
toString()
Return a string representation of the PropertiesFilter. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public PropertiesFilter()
PropertiesFilterFactory.get()
.
PropertiesFilterFactory.get(String, String, boolean)
Method Detail |
protected void init(String value, boolean required) throws PropertiesFilterException
value
- The value that gets associated with the filter.required
- Flag indicating whether this filter criteria
is required or optional.
PropertiesFilterException
- there was an error while initializing valuespublic abstract String getCondition() throws PropertiesFilterException
"locale"
and
"client"
.
Filter condition is an unmodifiable constant value.
PropertiesFilterException
- if there is an error in getting
the condition of the filter.public String getValue()
public boolean isRequired()
{locale=en, locale=US, date=03/03/2003}
,
you can get it to successfully match a property with the qualifier
{locale=en; date=03/03/2003}
even though it does not exactly match
the filter specification. This done by setting the locale filter
to be optional.
public abstract boolean match(String condition, String value) throws PropertiesFilterException
condition
- the condition to be matched against the filter conditionvalue
- the value to be matched against the filter value
PropertiesFilterException
- if there is an error in
processing properties to be matched.public String toString()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |