Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/**
* 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 [email protected].
*
* 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 David Blevins
*/
@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("Object: ");
out.print(tab+inv.objID+" [change]
");
// 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("No object have been created ");
out.print("
");
}
}
/**
* 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("Method: ");
out.print(tab+formatMethod(inv.method)+" [change]
");
// 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("Pick a method to invoke ");
//out.print("Methods: ");
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("
");
Method[] methods = clazz.getMethods();
for (int i=0; i < methods.length; i++){
Method m = methods[i];
if (Modifier.isPublic(m.getModifiers())){
out.print("