##### Coverage Report - org.webmacro.engine.PropertyVariable

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