Hi Jerome,
Looks like there is a bug in SetVariable.

The problem is that if the variable is not found, then
we need to create it in the proper container.

The revised getModifiedVariable() is below:  


  public Attribute getModifiedVariable() throws IllegalActionException
  {
        NamedObj container = (NamedObj) getContainer();

        if (container == null) {
            throw new IllegalActionException(this, "No container.");
        }

        String variableNameValue = variableName.getExpression();
        Attribute attribute = null;

        // Look for the variableName anywhere in the hierarchy
        while (attribute == null && container != null) {
            attribute = container.getAttribute(variableNameValue);
            if (attribute == null) {
                container = container.getContainer();
            }
        }

        if (attribute == null) {
            try {
                workspace().getWriteAccess();
                // container might be null, so create the variable
                // in the container of this actor.
                attribute = new Variable(getContainer(),
            variableNameValue);
            } catch (NameDuplicationException ex) {
                throw new InternalErrorException(ex);
            } finally {
                workspace().doneWriting();
            }
        }

        return attribute;
    }

I wrote:

> Hi Jerome,
> It looks like you change is more of an enhancement than a bug fix.
> The class was initially designed to only look in the container.
> 
> Your change was made to the ptolemy/actor/lib/SetVariable.java
> from Ptolemy II 4.0.1.  Basically your change is to
> getModifiedVariable(), where if the attribute is not found, we keep
> looking:
>           }
>   
>           String variableNameValue = variableName.getExpression();
> !         Attribute attribute = container.getAttribute(variableNameValue);
>   
>           if (attribute == null) {
>               try {
> --- 187,201 ----
>           }
>   
>           String variableNameValue = variableName.getExpression();
> !         Attribute attribute = null;
> ! 
> !         // Look for the variableName anywhere in the hierarchy
> !         while (attribute == null && container != null) {
> !             attribute = container.getAttribute(variableNameValue);
> !             if (attribute == null) {
> !                 container = container.getContainer();
> !             }
> !         }
>   
>           if (attribute == null) {
>               try {
> 
> I went ahead and folded this change in to the CVS devel tree and in
> to the Ptolemy II 5.0-beta tree.  I added you as a contributor to
> this class.
> 
> I also added a test that uses this feature. 
> 
> Many thanks for the suggestion!
> 
> _Christopher
> 
> 
> --------
> 
>     Hi,
>     
>     It seems there is a bug in the SetVariable actor. While referencing a 
>     parameter that have been declared in the top hierarchy, its value can 
>     not be evaluated.
>     
>     Unless this is a volontary bahaviour, here is the correction we have made.
>     
>     Regards,
>     
>     Jérôme
>     -- 
>     Jérôme BLANC, Software R&D Engineer
>     Signal Processing Environment & ARchitecture Pilot Program
>     THALES - Research & Technology - FRANCE
>     RD 128 - 91 767 PALAISEAU Cedex
>     Phone: +33 (0)1 69 41 59 53   Fax:
>     E-Mail: [EMAIL PROTECTED]
>     
>      >The information contained in this e-mail/fax and any attachments are the
>      >property of THALES and may be confidential. If you are not the intended
>      >recipient, please notify us immediately, send this message back to us
>      >and destroy it. You are hereby notified that any review, dissemination,
>      >distribution, copying or otherwise use of this e-mail/fax is strictly
>      >prohibited.
>     
> <<Attachement deleted>>

_Christopher

----------------------------------------------------------------------------
Posted to the ptolemy-hackers mailing list.  Please send administrative
mail for this list to: [EMAIL PROTECTED]

Reply via email to