Hi, I am reading JBoss 3.2.3 and have a question about the constructor of class 
JDBCCreateBeanClassInstanceCommand.
There are follow statements in the constructor:
      beanClass = theContainer.getBeanClass();
      fieldMap = createFieldMap();
      selectorMap = createSelectorMap();
      // use proxy generator to create one implementation
      EntityBridgeInvocationHandler handler = new EntityBridgeInvocationHandler(
            theContainer,
            fieldMap,
            selectorMap,
            beanClass);
      Class[] classes = new Class[] { beanClass };
      ClassLoader classLoader = beanClass.getClassLoader();

Object o = Proxy.newProxyInstance(classLoader, classes, handler);

I don?t understand why Proxy.newProxyInstance() executes successfully. Because the 
second parameter should be an array only contains Interface type. But in fact, the 
beanClass is a class type. I have tried a simple example, which is in the same 
structure with previous statements but encountered exception, here are details: 

import java.lang.reflect.*;

interface EntityBean
{
        public void fun();
}

abstract class BusinessLogicAbstractClass implements EntityBean
{
        public abstract void abstract_fun();
}


class StandardInvocationHandler implements InvocationHandler
{
         public Object invoke( Object proxy, Method method, Object[] args)
        {
                System.out.println( "invoke "+ proxy.getClass());
                System.out.println( " Method [" + method.toString()+"]");
                return null;
        }
}

public class Main
{
        public static void main(String[] args)
        {
                Main obj = new Main();
                obj.fun();
        }

        public void fun()
        {

                Class beanClass = BusinessLogicAbstractClass.class;

System.out.println(beanClass);

                InvocationHandler ih = new StandardInvocationHandler();

                Class[] classes = new Class[] { beanClass };
                ClassLoader classLoader = beanClass.getClassLoader();

                Object o = 
(BusinessLogicAbstractClass)Proxy.newProxyInstance(classLoader, classes, ih);

                try{
                        Constructor beanProxyConstructor = 
o.getClass().getConstructor(new Class[]{InvocationHandler.class});

                        StandardInvocationHandler handler = new 
StandardInvocationHandler();

                        BusinessLogicAbstractClass bli =(BusinessLogicAbstractClass) 
(beanProxyConstructor.newInstance(new Object[]{handler}));

                        bli.fun();
                        bli.abstract_fun();
                }catch(Exception e){
                        System.out.println("exception");
                }
         }
}

I:\java>java Main
class BusinessLogicAbstractClass
Exception in thread "main" java.lang.IllegalArgumentException: 
BusinessLogicAbstractClass is not an interface
        at java.lang.reflect.Proxy.getProxyClass(Proxy.java:340)
        at java.lang.reflect.Proxy.newProxyInstance(Proxy.java:552)
        at Main.fun(Main.java:44)
        at Main.main(Main.java:29)

Could you tell me what?s wrong with the code? I think it is in the same structure with 
JDBCCreateBeanClassInstanceCommand?s.
Any help is appreciated!


View the original post : 
http://www.jboss.org/index.html?module=bb&op=viewtopic&p=3836601#3836601

Reply to the post : 
http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=3836601



-------------------------------------------------------
This SF.Net email is sponsored by: Oracle 10g
Get certified on the hottest thing ever to hit the market... Oracle 10g. 
Take an Oracle 10g class now, and we'll give you the exam FREE.
http://ads.osdn.com/?ad_id=3149&alloc_id=8166&op=click
_______________________________________________
JBoss-Development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to