configuration.add("ClearCachesOnInvalidation", clearCaches);
}
public void contributePropBindingFactory(OrderedConfiguration<BindingFactory> configuration)
{
BindingFactory keywordFactory = new BindingFactory()
{
private final Map<String, Object> _keywords = newCaseInsensitiveMap();
{
_keywords.put("true", Boolean.TRUE);
_keywords.put("false", Boolean.FALSE);
_keywords.put("null", null);
}
public Binding newBinding(String description, ComponentResources container,
ComponentResources component, String expression, Location location)
{
String key = expression.trim();
if (_keywords.containsKey(key))
return new LiteralBinding(description, _keywords.get(key), location);
return null;
}
};
BindingFactory thisFactory = new BindingFactory()
{
public Binding newBinding(String description, ComponentResources container,
ComponentResources component, String expression, Location location)
{
if ("this".equalsIgnoreCase(expression.trim()))
return new LiteralBinding(description, container.getComponent(), location);
return null;
}
};
BindingFactory longFactory = new BindingFactory()
{
private final Pattern _pattern = Pattern.compile("^\\s*(-?\\d+)\\s*$");
public Binding newBinding(String description, ComponentResources container,
ComponentResources component, String expression, Location location)
{
Matcher matcher = _pattern.matcher(expression);
if (matcher.matches())
{
String value = matcher.group(1);
return new LiteralBinding(description, new Long(value), location);
}
return null;
}
};
BindingFactory intRangeFactory = new BindingFactory()
{
private final Pattern _pattern = Pattern
.compile("^\\s*(-?\\d+)\\s*\\.\\.\\s*(-?\\d+)\\s*$");
public Binding newBinding(String description, ComponentResources container,
ComponentResources component, String expression, Location location)
{
Matcher matcher = _pattern.matcher(expression);
if (matcher.matches())
{
int start = Integer.parseInt(matcher.group(1));
int finish = Integer.parseInt(matcher.group(2));
IntegerRange range = new IntegerRange(start, finish);
return new LiteralBinding(description, range, location);
}
return null;
}
};
BindingFactory doubleFactory = new BindingFactory()
{
// So, either 1234. or 1234.56 or .78
private final Pattern _pattern = Pattern
.compile("^\\s*(\\-?((\\d+\\.)|(\\d*\\.\\d+)))\\s*$");
public Binding newBinding(String description, ComponentResources container,
ComponentResources component, String expression, Location location)
{
Matcher matcher = _pattern.matcher(expression);
if (matcher.matches())
{
String value = matcher.group(1);
return new LiteralBinding(description, new Double(value), location);
}
return null;
}
};
BindingFactory stringFactory = new BindingFactory()
{
// This will match embedded single quotes as-is, no escaping necessary.
private final Pattern _pattern = Pattern.compile("^\\s*'(.*)'\\s*$");