Package java.lang.reflect

Examples of java.lang.reflect.Proxy


            localObj = (EJBLocalObjectInvocationHandlerDelegate) Proxy.getInvocationHandler(ejbRef);
           
        } catch(IllegalArgumentException iae) {

            Proxy proxy;

            if( ejbRef instanceof OptionalLocalInterfaceProvider ) {

                try {
View Full Code Here


    @Test
    public void testCustomTransactionManager() throws Exception
    {
        TransactionManager transactionManager = muleContext.getTransactionManager();
        assertTrue(transactionManager instanceof Proxy);
        Proxy proxy = (Proxy) transactionManager;
        TestTransactionManagerFactory.InternalInvocationHandler ihandler =
                (TestTransactionManagerFactory.InternalInvocationHandler) Proxy.getInvocationHandler(proxy);
        TestTransactionManagerFactory factory = ihandler.getParent();
        Map<?, ?> properties = factory.getEnvironment();
        assertEquals(properties.size(), 2);
View Full Code Here

     * @see #closeConnection(Connection)
     */
    protected void cleanupConnection(Connection conn) {
        if (conn != null) {
            if (conn instanceof Proxy) {
                Proxy connProxy = (Proxy)conn;
               
                InvocationHandler invocationHandler =
                    Proxy.getInvocationHandler(connProxy);
                if (invocationHandler instanceof AttributeRestoringConnectionInvocationHandler) {
                    AttributeRestoringConnectionInvocationHandler connHandler =
View Full Code Here

            Class nonpublicInterface =
                fnnLoader1.loadClass("NonpublicInterface");
            Class publicInterface =
                fnnLoader1.loadClass("PublicInterface");

            Proxy proxy1 = (Proxy) Proxy.newProxyInstance(parentNonpublic,
                new Class[] {nonpublicInterface, publicInterface},
                new TestInvocationHandler());
            unmarshalProxyClass(proxy1, fnnLoader1, parentNonpublic, 1, null);



            /* Case 2 */
            Class zipConstantsClass =
                Class.forName("java.util.zip.ZipConstants");
            URLClassLoader fnnLoader2 =
                new URLClassLoader(new URL[] {fnnUrl});
            Proxy proxy2 = (Proxy) Proxy.newProxyInstance(null,
                new Class[] {zipConstantsClass, Checksum.class},
                new TestInvocationHandler());
            unmarshalProxyClass(proxy2, fnnLoader2,
                                (ClassLoader) null, 2, null);



            /* Case 3 */
            Thread currentThread = Thread.currentThread();
            ClassLoader fnnLoader3 = new URLClassLoader(
                new URL[] {publicUrl, fnnUrl});
            ClassLoader newCtxLoader =
                new URLClassLoader(new URL[] {publicUrl}, fnnLoader3);
            Class publicInterface3 =
                fnnLoader3.loadClass("PublicInterface");
            ClassLoader currentCtxLoader =
                currentThread.getContextClassLoader();
            currentThread.setContextClassLoader(newCtxLoader);

            Proxy proxy3 = (Proxy) Proxy.newProxyInstance(newCtxLoader,
                new Class[] {publicInterface3},
                new TestInvocationHandler());

            unmarshalProxyClass(proxy3, fnnLoader3, fnnLoader3,
                3, new Case3Checker());

            currentThread.setContextClassLoader(currentCtxLoader);



            /* Case 4 */
            ClassLoader bothNonpublicLoader =
                new URLClassLoader(new URL[] {bothNonpublicUrl});
            Class nonpublicInterface4a =
                bothNonpublicLoader.loadClass("NonpublicInterface");
            Class nonpublicInterface4b =
                bothNonpublicLoader.loadClass("NonpublicInterface1");
            Proxy proxy4 = (Proxy) Proxy.newProxyInstance(bothNonpublicLoader,
                new Class[] {nonpublicInterface4a, nonpublicInterface4b},
                new TestInvocationHandler());

            ClassLoader nonpublicLoaderA =
                new URLClassLoader(new URL[] {nonpublicUrl});
            ClassLoader nonpublicLoaderB =
                new URLClassLoader(new URL[] {nonpublicUrl1}, nonpublicLoaderA);
            currentCtxLoader =
                currentThread.getContextClassLoader();
            currentThread.setContextClassLoader(nonpublicLoaderB);

            IllegalAccessError illegal = null;
            try {
                unmarshalProxyClass(proxy4, fnnLoader2, nonpublicLoaderB,
                                    4, null);
            } catch (IllegalAccessError e) {
                illegal = e;
            }

            if (illegal == null) {
                TestLibrary.bomb("case4: IllegalAccessError not thrown " +
                                 "when multiple nonpublic interfaces have \n" +
                                 "different class loaders");
            } else {
                System.err.println("\ncase4: IllegalAccessError correctly " +
                                   "thrown \n when trying to load proxy " +
                                   "with multiple nonpublic interfaces in \n" +
                                   "  different class loaders");
            }
            currentThread.setContextClassLoader(currentCtxLoader);



            /* Case 5*/
            ClassLoader publicLoader =
                new URLClassLoader(new URL[] {publicUrl});
            Class publicInterface5 =
                publicLoader.loadClass("PublicInterface");
            Proxy proxy5 = (Proxy) Proxy.newProxyInstance(publicLoader,
                new Class[] {publicInterface5},
                new TestInvocationHandler());

            currentCtxLoader =
                currentThread.getContextClassLoader();
            currentThread.setContextClassLoader(publicLoader);
            unmarshalProxyClass(proxy5, fnnLoader2, publicLoader, 5,
                                new Case5Checker());
            currentThread.setContextClassLoader(currentCtxLoader);



            /* Case 6 */
            ClassLoader fnnLoader6 =
                new URLClassLoader(new URL[] {fnnUrl, publicUrl});
            ClassLoader publicLoader6 =
                new URLClassLoader(new URL[] {publicUrl1}, fnnLoader6);

            Class publicInterface6a =
                publicLoader6.loadClass("PublicInterface1");
            Class publicInterface6b =
                fnnLoader6.loadClass("PublicInterface");
            Proxy proxy6 = (Proxy) Proxy.newProxyInstance(publicLoader6,
                new Class[] {publicInterface6a, publicInterface6b},
                new TestInvocationHandler());
            ClassNotFoundException cnfe = null;
            try {
                unmarshalProxyClass(proxy6, fnnLoader6, publicLoader6, 6,
View Full Code Here

        throws ClassNotFoundException, IOException,
               InstantiationException, IllegalAccessException
    {
        FnnUnmarshal fnnUnmarshal = (FnnUnmarshal)
                fnnLoader.loadClass("FnnClass").newInstance();
        Proxy unmarshalled = (Proxy)
            fnnUnmarshal.unmarshal(new MarshalledObject(proxy));
        ClassLoader unmarshalledLoader =
            unmarshalled.getClass().getClassLoader();

        if (checker != null) {
            checker.checkLoad(unmarshalled, expectedLoader);
        } else {
            if (unmarshalledLoader != expectedLoader) {
View Full Code Here

     * @see #closeConnection(Connection)
     */
    protected void cleanupConnection(Connection conn) {
        if (conn != null) {
            if (conn instanceof Proxy) {
                Proxy connProxy = (Proxy)conn;
               
                InvocationHandler invocationHandler =
                    Proxy.getInvocationHandler(connProxy);
                if (invocationHandler instanceof AttributeRestoringConnectionInvocationHandler) {
                    AttributeRestoringConnectionInvocationHandler connHandler =
View Full Code Here

                            }
                            return null;
                        }
                    });

                Proxy proxy = (Proxy) proxyField.get(managedBean);

                InterceptorInvoker invoker = (InterceptorInvoker) Proxy.getInvocationHandler(proxy);

                managedBeanInstance = invoker.getTargetInstance();
View Full Code Here

      Fake() {
        super(null);
      }
    }

    Proxy fake = new Proxy(new InvocationHandler() {
      public Object invoke(Object proxy, Method method, Object[] args)
          throws Throwable {
        return null;
      }
    }) {
    };

    assertTrue("Does not believe its a Proxy class ", Proxy
        .isProxyClass(proxy));
    assertTrue("Proxy subclasses do not count ", !Proxy
        .isProxyClass(Fake.class));
    assertTrue("Is not a runtime generated Proxy class ", !Proxy
        .isProxyClass(fake.getClass()));
  }
View Full Code Here

      Fake() {
        super(null);
      }
    }

    Proxy fake = new Proxy(new InvocationHandler() {
      public Object invoke(Object proxy, Method method, Object[] args)
          throws Throwable {
        return null;
      }
    }) {
    };

    assertTrue("Does not believe its a Proxy class ", Proxy
        .isProxyClass(proxy));
    assertTrue("Proxy subclasses do not count ", !Proxy
        .isProxyClass(Fake.class));
    assertTrue("Is not a runtime generated Proxy class ", !Proxy
        .isProxyClass(fake.getClass()));
  }
View Full Code Here

      Class nonpublicInterface =
    fnnLoader1.loadClass("NonpublicInterface");
      Class publicInterface =
    fnnLoader1.loadClass("PublicInterface");
     
      Proxy proxy1 = (Proxy) Proxy.newProxyInstance(parentNonpublic,
    new Class[] {nonpublicInterface, publicInterface},
    new TestInvocationHandler());
      unmarshalProxyClass(proxy1, fnnLoader1, parentNonpublic, 1, null);



      /* Case 2 */
      Class zipConstantsClass =
    Class.forName("java.util.zip.ZipConstants");
      URLClassLoader fnnLoader2 =
    new URLClassLoader(new URL[] {fnnUrl});
      Proxy proxy2 = (Proxy) Proxy.newProxyInstance(null,
    new Class[] {zipConstantsClass, Checksum.class},
    new TestInvocationHandler());
      unmarshalProxyClass(proxy2, fnnLoader2,
        (ClassLoader) null, 2, null);



      /* Case 3 */
      Thread currentThread = Thread.currentThread();
      ClassLoader fnnLoader3 = new URLClassLoader(
    new URL[] {publicUrl, fnnUrl});
      ClassLoader newCtxLoader =
    new URLClassLoader(new URL[] {publicUrl}, fnnLoader3);
      Class publicInterface3 =
    fnnLoader3.loadClass("PublicInterface");
      ClassLoader currentCtxLoader =
    currentThread.getContextClassLoader();
      currentThread.setContextClassLoader(newCtxLoader);

      Proxy proxy3 = (Proxy) Proxy.newProxyInstance(newCtxLoader,
    new Class[] {publicInterface3},
    new TestInvocationHandler());
     
      unmarshalProxyClass(proxy3, fnnLoader3, fnnLoader3,
    3, new Case3Checker());

      currentThread.setContextClassLoader(currentCtxLoader);



      /* Case 4 */
      ClassLoader bothNonpublicLoader =
    new URLClassLoader(new URL[] {bothNonpublicUrl});
      Class nonpublicInterface4a =
    bothNonpublicLoader.loadClass("NonpublicInterface");
      Class nonpublicInterface4b =
    bothNonpublicLoader.loadClass("NonpublicInterface1");
      Proxy proxy4 = (Proxy) Proxy.newProxyInstance(bothNonpublicLoader,
    new Class[] {nonpublicInterface4a, nonpublicInterface4b},
    new TestInvocationHandler());
     
      ClassLoader nonpublicLoaderA =
    new URLClassLoader(new URL[] {nonpublicUrl});
      ClassLoader nonpublicLoaderB =
    new URLClassLoader(new URL[] {nonpublicUrl1}, nonpublicLoaderA);
      currentCtxLoader =
    currentThread.getContextClassLoader();
      currentThread.setContextClassLoader(nonpublicLoaderB);

      IllegalAccessError illegal = null;
      try {
    unmarshalProxyClass(proxy4, fnnLoader2, nonpublicLoaderB,
            4, null);
      } catch (IllegalAccessError e) {
    illegal = e;
      }

      if (illegal == null) {
    TestLibrary.bomb("case4: IllegalAccessError not thrown " +
         "when multiple nonpublic interfaces have \n" +
         "different class loaders");
      } else {
    System.err.println("\ncase4: IllegalAccessError correctly " +
           "thrown \n when trying to load proxy " +
           "with multiple nonpublic interfaces in \n" +
           "  different class loaders");
      }
      currentThread.setContextClassLoader(currentCtxLoader);



      /* Case 5*/
      ClassLoader publicLoader =
    new URLClassLoader(new URL[] {publicUrl});
      Class publicInterface5 =
    publicLoader.loadClass("PublicInterface");
      Proxy proxy5 = (Proxy) Proxy.newProxyInstance(publicLoader,
    new Class[] {publicInterface5},
    new TestInvocationHandler());

      currentCtxLoader =
    currentThread.getContextClassLoader();
      currentThread.setContextClassLoader(publicLoader);
      unmarshalProxyClass(proxy5, fnnLoader2, publicLoader, 5,
        new Case5Checker());
      currentThread.setContextClassLoader(currentCtxLoader);



      /* Case 6 */
      ClassLoader fnnLoader6 =
    new URLClassLoader(new URL[] {fnnUrl, publicUrl});
      ClassLoader publicLoader6 =
    new URLClassLoader(new URL[] {publicUrl1}, fnnLoader6);

      Class publicInterface6a =
    publicLoader6.loadClass("PublicInterface1");
      Class publicInterface6b =
    fnnLoader6.loadClass("PublicInterface");
      Proxy proxy6 = (Proxy) Proxy.newProxyInstance(publicLoader6,
    new Class[] {publicInterface6a, publicInterface6b},
    new TestInvocationHandler());
      ClassNotFoundException cnfe = null;
      try {
    unmarshalProxyClass(proxy6, fnnLoader6, publicLoader6, 6,
View Full Code Here

TOP

Related Classes of java.lang.reflect.Proxy

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.