KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openejb > webadmin > clienttools > InvokeObjectBean


1 /**
2  * Redistribution and use of this software and associated documentation
3  * ("Software"), with or without modification, are permitted provided
4  * that the following conditions are met:
5  *
6  * 1. Redistributions of source code must retain copyright
7  * statements and notices. Redistributions must also contain a
8  * copy of this document.
9  *
10  * 2. Redistributions in binary form must reproduce the
11  * above copyright notice, this list of conditions and the
12  * following disclaimer in the documentation and/or other
13  * materials provided with the distribution.
14  *
15  * 3. The name "OpenEJB" must not be used to endorse or promote
16  * products derived from this Software without prior written
17  * permission of The OpenEJB Group. For written permission,
18  * please contact dev@openejb.org.
19  *
20  * 4. Products derived from this Software may not be called "OpenEJB"
21  * nor may "OpenEJB" appear in their names without prior written
22  * permission of The OpenEJB Group. OpenEJB is a registered
23  * trademark of The OpenEJB Group.
24  *
25  * 5. Due credit should be given to the OpenEJB Project
26  * (http://www.openejb.org/).
27  *
28  * THIS SOFTWARE IS PROVIDED BY THE OPENEJB GROUP AND CONTRIBUTORS
29  * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
30  * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
31  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
32  * THE OPENEJB GROUP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
33  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
34  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
35  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
37  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
38  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
39  * OF THE POSSIBILITY OF SUCH DAMAGE.
40  *
41  * Copyright 2001 (C) The OpenEJB Group. All Rights Reserved.
42  *
43  * $Id: InvokeObjectBean.java 1912 2005-06-16 22:29:56Z jlaskowski $
44  */

45 package org.openejb.webadmin.clienttools;
46
47 import java.io.ByteArrayOutputStream JavaDoc;
48 import java.io.IOException JavaDoc;
49 import java.io.PrintStream JavaDoc;
50 import java.io.PrintWriter JavaDoc;
51 import java.lang.reflect.InvocationTargetException JavaDoc;
52 import java.lang.reflect.Method JavaDoc;
53 import java.lang.reflect.Modifier JavaDoc;
54 import java.util.HashMap JavaDoc;
55 import java.util.Iterator JavaDoc;
56 import java.util.Set JavaDoc;
57
58 import org.openejb.webadmin.HttpRequest;
59 import org.openejb.webadmin.HttpResponse;
60 import org.openejb.webadmin.HttpSession;
61 import org.openejb.webadmin.WebAdminBean;
62
63 /**
64  * @author <a HREF="mailto:david.blevins@visi.com">David Blevins</a>
65  */

66 public class InvokeObjectBean extends WebAdminBean implements Constants {
67
68     private PrintWriter JavaDoc out;
69     private static String JavaDoc invLock = "lock";
70     private static int invCount;
71
72     private HttpSession session;
73     
74     public void preProcess(HttpRequest request, HttpResponse response)
75         throws IOException JavaDoc {
76     }
77
78     public void postProcess(HttpRequest request, HttpResponse response)
79         throws IOException JavaDoc {
80     }
81
82     public void writeHtmlTitle(PrintWriter JavaDoc out) throws IOException JavaDoc {
83         out.write("Client Tools -- Object Invoker");
84     }
85
86     public void writePageTitle(PrintWriter JavaDoc out) throws IOException JavaDoc {
87         out.write("Object Invoker");
88     }
89
90     public void writeBody(PrintWriter JavaDoc out) throws IOException JavaDoc {
91         this.out = out;
92         try{
93             synchronized (this) {
94                 main(request.getSession(), out);
95             }
96         } catch (Exception JavaDoc e){
97             out.println("FAIL");
98             //throw e;
99
return;
100         }
101     }
102
103     class Invocation {
104         
105         protected String JavaDoc id = "inv";
106         protected String JavaDoc objID;
107         protected Class JavaDoc clazz;
108         protected Object JavaDoc target;
109         protected Method JavaDoc method;
110         protected Object JavaDoc[] args;
111         protected Object JavaDoc result;
112
113         protected Invocation(){
114             synchronized (invLock){
115                 id += ++invCount;
116             }
117         }
118
119         public Object JavaDoc invoke() throws Exception JavaDoc{
120             if (target == null || method == null || args == null) {
121                 throw new Exception JavaDoc("This invocation contains null objects.");
122             }
123             return method.invoke(target,args);
124         }
125     }
126     
127     /**
128      * The main method of this JSP
129      */

130     public void main(HttpSession session, PrintWriter JavaDoc out) throws Exception JavaDoc{
131         this.session = session;
132         this.out = out;
133
134         printObjectSection();
135     }
136     
137     /**
138      * Print the list of objects with the focused object as
139      * selected in the box.
140      * If no object is selected, make an entry called "Pick an Object"
141      */

142     public void printObjectSection() throws Exception JavaDoc{
143         String JavaDoc removeID = request.getQueryParameter("remove");
144         if (removeID != null) {
145             removeObject(removeID);
146         }
147
148         Invocation inv = null;
149         String JavaDoc invID = request.getQueryParameter("inv");
150         
151         if (invID == null) {
152             String JavaDoc objID = request.getQueryParameter("obj");
153             if (objID != null) {
154                 inv = new Invocation();
155                 inv.target = getObject(objID);
156                 inv.objID = objID;
157                 setInvocation(inv.id,inv);
158             }
159         } else {
160             inv = getInvocation(invID);
161         }
162
163         if (inv == null || inv.target == null) {
164             // Pick from the list
165
printObjectList();
166
167         } else {
168             out.print("<b>Object:</b><br>");
169             out.print(tab+inv.objID+" <a HREF='"+INVOKE_OBJ+"'>[change]</a><br><br>");
170             
171             // Show the selected item and continue
172
printMethodSection(inv);
173         }
174     }
175
176     /**
177      * Prints the list of objects that can be invoked
178      */

179     public void printObjectList() throws Exception JavaDoc{
180         
181         HashMap JavaDoc objects = getObjectMap();
182         if (objects.size() == 0){
183             out.print("<b>No object have been created</b><br>");
184             out.print("<table>");
185             printRow(pepperImg,"<A HREF='"+VIEW_JNDI+"'>Browse for an EJB</A>");
186             out.print("</table>");
187             
188         } else {
189             out.print("<b>Pick and object to invoke</b><br>");
190
191             //out.print("<b>Objects:</b><br>");
192
Set JavaDoc keys = objects.keySet();
193             Iterator JavaDoc iterator = keys.iterator();
194             out.print("<table>");
195             while (iterator.hasNext()) {
196                 String JavaDoc entry = (String JavaDoc)iterator.next();
197                 printRow(tab+"<a HREF='"+INVOKE_OBJ+"?obj="+entry+"'>"+entry+"</a>",
198                         "<a HREF='"+INVOKE_OBJ+"?remove="+entry+"'>[remove]</a>");
199             }
200             out.print("</table>");
201         }
202     }
203     /**
204      * Print the list of methods with the focused method as
205      * selected in the box.
206      * If no method is selected, make an entry called "Pick a Method"
207      */

208     public void printMethodSection(Invocation inv) throws Exception JavaDoc{
209         String JavaDoc methodID = request.getQueryParameter("m");
210         
211         if (methodID != null) {
212             int method = Integer.parseInt(methodID);
213             Method JavaDoc[] methods = inv.clazz.getMethods();
214             if (method > -1 && method < methods.length) {
215                 inv.method = methods[method];
216             } else {
217                 inv.method = null;
218                 inv.args = null;
219             }
220         }
221
222         if (inv.method == null) {
223             // Pick from the list
224
printMethodList(inv);
225
226         } else {
227             out.print("<b>Method:</b><br>");
228             out.print(tab+formatMethod(inv.method)+" <a HREF='"+INVOKE_OBJ+"?m=-1&inv="+inv.id+"'>[change]</a><br><br>");
229             
230             // Show the selected item and continue
231
printArgumentSection(inv);
232         }
233         
234     }
235     
236     /**
237      * Prints the list of methods that can be invoked
238      */

239     public void printMethodList(Invocation inv) throws Exception JavaDoc{
240         out.print("<b>Pick a method to invoke</b><br>");
241         //out.print("<b>Methods:</b><br>");
242

243         Object JavaDoc obj = inv.target;
244         Class JavaDoc clazz = inv.target.getClass();
245         if (obj instanceof javax.ejb.EJBHome JavaDoc) {
246             clazz = obj.getClass().getInterfaces()[0];
247         } else if (obj instanceof javax.ejb.EJBObject JavaDoc) {
248             clazz = obj.getClass().getInterfaces()[0];
249         } else {
250             clazz = obj.getClass();
251         }
252         inv.clazz = clazz;
253
254         out.print("<table>");
255         Method JavaDoc[] methods = clazz.getMethods();
256         for (int i=0; i < methods.length; i++){
257             Method JavaDoc m = methods[i];
258             if (Modifier.isPublic(m.getModifiers())){
259                 out.print("<tr><td><font size='2'>");
260                 out.print(tab+"<a HREF='"+INVOKE_OBJ+"?inv="+inv.id+"&m="+i+"'>"+formatMethod(m)+"</a><br>");
261                 out.print("</font></td></tr>");
262             }
263         }
264         out.print("</table>");
265     }
266
267     /**
268      * Print the list of arguments.
269      * If no arguments have been selected,
270      * show the argument entry form.
271      */

272     public void printArgumentSection(Invocation inv) throws Exception JavaDoc{
273         String JavaDoc args = request.getQueryParameter("args");
274         
275         if (args != null) {
276             parseArgs(inv);
277         }
278
279         if (inv.method.getParameterTypes().length == 0) {
280             inv.args = new Object JavaDoc[]{};
281         }
282
283         if (inv.args == null) {
284             printArgumentList(inv);
285         } else {
286             out.print("<b>Arguments:</b><br>");
287             if (inv.args.length == 0) {
288                 out.print(tab+"none<br>");
289             }
290             for (int i=0; i < inv.args.length; i++){
291                 String JavaDoc val = formatObject(inv.args[i]);
292                 out.print(tab+"arg"+i+"&nbsp;&nbsp;<i>"+val+"</i><br>");
293             }
294             out.print("<br>");
295             printInvokeSection(inv);
296         }
297     }
298     
299     public void parseArgs(Invocation inv) throws Exception JavaDoc{
300         Class JavaDoc[] pTypes = inv.method.getParameterTypes();
301         inv.args = new Object JavaDoc[pTypes.length];
302
303         for (int i=0; i < pTypes.length; i++){
304             Class JavaDoc type = pTypes[i];
305             String JavaDoc unparsedArg = request.getQueryParameter("arg"+i);
306             inv.args[i] = getConverter(type).convert(type, unparsedArg);
307         }
308     }
309
310     public void printArgumentList(Invocation inv) throws Exception JavaDoc{
311         out.print("<b>Fill in the arguments</b><br>");
312         Class JavaDoc[] pTypes = inv.method.getParameterTypes();
313         out.print("<FORM NAME='args' METHOD='GET' ACTION='"+INVOKE_OBJ+"'>");
314         out.print("<INPUT type='HIDDEN' NAME='inv' VALUE='"+inv.id+"'>");
315         out.print("<table>");
316         for (int i=0; i < pTypes.length; i++){
317             Converter con = getConverter(pTypes[i]);
318             out.print("<tr>");
319             out.print("<td align='right'><font size='2'>");
320             out.print(tab+getShortClassRef(pTypes[i]));
321             out.print("</font></td>");
322             out.print("<td><font size='2'>");
323             out.print("&nbsp;&nbsp;arg"+i);
324             out.print("</font></td>");
325             out.print("<td><font size='2'>");
326             out.print("&nbsp;&nbsp;"+con.getInputControl(i,pTypes[i]));
327             out.print("</font></td>");
328         }
329         out.print("</table>");
330
331         out.print("<br><br>");
332         out.print("<INPUT type='SUBMIT' NAME='args' value='Continue'>");
333         out.print("</form>");
334
335     }
336
337     /**
338      * Print the list of arguments.
339      * If no arguments have been selected,
340      * show the argument entry form.
341      */

342     public void printInvokeSection(Invocation inv) throws Exception JavaDoc{
343         String JavaDoc doInvoke = request.getQueryParameter("invoke");
344         if (doInvoke != null) {
345             invoke(inv);
346         } else {
347             out.print("<FORM NAME='invoke' METHOD='GET' ACTION='"+INVOKE_OBJ+"'>");
348             out.print("<INPUT type='HIDDEN' NAME='inv' VALUE='"+inv.id+"'>");
349             out.print("<INPUT type='SUBMIT' NAME='invoke' value='Invoke'>");
350             out.print("</FORM>");
351         }
352
353     }
354     String JavaDoc pepperImg = "<img SRC='/images/pepper.gif' border='0'>";
355     public void invoke(Invocation inv) throws Exception JavaDoc{
356
357         try{
358             inv.result = inv.invoke();
359
360             out.print("<b>Result:</b><br>");
361             if (inv.method.getReturnType() == java.lang.Void.TYPE) {
362                 out.print(tab+"Done");
363             } else if (inv.result == null) {
364                 out.print(tab+"<i>null</i>");
365             } else {
366                 String JavaDoc clazz = inv.result.getClass().getName();
367                 String JavaDoc objID = getObjectID(inv.result);
368                 setObject(objID,inv.result);
369
370                 out.print("<table>");
371                 printRow("<i>id</i>",objID);
372                 printRow("<i>class</i>","<a HREF='"+VIEW_CLASS+"?class="+clazz+"'>"+clazz+"</a>");
373                 printRow("<i>toString</i>",formatObject(inv.result));
374                 out.print("</table>");
375
376                 out.print("<br><br><b>Actions:</b><br>");
377                 out.print("<table>");
378                 String JavaDoc invokerURL = "<a HREF='"+INVOKE_OBJ+"?obj="+objID+"'>Invoke a method on the object</a>";
379                 printRow(pepperImg,invokerURL);
380                 String JavaDoc discardURL = "<a HREF='"+INVOKE_OBJ+"?remove="+objID+"'>Discard the object</a>";
381                 printRow(pepperImg,discardURL);
382                 out.print("</table>");
383             }
384         } catch (InvocationTargetException JavaDoc e){
385             out.print("<b>Exception:</b><br><br>");
386             Throwable JavaDoc t = e.getTargetException();
387             out.print("Received a "+t.getClass().getName());
388             //out.print(inv.method+"<br><br>");
389
if (t instanceof java.rmi.RemoteException JavaDoc) {
390                 out.print(" <a HREF='re-help.html'>[Tip]</a><br><br>");
391                 java.rmi.RemoteException JavaDoc re = (java.rmi.RemoteException JavaDoc)t;
392                 out.print("<i>RemoteException message:</i><br>");
393                 out.print(t.getMessage()+"<br><br>");
394                 out.print("<i>Nested exception's stack trace:</i><br>");
395                 
396                 while (t instanceof java.rmi.RemoteException JavaDoc) {
397                     t = ((java.rmi.RemoteException JavaDoc)t).detail;
398                 }
399                 out.print(formatThrowable(t));
400             } else {
401                 out.print("<br><br>"+formatThrowable(t));
402             }
403
404         } catch (Throwable JavaDoc e){
405             out.print("<b>Exception:</b><br><br>");
406             out.print(formatObject(e));
407         }
408     }
409
410     public String JavaDoc formatThrowable(Throwable JavaDoc err) throws Exception JavaDoc{
411         ByteArrayOutputStream JavaDoc baos = new ByteArrayOutputStream JavaDoc();
412         err.printStackTrace(new PrintStream JavaDoc(baos));
413         byte[] bytes = baos.toByteArray();
414         StringBuffer JavaDoc sb = new StringBuffer JavaDoc(bytes.length);
415         for (int i=0; i < bytes.length; i++){
416             char c = (char)bytes[i];
417             switch (c) {
418                 case ' ': sb.append("&nbsp;"); break;
419                 case '\n': sb.append("<br>"); break;
420                 case '\r': break;
421                 default: sb.append(c);
422             }
423         }
424         return sb.toString();
425     }
426
427
428     public String JavaDoc formatObject(Object JavaDoc obj) throws Exception JavaDoc{
429         int max = 75;
430         String JavaDoc val = obj.toString();
431         val = (val.length() > max)? val.substring(0,max-3)+"...":val;
432         char[] chars = new char[val.length()];
433         val.getChars(0,chars.length,chars,0);
434
435         StringBuffer JavaDoc sb = new StringBuffer JavaDoc(chars.length);
436         for (int j=0; j < chars.length; j++){
437             char c = chars[j];
438             switch (c) {
439                 case '<': sb.append("&lt;"); break;
440                 case '>': sb.append("&gt;"); break;
441                 case '&': sb.append("&amp;"); break;
442                 default: sb.append(c);
443             }
444         }
445         return sb.toString();
446     }
447
448     /*-----------------------------------------------------------*/
449     // Method name formatting
450
/*-----------------------------------------------------------*/
451     public String JavaDoc formatMethod(Method JavaDoc m) throws Exception JavaDoc {
452         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
453
454         sb.append(getShortClassName(m.getReturnType())+"&nbsp;&nbsp;");
455         sb.append(m.getName());
456         
457         Class JavaDoc[] params = m.getParameterTypes();
458         sb.append("(");
459         for (int j=0; j < params.length; j++){
460             sb.append(getShortClassName(params[j]));
461             if (j != params.length-1) {
462                 sb.append(",&nbsp;");
463             }
464         }
465         sb.append(")");
466
467         Class JavaDoc[] excp = m.getExceptionTypes();
468         if (excp.length > 0) {
469             sb.append(" throws&nbsp;");
470             for (int j=0; j < excp.length; j++){
471                 sb.append(getShortClassName(excp[j]));
472                 if (j != excp.length-1) {
473                     sb.append(",&nbsp;");
474                 }
475             }
476         }
477         return sb.toString();
478     }
479
480     /*-----------------------------------------------------------*/
481     // Class name formatting
482
/*-----------------------------------------------------------*/
483     public String JavaDoc getShortClassName(Class JavaDoc clazz) throws Exception JavaDoc {
484         if (clazz.isPrimitive()) {
485             return clazz.getName();
486         } else if (clazz.isArray() && clazz.getComponentType().isPrimitive()) {
487             return clazz.getComponentType()+"[]";
488         } else if (clazz.isArray()) {
489             String JavaDoc name = clazz.getComponentType().getName();
490             int dot = name.lastIndexOf(".")+1;
491             String JavaDoc shortName = name.substring(dot,name.length());
492             return shortName+"[]";
493         } else {
494             String JavaDoc name = clazz.getName();
495             int dot = name.lastIndexOf(".")+1;
496             String JavaDoc shortName = name.substring(dot,name.length());
497             return shortName;
498         }
499     }
500
501     public String JavaDoc getShortClassRef(Class JavaDoc clazz) throws Exception JavaDoc {
502         if (clazz.isPrimitive()) {
503             return "<font color='gray'>"+clazz.getName()+"</font>";
504         } else if (clazz.isArray() && clazz.getComponentType().isPrimitive()) {
505             return "<font color='gray'>"+clazz.getComponentType()+"[]</font>";
506         } else if (clazz.isArray()) {
507             String JavaDoc name = clazz.getComponentType().getName();
508             int dot = name.lastIndexOf(".")+1;
509             String JavaDoc shortName = name.substring(dot,name.length());
510             return "<a HREF='"+VIEW_CLASS+"?class="+name+"'>"+shortName+"[]</a>";
511         } else {
512             String JavaDoc name = clazz.getName();
513             int dot = name.lastIndexOf(".")+1;
514             String JavaDoc shortName = name.substring(dot,name.length());
515             return "<a HREF='"+VIEW_CLASS+"?class="+name+"'>"+shortName+"</a>";
516         }
517     }
518
519     protected void printRow(String JavaDoc col1, String JavaDoc col2) throws Exception JavaDoc{
520         out.print("<tr><td><font size='2'>" );
521         out.print(col1);
522         out.print("</font></td><td><font size='2'>");
523         out.print(col2);
524         out.print("</font></td></tr>");
525     }
526
527     /*-----------------------------------------------------------*/
528     // Object list support
529
/*-----------------------------------------------------------*/
530     public String JavaDoc getObjectID(Object JavaDoc obj){
531         Class JavaDoc clazz = obj.getClass();
532         if (obj instanceof javax.ejb.EJBHome JavaDoc) {
533             clazz = obj.getClass().getInterfaces()[0];
534         } else if (obj instanceof javax.ejb.EJBObject JavaDoc) {
535             clazz = obj.getClass().getInterfaces()[0];
536         }
537         return clazz.getName()+"@"+obj.hashCode();
538     }
539
540     public Object JavaDoc getObject(String JavaDoc objID){
541         return getObjectMap().get(objID);
542     }
543     
544     public void setObject(String JavaDoc objID, Object JavaDoc obj){
545         getObjectMap().put(objID, obj);
546     }
547
548     public void removeObject(String JavaDoc objID){
549         getObjectMap().remove(objID);
550     }
551
552     public HashMap JavaDoc getObjectMap(){
553         HashMap JavaDoc objects = (HashMap JavaDoc)session.getAttribute("objects");
554         if (objects == null) {
555             objects = new HashMap JavaDoc();
556             session.setAttribute("objects",objects);
557         }
558         return objects;
559     }
560     
561     /*-----------------------------------------------------------*/
562     // Invocation list support
563
/*-----------------------------------------------------------*/
564     public Invocation getInvocation(String JavaDoc invID) {
565         return (Invocation)getInvocationMap().get(invID);
566     }
567     
568     public void setInvocation(String JavaDoc invID, Invocation obj){
569         getInvocationMap().put(invID, obj);
570     }
571
572     public HashMap JavaDoc getInvocationMap(){
573         HttpSession session = request.getSession();
574         HashMap JavaDoc invocations = (HashMap JavaDoc)session.getAttribute("invocations");
575         if (invocations == null) {
576             invocations = new HashMap JavaDoc();
577             session.setAttribute("invocations",invocations);
578         }
579         return invocations;
580     }
581
582     /*-----------------------------------------------------------*/
583     // String conversion support
584
/*-----------------------------------------------------------*/
585     final HashMap JavaDoc converters = initConverters();
586
587     public Converter getConverter(Class JavaDoc type){
588         Converter con = (Converter) converters.get(type);
589         if (con == null) {
590             con = defaultConverter;
591         }
592         return con;
593     }
594
595     final Converter defaultConverter = new ObjectConverter();
596
597     private HashMap JavaDoc initConverters(){
598         HashMap JavaDoc map = new HashMap JavaDoc();
599
600         map.put(String JavaDoc.class, new StringConverter());
601         map.put(Character JavaDoc.class, new CharacterConverter());
602         map.put(Boolean JavaDoc.class, new BooleanConverter());
603         map.put(Byte JavaDoc.class, new ByteConverter());
604         map.put(Short JavaDoc.class, new ShortConverter());
605         map.put(Integer JavaDoc.class, new IntegerConverter());
606         map.put(Long JavaDoc.class, new LongConverter());
607         map.put(Float JavaDoc.class, new FloatConverter());
608         map.put(Double JavaDoc.class, new DoubleConverter());
609         map.put(Object JavaDoc.class, new ObjectConverter());
610         map.put(Character.TYPE, map.get(Character JavaDoc.class));
611         map.put(Boolean.TYPE, map.get(Boolean JavaDoc.class));
612         map.put(Byte.TYPE, map.get(Byte JavaDoc.class));
613         map.put(Short.TYPE, map.get(Short JavaDoc.class));
614         map.put(Integer.TYPE, map.get(Integer JavaDoc.class));
615         map.put(Long.TYPE, map.get(Long JavaDoc.class));
616         map.put(Float.TYPE, map.get(Float JavaDoc.class));
617         map.put(Double.TYPE, map.get(Double JavaDoc.class));
618         
619         return map;
620     }
621
622
623     abstract class Converter {
624         public abstract Object JavaDoc convert(Class JavaDoc type, String JavaDoc raw) throws Exception JavaDoc;
625         public String JavaDoc getInputControl(int argNumber, Class JavaDoc type) throws Exception JavaDoc{
626             return "<INPUT type='text' NAME='arg"+argNumber+"'>";
627         }
628     }
629     
630     class StringConverter extends Converter{
631         public Object JavaDoc convert(Class JavaDoc type, String JavaDoc raw) throws Exception JavaDoc {
632             return raw;
633         }
634     }
635     
636     class CharacterConverter extends Converter{
637         public Object JavaDoc convert(Class JavaDoc type, String JavaDoc raw) throws Exception JavaDoc {
638             return new Character JavaDoc(raw.charAt(0));
639         }
640     }
641     
642     class BooleanConverter extends Converter{
643         public Object JavaDoc convert(Class JavaDoc type, String JavaDoc raw) throws Exception JavaDoc {
644             return new Boolean JavaDoc(raw);
645         }
646     }
647     
648     class ByteConverter extends Converter{
649         public Object JavaDoc convert(Class JavaDoc type, String JavaDoc raw) throws Exception JavaDoc {
650             return new Byte JavaDoc(raw);
651         }
652     }
653     
654     class ShortConverter extends Converter{
655         public Object JavaDoc convert(Class JavaDoc type, String JavaDoc raw) throws Exception JavaDoc {
656             return new Short JavaDoc(raw);
657         }
658     }
659     
660     class IntegerConverter extends Converter{
661         public Object JavaDoc convert(Class JavaDoc type, String JavaDoc raw) throws Exception JavaDoc {
662             return new Integer JavaDoc(raw);
663         }
664     }
665     
666     class LongConverter extends Converter{
667         public Object JavaDoc convert(Class JavaDoc type, String JavaDoc raw) throws Exception JavaDoc {
668             return new Long JavaDoc(raw);
669         }
670     }
671     
672     class FloatConverter extends Converter{
673         public Object JavaDoc convert(Class JavaDoc type, String JavaDoc raw) throws Exception JavaDoc {
674             return new Float JavaDoc(raw);
675         }
676     }
677     
678     class DoubleConverter extends Converter{
679         public Object JavaDoc convert(Class JavaDoc type, String JavaDoc raw) throws Exception JavaDoc {
680             return new Double JavaDoc(raw);
681         }
682     }
683     
684     class ObjectConverter extends Converter{
685         public Object JavaDoc convert(Class JavaDoc type, String JavaDoc raw) throws Exception JavaDoc {
686             return raw;
687         }
688     }
689 }
690
Popular Tags