This project has retired. For details please refer to its
Attic page.
DefaultAttributeResolver xref
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.apache.tiles.template;
23
24 import org.apache.tiles.Attribute;
25 import org.apache.tiles.AttributeContext;
26 import org.apache.tiles.Expression;
27 import org.apache.tiles.TilesContainer;
28
29 /***
30 * The default implementation of AttributeResolver.
31 *
32 * @version $Rev: 788032 $ $Date: 2009-06-24 16:08:32 +0200 (mer, 24 giu 2009) $
33 * @since 2.2.0
34 */
35 public class DefaultAttributeResolver implements AttributeResolver {
36
37 /*** {@inheritDoc} */
38 public Attribute computeAttribute(TilesContainer container, Attribute attribute,
39 String name, String role, boolean ignore,
40 Object defaultValue, String defaultValueRole, String defaultValueType, Object... requestItems) {
41 if (attribute == null) {
42 AttributeContext evaluatingContext = container
43 .getAttributeContext(requestItems);
44 attribute = evaluatingContext.getAttribute(name);
45 if (attribute == null) {
46 attribute = computeDefaultAttribute(defaultValue,
47 defaultValueRole, defaultValueType);
48 if (attribute == null && !ignore) {
49 throw new NoSuchAttributeException("Attribute '" + name
50 + "' not found.");
51 }
52 }
53 }
54 if (attribute != null && role != null && !"".equals(role.trim())) {
55 attribute = new Attribute(attribute);
56 attribute.setRole(role);
57 }
58 return attribute;
59 }
60
61 /***
62 * Computes the default attribute.
63 *
64 * @param defaultValue The default value of the attribute.
65 * @param defaultValueRole The default role of tha attribute.
66 * @param defaultValueType The default type of the attribute.
67 * @return The default attribute.
68 */
69 private Attribute computeDefaultAttribute(Object defaultValue,
70 String defaultValueRole, String defaultValueType) {
71 Attribute attribute = null;
72 if (defaultValue != null) {
73 if (defaultValue instanceof Attribute) {
74 attribute = (Attribute) defaultValue;
75 } else if (defaultValue instanceof String) {
76 attribute = new Attribute(defaultValue, (Expression) null,
77 defaultValueRole, defaultValueType);
78 }
79 }
80 return attribute;
81 }
82 }