You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tiles.apache.org by ap...@apache.org on 2007/02/22 14:48:46 UTC
svn commit: r510515 - in /tiles/framework/trunk:
tiles-api/src/main/java/org/apache/tiles/
tiles-core/src/main/java/org/apache/tiles/definition/
tiles-core/src/main/java/org/apache/tiles/impl/mgmt/
Author: apetrelli
Date: Thu Feb 22 05:48:45 2007
New Revision: 510515
URL: http://svn.apache.org/viewvc?view=rev&rev=510515
Log:
TILES-118
Now the attributes for custom definitions are correctly inherited.
Modified:
tiles/framework/trunk/tiles-api/src/main/java/org/apache/tiles/ComponentAttribute.java
tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/ComponentDefinition.java
tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/impl/mgmt/DefinitionManager.java
Modified: tiles/framework/trunk/tiles-api/src/main/java/org/apache/tiles/ComponentAttribute.java
URL: http://svn.apache.org/viewvc/tiles/framework/trunk/tiles-api/src/main/java/org/apache/tiles/ComponentAttribute.java?view=diff&rev=510515&r1=510514&r2=510515
==============================================================================
--- tiles/framework/trunk/tiles-api/src/main/java/org/apache/tiles/ComponentAttribute.java (original)
+++ tiles/framework/trunk/tiles-api/src/main/java/org/apache/tiles/ComponentAttribute.java Thu Feb 22 05:48:45 2007
@@ -23,6 +23,7 @@
package org.apache.tiles;
import java.io.Serializable;
+import java.util.HashMap;
import java.util.Map;
/**
@@ -74,6 +75,26 @@
*/
public ComponentAttribute(Object value) {
this.value = value;
+ }
+
+ /**
+ * Copy constructor.
+ *
+ * @param value Object to store.
+ */
+ public ComponentAttribute(ComponentAttribute attribute) {
+ this.name = attribute.name;
+ this.role = attribute.role;
+ this.type = attribute.type;
+ this.value = attribute.getValue();
+ if (attribute.attributes != null) {
+ this.attributes = new HashMap<String, ComponentAttribute>();
+ for (Map.Entry<String, ComponentAttribute> entry : attribute.attributes
+ .entrySet()) {
+ this.attributes.put(entry.getKey(), new ComponentAttribute(
+ entry.getValue()));
+ }
+ }
}
/**
Modified: tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/ComponentDefinition.java
URL: http://svn.apache.org/viewvc/tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/ComponentDefinition.java?view=diff&rev=510515&r1=510514&r2=510515
==============================================================================
--- tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/ComponentDefinition.java (original)
+++ tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/ComponentDefinition.java Thu Feb 22 05:48:45 2007
@@ -70,6 +70,7 @@
this.template = definition.getTemplate();
this.role = definition.getRole();
this.preparer = definition.getPreparer();
+ this.inherit = definition.getExtends();
}
/**
@@ -90,6 +91,16 @@
*/
public void putAttribute(String key, ComponentAttribute value) {
attributes.put(key, value);
+ }
+
+ /**
+ * Checks whether the <code>key</code> attribute has been set.
+ *
+ * @param key The attribute key to check.
+ * @return <code>true</code> if the attribute has a value.
+ */
+ public boolean hasAttributeValue(String key) {
+ return attributes.containsKey(key);
}
/**
Modified: tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/impl/mgmt/DefinitionManager.java
URL: http://svn.apache.org/viewvc/tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/impl/mgmt/DefinitionManager.java?view=diff&rev=510515&r1=510514&r2=510515
==============================================================================
--- tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/impl/mgmt/DefinitionManager.java (original)
+++ tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/impl/mgmt/DefinitionManager.java Thu Feb 22 05:48:45 2007
@@ -84,7 +84,7 @@
validate(definition);
if(definition.isExtending()) {
- this.resolveInheritance(definition);
+ this.resolveInheritance(definition, request);
}
for(ComponentAttribute attr : definition.getAttributes().values()) {
@@ -128,7 +128,8 @@
* @throws NoSuchDefinitionException If an inheritance can not be solved.
* @param definition def
*/
- protected void resolveInheritance(ComponentDefinition definition)
+ protected void resolveInheritance(ComponentDefinition definition,
+ TilesRequestContext request)
throws DefinitionsFactoryException {
// Already done, or not needed ?
if (definition.isIsVisited() || !definition.isExtending())
@@ -146,7 +147,7 @@
// however, this may cause errors for other implementations.
// we should probably make all factories agnostic and allow the manager to
// utilize the correct factory based on the context.
- ComponentDefinition parent = getDefinition(definition.getExtends(), null);
+ ComponentDefinition parent = getDefinition(definition.getExtends(), request);
if (parent == null) { // error
@@ -161,7 +162,7 @@
}
// Resolve parent before itself.
- resolveInheritance(parent);
+ resolveInheritance(parent, request);
overload(parent, definition);
}
@@ -179,7 +180,9 @@
ComponentDefinition child) {
// Iterate on each parent's attribute and add it if not defined in child.
for(Map.Entry<String, ComponentAttribute> entry : parent.getAttributes().entrySet()) {
- child.putAttribute(entry.getKey(), new ComponentAttribute(entry.getValue()));
+ if (!child.hasAttributeValue(entry.getKey())) {
+ child.putAttribute(entry.getKey(), new ComponentAttribute(entry.getValue()));
+ }
}
if (child.getTemplate() == null)