1 16 17 package org.apache.cocoon.components.modules.input; 18 19 import org.apache.avalon.framework.configuration.Configuration; 20 import org.apache.avalon.framework.configuration.ConfigurationException; 21 import org.apache.avalon.framework.thread.ThreadSafe; 22 23 import java.util.Iterator ; 24 import java.util.LinkedList ; 25 import java.util.List ; 26 import java.util.Map ; 27 import java.util.Vector ; 28 29 38 public class RandomNumberModule extends AbstractInputModule implements ThreadSafe { 39 40 final static Vector returnNames; 41 static { 42 Vector tmp = new Vector (); 43 tmp.add("randomNumber"); 44 returnNames = tmp; 45 } 46 47 public Object getAttribute( String name, Configuration modeConf, Map objectModel ) throws ConfigurationException { 48 49 long min = 0; 50 long max = java.lang.Long.MAX_VALUE; 51 if (modeConf != null) { 52 min = Long.parseLong(modeConf.getAttribute("min","0")); 53 max = Long.parseLong(modeConf.getAttribute("max",String.valueOf(max))); 54 55 min = Long.parseLong(modeConf.getChild("min").getValue("0")); 57 max = Long.parseLong(modeConf.getChild("max").getValue(String.valueOf(max))); 58 } 59 return Long.toString(java.lang.Math.round(java.lang.Math.random()*(max-min))); 60 61 } 62 63 64 public Iterator getAttributeNames( Configuration modeConf, Map objectModel ) throws ConfigurationException { 65 66 return RandomNumberModule.returnNames.iterator(); 67 } 68 69 70 public Object [] getAttributeValues( String name, Configuration modeConf, Map objectModel ) 71 throws ConfigurationException { 72 73 List values = new LinkedList (); 74 values.add( this.getAttribute(name, modeConf, objectModel ) ); 75 76 return values.toArray(); 77 78 } 79 80 } 81 | Popular Tags |