KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > SumCustomTag


1 /*
2  * Sun Public License
3  *
4  * The contents of this file are subject to the Sun Public License Version
5  * 1.0 (the "License"). You may not use this file except in compliance with
6  * the License. A copy of the License is available at http://www.sun.com/
7  *
8  * The Original Code is the SLAMD Distributed Load Generation Engine.
9  * The Initial Developer of the Original Code is Neil A. Wilson.
10  * Portions created by Neil A. Wilson are Copyright (C) 2004.
11  * Some preexisting portions Copyright (C) 2002-2004 Sun Microsystems, Inc.
12  * All Rights Reserved.
13  *
14  * Contributor(s): Neil A. Wilson
15  */

16
17
18
19 /**
20  * This class provides a very simple implementation of a custom tag that
21  * calculates the sum of all the arguments provided to it.
22  *
23  *
24  * @author Neil A. Wilson
25  */

26 public class SumCustomTag
27        extends CustomTag
28 {
29   /**
30    * Performs any necessary one-time initialization that should be performed
31    * when this custom tag is first created. In this case, no initialization is
32    * performed.
33    */

34   public void initialize()
35   {
36     // No implementation required.
37
}
38
39
40
41   /**
42    * Performs any initialization that should be performed each time the LDIF
43    * generation starts working on a new branch (e.g., to reset any internal
44    * variables that might have been in use). In this case, no reinitialization
45    * is performed.
46    */

47   public void reinitialize()
48   {
49     // No implementation required.
50
}
51
52
53
54   /**
55    * Parses the list of arguments, converts the values to integers, and totals
56    * those values.
57    *
58    * @param tagArguments The arguments containing the numeric values to be
59    * totaled.
60    *
61    * @return The string representation of the total of all the argument values.
62    */

63   public String JavaDoc generateOutput(String JavaDoc[] tagArguments)
64   {
65     int sum = 0;
66
67     for (int i=0; i < tagArguments.length; i++)
68     {
69       sum += Integer.parseInt(tagArguments[i]);
70     }
71
72     return String.valueOf(sum);
73   }
74 }
75
76
Popular Tags