Coverage Report - org.webmacro.directive.ParamDirective
 
Classes in this File Line Coverage Branch Coverage Complexity
ParamDirective
15%
3/19
0%
0/2
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 #param directive is provided for backward compatibility.
 36  
  * Invoking
 37  
  *   #param $a="stuff"
 38  
  * is equivalent to
 39  
  *   #attribute $a="stuff"
 40  
  *   #set $a="stuff"
 41  
  */
 42  
 
 43  0
 public class ParamDirective extends Directive
 44  
 {
 45  
 
 46  
     private static final int PARAM_TARGET = 1;
 47  
     private static final int PARAM_RESULT = 2;
 48  
 
 49  
     private static final ArgDescriptor[]
 50  2
             myArgs = new ArgDescriptor[]{
 51  
                 new LValueArg(PARAM_TARGET),
 52  
                 new AssignmentArg(),
 53  
                 new RValueArg(PARAM_RESULT)
 54  
             };
 55  
 
 56  
     private static final DirectiveDescriptor
 57  2
             myDescr = new DirectiveDescriptor("param", null, myArgs, null);
 58  
 
 59  
     public static DirectiveDescriptor getDescriptor ()
 60  
     {
 61  6
         return myDescr;
 62  
     }
 63  
 
 64  
     public Object build (DirectiveBuilder builder,
 65  
                          BuildContext bc)
 66  
             throws BuildException
 67  
     {
 68  0
         Variable target = null;
 69  0
         Object result = null;
 70  
         try
 71  
         {
 72  0
             target = (Variable) builder.getArg(PARAM_TARGET, bc);
 73  0
             result = builder.getArg(PARAM_RESULT, bc);
 74  
         }
 75  0
         catch (ClassCastException e)
 76  
         {
 77  0
             throw new NotVariableBuildException(myDescr.name, e);
 78  0
         }
 79  0
         if (!target.isSimpleName())
 80  0
             throw new NotSimpleVariableBuildException(myDescr.name);
 81  
         try
 82  
         {
 83  0
             target.setValue(bc, result);
 84  
         }
 85  0
         catch (PropertyException e)
 86  
         {
 87  0
             throw new BuildException("#param: Exception setting variable "
 88  
                     + target.toString(), e);
 89  0
         }
 90  0
         return new SetDirective(target, result);
 91  
     }
 92  
 
 93  
     public void write (FastWriter out, Context context)
 94  
             throws PropertyException, IOException
 95  
     {
 96  0
     }
 97  
 
 98  
 }
 99