1 16 19 import java.util.Hashtable ; 20 21 public class MyCounter { 22 static Hashtable counters = new Hashtable (); 23 24 25 public void init(org.apache.xalan.extensions.XSLProcessorContext context, 26 org.w3c.dom.Element elem) 27 { 28 String name = elem.getAttribute("name"); 29 String value = elem.getAttribute("value"); 30 int val; 31 try 32 { 33 val = Integer.parseInt (value); 34 } 35 catch (NumberFormatException e) 36 { 37 e.printStackTrace (); 38 val = 0; 39 } 40 counters.put (name, new Integer (val)); 41 } 42 43 public int read(String name) 44 { 45 Integer cval = (Integer )counters.get(name); 46 return (cval == null) ? 0 : cval.intValue(); 47 } 48 49 public void incr(org.apache.xalan.extensions.XSLProcessorContext context, 50 org.w3c.dom.Element elem) { 51 String name = elem.getAttribute("name"); 52 Integer cval = (Integer ) counters.get(name); 53 int nval = (cval == null) ? 0 : (cval.intValue () + 1); 54 counters.put (name, new Integer (nval)); 55 } 56 } 57 | Popular Tags |