struts-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From apetre...@apache.org
Subject svn commit: r488005 - in /struts/sandbox/trunk/tiles/tiles-core/src: main/java/org/apache/tiles/definition/ test/java/org/apache/tiles/definition/
Date Sun, 17 Dec 2006 16:48:28 GMT
Author: apetrelli
Date: Sun Dec 17 08:48:28 2006
New Revision: 488005

URL: http://svn.apache.org/viewvc?view=rev&rev=488005
Log:
Fixed a problem in localized definitions inside definitions.

Modified:
    struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/definition/ComponentDefinitions.java
    struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/definition/ComponentDefinitionsImpl.java
    struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/definition/TestComponentDefinitions.java

Modified: struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/definition/ComponentDefinitions.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/definition/ComponentDefinitions.java?view=diff&rev=488005&r1=488004&r2=488005
==============================================================================
--- struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/definition/ComponentDefinitions.java
(original)
+++ struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/definition/ComponentDefinitions.java
Sun Dec 17 08:48:28 2006
@@ -65,7 +65,7 @@
      * @throws NoSuchDefinitionException if a ComponentDefinition extends from
      *                                   one that doesn't exist.
      */
-    public void addDefinitions(Map defsMap, Locale locale) throws NoSuchDefinitionException;
+    public void addDefinitions(Map<String, ComponentDefinition> defsMap, Locale locale)
throws NoSuchDefinitionException;
 
     /**
      * Returns a ComponentDefinition object that matches the given name and locale.

Modified: struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/definition/ComponentDefinitionsImpl.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/definition/ComponentDefinitionsImpl.java?view=diff&rev=488005&r1=488004&r2=488005
==============================================================================
--- struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/definition/ComponentDefinitionsImpl.java
(original)
+++ struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/definition/ComponentDefinitionsImpl.java
Sun Dec 17 08:48:28 2006
@@ -48,14 +48,14 @@
     /**
      * The locale-specific set of definitions objects.
      */
-    private Map<Locale, Map> localeSpecificDefinitions;
+    private Map<Locale, Map<String, ComponentDefinition>> localeSpecificDefinitions;
 
     /**
      * Creates a new instance of ComponentDefinitionsImpl
      */
     public ComponentDefinitionsImpl() {
         baseDefinitions = new HashMap<String, ComponentDefinition>();
-        localeSpecificDefinitions = new HashMap<Locale, Map>();
+        localeSpecificDefinitions = new HashMap<Locale, Map<String, ComponentDefinition>>();
     }
 
     /**
@@ -89,7 +89,7 @@
      * @param defsMap The new definitions to add.
      * @param locale  The locale to add the definitions to.
      */
-    public void addDefinitions(Map defsMap, Locale locale) throws NoSuchDefinitionException
{
+    public void addDefinitions(Map<String, ComponentDefinition> defsMap, Locale locale)
throws NoSuchDefinitionException {
         localeSpecificDefinitions.put(locale, defsMap);
         resolveAttributeDependencies(locale);
         resolveInheritances(locale);
@@ -135,11 +135,9 @@
     public void resolveInheritances(Locale locale) throws NoSuchDefinitionException {
         resolveInheritances();
 
-        Map map = (Map) localeSpecificDefinitions.get(locale);
+        Map<String, ComponentDefinition> map = localeSpecificDefinitions.get(locale);
         if (map != null) {
-            Iterator i = map.values().iterator();
-            while (i.hasNext()) {
-                ComponentDefinition definition = (ComponentDefinition) i.next();
+            for (ComponentDefinition definition : map.values()) {
                 resolveInheritance(definition, locale);
             }  // end loop
         }
@@ -150,7 +148,7 @@
      */
     public void reset() {
         this.baseDefinitions = new HashMap<String, ComponentDefinition>();
-        this.localeSpecificDefinitions = new HashMap<Locale, Map>();
+        this.localeSpecificDefinitions = new HashMap<Locale, Map<String, ComponentDefinition>>();
     }
 
     /**
@@ -168,6 +166,7 @@
                     ComponentDefinition subDef =
                         getDefinitionByAttribute(attr);
                     attr.setAttributes(subDef.getAttributes());
+                    attr.setType("definition");
                 }
             }
         }
@@ -189,32 +188,19 @@
 
     public void resolveAttributeDependencies(Locale locale) {
         resolveAttributeDependencies(); // FIXME Is it necessary?
-        Map defsMap = (Map) localeSpecificDefinitions.get(locale);
+        Map<String, ComponentDefinition> defsMap = localeSpecificDefinitions.get(locale);
         if (defsMap == null) {
             return;
         }
 
-        Iterator i = defsMap.values().iterator();
-
-        while (i.hasNext()) {
-            ComponentDefinition def = (ComponentDefinition) i.next();
-            Map attributes = def.getAttributes();
-            Iterator j = attributes.values().iterator();
-            while (j.hasNext()) {
-                ComponentAttribute attr = (ComponentAttribute) j.next();
-                if (attr.getType() != null) {
-                    if (attr.getType().equalsIgnoreCase("definition") ||
-                        attr.getType().equalsIgnoreCase("instance")) {
-                        ComponentDefinition subDef = getDefinitionByAttribute(
-                            attr, locale);
-                        attr.setValue(subDef);
-                    }
-                } else {
-                    ComponentDefinition subDef = getDefinitionByAttribute(attr,
-                        locale);
-                    if (subDef != null) {
-                        attr.setValue(subDef);
-                    }
+        for (ComponentDefinition def : defsMap.values()) {
+            Map<String, ComponentAttribute> attributes = def.getAttributes();
+            for (ComponentAttribute attr : attributes.values()) {
+                if (isDefinitionType(attr)) {
+                    ComponentDefinition subDef =
+                        getDefinitionByAttribute(attr, locale);
+                    attr.setAttributes(subDef.getAttributes());
+                    attr.setType("definition");
                 }
             }
         }

Modified: struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/definition/TestComponentDefinitions.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/definition/TestComponentDefinitions.java?view=diff&rev=488005&r1=488004&r2=488005
==============================================================================
--- struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/definition/TestComponentDefinitions.java
(original)
+++ struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/definition/TestComponentDefinitions.java
Sun Dec 17 08:48:28 2006
@@ -266,19 +266,15 @@
         
         Object newAttr = newDef.getAttribute("attr1");
         assertNotNull("Dependent attribute not found.", newAttr);
-        assertTrue("Dependent attribute incorrect type.", 
-                newAttr instanceof ComponentDefinition);
         
         newDef = definitions.getDefinition("parent.notype.def1");
         assertNotNull("Parent definition not found.", newDef);
         
         newAttr = newDef.getAttribute("attr1");
         assertNotNull("Dependent attribute not found.", newAttr);
-        assertTrue("Dependent attribute incorrect type.", 
-                newAttr instanceof ComponentDefinition);
         
         assertEquals("Incorrect dependent attribute name.", "tiles.def2",
-                ((ComponentDefinition) newAttr).getName());
+                newAttr);
         
         // Part of the test for locale-specific definitions.
         newDef = definitions.getDefinition("parent.def1", Locale.ITALIAN);
@@ -286,8 +282,6 @@
         
         newAttr = newDef.getAttribute("attr1");
         assertNotNull("Dependent attribute not found.", newAttr);
-        assertTrue("Dependent attribute incorrect type.", 
-                newAttr instanceof ComponentDefinition);
         
         newDef = definitions.getDefinition("parent.notype.def1",
         		Locale.ITALIAN);
@@ -295,10 +289,8 @@
         
         newAttr = newDef.getAttribute("attr1");
         assertNotNull("Dependent attribute not found.", newAttr);
-        assertTrue("Dependent attribute incorrect type.", 
-                newAttr instanceof ComponentDefinition);
         
         assertEquals("Incorrect dependent attribute name.", "tiles.def2",
-                ((ComponentDefinition) newAttr).getName());
+                newAttr);
     }
 }



Mime
View raw message