Coverage Report - org.webmacro.engine.SimplePropertyVariable
 
Classes in this File Line Coverage Branch Coverage Complexity
SimplePropertyVariable
85%
6/7
25%
1/4
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.PropertyException;
 28  
 
 29  
 
 30  
 /**
 31  
  * Operate on bean properties in a context; special case for simple variables
 32  
  * (only one name)
 33  
  */
 34  
 final class SimplePropertyVariable extends Variable
 35  
 {
 36  
 
 37  
     /**
 38  
      * No special initialization
 39  
      */
 40  
     SimplePropertyVariable (Object names[])
 41  
     {
 42  8011
         super(names);
 43  8011
     }
 44  
 
 45  
     /**
 46  
      * Look up my value in the corresponding Map, possibly using introspection,
 47  
      * and return it
 48  
      * @exception PropertyException If the property does not exist
 49  
      */
 50  
     public final Object getValue (Context context)
 51  
             throws PropertyException
 52  
     {
 53  8270
         return context.getProperty(_names[0]);
 54  
     }
 55  
 
 56  
     /**
 57  
      * Look up my the value of this variable in the specified Map, possibly
 58  
      * using introspection, and set it to the supplied value.
 59  
      * @exception PropertyException If the property does not exist
 60  
      */
 61  
     public final void setValue (Context context, Object newValue)
 62  
             throws PropertyException
 63  
     {
 64  5557
         if (!context.setProperty(_names[0], newValue))
 65  
         {
 66  0
             throw new PropertyException("No method to set \"" + getVariableName() +
 67  
                     "\" to type " +
 68  
                     ((newValue == null) ? "null" : newValue.getClass().toString())
 69  
                     + " in supplied context (" + context.getClass() + ")");
 70  
         }
 71  5557
     }
 72  
 
 73  
     /**
 74  
      * Return a string representation naming the variable for
 75  
      * debugging purposes.
 76  
      */
 77  
     public final String toString ()
 78  
     {
 79  120
         return "property:" + getVariableName();
 80  
     }
 81  
 
 82  
 }