##### Coverage Report - org.webmacro.directive.AttributeDirective

Classes in this File | Line Coverage | Branch Coverage | Complexity
AttributeDirective |
15% | 3/19
0% | 0/2
| 3.0;3

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 |  |
     package org.webmacro.directive;
24 |  |
25 |  |
     import org.webmacro.Context;
26 |  |
     import org.webmacro.FastWriter;
27 |  |
     import org.webmacro.PropertyException;
28 |  |
     import org.webmacro.engine.BuildContext;
29 |  |
     import org.webmacro.engine.BuildException;
30 |  |
     import org.webmacro.engine.Variable;
31 |  |
32 |  |
     import java.io.IOException;
33 |  |
34 |  |
     /**
35 |  |
      * The #attribute directive allows you to set a template attribute such
36 |  |
      * that it is accessible from the servlet.
37 |  |
      */
38 |  |
39 | 0 |
     public class AttributeDirective extends Directive
40 |  |
     {
41 |  |
42 |  |
         private static final int ATTRIBUTE_TARGET = 1;
43 |  |
         private static final int ATTRIBUTE_RESULT = 2;
44 |  |
45 |  |
         private static final ArgDescriptor[]
46 | 2 |
                 myArgs = new ArgDescriptor[]{
47 |  |
                     new LValueArg(ATTRIBUTE_TARGET),
48 |  |
                     new AssignmentArg(),
49 |  |
                     new RValueArg(ATTRIBUTE_RESULT)
50 |  |
                 };
51 |  |
52 |  |
         private static final DirectiveDescriptor
53 | 2 |
                 myDescr = new DirectiveDescriptor(null, null, myArgs, null);
54 |  |
55 |  |
         public static DirectiveDescriptor getDescriptor ()
56 |  |
         {
57 | 12 |
             return myDescr;
58 |  |
         }
59 |  |
60 |  |
         public Object build (DirectiveBuilder builder,
61 |  |
                              BuildContext bc)
62 |  |
                 throws BuildException
63 |  |
         {
64 | 0 |
             Variable target = null;
65 | 0 |
             Object result = null;
66 |  |
             try {
67 | 0 |
                 target = (Variable) builder.getArg(ATTRIBUTE_TARGET, bc);
68 | 0 |
                 result = builder.getArg(ATTRIBUTE_RESULT, bc);
69 |  |
             }
70 | 0 |
             catch (ClassCastException e)
71 |  |
             {
72 | 0 |
                 throw new NotVariableBuildException(myDescr.name, e);
73 | 0 |
             }
74 | 0 |
             if (!target.isSimpleName())
75 | 0 |
                 throw new NotSimpleVariableBuildException(myDescr.name);
76 |  |
77 |  |
             try
78 |  |
             {
79 | 0 |
                 target.setValue(bc, result);
80 |  |
             }
81 | 0 |
             catch (PropertyException e)
82 |  |
             {
83 | 0 |
                 throw new BuildException("#attribute: Exception setting variable "
84 |  |
                         + target.toString(), e);
85 | 0 |
             }
86 | 0 |
             return null;
87 |  |
         }
88 |  |
89 |  |
         public void write (FastWriter out, Context context)
90 |  |
                 throws PropertyException, IOException
91 |  |
         {
92 | 0 |
         }
93 |  |
94 |  |
     }
95 |  |