You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by db...@apache.org on 2007/08/03 07:22:00 UTC

svn commit: r562334 [2/8] - in /openejb/trunk/openejb3/server: ./ openejb-webadmin/ openejb-webadmin/src/ openejb-webadmin/src/main/ openejb-webadmin/src/main/etc/ openejb-webadmin/src/main/java/ openejb-webadmin/src/main/java/org/ openejb-webadmin/src...

Added: openejb/trunk/openejb3/server/openejb-webadmin/src/main/java/org/apache/openejb/webadmin/clienttools/InvokeObjectBean.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/server/openejb-webadmin/src/main/java/org/apache/openejb/webadmin/clienttools/InvokeObjectBean.java?view=auto&rev=562334
==============================================================================
--- openejb/trunk/openejb3/server/openejb-webadmin/src/main/java/org/apache/openejb/webadmin/clienttools/InvokeObjectBean.java (added)
+++ openejb/trunk/openejb3/server/openejb-webadmin/src/main/java/org/apache/openejb/webadmin/clienttools/InvokeObjectBean.java Thu Aug  2 22:21:56 2007
@@ -0,0 +1,695 @@
+/**
+ * Redistribution and use of this software and associated documentation
+ * ("Software"), with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain copyright
+ *    statements and notices.  Redistributions must also contain a
+ *    copy of this document.
+ *
+ * 2. Redistributions in binary form must reproduce the
+ *    above copyright notice, this list of conditions and the
+ *    following disclaimer in the documentation and/or other
+ *    materials provided with the distribution.
+ *
+ * 3. The name "OpenEJB" must not be used to endorse or promote
+ *    products derived from this Software without prior written
+ *    permission of The OpenEJB Group.  For written permission,
+ *    please contact dev@openejb.org.
+ *
+ * 4. Products derived from this Software may not be called "OpenEJB"
+ *    nor may "OpenEJB" appear in their names without prior written
+ *    permission of The OpenEJB Group. OpenEJB is a registered
+ *    trademark of The OpenEJB Group.
+ *
+ * 5. Due credit should be given to the OpenEJB Project
+ *    (http://www.openejb.org/).
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE OPENEJB GROUP AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
+ * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
+ * THE OPENEJB GROUP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Copyright 2001 (C) The OpenEJB Group. All Rights Reserved.
+ *
+ * $Id: InvokeObjectBean.java 445460 2005-06-16 22:29:56Z jlaskowski $
+ */
+package org.apache.openejb.webadmin.clienttools;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.PrintStream;
+import java.io.PrintWriter;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Set;
+
+import org.apache.openejb.webadmin.HttpRequest;
+import org.apache.openejb.webadmin.HttpResponse;
+import org.apache.openejb.webadmin.HttpSession;
+import org.apache.openejb.webadmin.WebAdminBean;
+import org.apache.openejb.webadmin.HttpHome;
+
+import javax.ejb.Stateless;
+import javax.ejb.RemoteHome;
+
+/**
+ * @author <a href="mailto:david.blevins@visi.com">David Blevins</a>
+ */
+@Stateless(name = "ClientTools/ViewJndi")
+@RemoteHome(HttpHome.class)
+public class InvokeObjectBean extends WebAdminBean implements Constants {
+
+    private PrintWriter out;
+    private static String invLock = "lock";
+    private static int invCount;
+
+    private HttpSession session;
+
+    public void preProcess(HttpRequest request, HttpResponse response)
+        throws IOException {
+    }
+
+    public void postProcess(HttpRequest request, HttpResponse response)
+        throws IOException {
+    }
+
+    public void writeHtmlTitle(PrintWriter out) throws IOException {
+        out.write("Client Tools -- Object Invoker");
+    }
+
+    public void writePageTitle(PrintWriter out) throws IOException {
+        out.write("Object Invoker");
+    }
+
+    public void writeBody(PrintWriter out) throws IOException {
+        this.out = out;
+        try{
+            synchronized (this) {
+                main(request.getSession(), out);
+            }
+        } catch (Exception e){
+            out.println("FAIL");
+            //throw e;
+            return;
+        }
+    }
+
+    class Invocation {
+
+        protected String id = "inv";
+        protected String objID;
+        protected Class clazz;
+        protected Object target;
+        protected Method method;
+        protected Object[] args;
+        protected Object result;
+
+        protected Invocation(){
+            synchronized (invLock){
+                id += ++invCount;
+            }
+        }
+
+        public Object invoke() throws Exception{
+            if (target == null || method == null || args == null) {
+                throw new Exception("This invocation contains null objects.");
+            }
+            return method.invoke(target,args);
+        }
+    }
+
+    /**
+     * The main method of this JSP
+     */
+    public void main(HttpSession session, PrintWriter out) throws Exception{
+        this.session = session;
+        this.out = out;
+
+        printObjectSection();
+    }
+
+    /**
+     * Print the list of objects with the focused object as
+     * selected in the box.
+     * If no object is selected, make an entry called "Pick an Object"
+     */
+    public void printObjectSection() throws Exception{
+        String removeID = request.getQueryParameter("remove");
+        if (removeID != null) {
+            removeObject(removeID);
+        }
+
+        Invocation inv = null;
+        String invID = request.getQueryParameter("inv");
+
+        if (invID == null) {
+            String objID = request.getQueryParameter("obj");
+            if (objID != null) {
+                inv = new Invocation();
+                inv.target = getObject(objID);
+                inv.objID = objID;
+                setInvocation(inv.id,inv);
+            }
+        } else {
+            inv = getInvocation(invID);
+        }
+
+        if (inv == null || inv.target == null) {
+            // Pick from the list
+            printObjectList();
+
+        } else {
+            out.print("<b>Object:</b><br>");
+            out.print(tab+inv.objID+" <a href='"+INVOKE_OBJ+"'>[change]</a><br><br>");
+
+            // Show the selected item and continue
+            printMethodSection(inv);
+        }
+    }
+
+    /**
+     * Prints the list of objects that can be invoked
+     */
+    public void printObjectList() throws Exception{
+
+        HashMap objects = getObjectMap();
+        if (objects.size() == 0){
+            out.print("<b>No object have been created</b><br>");
+            out.print("<table>");
+            printRow(pepperImg,"<A HREF='"+VIEW_JNDI+"'>Browse for an EJB</A>");
+            out.print("</table>");
+
+        } else {
+            out.print("<b>Pick and object to invoke</b><br>");
+
+            //out.print("<b>Objects:</b><br>");
+            Set keys = objects.keySet();
+            Iterator iterator = keys.iterator();
+            out.print("<table>");
+            while (iterator.hasNext()) {
+                String entry = (String)iterator.next();
+                printRow(tab+"<a href='"+INVOKE_OBJ+"?obj="+entry+"'>"+entry+"</a>",
+                        "<a href='"+INVOKE_OBJ+"?remove="+entry+"'>[remove]</a>");
+            }
+            out.print("</table>");
+        }
+    }
+    /**
+     * Print the list of methods with the focused method as
+     * selected in the box.
+     * If no method is selected, make an entry called "Pick a Method"
+     */
+    public void printMethodSection(Invocation inv) throws Exception{
+        String methodID = request.getQueryParameter("m");
+
+        if (methodID != null) {
+            int method = Integer.parseInt(methodID);
+            Method[] methods = inv.clazz.getMethods();
+            if (method > -1 && method < methods.length) {
+                inv.method = methods[method];
+            } else {
+                inv.method = null;
+                inv.args = null;
+            }
+        }
+
+        if (inv.method == null) {
+            // Pick from the list
+            printMethodList(inv);
+
+        } else {
+            out.print("<b>Method:</b><br>");
+            out.print(tab+formatMethod(inv.method)+" <a href='"+INVOKE_OBJ+"?m=-1&inv="+inv.id+"'>[change]</a><br><br>");
+
+            // Show the selected item and continue
+            printArgumentSection(inv);
+        }
+
+    }
+
+    /**
+     * Prints the list of methods that can be invoked
+     */
+    public void printMethodList(Invocation inv) throws Exception{
+        out.print("<b>Pick a method to invoke</b><br>");
+        //out.print("<b>Methods:</b><br>");
+
+        Object obj = inv.target;
+        Class clazz = inv.target.getClass();
+        if (obj instanceof javax.ejb.EJBHome) {
+            clazz = obj.getClass().getInterfaces()[0];
+        } else if (obj instanceof javax.ejb.EJBObject) {
+            clazz = obj.getClass().getInterfaces()[0];
+        } else {
+            clazz = obj.getClass();
+        }
+        inv.clazz = clazz;
+
+        out.print("<table>");
+        Method[] methods = clazz.getMethods();
+        for (int i=0; i < methods.length; i++){
+            Method m = methods[i];
+            if (Modifier.isPublic(m.getModifiers())){
+                out.print("<tr><td><font size='2'>");
+                out.print(tab+"<a href='"+INVOKE_OBJ+"?inv="+inv.id+"&m="+i+"'>"+formatMethod(m)+"</a><br>");
+                out.print("</font></td></tr>");
+            }
+        }
+        out.print("</table>");
+    }
+
+    /**
+     * Print the list of arguments.
+     * If no arguments have been selected, 
+     * show the argument entry form.
+     */
+    public void printArgumentSection(Invocation inv) throws Exception{
+        String args = request.getQueryParameter("args");
+
+        if (args != null) {
+            parseArgs(inv);
+        }
+
+        if (inv.method.getParameterTypes().length == 0) {
+            inv.args = new Object[]{};
+        }
+
+        if (inv.args == null) {
+            printArgumentList(inv);
+        } else {
+            out.print("<b>Arguments:</b><br>");
+            if (inv.args.length == 0) {
+                out.print(tab+"none<br>");
+            }
+            for (int i=0; i < inv.args.length; i++){
+                String val = formatObject(inv.args[i]);
+                out.print(tab+"arg"+i+"&nbsp;&nbsp;<i>"+val+"</i><br>");
+            }
+            out.print("<br>");
+            printInvokeSection(inv);
+        }
+    }
+
+    public void parseArgs(Invocation inv) throws Exception{
+        Class[] pTypes = inv.method.getParameterTypes();
+        inv.args = new Object[pTypes.length];
+
+        for (int i=0; i < pTypes.length; i++){
+            Class type = pTypes[i];
+            String unparsedArg = request.getQueryParameter("arg"+i);
+            inv.args[i] = getConverter(type).convert(type, unparsedArg);
+        }
+    }
+
+    public void printArgumentList(Invocation inv) throws Exception{
+        out.print("<b>Fill in the arguments</b><br>");
+        Class[] pTypes = inv.method.getParameterTypes();
+        out.print("<FORM NAME='args' METHOD='GET' ACTION='"+INVOKE_OBJ+"'>");
+        out.print("<INPUT type='HIDDEN' NAME='inv' VALUE='"+inv.id+"'>");
+        out.print("<table>");
+        for (int i=0; i < pTypes.length; i++){
+            Converter con = getConverter(pTypes[i]);
+            out.print("<tr>");
+            out.print("<td align='right'><font size='2'>");
+            out.print(tab+getShortClassRef(pTypes[i]));
+            out.print("</font></td>");
+            out.print("<td><font size='2'>");
+            out.print("&nbsp;&nbsp;arg"+i);
+            out.print("</font></td>");
+            out.print("<td><font size='2'>");
+            out.print("&nbsp;&nbsp;"+con.getInputControl(i,pTypes[i]));
+            out.print("</font></td>");
+        }
+        out.print("</table>");
+
+        out.print("<br><br>");
+        out.print("<INPUT type='SUBMIT' NAME='args' value='Continue'>");
+        out.print("</form>");
+
+    }
+
+    /**
+     * Print the list of arguments.
+     * If no arguments have been selected, 
+     * show the argument entry form.
+     */
+    public void printInvokeSection(Invocation inv) throws Exception{
+        String doInvoke = request.getQueryParameter("invoke");
+        if (doInvoke != null) {
+            invoke(inv);
+        } else {
+            out.print("<FORM NAME='invoke' METHOD='GET' ACTION='"+INVOKE_OBJ+"'>");
+            out.print("<INPUT type='HIDDEN' NAME='inv' VALUE='"+inv.id+"'>");
+            out.print("<INPUT type='SUBMIT' NAME='invoke' value='Invoke'>");
+            out.print("</FORM>");
+        }
+
+    }
+    String pepperImg = "<img src='/images/pepper.gif' border='0'>";
+    public void invoke(Invocation inv) throws Exception{
+
+        try{
+            inv.result = inv.invoke();
+
+            out.print("<b>Result:</b><br>");
+            if (inv.method.getReturnType() == java.lang.Void.TYPE) {
+                out.print(tab+"Done");
+            } else if (inv.result == null) {
+                out.print(tab+"<i>null</i>");
+            } else {
+                String clazz = inv.result.getClass().getName();
+                String objID = getObjectID(inv.result);
+                setObject(objID,inv.result);
+
+                out.print("<table>");
+                printRow("<i>id</i>",objID);
+                printRow("<i>class</i>","<a href='"+VIEW_CLASS+"?class="+clazz+"'>"+clazz+"</a>");
+                printRow("<i>toString</i>",formatObject(inv.result));
+                out.print("</table>");
+
+                out.print("<br><br><b>Actions:</b><br>");
+                out.print("<table>");
+                String invokerURL = "<a href='"+INVOKE_OBJ+"?obj="+objID+"'>Invoke a method on the object</a>";
+                printRow(pepperImg,invokerURL);
+                String discardURL = "<a href='"+INVOKE_OBJ+"?remove="+objID+"'>Discard the object</a>";
+                printRow(pepperImg,discardURL);
+                out.print("</table>");
+            }
+        } catch (InvocationTargetException e){
+            out.print("<b>Exception:</b><br><br>");
+            Throwable t = e.getTargetException();
+            out.print("Received a "+t.getClass().getName());
+            //out.print(inv.method+"<br><br>");
+            if (t instanceof java.rmi.RemoteException) {
+                out.print(" <a href='re-help.html'>[Tip]</a><br><br>");
+                java.rmi.RemoteException re = (java.rmi.RemoteException)t;
+                out.print("<i>RemoteException message:</i><br>");
+                out.print(t.getMessage()+"<br><br>");
+                out.print("<i>Nested exception's stack trace:</i><br>");
+
+                while (t instanceof java.rmi.RemoteException) {
+                    t = ((java.rmi.RemoteException)t).detail;
+                }
+                out.print(formatThrowable(t));
+            } else {
+                out.print("<br><br>"+formatThrowable(t));
+            }
+
+        } catch (Throwable e){
+            out.print("<b>Exception:</b><br><br>");
+            out.print(formatObject(e));
+        }
+    }
+
+    public String formatThrowable(Throwable err) throws Exception{
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        err.printStackTrace(new PrintStream(baos));
+        byte[] bytes = baos.toByteArray();
+        StringBuffer sb = new StringBuffer(bytes.length);
+        for (int i=0; i < bytes.length; i++){
+            char c = (char)bytes[i];
+            switch (c) {
+                case ' ': sb.append("&nbsp;"); break;
+                case '\n': sb.append("<br>"); break;
+                case '\r': break;
+                default: sb.append(c);
+            }
+        }
+        return sb.toString();
+    }
+
+
+    public String formatObject(Object obj) throws Exception{
+        int max = 75;
+        String val = obj.toString();
+        val = (val.length() > max)? val.substring(0,max-3)+"...":val;
+        char[] chars = new char[val.length()];
+        val.getChars(0,chars.length,chars,0);
+
+        StringBuffer sb = new StringBuffer(chars.length);
+        for (int j=0; j < chars.length; j++){
+            char c = chars[j];
+            switch (c) {
+                case '<': sb.append("&lt;"); break;
+                case '>': sb.append("&gt;"); break;
+                case '&': sb.append("&amp;"); break;
+                default: sb.append(c);
+            }
+        }
+        return sb.toString();
+    }
+
+    /*-----------------------------------------------------------*/
+    // Method name formatting
+    /*-----------------------------------------------------------*/
+    public String formatMethod(Method m) throws Exception {
+        StringBuffer sb = new StringBuffer();
+
+        sb.append(getShortClassName(m.getReturnType())+"&nbsp;&nbsp;");
+        sb.append(m.getName());
+
+        Class[] params = m.getParameterTypes();
+        sb.append("(");
+        for (int j=0; j < params.length; j++){
+            sb.append(getShortClassName(params[j]));
+            if (j != params.length-1) {
+                sb.append(",&nbsp;");
+            }
+        }
+        sb.append(")");
+
+        Class[] excp = m.getExceptionTypes();
+        if (excp.length > 0) {
+            sb.append(" throws&nbsp;");
+            for (int j=0; j < excp.length; j++){
+                sb.append(getShortClassName(excp[j]));
+                if (j != excp.length-1) {
+                    sb.append(",&nbsp;");
+                }
+            }
+        }
+        return sb.toString();
+    }
+
+    /*-----------------------------------------------------------*/
+    // Class name formatting
+    /*-----------------------------------------------------------*/
+    public String getShortClassName(Class clazz) throws Exception {
+        if (clazz.isPrimitive()) {
+            return clazz.getName();
+        } else if (clazz.isArray() && clazz.getComponentType().isPrimitive()) {
+            return clazz.getComponentType()+"[]";
+        } else if (clazz.isArray()) {
+            String name = clazz.getComponentType().getName();
+            int dot = name.lastIndexOf(".")+1;
+            String shortName = name.substring(dot,name.length());
+            return shortName+"[]";
+        } else {
+            String name = clazz.getName();
+            int dot = name.lastIndexOf(".")+1;
+            String shortName = name.substring(dot,name.length());
+            return shortName;
+        }
+    }
+
+    public String getShortClassRef(Class clazz) throws Exception {
+        if (clazz.isPrimitive()) {
+            return "<font color='gray'>"+clazz.getName()+"</font>";
+        } else if (clazz.isArray() && clazz.getComponentType().isPrimitive()) {
+            return "<font color='gray'>"+clazz.getComponentType()+"[]</font>";
+        } else if (clazz.isArray()) {
+            String name = clazz.getComponentType().getName();
+            int dot = name.lastIndexOf(".")+1;
+            String shortName = name.substring(dot,name.length());
+            return "<a href='"+VIEW_CLASS+"?class="+name+"'>"+shortName+"[]</a>";
+        } else {
+            String name = clazz.getName();
+            int dot = name.lastIndexOf(".")+1;
+            String shortName = name.substring(dot,name.length());
+            return "<a href='"+VIEW_CLASS+"?class="+name+"'>"+shortName+"</a>";
+        }
+    }
+
+    protected void printRow(String col1, String col2) throws Exception{
+        out.print("<tr><td><font size='2'>"  );
+        out.print(col1);
+        out.print("</font></td><td><font size='2'>");
+        out.print(col2);
+        out.print("</font></td></tr>");
+    }
+
+    /*-----------------------------------------------------------*/
+    // Object list support
+    /*-----------------------------------------------------------*/
+    public String getObjectID(Object obj){
+        Class clazz = obj.getClass();
+        if (obj instanceof javax.ejb.EJBHome) {
+            clazz = obj.getClass().getInterfaces()[0];
+        } else if (obj instanceof javax.ejb.EJBObject) {
+            clazz = obj.getClass().getInterfaces()[0];
+        }
+        return clazz.getName()+"@"+obj.hashCode();
+    }
+
+    public Object getObject(String objID){
+        return getObjectMap().get(objID);
+    }
+
+    public void setObject(String objID, Object obj){
+        getObjectMap().put(objID, obj);
+    }
+
+    public void removeObject(String objID){
+        getObjectMap().remove(objID);
+    }
+
+    public HashMap getObjectMap(){
+        HashMap objects = (HashMap)session.getAttribute("objects");
+        if (objects == null) {
+            objects = new HashMap();
+            session.setAttribute("objects",objects);
+        }
+        return objects;
+    }
+
+    /*-----------------------------------------------------------*/
+    // Invocation list support
+    /*-----------------------------------------------------------*/
+    public Invocation getInvocation(String invID) {
+        return (Invocation)getInvocationMap().get(invID);
+    }
+
+    public void setInvocation(String invID, Invocation obj){
+        getInvocationMap().put(invID, obj);
+    }
+
+    public HashMap getInvocationMap(){
+        HttpSession session = request.getSession();
+        HashMap invocations = (HashMap)session.getAttribute("invocations");
+        if (invocations == null) {
+            invocations = new HashMap();
+            session.setAttribute("invocations",invocations);
+        }
+        return invocations;
+    }
+
+    /*-----------------------------------------------------------*/
+    // String conversion support
+    /*-----------------------------------------------------------*/
+    final HashMap converters = initConverters();
+
+    public Converter getConverter(Class type){
+        Converter con = (Converter) converters.get(type);
+        if (con == null) {
+            con = defaultConverter;
+        }
+        return con;
+    }
+
+    final Converter defaultConverter = new ObjectConverter();
+
+    private HashMap initConverters(){
+        HashMap map = new HashMap();
+
+        map.put(String.class,    new StringConverter());
+        map.put(Character.class, new CharacterConverter());
+        map.put(Boolean.class,   new BooleanConverter());
+        map.put(Byte.class,      new ByteConverter());
+        map.put(Short.class,     new ShortConverter());
+        map.put(Integer.class,   new IntegerConverter());
+        map.put(Long.class,      new LongConverter());
+        map.put(Float.class,     new FloatConverter());
+        map.put(Double.class,    new DoubleConverter());
+        map.put(Object.class,    new ObjectConverter());
+        map.put(Character.TYPE,  map.get(Character.class));
+        map.put(Boolean.TYPE,    map.get(Boolean.class));
+        map.put(Byte.TYPE,       map.get(Byte.class));
+        map.put(Short.TYPE,      map.get(Short.class));
+        map.put(Integer.TYPE,    map.get(Integer.class));
+        map.put(Long.TYPE,       map.get(Long.class));
+        map.put(Float.TYPE,      map.get(Float.class));
+        map.put(Double.TYPE,     map.get(Double.class));
+
+        return map;
+    }
+
+
+    abstract class Converter {
+        public abstract Object convert(Class type, String raw) throws Exception;
+        public String getInputControl(int argNumber, Class type) throws Exception{
+            return "<INPUT type='text' NAME='arg"+argNumber+"'>";
+        }
+    }
+
+    class StringConverter extends Converter{
+        public Object convert(Class type, String raw) throws Exception {
+            return raw;
+        }
+    }
+
+    class CharacterConverter extends Converter{
+        public Object convert(Class type, String raw) throws Exception {
+            return new Character(raw.charAt(0));
+        }
+    }
+
+    class BooleanConverter extends Converter{
+        public Object convert(Class type, String raw) throws Exception {
+            return new Boolean(raw);
+        }
+    }
+
+    class ByteConverter extends Converter{
+        public Object convert(Class type, String raw) throws Exception {
+            return new Byte(raw);
+        }
+    }
+
+    class ShortConverter extends Converter{
+        public Object convert(Class type, String raw) throws Exception {
+            return new Short(raw);
+        }
+    }
+
+    class IntegerConverter extends Converter{
+        public Object convert(Class type, String raw) throws Exception {
+            return new Integer(raw);
+        }
+    }
+
+    class LongConverter extends Converter{
+        public Object convert(Class type, String raw) throws Exception {
+            return new Long(raw);
+        }
+    }
+
+    class FloatConverter extends Converter{
+        public Object convert(Class type, String raw) throws Exception {
+            return new Float(raw);
+        }
+    }
+
+    class DoubleConverter extends Converter{
+        public Object convert(Class type, String raw) throws Exception {
+            return new Double(raw);
+        }
+    }
+
+    class ObjectConverter extends Converter{
+        public Object convert(Class type, String raw) throws Exception {
+            return raw;
+        }
+    }
+}

Propchange: openejb/trunk/openejb3/server/openejb-webadmin/src/main/java/org/apache/openejb/webadmin/clienttools/InvokeObjectBean.java
------------------------------------------------------------------------------
    svn:executable = *

Added: openejb/trunk/openejb3/server/openejb-webadmin/src/main/java/org/apache/openejb/webadmin/clienttools/ViewClassBean.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/server/openejb-webadmin/src/main/java/org/apache/openejb/webadmin/clienttools/ViewClassBean.java?view=auto&rev=562334
==============================================================================
--- openejb/trunk/openejb3/server/openejb-webadmin/src/main/java/org/apache/openejb/webadmin/clienttools/ViewClassBean.java (added)
+++ openejb/trunk/openejb3/server/openejb-webadmin/src/main/java/org/apache/openejb/webadmin/clienttools/ViewClassBean.java Thu Aug  2 22:21:56 2007
@@ -0,0 +1,264 @@
+/**
+ * Redistribution and use of this software and associated documentation
+ * ("Software"), with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain copyright
+ *    statements and notices.  Redistributions must also contain a
+ *    copy of this document.
+ *
+ * 2. Redistributions in binary form must reproduce the
+ *    above copyright notice, this list of conditions and the
+ *    following disclaimer in the documentation and/or other
+ *    materials provided with the distribution.
+ *
+ * 3. The name "OpenEJB" must not be used to endorse or promote
+ *    products derived from this Software without prior written
+ *    permission of The OpenEJB Group.  For written permission,
+ *    please contact dev@openejb.org.
+ *
+ * 4. Products derived from this Software may not be called "OpenEJB"
+ *    nor may "OpenEJB" appear in their names without prior written
+ *    permission of The OpenEJB Group. OpenEJB is a registered
+ *    trademark of The OpenEJB Group.
+ *
+ * 5. Due credit should be given to the OpenEJB Project
+ *    (http://www.openejb.org/).
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE OPENEJB GROUP AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
+ * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
+ * THE OPENEJB GROUP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Copyright 2001 (C) The OpenEJB Group. All Rights Reserved.
+ *
+ * $Id: ViewClassBean.java 445460 2005-06-16 22:29:56Z jlaskowski $
+ */
+package org.apache.openejb.webadmin.clienttools;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+
+import org.apache.openejb.webadmin.HttpRequest;
+import org.apache.openejb.webadmin.HttpResponse;
+import org.apache.openejb.webadmin.WebAdminBean;
+import org.apache.openejb.webadmin.HttpHome;
+
+import javax.ejb.Stateless;
+import javax.ejb.RemoteHome;
+
+/**
+ * @author <a href="mailto:david.blevins@visi.com">David Blevins</a>
+ */
+@Stateless(name = "ClientTools/ViewClass")
+@RemoteHome(HttpHome.class)
+public class ViewClassBean extends WebAdminBean  implements Constants {
+
+    boolean hasMethods;
+
+    public void preProcess(HttpRequest request, HttpResponse response)
+        throws IOException {
+    }
+
+    public void postProcess(HttpRequest request, HttpResponse response)
+        throws IOException {
+    }
+
+    public void writeHtmlTitle(PrintWriter out) throws IOException {
+        out.write("Client Tools -- JNDI Viewer");
+    }
+
+    public void writePageTitle(PrintWriter out) throws IOException {
+        out.write("JNDI Viewer");
+    }
+
+    public void writeBody(PrintWriter out) throws IOException {
+        try {
+            String className = request.getQueryParameter("class");
+            if (className == null) {
+                out.print("<b>Enter a class name to browse:</b>");
+                out.print(
+                    "<FORM NAME='view' METHOD='GET' ACTION='"+VIEW_CLASS+"'>");
+                out.print(
+                    "<INPUT type='text' NAME='class' size='40' VALUE=''>");
+                out.print("<INPUT type='SUBMIT' NAME='view' value='View'>");
+                out.print("</form>");
+                out.print("<b>Or browse one of these fun classes:</b><br><br>");
+                out.print(tab + getClassRef("javax.ejb.EJBHome") + "<br>");
+                out.print(tab + getClassRef("javax.ejb.EJBObject") + "<br>");
+                out.print(
+                    tab + getClassRef("javax.ejb.EnterpriseBean") + "<br>");
+                out.print(tab + getClassRef("javax.ejb.SessionBean") + "<br>");
+                out.print(tab + getClassRef("javax.ejb.EntityBean") + "<br>");
+                out.print(
+                    tab
+                        + getClassRef("javax.servlet.http.HttpServlet")
+                        + "<br>");
+                out.print(
+                    tab
+                        + getClassRef("javax.servlet.http.HttpServletRequest")
+                        + "<br>");
+                out.print(
+                    tab
+                        + getClassRef("javax.servlet.http.HttpServletResponse")
+                        + "<br>");
+                out.print(
+                    tab
+                        + getClassRef("javax.servlet.http.HttpSession")
+                        + "<br>");
+                out.print(
+                    tab + getClassRef("javax.naming.InitialContext") + "<br>");
+                out.print(tab + getClassRef("javax.naming.Context") + "<br>");
+
+            } else {
+                Class clazz = this.getClass().forName(className);
+                printClass(clazz, out);
+            }
+        } catch (Exception e) {
+            out.println("FAIL");
+            return;
+        }
+        out.print("<BR><BR>");
+        if (hasMethods) {
+            out.print("<font color='green'>*</font>&nbsp;Public &nbsp; ");
+            out.print("<font color='red'>*</font>&nbsp;Private &nbsp;");
+            out.print("<font color='blue'>*</font>&nbsp;Protected &nbsp;");
+            out.print("<font color='yellow'>*</font>&nbsp;Default ");
+            out.print("<BR>");
+        }
+    }
+
+
+    public void printClass(Class clazz, PrintWriter out)
+        throws Exception {
+        out.print("<b>" + clazz.getName() + "</b><br>");
+        Method[] methods = clazz.getDeclaredMethods();
+        hasMethods = (methods.length > 0);
+        for (int i = 0; i < methods.length; i++) {
+            printMethod(methods[i], out);
+        }
+
+        /*
+		 * //out.print("&nbsp;&nbsp; <font color='gray'><u> Public Methods:
+		 * </u></font><br> "); for (int i=0; i < methods.length; i++){ if
+		 * (Modifier.isPublic(methods[i].getModifiers())){ printMethod(
+		 * methods[i], out ); } } //out.print("&nbsp;&nbsp; <font color='gray'>
+		 * <u> Private Methods: </u></font><br> "); for (int i=0; i
+		 * < methods.length; i++){ if
+		 * (Modifier.isPrivate(methods[i].getModifiers())){ printMethod(
+		 * methods[i], out ); } } for (int i=0; i < methods.length; i++){ if
+		 * (Modifier.isProtected(methods[i].getModifiers())){ printMethod(
+		 * methods[i], out ); } } for (int i=0; i < methods.length; i++){ if
+		 * (!Modifier.isSrict(methods[i].getModifiers())){ printMethod(
+		 * methods[i], out ); } }
+		 */
+        Class sup = clazz.getSuperclass();
+        if (sup != null) {
+            out.print("<br><b>Extends:</b><br>");
+            out.print(tab + getClassRef(sup) + "<br>");
+        }
+
+        Class[] intf = clazz.getInterfaces();
+
+        if (intf.length > 0) {
+            out.print("<br><b>Implements:</b><br>");
+            for (int i = 0; i < intf.length; i++) {
+                out.print(tab + getClassRef(intf[i]) + "<br>");
+            }
+        }
+    }
+
+    public void printMethod(Method m, PrintWriter out)
+        throws Exception {
+        out.print(tab);
+        out.print(" " + getModifier(m));
+
+        out.print(" " + getShortClassRef(m.getReturnType()) + "&nbsp;&nbsp;");
+
+        out.print("" + m.getName() + "&nbsp;");
+        Class[] params = m.getParameterTypes();
+        out.print("<font color='gray'>(</font>");
+        for (int j = 0; j < params.length; j++) {
+            out.print(getShortClassRef(params[j]));
+            if (j != params.length - 1) {
+                out.print(",&nbsp;");
+            }
+        }
+        out.print("<font color='gray'>)</font>");
+
+        Class[] excp = m.getExceptionTypes();
+        if (excp.length > 0) {
+            out.print(" <font color='gray'>throws</font>&nbsp;&nbsp;");
+            for (int j = 0; j < excp.length; j++) {
+                out.print(getShortClassRef(excp[j]));
+                if (j != excp.length - 1) {
+                    out.print(",&nbsp;");
+                }
+            }
+        }
+        out.print("<br>");
+    }
+
+    public String getModifier(Method m) throws Exception {
+        int mod = m.getModifiers();
+        String color = "";
+
+        if (Modifier.isPublic(mod)) {
+            color = "green";
+        } else if (Modifier.isPrivate(mod)) {
+            color = "red";
+        } else if (Modifier.isProtected(mod)) {
+            color = "blue";
+        } else {
+            color = "yellow";
+        }
+        return "<font color='" + color + "'>*</font>";
+    }
+
+    public String getClassRef(Class clazz) throws Exception {
+        String name = clazz.getName();
+        return "<a href='"+VIEW_CLASS+"?class=" + name + "'>" + name + "</a>";
+    }
+
+    public String getClassRef(String name) throws Exception {
+        return "<a href='"+VIEW_CLASS+"?class=" + name + "'>" + name + "</a>";
+    }
+
+    public String getShortClassRef(Class clazz) throws Exception {
+        if (clazz.isPrimitive()) {
+            return "<font color='gray'>" + clazz.getName() + "</font>";
+        } else if (clazz.isArray() && clazz.getComponentType().isPrimitive()) {
+            return "<font color='gray'>"
+                + clazz.getComponentType()
+                + "[]</font>";
+        } else if (clazz.isArray()) {
+            String name = clazz.getComponentType().getName();
+            int dot = name.lastIndexOf(".") + 1;
+            String shortName = name.substring(dot, name.length());
+            return "<a href='"+VIEW_CLASS+"?class="
+                + name
+                + "'>"
+                + shortName
+                + "[]</a>";
+        } else {
+            String name = clazz.getName();
+            int dot = name.lastIndexOf(".") + 1;
+            String shortName = name.substring(dot, name.length());
+            return "<a href='"+VIEW_CLASS+"?class="
+                + name
+                + "'>"
+                + shortName
+                + "</a>";
+        }
+    }
+}

Propchange: openejb/trunk/openejb3/server/openejb-webadmin/src/main/java/org/apache/openejb/webadmin/clienttools/ViewClassBean.java
------------------------------------------------------------------------------
    svn:executable = *

Added: openejb/trunk/openejb3/server/openejb-webadmin/src/main/java/org/apache/openejb/webadmin/clienttools/ViewEjbBean.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/server/openejb-webadmin/src/main/java/org/apache/openejb/webadmin/clienttools/ViewEjbBean.java?view=auto&rev=562334
==============================================================================
--- openejb/trunk/openejb3/server/openejb-webadmin/src/main/java/org/apache/openejb/webadmin/clienttools/ViewEjbBean.java (added)
+++ openejb/trunk/openejb3/server/openejb-webadmin/src/main/java/org/apache/openejb/webadmin/clienttools/ViewEjbBean.java Thu Aug  2 22:21:56 2007
@@ -0,0 +1,307 @@
+/**
+ * Redistribution and use of this software and associated documentation
+ * ("Software"), with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain copyright
+ *    statements and notices.  Redistributions must also contain a
+ *    copy of this document.
+ *
+ * 2. Redistributions in binary form must reproduce the
+ *    above copyright notice, this list of conditions and the
+ *    following disclaimer in the documentation and/or other
+ *    materials provided with the distribution.
+ *
+ * 3. The name "OpenEJB" must not be used to endorse or promote
+ *    products derived from this Software without prior written
+ *    permission of The OpenEJB Group.  For written permission,
+ *    please contact dev@openejb.org.
+ *
+ * 4. Products derived from this Software may not be called "OpenEJB"
+ *    nor may "OpenEJB" appear in their names without prior written
+ *    permission of The OpenEJB Group. OpenEJB is a registered
+ *    trademark of The OpenEJB Group.
+ *
+ * 5. Due credit should be given to the OpenEJB Project
+ *    (http://www.openejb.org/).
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE OPENEJB GROUP AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
+ * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
+ * THE OPENEJB GROUP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Copyright 2001 (C) The OpenEJB Group. All Rights Reserved.
+ *
+ * $Id: ViewEjbBean.java 445460 2005-06-16 22:29:56Z jlaskowski $
+ */
+package org.apache.openejb.webadmin.clienttools;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.ejb.Stateless;
+import javax.ejb.RemoteHome;
+
+import org.apache.openejb.webadmin.HttpRequest;
+import org.apache.openejb.webadmin.HttpResponse;
+import org.apache.openejb.webadmin.HttpSession;
+import org.apache.openejb.webadmin.WebAdminBean;
+import org.apache.openejb.webadmin.HttpHome;
+import org.apache.openejb.assembler.classic.ContainerInfo;
+import org.apache.openejb.assembler.classic.EnterpriseBeanInfo;
+import org.apache.openejb.config.ConfigurationFactory;
+import org.apache.openejb.core.CoreDeploymentInfo;
+import org.apache.openejb.assembler.classic.ContainerInfo;
+import org.apache.openejb.assembler.classic.EnterpriseBeanInfo;
+import org.apache.openejb.assembler.classic.OpenEjbConfiguration;
+import org.apache.openejb.assembler.classic.AppInfo;
+import org.apache.openejb.assembler.classic.EjbJarInfo;
+import org.apache.openejb.config.ConfigurationFactory;
+import org.apache.openejb.loader.SystemInstance;
+import org.apache.openejb.spi.ContainerSystem;
+import org.apache.openejb.DeploymentInfo;
+import org.apache.openejb.BeanType;
+
+/**
+ * @author <a href="mailto:david.blevins@visi.com">David Blevins</a>
+ */
+@Stateless(name = "ClientTools/ViewEjb")
+@RemoteHome(HttpHome.class)
+public class ViewEjbBean extends WebAdminBean implements Constants {
+
+    public void preProcess(HttpRequest request, HttpResponse response)
+        throws IOException {
+    }
+
+    public void postProcess(HttpRequest request, HttpResponse response)
+        throws IOException {
+    }
+
+    public void writeHtmlTitle(PrintWriter out) throws IOException {
+        out.write("Client Tools -- EJB Viewer");
+    }
+
+    public void writePageTitle(PrintWriter out) throws IOException {
+        out.write("EJB Viewer");
+    }
+
+    public void writeBody(PrintWriter out) throws IOException {
+        try {
+            String ejb = request.getQueryParameter("ejb");
+            if (ejb == null) {
+                OpenEjbConfiguration configuration = SystemInstance.get().getComponent(OpenEjbConfiguration.class);
+                for (AppInfo appInfo : configuration.containerSystem.applications) {
+                    for (EjbJarInfo ejbJarInfo : appInfo.ejbJars) {
+                        for (EnterpriseBeanInfo bean : ejbJarInfo.enterpriseBeans) {
+                            out.print("<a href='"+VIEW_EJB+"?ejb="+bean.ejbDeploymentId+"'>"+ejbImg+"&nbsp;&nbsp;"+bean.ejbDeploymentId+"</a><br>");
+                        }
+                    }
+                }
+            } else {
+                printEjb(ejb, out, request.getSession());
+            }
+        } catch (Exception e) {
+
+            out.println("FAIL: ");
+            out.print(e.getMessage());
+            //            throw e;
+            //return;
+        }
+    }
+
+    public void printEjb(String name, PrintWriter out, HttpSession session)
+        throws Exception {
+
+        SystemInstance system = SystemInstance.get();
+        ContainerSystem containerSystem = system.getComponent(ContainerSystem.class);
+
+        String id = (name.startsWith("/")) ? name.substring(1, name.length()) : name;
+
+        org.apache.openejb.DeploymentInfo ejb = containerSystem.getDeploymentInfo(id);
+
+
+        if (ejb == null) {
+            out.print("No such EJB: " + id);
+            return;
+        }
+        String type = null;
+
+        switch (ejb.getComponentType()) {
+            case CMP_ENTITY :
+                type = "EntityBean with Container-Managed Persistence";
+                break;
+            case BMP_ENTITY :
+                type = "EntityBean with Bean-Managed Persistence";
+                break;
+            case STATEFUL :
+                type = "Stateful SessionBean";
+                break;
+            case STATELESS :
+                type = "Stateless SessionBean";
+                break;
+            default :
+                type = "Unkown Bean Type";
+                break;
+        }
+        out.print("<b>" + type + "</b><br>");
+        out.print("<table>");
+        printRow("JNDI Name", name, out);
+
+
+        boolean hasLocal = ejb.getLocalInterface() != null;
+        boolean hasRemote = ejb.getRemoteInterface() != null;
+
+        String remoteInterfaceClassRef;
+        String homeInterfaceClassRef;
+        if (hasRemote){
+            remoteInterfaceClassRef = getClassRef(ejb.getRemoteInterface());
+            homeInterfaceClassRef = getClassRef(ejb.getHomeInterface());
+        } else {
+            remoteInterfaceClassRef = "none";
+            homeInterfaceClassRef = "none";
+        }
+
+        printRow("Remote Interface",remoteInterfaceClassRef,out);
+        printRow("Home Interface", homeInterfaceClassRef, out);
+
+        if (hasLocal){
+            String clzz = getClassRef(ejb.getLocalInterface());
+            printRow("Local Interface",clzz,out);
+            clzz = getClassRef(ejb.getLocalHomeInterface());
+            printRow("LocalHome Interface",clzz,out);
+        }
+
+        printRow("Bean Class", getClassRef(ejb.getBeanClass()), out);
+
+        if (ejb.getComponentType() == BeanType.BMP_ENTITY
+            || ejb.getComponentType() == BeanType.CMP_ENTITY) {
+            printRow("Primary Key", getClassRef(ejb.getPrimaryKeyClass()), out);
+        }
+
+        out.print("</table>");
+        out.print("<br><br><b>Actions:</b><br>");
+        out.print("<table>");
+
+        // Browse JNDI with this ejb
+        //javax.servlet.http.HttpSession session = this.session;
+        HashMap objects = (HashMap) session.getAttribute("objects");
+        if (objects == null) {
+            objects = new HashMap();
+            session.setAttribute("objects", objects);
+        }
+
+        InitialContext ctx;
+        Properties p = new Properties();
+
+        p.put(
+            Context.INITIAL_CONTEXT_FACTORY,
+            "org.apache.openejb.client.LocalInitialContextFactory");
+        p.put("openejb.loader", "embed");
+
+        ctx = new InitialContext(p);
+
+
+        if (hasRemote){
+            Object obj = ctx.lookup(name);
+            String objID = ejb.getHomeInterface().getName() + "@" + obj.hashCode();
+            objects.put(objID, obj);
+            String invokerURL =
+                "<a href='"
+                    + INVOKE_OBJ
+                    + "?obj="
+                    + objID
+                    + "'>Invoke this EJB's home interface</a>";
+            printRow(pepperImg, invokerURL, out);
+        }
+        if (hasLocal){
+            Object obj = ctx.lookup(name+"Local");
+            String objID = ejb.getLocalHomeInterface().getName() + "@" + obj.hashCode();
+            objects.put(objID, obj);
+            String invokerURL =
+                "<a href='"
+                    + INVOKE_OBJ
+                    + "?obj="
+                    + objID
+                    + "'>Invoke this EJB's local home interface</a>";
+            printRow(pepperImg, invokerURL, out);
+        }
+
+        Context enc = ((org.apache.openejb.core.CoreDeploymentInfo) ejb).getJndiEnc();
+        String ctxID = "enc" + enc.hashCode();
+        session.setAttribute(ctxID, enc);
+        String jndiURL =
+            "<a href='"
+                + VIEW_JNDI
+                + "?ctx="
+                + ctxID
+                + "'>Browse this EJB's private JNDI namespace</a>";
+        printRow(pepperImg, jndiURL, out);
+        out.print("</table>");
+
+    }
+
+    protected void printRow(String col1, String col2, PrintWriter out)
+        throws IOException {
+        out.print("<tr><td><font size='2'>");
+        out.print(col1);
+        out.print("</font></td><td><font size='2'>");
+        out.print(col2);
+        out.print("</font></td></tr>");
+    }
+
+    public String getClassRef(Class clazz) throws Exception {
+        String name = clazz.getName();
+        return "<a href='"
+            + VIEW_CLASS
+            + "?class="
+            + name
+            + "'>"
+            + name
+            + "</a>";
+    }
+
+    public String getShortClassRef(Class clazz) throws Exception {
+        if (clazz.isPrimitive()) {
+            return "<font color='gray'>" + clazz.getName() + "</font>";
+        } else if (clazz.isArray() && clazz.getComponentType().isPrimitive()) {
+            return "<font color='gray'>"
+                + clazz.getComponentType()
+                + "[]</font>";
+        } else if (clazz.isArray()) {
+            String name = clazz.getComponentType().getName();
+            int dot = name.lastIndexOf(".") + 1;
+            String shortName = name.substring(dot, name.length());
+            return "<a href='"
+                + VIEW_CLASS
+                + "?class="
+                + name
+                + "'>"
+                + shortName
+                + "[]</a>";
+        } else {
+            String name = clazz.getName();
+            int dot = name.lastIndexOf(".") + 1;
+            String shortName = name.substring(dot, name.length());
+            return "<a href='"
+                + VIEW_CLASS
+                + "?class="
+                + name
+                + "'>"
+                + shortName
+                + "</a>";
+        }
+    }
+}

Propchange: openejb/trunk/openejb3/server/openejb-webadmin/src/main/java/org/apache/openejb/webadmin/clienttools/ViewEjbBean.java
------------------------------------------------------------------------------
    svn:executable = *

Added: openejb/trunk/openejb3/server/openejb-webadmin/src/main/java/org/apache/openejb/webadmin/clienttools/ViewJndiBean.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/server/openejb-webadmin/src/main/java/org/apache/openejb/webadmin/clienttools/ViewJndiBean.java?view=auto&rev=562334
==============================================================================
--- openejb/trunk/openejb3/server/openejb-webadmin/src/main/java/org/apache/openejb/webadmin/clienttools/ViewJndiBean.java (added)
+++ openejb/trunk/openejb3/server/openejb-webadmin/src/main/java/org/apache/openejb/webadmin/clienttools/ViewJndiBean.java Thu Aug  2 22:21:56 2007
@@ -0,0 +1,260 @@
+/**
+ * Redistribution and use of this software and associated documentation
+ * ("Software"), with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain copyright
+ *    statements and notices.  Redistributions must also contain a
+ *    copy of this document.
+ *
+ * 2. Redistributions in binary form must reproduce the
+ *    above copyright notice, this list of conditions and the
+ *    following disclaimer in the documentation and/or other
+ *    materials provided with the distribution.
+ *
+ * 3. The name "OpenEJB" must not be used to endorse or promote
+ *    products derived from this Software without prior written
+ *    permission of The OpenEJB Group.  For written permission,
+ *    please contact dev@openejb.org.
+ *
+ * 4. Products derived from this Software may not be called "OpenEJB"
+ *    nor may "OpenEJB" appear in their names without prior written
+ *    permission of The OpenEJB Group. OpenEJB is a registered
+ *    trademark of The OpenEJB Group.
+ *
+ * 5. Due credit should be given to the OpenEJB Project
+ *    (http://www.openejb.org/).
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE OPENEJB GROUP AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
+ * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
+ * THE OPENEJB GROUP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Copyright 2001 (C) The OpenEJB Group. All Rights Reserved.
+ *
+ * $Id: ViewJndiBean.java 446035 2006-02-22 22:05:03Z dblevins $
+ */
+package org.apache.openejb.webadmin.clienttools;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.Properties;
+
+import javax.ejb.EJBHome;
+import javax.ejb.EJBLocalHome;
+import javax.ejb.Stateless;
+import javax.ejb.RemoteHome;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NameClassPair;
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+
+import org.apache.openejb.webadmin.HttpRequest;
+import org.apache.openejb.webadmin.HttpResponse;
+import org.apache.openejb.webadmin.HttpSession;
+import org.apache.openejb.webadmin.WebAdminBean;
+import org.apache.openejb.webadmin.HttpHome;
+
+/**
+ * @author <a href="mailto:david.blevins@visi.com">David Blevins</a>
+ */
+@Stateless(name = "ClientTools/InvokeObject")
+@RemoteHome(HttpHome.class)
+public class ViewJndiBean extends WebAdminBean  implements Constants {
+
+
+    private HttpSession session;
+    private String selected;
+    private String ctxID;
+    private Context ctx;
+
+    public void preProcess(HttpRequest request, HttpResponse response)
+        throws IOException {
+        session = request.getSession(true);
+        selected = request.getQueryParameter("selected");
+        if (selected == null) {
+            selected = "";
+        }
+        ctxID = request.getQueryParameter("ctx");
+        ctx = null;
+    }
+
+    public void postProcess(HttpRequest request, HttpResponse response)
+        throws IOException {
+    }
+
+    public void writeHtmlTitle(PrintWriter out) throws IOException {
+        out.write("Client Tools -- JNDI Viewer");
+    }
+
+    public void writePageTitle(PrintWriter out) throws IOException {
+        if (ctxID == null){
+            out.print("JNDI Environment Naming Context (ENC)");
+        } else if (ctxID.startsWith("enc")) {
+                out.print("OpenEJB Global JNDI Namespace");
+        }
+    }
+
+    public void writeBody(PrintWriter out) throws IOException {
+
+        if (ctxID == null) {
+            Properties p = new Properties();
+            p.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.LocalInitialContextFactory");
+            p.put("openejb.loader", "embed");
+            try {
+                ctx = new InitialContext( p );
+            } catch (NamingException e) {
+                // TODO Auto-generated catch block
+                e.printStackTrace();
+            }
+            ctxID = null;
+            out.print("<b>OpenEJB Global JNDI Namespace</b><br><br>");
+        } else {
+            ctx = (Context)session.getAttribute(ctxID);
+            if (ctxID.startsWith("enc")) {
+                out.print("This is the private namespace of an Enterprise JavaBean.");
+                out.print("<BR><BR>");
+            }
+        }
+
+        Node root = new RootNode();
+        try {
+            buildNode(root,ctx);
+
+            printNodes(root, out, "", selected);
+        } catch (Exception e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace(out);
+        }
+    }
+
+    class Node {
+        static final int CONTEXT = 1;
+        static final int BEAN = 2;
+        static final int OTHER = 3;
+        Node parent;
+        Node[] children = new Node[0];
+        String name;
+        int type = 0;
+
+        public String getID(){
+            if (parent instanceof RootNode) {
+                return name;
+            } else {
+                return parent.getID()+"/"+name;
+            }
+        }
+        public String getName(){
+            return name;
+        }
+        public int getType(){
+            return type;
+        }
+        public void addChild(Node child){
+            int len = children.length;
+            Node[] newChildren = new Node[len+1];
+            System.arraycopy(children,0,newChildren,0,len);
+            newChildren[len] = child;
+            children = newChildren;
+            child.parent = this;
+        }
+    }
+
+    class RootNode extends Node{
+        public String getID() {
+            return "";
+        }
+        public String getName() {
+            return "";
+        }
+        public int getType() {
+            return Node.CONTEXT;
+        }
+    }
+
+    public void buildNode(Node parent, Context ctx) throws Exception{
+        if (false) throw new NullPointerException();
+        NamingEnumeration enumeration = ctx.list( "" );
+        while (enumeration.hasMoreElements()){
+            NameClassPair pair = (NameClassPair)enumeration.next();
+            Node node = new Node();
+            parent.addChild(node);
+            node.name = pair.getName();
+
+            Object obj = ctx.lookup(node.getName());
+            if ( obj instanceof Context ){
+                node.type = Node.CONTEXT;
+                buildNode(node,(Context)obj);
+            } else if (obj instanceof EJBHome || obj instanceof EJBLocalHome) {
+                node.type = Node.BEAN;
+            } else {
+                node.type = Node.OTHER;
+            }
+        }
+    }
+
+
+
+    public void printNodes(Node node, PrintWriter out, String tabs, String selected) throws Exception {
+        switch (node.getType()) {
+            case Node.CONTEXT: printContextNode(node,out,tabs,selected); break;
+           case Node.BEAN: printBeanNode(node,out,tabs,selected); break;
+          default: printOtherNode(node,out,tabs,selected); break;
+        }
+
+    }
+
+    public void printContextNode(Node node, PrintWriter out, String tabs, String selected) throws Exception {
+        String id = node.getID();
+        if ( selected.startsWith(id) ) {
+            if (ctxID != null) {
+                out.print(tabs+"<a href='"+VIEW_JNDI+"?ctx="+ctxID+"&selected="+id+"'>"+openImg+"&nbsp;&nbsp;"+node.getName()+"</a><br>");
+            } else {
+                out.print(tabs+"<a href='"+VIEW_JNDI+"?selected="+id+"'>"+openImg+"&nbsp;&nbsp;"+node.getName()+"</a><br>");
+            }
+            for (int i=0; i < node.children.length; i++){
+                Node child = node.children[i];
+                printNodes(child,out,tabs+"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;",selected);
+            }
+        } else {
+            if (ctxID != null) {
+                out.print(tabs+"<a href='"+VIEW_JNDI+"?ctx="+ctxID+"&selected="+id+"'>"+closedImg+"&nbsp;&nbsp;"+node.getName()+"</a><br>");
+            } else {
+                out.print(tabs+"<a href='"+VIEW_JNDI+"?selected="+id+"'>"+closedImg+"&nbsp;&nbsp;"+node.getName()+"</a><br>");
+            }
+        }
+    }
+
+    public void printBeanNode(Node node, PrintWriter out, String tabs, String selected) throws Exception {
+        String id = node.getID();
+//        if (ctxID != null && ctxID.startsWith("enc")) {
+            // HACK!
+            try{
+                Object ejb = ctx.lookup(id);
+                Object handler = org.apache.openejb.util.proxy.ProxyManager.getInvocationHandler(ejb);
+                Object deploymentID = ((org.apache.openejb.core.ivm.BaseEjbProxyHandler)handler).deploymentID;
+                out.print(tabs+"<a href='"+VIEW_EJB+"?ejb="+deploymentID+"'>"+ejbImg+"&nbsp;&nbsp;"+node.getName()+"</a><br>");
+            } catch (Exception e){
+                out.print(tabs+ejbImg+"&nbsp;&nbsp;"+node.getName()+"<br>");
+            }
+//        } else {
+//            out.print(tabs+"<a href='"+VIEW_EJB+"?ejb="+id+"'>"+ejbImg+"&nbsp;&nbsp;"+node.getName()+"</a><br>");
+//        }
+    }
+
+    public void printOtherNode(Node node, PrintWriter out, String tabs, String selected) throws Exception {
+        String id = node.getID();
+        Object obj = ctx.lookup(id);
+        String clazz = obj.getClass().getName();
+        out.print(tabs+"<a href='"+VIEW_CLASS+"?class="+clazz+"'>"+javaImg+"&nbsp;&nbsp;"+node.getName()+"</a><br>");
+    }
+}

Propchange: openejb/trunk/openejb3/server/openejb-webadmin/src/main/java/org/apache/openejb/webadmin/clienttools/ViewJndiBean.java
------------------------------------------------------------------------------
    svn:executable = *

Added: openejb/trunk/openejb3/server/openejb-webadmin/src/main/java/org/apache/openejb/webadmin/httpd/DefaultHttpBean.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/server/openejb-webadmin/src/main/java/org/apache/openejb/webadmin/httpd/DefaultHttpBean.java?view=auto&rev=562334
==============================================================================
--- openejb/trunk/openejb3/server/openejb-webadmin/src/main/java/org/apache/openejb/webadmin/httpd/DefaultHttpBean.java (added)
+++ openejb/trunk/openejb3/server/openejb-webadmin/src/main/java/org/apache/openejb/webadmin/httpd/DefaultHttpBean.java Thu Aug  2 22:21:56 2007
@@ -0,0 +1,257 @@
+/** 
+ * Redistribution and use of this software and associated documentation
+ * ("Software"), with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain copyright
+ *    statements and notices.  Redistributions must also contain a
+ *    copy of this document.
+ *
+ * 2. Redistributions in binary form must reproduce the
+ *    above copyright notice, this list of conditions and the
+ *    following disclaimer in the documentation and/or other
+ *    materials provided with the distribution.
+ *
+ * 3. The name "OpenEJB" must not be used to endorse or promote
+ *    products derived from this Software without prior written
+ *    permission of The OpenEJB Group.  For written permission,
+ *    please contact dev@openejb.org.
+ *
+ * 4. Products derived from this Software may not be called "OpenEJB"
+ *    nor may "OpenEJB" appear in their names without prior written
+ *    permission of The OpenEJB Group. OpenEJB is a registered
+ *    trademark of The OpenEJB Group.
+ *
+ * 5. Due credit should be given to the OpenEJB Project
+ *    (http://www.openejb.org/).
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE OPENEJB GROUP AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
+ * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
+ * THE OPENEJB GROUP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Copyright 2001 (C) The OpenEJB Group. All Rights Reserved.
+ *
+ * $Id: DefaultHttpBean.java 445536 2005-07-09 08:51:00Z dblevins $
+ */
+package org.apache.openejb.webadmin.httpd;
+
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLConnection;
+import java.util.ArrayList;
+import java.util.StringTokenizer;
+
+import javax.ejb.SessionContext;
+import javax.ejb.Stateless;
+import javax.ejb.RemoteHome;
+
+import org.apache.openejb.webadmin.HttpBean;
+import org.apache.openejb.webadmin.HttpRequest;
+import org.apache.openejb.webadmin.HttpResponse;
+import org.apache.openejb.webadmin.HttpHome;
+import org.apache.openejb.loader.SystemInstance;
+
+/** This is a webadmin bean which has default functionality such as genderating
+ * error pages and setting page content.
+ * @author <a href="mailto:david.blevins@visi.com">David Blevins</a>
+ */
+@Stateless(name = "httpd/DefaultBean")
+@RemoteHome(HttpHome.class)
+public class DefaultHttpBean implements HttpBean {
+
+    /** The path in which to look for files. */
+    private static final URL[] PATH = getSearchPath();
+    
+    /** the ejb session context */
+	private SessionContext context;
+
+    
+    private static URL[] getSearchPath(){
+        ArrayList path = new ArrayList();
+
+        try {
+            //OpenEJB Home and Base folders
+            URL base = SystemInstance.get().getBase().getDirectory().toURL();
+            URL home = SystemInstance.get().getHome().getDirectory().toURL();
+
+            ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+
+            if (!base.sameFile(home)) {
+                path.add(new URL(base, "htdocs/"));
+            }
+            path.add(new URL(home, "htdocs/"));
+            path.add(classLoader.getResource("/htdocs/"));
+            path.add(classLoader.getResource("/openejb/webadmin/"));
+        } catch (Exception e) {
+            // TODO: 1: We should never get an exception here
+            e.printStackTrace();
+        }
+
+        return (URL[]) path.toArray(new URL[0]);
+    }
+
+	/** Creates a new instance */
+	public void ejbCreate() {}
+
+	/** the main processing part of the this bean
+	 * @param request the http request object
+	 * @param response the http response object
+	 * @throws IOException if an exception is thrown
+	 */
+	public void onMessage(HttpRequest request, HttpResponse response) throws java.io.IOException {
+        InputStream in = null;  
+        OutputStream out = null;
+		// Internationalize this
+		try {
+			String file = request.getURI().getFile();
+			String ext = (file.indexOf('.') == -1) ? null : file.substring(file.indexOf('.'));
+
+			if (ext != null) {
+				//resolve the content type
+				if (ext.equalsIgnoreCase(".gif")) {
+					response.setContentType("image/gif");
+				} else if (ext.equalsIgnoreCase(".jpeg") || ext.equalsIgnoreCase(".jpg")) {
+					response.setContentType("image/jpeg");
+				} else if (ext.equalsIgnoreCase(".png")) {
+					response.setContentType("image/png");
+				} else if (ext.equalsIgnoreCase(".css")) {
+					response.setContentType("text/css");
+				} else if (ext.equalsIgnoreCase(".js")) {
+					response.setContentType("text/javascript");
+				} else if (ext.equalsIgnoreCase(".txt")) {
+					response.setContentType("text/plain");
+				} else if (ext.equalsIgnoreCase(".java")) {
+					response.setContentType("text/plain");
+				} else if (ext.equalsIgnoreCase(".xml")) {
+					response.setContentType("text/plain");
+				} else if (ext.equalsIgnoreCase(".zip")) {
+					response.setContentType("application/zip");
+				}
+			}
+
+            
+            
+			URLConnection resource = findResource(request.getURI().getFile());  
+            HttpResponseImpl res = (HttpResponseImpl)response;
+            res.setContent(resource);
+
+        } catch (java.io.FileNotFoundException e) {
+			do404(request, response);
+
+		} catch (java.io.IOException e) {
+			do500(request, response, e.getMessage());
+		} finally {
+            if (in != null) in.close();
+        }
+	}
+
+    private URLConnection findResource(String fileName) throws FileNotFoundException, IOException{
+        if (fileName.startsWith("/")){
+            fileName = fileName.substring(1);
+        }
+        
+        for (int i = 0; i < PATH.length; i++) {
+            try {
+                URL base = PATH[i];
+                URL resource = new URL(base, fileName);
+                URLConnection conn = resource.openConnection();
+                if (resource.openConnection().getContentLength() > 0){
+                    return conn;
+                }
+            } catch (MalformedURLException e) {
+            } catch (FileNotFoundException e) {
+            }
+        }
+        throw new FileNotFoundException("Cannot locate resource: "+fileName);
+    }
+	/** Creates a "Page not found" error screen
+	 * @param request the HTTP request object
+	 * @param response the HTTP response object
+	 */
+	public void do404(HttpRequest request, HttpResponse response) {
+		response.reset(404, "Object not found.");
+		java.io.PrintWriter body = response.getPrintWriter();
+
+		body.println("<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">");
+		body.println("<HTML><HEAD>");
+		body.println("<TITLE>404 Not Found</TITLE>");
+		body.println("</HEAD><BODY>");
+		body.println("<H1>Not Found</H1>");
+		body.println(
+			"The requested URL <font color=\"red\">"
+				+ request.getURI().getFile()
+				+ "</font> was not found on this server.<P>");
+		body.println("<HR>");
+		body.println("<ADDRESS>" + response.getServerName() + "</ADDRESS>");
+		body.println("</BODY></HTML>");
+	}
+
+	/** Creates and "Internal Server Error" page
+	 * @param request the HTTP request object
+	 * @param response the HTTP response object
+	 * @param message the message to be sent back to the browser
+	 */
+	public void do500(HttpRequest request, HttpResponse response, String message) {
+		response.reset(500, "Internal Server Error.");
+		java.io.PrintWriter body = response.getPrintWriter();
+		body.println("<html>");
+		body.println("<body>");
+		body.println("<h3>Internal Server Error</h3>");
+		body.println("<br><br>");
+
+		if (message != null) {
+			StringTokenizer msg = new StringTokenizer(message, "\n\r");
+			while (msg.hasMoreTokens()) {
+				body.print(msg.nextToken());
+				body.println("<br>");
+			}
+		}
+
+		body.println("</body>");
+		body.println("</html>");
+	}
+
+	/** called on a stateful sessionbean after the bean is
+	 * deserialized from storage and put back into use.      
+	 * @throws javax.ejb.EJBException if an exeption is thrown
+	 * @throws java.rmi.RemoteException if an exception is thrown
+	 */
+	public void ejbActivate() throws javax.ejb.EJBException, java.rmi.RemoteException {}
+
+	/** called on a stateful sessionbean before the bean is 
+	 * removed from memory and serialized to a temporary store.  
+	 * This method is never called on a stateless sessionbean
+	 * @throws javax.ejb.EJBException if an exception is thrown
+	 * @throws java.rmi.RemoteException if an exception is thrown
+	 */
+	public void ejbPassivate() throws javax.ejb.EJBException, java.rmi.RemoteException {}
+
+	/** called by the ejb container when this bean is about to be garbage collected
+	 * @throws javax.ejb.EJBException if an exception is thrown
+	 * @throws java.rmi.RemoteException if an exception is thrown
+	 */
+	public void ejbRemove() throws javax.ejb.EJBException, java.rmi.RemoteException {}
+
+	/** sets the session context for this bean
+	 * @param sessionContext the session context to be set
+	 * @throws javax.ejb.EJBException if an exception is thrown
+	 * @throws java.rmi.RemoteException if an exception is thrown
+	 */
+	public void setSessionContext(javax.ejb.SessionContext sessionContext)
+		throws javax.ejb.EJBException, java.rmi.RemoteException {
+		this.context = sessionContext;
+	}
+}

Propchange: openejb/trunk/openejb3/server/openejb-webadmin/src/main/java/org/apache/openejb/webadmin/httpd/DefaultHttpBean.java
------------------------------------------------------------------------------
    svn:executable = *