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.
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
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("