Author: apetrelli
Date: Fri May 11 05:53:36 2007
New Revision: 537184
URL: http://svn.apache.org/viewvc?view=rev&rev=537184
Log:
TILES-176
Removed "isVisited" property out of Definition, and moved the visit algorithm
in DefinitionsImpl.
Removed the check in DefinitionManager, since it is not necessary.
Modified:
tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/Definition.java
tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/DefinitionsImpl.java
tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/impl/mgmt/DefinitionManager.java
Modified:
tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/Definition.java
URL:
http://svn.apache.org/viewvc/tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/Definition.java?view=diff&rev=537184&r1=537183&r2=537184
==============================================================================
---
tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/Definition.java
(original)
+++
tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/Definition.java
Fri May 11 05:53:36 2007
@@ -46,11 +46,6 @@
protected static Log log = LogFactory.getLog(Definition.class);
/**
- * Used for resolving inheritance.
- */
- private boolean isVisited = false;
-
- /**
* Constructor.
*/
public Definition() {
@@ -138,6 +133,12 @@
putAttribute(name, attribute);
}
+ /** [EMAIL PROTECTED] */
+ @Override
+ public int hashCode() {
+ return name != null ? name.hashCode() : 0;
+ }
+
/**
* Returns a description of the attributes.
*
@@ -164,23 +165,5 @@
*/
public boolean isExtending() {
return inherit != null;
- }
-
- /**
- * Sets the visit flag, used during inheritance resolution.
- *
- * @param isVisited <code>true</code> is the definition has been visited.
- */
- public void setIsVisited(boolean isVisited) {
- this.isVisited = isVisited;
- }
-
- /**
- * Returns the visit flag, used during inheritance resolution.
- *
- * @return isVisited <code>true</code> is the definition has been visited.
- */
- public boolean isIsVisited() {
- return isVisited;
}
}
Modified:
tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/DefinitionsImpl.java
URL:
http://svn.apache.org/viewvc/tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/DefinitionsImpl.java?view=diff&rev=537184&r1=537183&r2=537184
==============================================================================
---
tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/DefinitionsImpl.java
(original)
+++
tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/DefinitionsImpl.java
Fri May 11 05:53:36 2007
@@ -26,8 +26,10 @@
import org.apache.tiles.Attribute;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.Locale;
import java.util.Map;
+import java.util.Set;
/**
* @version $Rev$ $Date$
@@ -127,8 +129,10 @@
* @throws NoSuchDefinitionException If a parent definition is not found.
*/
public void resolveInheritances() throws NoSuchDefinitionException {
+ Set<String> alreadyResolvedDefinitions = new HashSet<String>();
+
for (Definition definition : baseDefinitions.values()) {
- resolveInheritance(definition, null);
+ resolveInheritance(definition, null, alreadyResolvedDefinitions);
} // end loop
}
@@ -143,8 +147,10 @@
Map<String, Definition> map = localeSpecificDefinitions.get(locale);
if (map != null) {
+ Set<String> alreadyResolvedDefinitions = new HashSet<String>();
for (Definition definition : map.values()) {
- resolveInheritance(definition, locale);
+ resolveInheritance(definition, locale,
+ alreadyResolvedDefinitions);
} // end loop
}
}
@@ -198,12 +204,16 @@
*
* @param definition The definition to resolve
* @param locale The locale to use.
+ * @param alreadyResolvedDefinitions The set of the definitions that have
+ * been already resolved.
* @throws NoSuchDefinitionException If an inheritance can not be solved.
*/
- protected void resolveInheritance(Definition definition,
- Locale locale) throws
NoSuchDefinitionException {
+ protected void resolveInheritance(Definition definition, Locale locale,
+ Set<String> alreadyResolvedDefinitions)
+ throws NoSuchDefinitionException {
// Already done, or not needed ?
- if (definition.isIsVisited() || !definition.isExtending()) {
+ if (!definition.isExtending()
+ || alreadyResolvedDefinitions.contains(definition.getName())) {
return;
}
@@ -214,7 +224,7 @@
}
// Set as visited to avoid endless recurisvity.
- definition.setIsVisited(true);
+ alreadyResolvedDefinitions.add(definition.getName());
// Resolve parent before itself.
Definition parent = getDefinition(definition.getExtends(),
@@ -230,7 +240,7 @@
throw new NoSuchDefinitionException(msg);
}
- resolveInheritance(parent, locale);
+ resolveInheritance(parent, locale, alreadyResolvedDefinitions);
overload(parent, definition);
}
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=537184&r1=537183&r2=537184
==============================================================================
---
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
Fri May 11 05:53:36 2007
@@ -174,7 +174,7 @@
TilesRequestContext request)
throws DefinitionsFactoryException {
// Already done, or not needed ?
- if (definition.isIsVisited() || !definition.isExtending()) {
+ if (!definition.isExtending()) {
return;
}
@@ -184,15 +184,11 @@
+ "' extends='" + definition.getExtends() + "'.");
}
- // Set as visited to avoid endless recurisvity.
- definition.setIsVisited(true);
-
// TODO Factories our factory implementations will be context agnostic,
// 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.
Definition parent = getDefinition(definition.getExtends(), request);
-
if (parent == null) { // error
String msg = "Error while resolving definition inheritance: child
'"