Java 类net.sf.cglib.proxy.LazyLoader 实例源码

项目:jcrom-extended    文件:Mapper.java   
Object triggerLazyLoading(Object obj) throws IllegalAccessException
{
    for (Field field : ReflectionUtils.getDeclaredAndInheritedFields(obj.getClass(), false))
    {
        field.setAccessible(true);
        if (field.getName().equals("CGLIB$CALLBACK_0"))
        {
            try
            {
                return ((LazyLoader) field.get(obj)).loadObject();
            }
            catch (Exception e)
            {
                throw new JcrMappingException("Could not trigger lazy loading", e);
            }
        }
    }
    return obj;
}
项目:furnace    文件:ClassLoaderAdapterProxiedTest.java   
@Test
public void testAdaptProxiedType() throws Exception
{
   ClassLoader loader = MockService.class.getClassLoader();
   final MockService internal = new MockService();

   MockService delegate = (MockService) Enhancer.create(MockService.class, new LazyLoader()
   {
      @Override
      public Object loadObject() throws Exception
      {
         return internal;
      }
   });

   MockService adapter = ClassLoaderAdapterBuilder.callingLoader(loader).delegateLoader(loader)
            .enhance(delegate, MockService.class);

   Assert.assertNotEquals(internal.getResult(), adapter.getResult());
   Assert.assertEquals(internal.getResult().getValue(), adapter.getResult().getValue());
}
项目:furnace    文件:ClassLoaderAdapterProxiedTest.java   
@Test
public void testAdaptProxiedResult() throws Exception
{
   ClassLoader loader = MockService.class.getClassLoader();
   final MockService internal = new MockService();

   MockService delegate = (MockService) Enhancer.create(MockService.class, new LazyLoader()
   {
      @Override
      public Object loadObject() throws Exception
      {
         return internal;
      }
   });

   MockService adapter = ClassLoaderAdapterBuilder.callingLoader(loader).delegateLoader(loader)
            .enhance(delegate, MockService.class);

   Assert.assertNotEquals(internal.getResult(), adapter.getResultEnhanced());
}
项目:furnace    文件:ClassLoaderAdapterProxiedTest.java   
@Test
public void testAdaptProxiedResultReturnTypeObject() throws Exception
{
   ClassLoader loader = MockService.class.getClassLoader();
   final MockService internal = new MockService();

   MockService delegate = (MockService) Enhancer.create(MockService.class, new LazyLoader()
   {
      @Override
      public Object loadObject() throws Exception
      {
         return internal;
      }
   });

   MockService adapter = ClassLoaderAdapterBuilder.callingLoader(loader).delegateLoader(loader)
            .enhance(delegate, MockService.class);

   Assert.assertNotEquals(internal.getResult(), adapter.getResultEnhancedReturnTypeObject());
}
项目:furnace    文件:ClassLoaderAdapterProxiedTest.java   
@Test(expected = ClassCastException.class)
public void testCannotAdaptFinalResultReturnType() throws Exception
{
   ClassLoader loader = MockService.class.getClassLoader();
   final MockService internal = new MockService();

   MockService delegate = (MockService) Enhancer.create(MockService.class, new LazyLoader()
   {
      @Override
      public Object loadObject() throws Exception
      {
         return internal;
      }
   });

   MockService adapter = ClassLoaderAdapterBuilder.callingLoader(loader).delegateLoader(loader)
            .enhance(delegate, MockService.class);
   adapter.getResultFinalReturnType();
}
项目:furnace    文件:ClassLoaderAdapterProxiedTest.java   
@Test
public void testCanAdaptFinalResultReturnTypeObject() throws Exception
{
   ClassLoader loader = MockService.class.getClassLoader();
   final MockService internal = new MockService();

   MockService delegate = (MockService) Enhancer.create(MockService.class, new LazyLoader()
   {
      @Override
      public Object loadObject() throws Exception
      {
         return internal;
      }
   });

   MockService adapter = ClassLoaderAdapterBuilder.callingLoader(loader).delegateLoader(loader)
            .enhance(delegate, MockService.class);

   Assert.assertNotEquals(internal.getResultFinalReturnTypeObject(), adapter.getResultFinalReturnTypeObject());
   Assert.assertEquals(((Result) internal.getResultFinalReturnTypeObject()).getValue(),
            ((Result) adapter.getResultFinalReturnTypeObject()).getValue());
}
项目:furnace    文件:ClassLoaderAdapterProxiedTest.java   
@Test
public void testAdaptFinalResult() throws Exception
{
   ClassLoader loader = MockService.class.getClassLoader();
   final MockService internal = new MockService();

   MockService delegate = (MockService) Enhancer.create(MockService.class, new LazyLoader()
   {
      @Override
      public Object loadObject() throws Exception
      {
         return internal;
      }
   });

   MockService adapter = ClassLoaderAdapterBuilder.callingLoader(loader).delegateLoader(loader)
            .enhance(delegate, MockService.class);

   Assert.assertNotEquals(internal.getResultInterfaceFinalImpl(), adapter.getResultInterfaceFinalImpl());
   Object unwrapped = Proxies.unwrap(adapter);
   Assert.assertNotSame(adapter, unwrapped);
}
项目:furnace    文件:ClassLoaderAdapterProxiedTest.java   
@Test
public void testNullValuesAsMethodParameters() throws Exception
{
   ClassLoader loader = MockService.class.getClassLoader();
   final MockService internal = new MockService();

   MockService delegate = (MockService) Enhancer.create(MockService.class, new LazyLoader()
   {
      @Override
      public Object loadObject() throws Exception
      {
         return internal;
      }
   });
   MockService adapter = ClassLoaderAdapterBuilder.callingLoader(loader).delegateLoader(loader)
            .enhance(delegate, MockService.class);
   Assert.assertNull(internal.echo(null));
   Assert.assertNull(adapter.echo(null));
}
项目:furnace    文件:ClassLoaderAdapterProxiedTest.java   
@Test
public void testShouldNotProxyJavaNioPath() throws Exception
{
   ClassLoader loader = JavaIOFactory.class.getClassLoader();
   final JavaIOFactory internal = new JavaIOFactory();

   JavaIOFactory delegate = (JavaIOFactory) Enhancer.create(JavaIOFactory.class, new LazyLoader()
   {
      @Override
      public Object loadObject() throws Exception
      {
         return internal;
      }
   });
   JavaIOFactory adapter = ClassLoaderAdapterBuilder.callingLoader(loader).delegateLoader(loader)
            .enhance(delegate, JavaIOFactory.class);
   Path path = adapter.getPath();
   Assert.assertFalse(Proxies.isProxyType(path.getClass()));
}
项目:furnace    文件:ClassLoaderAdapterProxiedTest.java   
@Test
public void testShouldNotProxyJavaUtilLogging() throws Exception {
   ClassLoader loader = JavaUtilLoggingFactory.class.getClassLoader();
   final JavaUtilLoggingFactory internal = new JavaUtilLoggingFactory();

   JavaUtilLoggingFactory delegate = (JavaUtilLoggingFactory) Enhancer.create(JavaUtilLoggingFactory.class, new LazyLoader() {
      @Override
      public Object loadObject() throws Exception {
         return internal;
      }
   });

   JavaUtilLoggingFactory adapter = ClassLoaderAdapterBuilder.callingLoader(loader).delegateLoader(loader)
           .enhance(delegate, JavaUtilLoggingFactory.class);
   LogRecord logRecord = adapter.getLogRecord();
   Assert.assertFalse(Proxies.isProxyType(logRecord.getClass()));
   Assert.assertFalse(Proxies.isProxyType(logRecord.getLevel().getClass()));
}
项目:forge-furnace    文件:ClassLoaderAdapterProxiedTest.java   
@Test
public void testAdaptProxiedType() throws Exception
{
   ClassLoader loader = MockService.class.getClassLoader();
   final MockService internal = new MockService();

   MockService delegate = (MockService) Enhancer.create(MockService.class, new LazyLoader()
   {
      @Override
      public Object loadObject() throws Exception
      {
         return internal;
      }
   });

   MockService adapter = ClassLoaderAdapterBuilder.callingLoader(loader).delegateLoader(loader)
            .enhance(delegate, MockService.class);

   Assert.assertNotEquals(internal.getResult(), adapter.getResult());
   Assert.assertEquals(internal.getResult().getValue(), adapter.getResult().getValue());
}
项目:forge-furnace    文件:ClassLoaderAdapterProxiedTest.java   
@Test
public void testAdaptProxiedResult() throws Exception
{
   ClassLoader loader = MockService.class.getClassLoader();
   final MockService internal = new MockService();

   MockService delegate = (MockService) Enhancer.create(MockService.class, new LazyLoader()
   {
      @Override
      public Object loadObject() throws Exception
      {
         return internal;
      }
   });

   MockService adapter = ClassLoaderAdapterBuilder.callingLoader(loader).delegateLoader(loader)
            .enhance(delegate, MockService.class);

   Assert.assertNotEquals(internal.getResult(), adapter.getResultEnhanced());
}
项目:forge-furnace    文件:ClassLoaderAdapterProxiedTest.java   
@Test
public void testAdaptProxiedResultReturnTypeObject() throws Exception
{
   ClassLoader loader = MockService.class.getClassLoader();
   final MockService internal = new MockService();

   MockService delegate = (MockService) Enhancer.create(MockService.class, new LazyLoader()
   {
      @Override
      public Object loadObject() throws Exception
      {
         return internal;
      }
   });

   MockService adapter = ClassLoaderAdapterBuilder.callingLoader(loader).delegateLoader(loader)
            .enhance(delegate, MockService.class);

   Assert.assertNotEquals(internal.getResult(), adapter.getResultEnhancedReturnTypeObject());
}
项目:forge-furnace    文件:ClassLoaderAdapterProxiedTest.java   
@Test(expected = ClassCastException.class)
public void testCannotAdaptFinalResultReturnType() throws Exception
{
   ClassLoader loader = MockService.class.getClassLoader();
   final MockService internal = new MockService();

   MockService delegate = (MockService) Enhancer.create(MockService.class, new LazyLoader()
   {
      @Override
      public Object loadObject() throws Exception
      {
         return internal;
      }
   });

   MockService adapter = ClassLoaderAdapterBuilder.callingLoader(loader).delegateLoader(loader)
            .enhance(delegate, MockService.class);
   adapter.getResultFinalReturnType();
}
项目:forge-furnace    文件:ClassLoaderAdapterProxiedTest.java   
@Test
public void testCanAdaptFinalResultReturnTypeObject() throws Exception
{
   ClassLoader loader = MockService.class.getClassLoader();
   final MockService internal = new MockService();

   MockService delegate = (MockService) Enhancer.create(MockService.class, new LazyLoader()
   {
      @Override
      public Object loadObject() throws Exception
      {
         return internal;
      }
   });

   MockService adapter = ClassLoaderAdapterBuilder.callingLoader(loader).delegateLoader(loader)
            .enhance(delegate, MockService.class);

   Assert.assertNotEquals(internal.getResultFinalReturnTypeObject(), adapter.getResultFinalReturnTypeObject());
   Assert.assertEquals(((Result) internal.getResultFinalReturnTypeObject()).getValue(),
            ((Result) adapter.getResultFinalReturnTypeObject()).getValue());
}
项目:forge-furnace    文件:ClassLoaderAdapterProxiedTest.java   
@Test
public void testAdaptFinalResult() throws Exception
{
   ClassLoader loader = MockService.class.getClassLoader();
   final MockService internal = new MockService();

   MockService delegate = (MockService) Enhancer.create(MockService.class, new LazyLoader()
   {
      @Override
      public Object loadObject() throws Exception
      {
         return internal;
      }
   });

   MockService adapter = ClassLoaderAdapterBuilder.callingLoader(loader).delegateLoader(loader)
            .enhance(delegate, MockService.class);

   Assert.assertNotEquals(internal.getResultInterfaceFinalImpl(), adapter.getResultInterfaceFinalImpl());
   Object unwrapped = Proxies.unwrap(adapter);
   Assert.assertNotSame(adapter, unwrapped);
}
项目:forge-furnace    文件:ClassLoaderAdapterProxiedTest.java   
@Test
public void testNullValuesAsMethodParameters() throws Exception
{
   ClassLoader loader = MockService.class.getClassLoader();
   final MockService internal = new MockService();

   MockService delegate = (MockService) Enhancer.create(MockService.class, new LazyLoader()
   {
      @Override
      public Object loadObject() throws Exception
      {
         return internal;
      }
   });
   MockService adapter = ClassLoaderAdapterBuilder.callingLoader(loader).delegateLoader(loader)
            .enhance(delegate, MockService.class);
   Assert.assertNull(internal.echo(null));
   Assert.assertNull(adapter.echo(null));
}
项目:jcromfx    文件:Mapper.java   
Object triggerLazyLoading(Object obj) throws IllegalAccessException {
    for (Field field : ReflectionUtils.getDeclaredAndInheritedFields(obj.getClass(), false)) {
        field.setAccessible(true);
        if (field.getName().equals("CGLIB$CALLBACK_0")) {
            try {
                return ((LazyLoader) getObject(field, obj)).loadObject();
            } catch (Exception e) {
                throw new JcrMappingException("Could not trigger lazy loading", e);
            }
        }
    }
    return obj;
}
项目:furnace    文件:MockService.java   
public MockResult getResultEnhanced()
{
   final MockResult internal = new MockResult();
   MockResult delegate = (MockResult) Enhancer.create(MockResult.class, new LazyLoader()
   {
      @Override
      public Object loadObject() throws Exception
      {
         return internal;
      }
   });

   return delegate;
}
项目:some-ldap    文件:EntityProxyFactory.java   
static Object getLazyLoadingProxiedEntity(final Session session, final Class<?> entityClass, final String dn) {
    Object entity = null;
    if (isDistinguishable(entityClass)) {
        entity = Enhancer.create(entityClass, new Class[] { Persistent.class, Distinguishable.class },
                FINALIZE_AND_DISTINGUISHABLE_INTEFERCE_FILTER,
                new Callback[] {
                    new LazyLoader() {
                        public Object loadObject() throws Exception {
                            return session.read(entityClass, dn);
                        }
                    },
                    NoOp.INSTANCE
                }
            );
        ((Distinguishable)entity).setDN(dn);

    } else {
        entity = Enhancer.create(entityClass, new Class[] { Persistent.class }, FINALIZE_FILTER,
                new Callback[] {
                    new LazyLoader() {
                        public Object loadObject() throws Exception {
                            return session.read(entityClass, dn);
                        }
                    },
                    NoOp.INSTANCE
                }
            );
    }

    return entity;
}
项目:forge-furnace    文件:MockService.java   
public MockResult getResultEnhanced()
{
   final MockResult internal = new MockResult();
   MockResult delegate = (MockResult) Enhancer.create(MockResult.class, new LazyLoader()
   {
      @Override
      public Object loadObject() throws Exception
      {
         return internal;
      }
   });

   return delegate;
}