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/23 16:58:59 UTC

svn commit: r510994 - /tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/ComponentDefinitionsImpl.java

Author: apetrelli
Date: Fri Feb 23 07:58:59 2007
New Revision: 510994

URL: http://svn.apache.org/viewvc?view=rev&rev=510994
Log:
TILES-88
Removed replication where possible.

Modified:
    tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/ComponentDefinitionsImpl.java

Modified: tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/ComponentDefinitionsImpl.java
URL: http://svn.apache.org/viewvc/tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/ComponentDefinitionsImpl.java?view=diff&rev=510994&r1=510993&r2=510994
==============================================================================
--- tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/ComponentDefinitionsImpl.java (original)
+++ tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/ComponentDefinitionsImpl.java Fri Feb 23 07:58:59 2007
@@ -78,7 +78,7 @@
      */
     public void addDefinitions(Map<String, ComponentDefinition> defsMap) throws NoSuchDefinitionException {
         this.baseDefinitions.putAll(defsMap);
-        resolveAttributeDependencies();
+        resolveAttributeDependencies(null);
         resolveInheritances();
     }
 
@@ -125,7 +125,7 @@
      */
     public void resolveInheritances() throws NoSuchDefinitionException {
         for (ComponentDefinition definition : baseDefinitions.values()) {
-            resolveInheritance(definition);
+            resolveInheritance(definition, null);
         }  // end loop
     }
 
@@ -158,20 +158,6 @@
         return baseDefinitions;
     }
 
-    public void resolveAttributeDependencies() {
-        for (ComponentDefinition def : baseDefinitions.values()) {
-            Map<String, ComponentAttribute> attributes = def.getAttributes();
-            for (ComponentAttribute attr : attributes.values()) {
-                if (isDefinitionType(attr)) {
-                    ComponentDefinition subDef =
-                        getDefinitionByAttribute(attr);
-                    attr.setAttributes(subDef.getAttributes());
-                    attr.setType("definition");
-                }
-            }
-        }
-    }
-
     private boolean isDefinitionType(ComponentAttribute attr) {
         boolean explicit = (attr.getType() != null &&
             (attr.getType().equalsIgnoreCase("definition") ||
@@ -186,8 +172,10 @@
 
     }
 
-    public void resolveAttributeDependencies(Locale locale) {
-        resolveAttributeDependencies(); // FIXME Is it necessary?
+    protected void resolveAttributeDependencies(Locale locale) {
+        if (locale != null) {
+            resolveAttributeDependencies(null); // FIXME Is it necessary?
+        }
         Map<String, ComponentDefinition> defsMap = localeSpecificDefinitions.get(locale);
         if (defsMap == null) {
             return;
@@ -209,28 +197,6 @@
     /**
      * Searches for a definition specified as an attribute.
      *
-     * @param attr The attribute to use.
-     * @return The required definition if found, otherwise it returns
-     *         <code>null</code>.
-     */
-    private ComponentDefinition getDefinitionByAttribute(
-        ComponentAttribute attr) {
-        ComponentDefinition retValue = null;
-
-        Object attrValue = attr.getValue();
-        if (attrValue instanceof ComponentDefinition) {
-            retValue = (ComponentDefinition) attrValue;
-        } else if (attrValue instanceof String) {
-            retValue = this.getDefinition((String) attr
-                .getValue());
-        }
-
-        return retValue;
-    }
-
-    /**
-     * Searches for a definition specified as an attribute.
-     *
      * @param attr   The attribute to use.
      * @param locale The locale to search into.
      * @return The required definition if found, otherwise it returns
@@ -249,47 +215,6 @@
         }
 
         return retValue;
-    }
-
-    /**
-     * Resolve inheritance.
-     * First, resolve parent's inheritance, then set template to the parent's
-     * template.
-     * Also copy attributes setted in parent, and not set in child
-     * If instance doesn't extend anything, do nothing.
-     *
-     * @throws NoSuchDefinitionException If an inheritance can not be solved.
-     */
-    protected void resolveInheritance(ComponentDefinition definition)
-        throws NoSuchDefinitionException {
-        // Already done, or not needed ?
-        if (definition.isIsVisited() || !definition.isExtending())
-            return;
-
-        if (log.isDebugEnabled())
-            log.debug("Resolve definition for child name='"
-                + definition.getName()
-                + "' extends='" + definition.getExtends() + "'.");
-
-        // Set as visited to avoid endless recurisvity.
-        definition.setIsVisited(true);
-
-        // Resolve parent before itself.
-        ComponentDefinition parent = getDefinition(definition.getExtends());
-        if (parent == null) { // error
-            String msg = "Error while resolving definition inheritance: child '"
-                + definition.getName()
-                + "' can't find its ancestor '"
-                + definition.getExtends()
-                + "'. Please check your description file.";
-            log.error(msg);
-            // to do : find better exception
-            throw new NoSuchDefinitionException(msg);
-        }
-
-        resolveInheritance(parent);
-
-        overload(parent, definition);
     }
 
     /**