Coverage Report - org.webmacro.engine.MacroPropertyVariable
 
Classes in this File Line Coverage Branch Coverage Complexity
MacroPropertyVariable
66%
6/9
50%
1/2
1.75
 
 1  
 /*
 2  
  * Copyright (C) 1998-2000 Semiotek Inc.  All Rights Reserved.
 3  
  *
 4  
  * Redistribution and use in source and binary forms, with or without
 5  
  * modification, are permitted under the terms of either of the following
 6  
  * Open Source licenses:
 7  
  *
 8  
  * The GNU General Public License, version 2, or any later version, as
 9  
  * published by the Free Software Foundation
 10  
  * (http://www.fsf.org/copyleft/gpl.html);
 11  
  *
 12  
  *  or
 13  
  *
 14  
  * The Semiotek Public License (http://webmacro.org/LICENSE.)
 15  
  *
 16  
  * This software is provided "as is", with NO WARRANTY, not even the
 17  
  * implied warranties of fitness to purpose, or merchantability. You
 18  
  * assume all risks and liabilities associated with its use.
 19  
  *
 20  
  * See www.webmacro.org for more information on the WebMacro project.
 21  
  */
 22  
 
 23  
 
 24  
 package org.webmacro.engine;
 25  
 
 26  
 import org.webmacro.Context;
 27  
 import org.webmacro.Macro;
 28  
 import org.webmacro.PropertyException;
 29  
 
 30  
 
 31  
 /**
 32  
  * Operate on bean properties of an existing macro; used when a Macro
 33  
  * is passed as an argument to a macro
 34  
  * @author Brian Goetz
 35  
  * @since 1.1
 36  
  */
 37  
 public class MacroPropertyVariable extends Variable
 38  
 {
 39  
 
 40  
     private Macro value;
 41  
 
 42  
     /**
 43  
      * No special initialization
 44  
      */
 45  
     MacroPropertyVariable (Macro value, Object names[])
 46  
     {
 47  87
         super(names);
 48  87
         this.value = value;
 49  87
     }
 50  
 
 51  
     /**
 52  
      * Look up my value in the corresponding Map, possibly using introspection,
 53  
      * and return it
 54  
      * @exception PropertyException If the property does not exist
 55  
      */
 56  
     public final Object getValue (Context context)
 57  
             throws PropertyException
 58  
     {
 59  90
         Object v = value.evaluate(context);
 60  90
         if (v == null)
 61  0
             throw new PropertyException.NullValueException(_names[0].toString());
 62  
         else
 63  90
             return context.getBroker()
 64  
                     ._propertyOperators.getProperty(context, v, _names, 1);
 65  
     }
 66  
 
 67  
     /**
 68  
      * Look up my the value of this variable in the specified Map, possibly
 69  
      * using introspection, and set it to the supplied value.
 70  
      * @exception PropertyException If the property does not exist
 71  
      */
 72  
     public final void setValue (Context context, Object newValue)
 73  
             throws PropertyException
 74  
     {
 75  0
         throw new PropertyException("Cannot set properties of a constant");
 76  
     }
 77  
 
 78  
     /**
 79  
      * Return a string representation naming the variable for
 80  
      * debugging purposes.
 81  
      */
 82  
     public final String toString ()
 83  
     {
 84  0
         return "macro-property:" + getVariableName();
 85  
     }
 86  
 
 87  
 }