Examples of Enhancer


Examples of net.sf.cglib.proxy.Enhancer

        }
        TypeInfo.register(typeInfo, typeMapping);
    }

    private Class enhanceServiceEndpointInterface(Class serviceEndpointInterface, ClassLoader classLoader) {
        Enhancer enhancer = new Enhancer();
        enhancer.setClassLoader(classLoader);
        enhancer.setSuperclass(GenericServiceEndpointWrapper.class);
        enhancer.setInterfaces(new Class[]{serviceEndpointInterface});
        enhancer.setCallbackFilter(new NoOverrideCallbackFilter(GenericServiceEndpointWrapper.class));
        enhancer.setCallbackTypes(new Class[]{NoOp.class, MethodInterceptor.class});
        enhancer.setUseFactory(false);
        enhancer.setUseCache(false);

        return enhancer.createClass();
    }
View Full Code Here

Examples of net.sf.cglib.proxy.Enhancer

    }
    else
    {
      CGLibInterceptor handler = new CGLibInterceptor(type, locator);

      Enhancer e = new Enhancer();
      e.setInterfaces(new Class[] { Serializable.class, ILazyInitProxy.class,
          IWriteReplace.class });
      e.setSuperclass(type);
      e.setCallback(handler);
      e.setNamingPolicy(new DefaultNamingPolicy()
      {
        @Override
        public String getClassName(final String prefix, final String source,
          final Object key, final Predicate names)
        {
          return super.getClassName("WICKET_" + prefix, source, key, names);
        }
      });

      return e.create();
    }
  }
View Full Code Here

Examples of net.sf.cglib.proxy.Enhancer

        basedir.mkdirs();
        try {
            basedir.deleteOnExit();
            URI configID = new URI("test");
            DeploymentContext context = new DeploymentContext(basedir, configID, ConfigurationModuleType.CAR, null, "foo", "bar", null);
            Enhancer enhancer = new Enhancer();
            enhancer.setInterfaces(new Class[]{DataSource.class});
            enhancer.setCallbackType(MethodInterceptor.class);
            enhancer.setStrategy(new DefaultGeneratorStrategy() {
                public byte[] transform(byte[] b) {
                    classBytes = b;
                    return b;
                }
            });
            enhancer.setClassLoader(new URLClassLoader(new URL[0], this.getClass().getClassLoader()));
            Class type = enhancer.createClass();
            URI location = new URI("cglib/");
            context.addClass(location, type.getName(), classBytes, true);
            ClassLoader cl = context.getClassLoader(null);
            Class loadedType = cl.loadClass(type.getName());
            assertTrue(DataSource.class.isAssignableFrom(loadedType));
View Full Code Here

Examples of net.sf.cglib.proxy.Enhancer

    public Object createServiceInterfaceProxy(Class serviceInterface, Map seiPortNameToFactoryMap, Map seiClassNameToFactoryMap, DeploymentContext deploymentContext, Module module, ClassLoader classLoader) throws DeploymentException {

        Callback callback = new ServiceMethodInterceptor(seiPortNameToFactoryMap);
        Callback[] methodInterceptors = new Callback[]{SerializableNoOp.INSTANCE, callback};

        Enhancer enhancer = new Enhancer();
        enhancer.setClassLoader(classLoader);
        enhancer.setSuperclass(ServiceImpl.class);
        enhancer.setInterfaces(new Class[]{serviceInterface});
        enhancer.setCallbackFilter(new NoOverrideCallbackFilter(Service.class));
        enhancer.setCallbackTypes(new Class[]{NoOp.class, MethodInterceptor.class});
        enhancer.setUseFactory(false);
        ByteArrayRetrievingGeneratorStrategy strategy = new ByteArrayRetrievingGeneratorStrategy();
        enhancer.setStrategy(strategy);
        Class serviceClass = enhancer.createClass();

        try {
            module.addClass(serviceClass.getName(), strategy.getClassBytes(), deploymentContext);
        } catch (IOException e) {
            throw new DeploymentException("Could not write out class bytes", e);
View Full Code Here

Examples of net.sf.cglib.proxy.Enhancer

        }
        return handlerInfos;
    }

    public Class enhanceServiceEndpointInterface(Class serviceEndpointInterface, DeploymentContext deploymentContext, Module module, ClassLoader classLoader) throws DeploymentException {
        Enhancer enhancer = new Enhancer();
        enhancer.setClassLoader(classLoader);
        enhancer.setSuperclass(GenericServiceEndpointWrapper.class);
        enhancer.setInterfaces(new Class[]{serviceEndpointInterface});
        enhancer.setCallbackFilter(new NoOverrideCallbackFilter(GenericServiceEndpointWrapper.class));
        enhancer.setCallbackTypes(new Class[]{NoOp.class, MethodInterceptor.class});
        enhancer.setUseFactory(false);
        ByteArrayRetrievingGeneratorStrategy strategy = new ByteArrayRetrievingGeneratorStrategy();
        enhancer.setStrategy(strategy);
        Class serviceEndpointClass = enhancer.createClass();

        try {
            module.addClass(serviceEndpointClass.getName(), strategy.getClassBytes(), deploymentContext);
        } catch (IOException e) {
            throw new DeploymentException("Could not write out class bytes", e);
View Full Code Here

Examples of net.sf.cglib.proxy.Enhancer

  @SuppressWarnings("unchecked")
  public static <T> T createProxy(final T underlying, final GenericInvocationHandler<T> invocationHandler) {
    // TODO refactor - to get rid of endless try - catch
    final ClassLoader currentThreadClassLoader = Thread.currentThread().getContextClassLoader();
    try {
      final Enhancer enhancer = createProxy(underlying, invocationHandler, ProxyNamingPolicy.INSTANCE, currentThreadClassLoader);
      return (T) enhancer.create();
    } catch (CodeGenerationException e) {
      // fallback, as proxied class might implement non-public interfaces
      // that have trouble with our ProxyNamingPolicy (for example for SQLite)
      try {
        final Enhancer enhancer = createProxy(underlying, invocationHandler, null, currentThreadClassLoader);
        return (T) enhancer.create();
      } catch (CodeGenerationException ex) {
        //
        // well, wildfly (8.1.CR1) just doesn't like currentThreadClassLoader => needs to use the default one
        //
        try {
          final Enhancer enhancer = createProxy(underlying, invocationHandler, ProxyNamingPolicy.INSTANCE, null);
          return (T) enhancer.create();
        } catch (CodeGenerationException exc) {
          // fallback, as proxied class might implement non-public interfaces
          // that have trouble with our ProxyNamingPolicy (for example for SQLite)
            final Enhancer enhancer = createProxy(underlying, invocationHandler, null, null);
            return (T) enhancer.create();
        }
      }
    }
  }
View Full Code Here

Examples of net.sf.cglib.proxy.Enhancer

   */
  private static <T> Enhancer createProxy(final T underlying,
                                           final GenericInvocationHandler<T> invocationHandler,
                                           final NamingPolicy namingPolicy, final ClassLoader classLoader) {
    // noinspection unchecked
    final Enhancer enhancer = new Enhancer();
    enhancer.setCallback(invocationHandler);
    enhancer.setInterfaces(getInterfaces(underlying.getClass()));
    // fix for the https://github.com/p6spy/p6spy/issues/188
    if (null != classLoader) {
      enhancer.setClassLoader(classLoader);
    }
    if (null != namingPolicy) {
      enhancer.setNamingPolicy(namingPolicy)
    }
    return enhancer;
  }
View Full Code Here

Examples of net.sf.cglib.proxy.Enhancer

    private <T> Class<?> createProxyClass(Class<?> mockedType) {
        if (mockedType == Object.class) {
            mockedType = ClassWithSuperclassToWorkAroundCglibBug.class;
        }
       
        Enhancer enhancer = new Enhancer() {
            @Override
            @SuppressWarnings("unchecked")
            protected void filterConstructors(Class sc, List constructors) {
                // Don't filter
            }
        };
        enhancer.setClassLoader(SearchingClassLoader.combineLoadersOf(mockedType));
        enhancer.setUseFactory(true);
        if (mockedType.isInterface()) {
            enhancer.setSuperclass(Object.class);
            enhancer.setInterfaces(prepend(mockedType));
        } else {
            enhancer.setSuperclass(mockedType);
        }
        enhancer.setCallbackTypes(new Class[]{MethodInterceptor.class, NoOp.class});
        enhancer.setCallbackFilter(IGNORE_BRIDGE_METHODS);
        if (mockedType.getSigners() != null) {
            enhancer.setNamingPolicy(NAMING_POLICY_THAT_ALLOWS_IMPOSTERISATION_OF_CLASSES_IN_SIGNED_PACKAGES);
        }
       
        try {
            return enhancer.createClass();
        } catch (CodeGenerationException e) {
            throw new IllegalArgumentException("could not imposterise " + mockedType, e);
        }
    }
View Full Code Here

Examples of net.sf.cglib.proxy.Enhancer

    }
    else
    {
      CGLibInterceptor handler = new CGLibInterceptor(type, locator);

      Enhancer e = new Enhancer();
      e.setInterfaces(new Class[] { Serializable.class, ILazyInitProxy.class,
          IWriteReplace.class });
      e.setSuperclass(type);
      e.setCallback(handler);
      e.setNamingPolicy(new DefaultNamingPolicy()
      {
        @Override
        public String getClassName(final String prefix, final String source,
          final Object key, final Predicate names)
        {
          return super.getClassName("WICKET_" + prefix, source, key, names);
        }
      });

      return e.create();
    }
  }
View Full Code Here

Examples of net.sf.cglib.proxy.Enhancer

     * @return dynamic implementation instance
     */
    public static java.lang.Object createInstance(Object reference, Class<?> forClass) {
        java.lang.Object result = null;
        try {
            Enhancer enhancer = new Enhancer();
            enhancer.setInterfaces(new Class[] {forClass});
            enhancer.setCallbackFilter(FILTER);
            enhancer.setCallbackTypes(new Class[] {NoOp.class, MethodInterceptor.class});
            Class<?> newClass = enhancer.createClass();
            Enhancer.registerStaticCallbacks(newClass, new Callback[] {NoOp.INSTANCE,
                                                                       new InterfaceMethodInterceptor(reference, forClass)});
            result = newClass.newInstance();
        } catch (Exception e) {
            e.printStackTrace();
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.