ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From co...@apache.org
Subject cvs commit: jakarta-ant/proposal/mutant/src/java/common/org/apache/ant/common/service ComponentService.java
Date Fri, 17 May 2002 12:20:38 GMT
conor       02/05/17 05:20:38

  Modified:    proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution
                        ComponentManager.java Frame.java
               proposal/mutant/src/java/antlibs/system/org/apache/ant/antlib/system
                        AntAspect.java
               proposal/mutant/src/java/common/org/apache/ant/common/antlib
                        AbstractAspect.java Aspect.java
               proposal/mutant/src/java/common/org/apache/ant/common/service
                        ComponentService.java
  Log:
  Convert refids to an aspect based implementation
  
  Revision  Changes    Path
  1.18      +46 -54    jakarta-ant/proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/ComponentManager.java
  
  Index: ComponentManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/ComponentManager.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -w -u -r1.17 -r1.18
  --- ComponentManager.java	16 May 2002 13:31:46 -0000	1.17
  +++ ComponentManager.java	17 May 2002 12:20:38 -0000	1.18
  @@ -440,9 +440,18 @@
        * @exception ExecutionException if there is a problem creating or
        *      configuring the component
        */
  -    protected Object createComponent(String componentName, BuildElement model)
  +    private Object createComponent(String componentName, BuildElement model)
            throws ExecutionException {
   
  +        Object component = null;
  +        if (model != null) {             
  +            for (Iterator i = aspects.iterator(); i.hasNext();) {
  +                Aspect aspect = (Aspect) i.next();
  +                component = aspect.preCreateComponent(component, model);
  +            }
  +        }
  +        
  +        if (component == null) {
           ImportInfo importInfo = getImport(componentName);
           if (importInfo == null) {
               throw new ExecutionException("There is no definition of the <"
  @@ -453,10 +462,20 @@
           ComponentLibrary componentLibrary
                = importInfo.getComponentLibrary();
   
  -        return createComponentFromDef(componentName, componentLibrary,
  +            component = createComponentFromDef(componentName, componentLibrary,
               importInfo.getDefinition(), model);
       }
   
  +        if (model != null) {
  +            for (Iterator i = aspects.iterator(); i.hasNext();) {
  +                Aspect aspect = (Aspect) i.next();
  +                component = aspect.postCreateComponent(component, model);
  +            }
  +        }
  +        
  +        return component;
  +    }
  +
       /**
        * Create a component from its library definition.
        *
  @@ -672,36 +691,12 @@
           // is there a polymorph indicator - look in Ant aspects
           String typeName 
               = model.getAspectAttributeValue(Constants.ANT_ASPECT, "type");
  -        String refId 
  -            = model.getAspectAttributeValue(Constants.ANT_ASPECT, "refid");
  -        if (refId != null && typeName != null) {
  -            throw new ExecutionException("Only one of " + Constants.ANT_ASPECT
  -                 + ":type and " + Constants.ANT_ASPECT
  -                 + ":refid may be specified at a time", model.getLocation());
  -        }
   
           Object typeInstance = null;
           if (typeName != null) {
               // the build file has specified the actual type of the element.
               // we need to look up that type and use it
               typeInstance = createComponent(typeName, model);
  -        } else if (refId != null) {
  -            // We have a reference to an existing instance. Need to check if
  -            // it is compatible with the type expected by the nested element's
  -            // adder method
  -            typeInstance = frame.getDataValue(refId);
  -            if (model.getAttributeNames().hasNext() ||
  -                model.getNestedElements().hasNext() ||
  -                model.getText().length() != 0) {
  -                throw new ExecutionException("Element <" + nestedElementName
  -                     + "> is defined by reference and hence may not specify "
  -                     + "any attributes, nested elements or content",
  -                    model.getLocation());
  -            }
  -            if (typeInstance == null) {
  -                throw new ExecutionException("The given ant:refid value '"
  -                     + refId + "' is not defined", model.getLocation());
  -            }
           } else if (nestedType != null) {
               // We need to create an instance of the class expected by the nested
               // element's adder method if that is possible
  @@ -723,17 +718,9 @@
           // is the typeInstance compatible with the type expected
           // by the element's add method
           if (!nestedType.isInstance(typeInstance)) {
  -            if (refId != null) {
  -                throw new ExecutionException("The value specified by refId "
  -                     + refId + " is not compatible with the <"
  -                     + nestedElementName + "> nested element",
  -                    model.getLocation());
  -            } else if (typeName != null) {
                   throw new ExecutionException("The type "
                        + typeName + " is not compatible with the <"
  -                     + nestedElementName + "> nested element",
  -                    model.getLocation());
  -            }
  +                + nestedElementName + "> nested element", model.getLocation());
           }
           setter.addElement(element, nestedElementName, typeInstance);
       }
  @@ -781,23 +768,28 @@
        *
        * @param object the object to be configured.
        * @param attributeValues a map containing named attribute values.
  -     *
  +     * @param ignoreUnsupported if this is true, attribute names for which no
  +     *                          setter method exists are ignored.
        * @exception ExecutionException if the object does not support an
        *            attribute in the map.
        */
  -    public void configureAttributes(Object object, Map attributeValues)
  +    public void configureAttributes(Object object, Map attributeValues,
  +                                    boolean ignoreUnsupported)
            throws ExecutionException {
           Setter setter = getSetter(object.getClass());
           for (Iterator i = attributeValues.keySet().iterator(); i.hasNext();) {
               String attributeName = (String) i.next();
               String attributeValue = (String) attributeValues.get(attributeName);
               if (!setter.supportsAttribute(attributeName)) {
  +                if (!ignoreUnsupported) {
                   throw new ExecutionException(object.getClass().getName()
                        + " does not support the \"" + attributeName
                        + "\" attribute");
               }
  +            } else {
               setter.setAttribute(object, attributeName,
                   frame.replacePropertyRefs(attributeValue));
  +            }
           }
       }
   
  
  
  
  1.26      +2 -10     jakarta-ant/proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/Frame.java
  
  Index: Frame.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/Frame.java,v
  retrieving revision 1.25
  retrieving revision 1.26
  diff -u -w -u -r1.25 -r1.26
  --- Frame.java	16 May 2002 13:31:46 -0000	1.25
  +++ Frame.java	17 May 2002 12:20:38 -0000	1.26
  @@ -868,6 +868,7 @@
        */
       protected void executeTask(Task task, AspectValueCollection aspectValues) 
            throws ExecutionException {
  +
           List aspects = componentManager.getAspects();
           Map aspectContexts = new HashMap();
           for (Iterator i = aspects.iterator(); i.hasNext();) {
  @@ -897,6 +898,7 @@
           }
   
           // Now call back the aspects that registered interest
  +
           Set activeAspects = aspectContexts.keySet();
           for (Iterator i = activeAspects.iterator(); i.hasNext();) {
               Aspect aspect = (Aspect) i.next();
  @@ -932,18 +934,8 @@
               BuildElement model = (BuildElement) taskIterator.next();
   
               // what sort of element is this.
  -            List aspects = componentManager.getAspects();
               try {
                   Object component = componentManager.createComponent(model);
  -                for (Iterator i = aspects.iterator(); i.hasNext();) {
  -                    Aspect aspect = (Aspect) i.next();
  -                    Object replacement 
  -                        = aspect.postCreateComponent(component, model);
  -                    if (replacement != null) {
  -                        component = replacement;
  -                    }
  -                }
  -
                   if (component instanceof Task) {
                       execService.executeTask((Task) component);
                   } 
  
  
  
  1.3       +38 -2     jakarta-ant/proposal/mutant/src/java/antlibs/system/org/apache/ant/antlib/system/AntAspect.java
  
  Index: AntAspect.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/mutant/src/java/antlibs/system/org/apache/ant/antlib/system/AntAspect.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -w -u -r1.2 -r1.3
  --- AntAspect.java	16 May 2002 13:31:46 -0000	1.2
  +++ AntAspect.java	17 May 2002 12:20:38 -0000	1.3
  @@ -91,6 +91,41 @@
               = (ComponentService) context.getCoreService(ComponentService.class);
       }
       
  +
  +    /**
  +     * This join point is activated before a component has been created.
  +     * The aspect can return an object to be used rather than the core creating 
  +     * the object. 
  +     *
  +     * @param component the component that has been created. This will be null
  +     *                  unless another aspect has created the component
  +     * @param model the Build model that applies to the component
  +     *
  +     * @return a component to use.
  +     * @exception ExecutionException if the aspect cannot process the component.
  +     */         
  +    public Object preCreateComponent(Object component, BuildElement model)
  +         throws ExecutionException {
  +        String refId = model.getAspectAttributeValue(ANT_ASPECT, "refid");
  +        if (refId != null) {
  +            if (model.getAttributeNames().hasNext() ||
  +                model.getNestedElements().hasNext() ||
  +                model.getText().length() != 0) {
  +                throw new ExecutionException("Element <" + model.getType()
  +                     + "> is defined by reference and hence may not specify "
  +                     + "any attributes, nested elements or content",
  +                    model.getLocation());
  +            }
  +            Object referredComponent = dataService.getDataValue(refId);
  +            if (referredComponent == null) {
  +                throw new ExecutionException("The given ant:refid value '"
  +                     + refId + "' is not defined", model.getLocation());
  +            }
  +            return referredComponent;
  +        }             
  +        return component;
  +    }
  +    
       /**
        * This join point is activated after a component has been created and
        * configured. If the aspect wishes, an object can be returned in place
  @@ -111,7 +146,7 @@
               dataService.setMutableDataValue(typeId, component);
           }
           
  -        return null;
  +        return super.postCreateComponent(component, model);
       }
   
       /**
  @@ -135,7 +170,8 @@
               return null;
           }
           
  -        componentService.configureAttributes(aspectContext, antAspectValues);
  +        componentService.configureAttributes(aspectContext, antAspectValues, 
  +            true);
           if (aspectContext.isRequired()) {
               return aspectContext;
           }
  
  
  
  1.3       +20 -4     jakarta-ant/proposal/mutant/src/java/common/org/apache/ant/common/antlib/AbstractAspect.java
  
  Index: AbstractAspect.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/mutant/src/java/common/org/apache/ant/common/antlib/AbstractAspect.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -w -u -r1.2 -r1.3
  --- AbstractAspect.java	16 May 2002 13:31:46 -0000	1.2
  +++ AbstractAspect.java	17 May 2002 12:20:38 -0000	1.3
  @@ -88,6 +88,22 @@
           return context;
       }
   
  +    /**
  +     * This join point is activated before a component is to be created.
  +     * The aspect can return an object to be used rather than the core creating 
  +     * the object. 
  +     *
  +     * @param component the component that has been created. This will be null
  +     *                  unless another aspect has created the component
  +     * @param model the Build model that applies to the component
  +     *
  +     * @return a component to use.
  +     * @exception ExecutionException if the aspect cannot process the component.
  +     */         
  +    public Object preCreateComponent(Object component, BuildElement model)
  +         throws ExecutionException {
  +        return component;
  +    }
            
       /**
        * This join point is activated after a component has been created and
  @@ -103,7 +119,7 @@
        */         
       public Object postCreateComponent(Object component, BuildElement model) 
            throws ExecutionException {
  -        return null;
  +        return component;
       }
   
       /**
  @@ -111,8 +127,8 @@
        *
        * @param task the task being executed.
        * @param aspectValues a collection of aspect attribute values for use 
  -     *        during the task execution.
  -     *
  +     *        during the task execution - may be null if no aspect values are
  +     *        provided.
        * @return an object which indicates that this aspect wishes to 
        * be notified after execution has been completed, in which case the obkect
        * is returned to provide the aspect its context. If this returns null
  
  
  
  1.3       +16 -2     jakarta-ant/proposal/mutant/src/java/common/org/apache/ant/common/antlib/Aspect.java
  
  Index: Aspect.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/mutant/src/java/common/org/apache/ant/common/antlib/Aspect.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -w -u -r1.2 -r1.3
  --- Aspect.java	16 May 2002 13:31:46 -0000	1.2
  +++ Aspect.java	17 May 2002 12:20:38 -0000	1.3
  @@ -76,6 +76,21 @@
   
            
       /**
  +     * This join point is activated before a component has been created.
  +     * The aspect can return an object to be used rather than the core creating 
  +     * the object. 
  +     *
  +     * @param component the component that has been created. This will be null
  +     *                  unless another aspect has created the component
  +     * @param model the Build model that applies to the component
  +     *
  +     * @return a component to use.
  +     * @exception ExecutionException if the aspect cannot process the component.
  +     */         
  +    Object preCreateComponent(Object component, BuildElement model)
  +        throws ExecutionException;
  +
  +    /**
        * This join point is activated after a component has been created and
        * configured. If the aspect wishes, an object can be returned in place
        * of the one created by Ant. 
  @@ -83,8 +98,7 @@
        * @param component the component that has been created.
        * @param model the Build model used to create the component.
        *
  -     * @return a replacement for the component if desired. If null is returned
  -     *         the current component is used.
  +     * @return a component to use
        * @exception ExecutionException if the aspect cannot process the component.
        */         
       Object postCreateComponent(Object component, BuildElement model)
  
  
  
  1.15      +5 -3      jakarta-ant/proposal/mutant/src/java/common/org/apache/ant/common/service/ComponentService.java
  
  Index: ComponentService.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/mutant/src/java/common/org/apache/ant/common/service/ComponentService.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -w -u -r1.14 -r1.15
  --- ComponentService.java	16 May 2002 13:31:46 -0000	1.14
  +++ ComponentService.java	17 May 2002 12:20:38 -0000	1.15
  @@ -190,15 +190,17 @@
           throws ExecutionException;
           
       /**
  -     * Configure an object with attribtes from the given map
  +     * configure an object with attribtes from the given map
        *
        * @param object the object to be configured.
        * @param attributeValues a map containing named attribute values.
  -     *
  +     * @param ignoreUnsupported if this is true, attribute names for which no
  +     *                          setter method exists are ignored.
        * @exception ExecutionException if the object does not support an
        *            attribute in the map.
        */
  -    void configureAttributes(Object object, Map attributeValues)
  +    void configureAttributes(Object object, Map attributeValues,
  +                             boolean ignoreUnsupported)
            throws ExecutionException;
   }
   
  
  
  

--
To unsubscribe, e-mail:   <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>


Mime
View raw message