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.struts.tiles.xmlDefinition;
23
24 import org.apache.struts.tiles.ComponentDefinition;
25 import org.apache.struts.tiles.NoSuchDefinitionException;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
28
29
30
31
32 public class XmlDefinition extends ComponentDefinition
33 {
34 private static final long serialVersionUID = -5843791058928194033L;
35
36
37
38
39 private String inherit;
40
41
42
43
44 private transient final Logger log =
45 LoggerFactory.getLogger(XmlDefinition.class);
46
47
48
49
50 private boolean isVisited=false;
51
52
53
54
55
56 public XmlDefinition()
57 {
58 super();
59
60
61 }
62
63
64
65
66
67
68 public void addAttribute( XmlAttribute attribute)
69 {
70 putAttribute( attribute.getName(), attribute.getValue() );
71 }
72
73
74
75
76
77
78 public void setExtends(String name)
79 {
80 inherit = name;
81 }
82
83
84
85
86
87
88 public String getExtends()
89 {
90 return inherit;
91 }
92
93
94
95
96
97 public boolean isExtending( )
98 {
99 return inherit!=null;
100 }
101
102
103
104
105
106 public void setIsVisited( boolean isVisited )
107 {
108 this.isVisited = isVisited;
109 }
110
111
112
113
114
115
116
117
118 public void resolveInheritance( XmlDefinitionsSet definitionsSet )
119 throws NoSuchDefinitionException
120 {
121
122 if( isVisited || !isExtending() )
123 return;
124
125 log.debug("Resolve definition for child name='{}' extends='{}'.",
126 getName(), getExtends());
127
128
129 setIsVisited( true );
130
131
132 XmlDefinition parent = definitionsSet.getDefinition( getExtends() );
133 if( parent == null )
134 {
135 String msg = "Error while resolving definition inheritance: child '"
136 + getName() + "' can't find its ancestor '"
137 + getExtends() +
138 "'. Please check your description file.";
139 log.error( msg );
140
141 throw new NoSuchDefinitionException( msg );
142 }
143
144 parent.resolveInheritance( definitionsSet );
145
146
147 for( String name : parent.getAttributes().keySet() )
148 {
149 if( !getAttributes().containsKey(name) )
150 putAttribute( name, parent.getAttribute(name) );
151 }
152
153 if( path == null )
154 setPath( parent.getPath() );
155 if( role == null )
156 setRole( parent.getRole() );
157 if( controller==null )
158 {
159 setController( parent.getController());
160 setControllerType( parent.getControllerType());
161 }
162 }
163
164
165
166
167
168
169
170
171
172 public void overload( XmlDefinition child )
173 {
174 if( child.getPath() != null )
175 {
176 path = child.getPath();
177 }
178 if( child.getExtends() != null )
179 {
180 inherit = child.getExtends();
181 }
182 if( child.getRole() != null )
183 {
184 role = child.getRole();
185 }
186 if( child.getController()!=null )
187 {
188 controller = child.getController();
189 controllerType = child.getControllerType();
190 }
191
192 attributes.putAll( child.getAttributes());
193 }
194 }