Thread: [Ejtools-cvs] CVS: applications/jndi.browser/src/main/net/sourceforge/ejtools/jndibrowser/model/ejb
Brought to you by:
letiemble
From: Laurent E. <let...@us...> - 2002-04-22 17:39:07
|
Update of /cvsroot/ejtools/applications/jndi.browser/src/main/net/sourceforge/ejtools/jndibrowser/model/ejb In directory usw-pr-cvs1:/tmp/cvs-serv29020/jndi.browser/src/main/net/sourceforge/ejtools/jndibrowser/model/ejb Added Files: EJBHomeProxy.java EJBObjectProxy.java Log Message: Initial Import --- NEW FILE: EJBHomeProxy.java --- /* * EJTools, the Enterprise Java Tools * * Distributable under LGPL license. * See terms of license at www.gnu.org. */ package net.sourceforge.ejtools.jndibrowser.model.ejb; // Standard Imports import java.awt.Component; import java.beans.BeanInfo; import java.beans.Introspector; import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; import java.lang.reflect.Proxy; import java.util.Collection; import java.util.Iterator; import javax.ejb.EJBHome; import javax.rmi.PortableRemoteObject; // Other Imports //import com.dreambean.awt.GenericCustomizer; import net.sourceforge.ejtools.awt.GenericCustomizer; import net.sourceforge.ejtools.jndibrowser.model.JNDIEntry; /** *Description of the Class * * @author letiembl * @created 13 décembre 2001 */ public class EJBHomeProxy extends JNDIEntry implements InvocationHandler { /**Description of the Field */ protected Class homeClass; /**Description of the Field */ protected BeanInfo info; protected BeanInfo proxyInfo; /**Description of the Field */ protected EJBHome home; /** *Sets the home attribute of the EJBean object * * @param o Description of Parameter * @exception Exception Description of Exception */ public EJBHomeProxy(Object o) throws Exception { home = (EJBHome) PortableRemoteObject.narrow(o, EJBHome.class); Class[] intf = home.getClass().getInterfaces(); for (int i = 0; i < intf.length; i++) { if (EJBHome.class.isAssignableFrom(intf[i])) { homeClass = intf[i]; } } this.info = Introspector.getBeanInfo(this.getClass()); this.proxyInfo = Introspector.getBeanInfo(this.homeClass); System.out.println("BeanInfo " +info ); System.out.println("BeanInfo " +proxyInfo ); this.className = homeClass.getName(); } /** *Gets the component attribute of the EJBHomeProxy object * * @return The component value */ public Component getComponent() { if (c == null) { try { c = new GenericCustomizer(Proxy.newProxyInstance(homeClass.getClassLoader(), new Class[]{BeanInfo.class, homeClass}, this)); } catch (Exception e) { e.printStackTrace(); } } return (Component) c; } /** *Description of the Method * * @param proxy Description of Parameter * @param method Description of Parameter * @param args Description of Parameter * @return Description of the Returned Value * @exception Throwable Description of Exception */ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { if (method.getDeclaringClass().equals(BeanInfo.class)) { if (method.getName().startsWith("getIcon")){ return method.invoke(info, args); }else{ return method.invoke(proxyInfo, args); } } else if (method.getDeclaringClass().equals(Object.class)) { return method.invoke(this, args); } else { Iterator iterator = iterator(); while (iterator.hasNext()) { remove(iterator.next()); } Object result = method.invoke(home, args); if (result instanceof Collection) { Iterator enum = ((Collection) result).iterator(); while (enum.hasNext()) { add(new EJBObjectProxy(enum.next(), homeClass.getClassLoader())); } } else { add(new EJBObjectProxy(result, homeClass.getClassLoader())); } return null; } } /* * public String toString() * { * return homeClass.getName().substring(homeClass.getName().lastIndexOf(".") + 1); * } */ } --- NEW FILE: EJBObjectProxy.java --- /* * EJTools, the Enterprise Java Tools * * Distributable under LGPL license. * See terms of license at www.gnu.org. */ package net.sourceforge.ejtools.jndibrowser.model.ejb; // Standard Imports import java.awt.Component; import java.beans.BeanInfo; import java.beans.Customizer; import java.beans.Introspector; import java.beans.PropertyChangeListener; import java.beans.PropertyChangeSupport; import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; import java.lang.reflect.Proxy; import java.util.Collection; import javax.ejb.EJBObject; // Other Imports //import com.dreambean.awt.GenericCustomizer; import net.sourceforge.ejtools.awt.GenericCustomizer; import net.sourceforge.ejtools.jndibrowser.model.JNDIEntry; /** * @author Rickard Oberg (ri...@dr...) * @created 2 janvier 2002 * @see <related> * @version $Revision: 1.1 $ */ public class EJBObjectProxy extends JNDIEntry implements InvocationHandler { /** Description of the Field */ BeanInfo info; /** Description of the Field */ BeanInfo proxyInfo; /** Description of the Field */ Object obj; /** Description of the Field */ Customizer c; /** Description of the Field */ Class remote; /** Description of the Field */ String desc; /** Description of the Field */ Object proxy; /** Description of the Field */ PropertyChangeSupport ps; /** *Constructor for the EJBObjectProxy object * * @param obj Description of Parameter * @param cl Description of Parameter * @exception Exception Description of Exception */ public EJBObjectProxy(Object obj, ClassLoader cl) throws Exception { this.obj = obj; Class[] intf = obj.getClass().getInterfaces(); for (int i = 0; i < intf.length; i++) { if (EJBObject.class.isAssignableFrom(intf[i])) { remote = intf[i]; } } this.info = Introspector.getBeanInfo(this.getClass()); this.proxyInfo = Introspector.getBeanInfo(this.remote); proxy = Proxy.newProxyInstance(cl, new Class[]{BeanInfo.class, remote, PropertyChanger.class}, this); ps = new PropertyChangeSupport(proxy); } /** *Gets the component attribute of the EJBObjectProxy object * * @return The component value */ public Component getComponent() { if (c == null) { c = new GenericCustomizer(proxy); } return (Component) c; } /** *Description of the Method * * @param proxy Description of Parameter * @param method Description of Parameter * @param args Description of Parameter * @return Description of the Returned Value * @exception Throwable Description of Exception */ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { System.out.println("Invoke " + method); if (method.getDeclaringClass().equals(BeanInfo.class)) { System.out.println("Invoke " + method.getName()); if (method.getName().equals("getIcon")){ return method.invoke(info, args); }else{ return method.invoke(proxyInfo, args); } } else if (method.getDeclaringClass().equals(Object.class)) { return method.invoke(this, args); } else if (method.getDeclaringClass().equals(PropertyChanger.class)) { if (method.getName().startsWith("add")) { ps.addPropertyChangeListener((PropertyChangeListener) args[0]); } else { ps.removePropertyChangeListener((PropertyChangeListener) args[0]); } return null; } else { try { return method.invoke(obj, args); } finally { if (!(method.getName().startsWith("get") || method.getName().startsWith("is"))) { ps.firePropertyChange(null, null, null); } } } } /** *Description of the Method * * @return Description of the Returned Value */ public String toString() { if (desc == null) { /* * try * { * Method m = EJBObject.class.getMethod("getPrimaryKey", new Class[0]); * desc = m.invoke(obj, new Object[0]).toString(); * } * catch (Exception e) * { */ // desc = remote.getName().substring(remote.getName().lastIndexOf(".") + 1); desc = remote.toString(); /* * } */ } return desc; } } |