Package net.sf.cglib.proxy

Examples of net.sf.cglib.proxy.Enhancer


    public Object create(Class  realMpClass, MessageProcessorId id, Map<String, String> attributes, String fileName, String lineNumber,
                         Object[] constructorArguments)
    {
        try
        {
            Enhancer e = createEnhancer(realMpClass, id, attributes, fileName, lineNumber);
            if (constructorArguments != null && constructorArguments.length != 0)
            {
                Class[] classes = findConstructorArgumentTypes(realMpClass, constructorArguments);
                if (classes != null)
                {
                    return e.create(classes, constructorArguments);
                }
                else
                {
                    throw new Error("The message processor " + id.getFullName() + " could not be created, because " +
                                    "there is no matching constructor");
                }
            }
            else
            {
                return e.create();
            }
        }
        catch (Throwable e)
        {
            logger.warn("The message processor " + id.getFullName() + " could not be mocked");
View Full Code Here


    }

    protected Enhancer createEnhancer(Class realMpClass, MessageProcessorId id, Map<String, String> attributes, String fileName, String lineNumber)
    {

        Enhancer e = new Enhancer();
        e.setSuperclass(realMpClass);
        e.setUseCache(false);
        e.setAttemptLoad(true);
        e.setInterceptDuringConstruction(true);
        e.setNamingPolicy(new MunitNamingPolicy());

        if (FactoryBean.class.isAssignableFrom(realMpClass))
        {
            createFactoryBeanCallback(id, attributes, fileName, lineNumber, e);
        }
View Full Code Here

                callback.setAttributes(attributes);
                callback.setFileName(fileName);
                callback.setLineNumber(lineNumber);


                Enhancer e = new Enhancer();
                e.setSuperclass(o.getClass());
                e.setInterceptDuringConstruction(true);
                e.setUseCache(false);
                e.setAttemptLoad(true);
                e.setNamingPolicy(new MunitNamingPolicy());
                e.setCallbackTypes(new Class[] {WrapperMunitMessageProcessorInterceptor.class});

                return createProxy(e.createClass(), callback);

            }
            else
            {
                return o;
View Full Code Here

        }
      };
    }
     
    // CGLib is amazing
      Enhancer ex = new Enhancer();
      ex.setSuperclass(InjectorContainer.class);
      ex.setInterfaces(new Class[] { Player.class });
    ex.setCallbacks(new Callback[] { NoOp.INSTANCE, implementation });
    ex.setCallbackFilter(callbackFilter);
     
      return (Player) ex.create();
  }
View Full Code Here

        public ManagedProxyFactory(Class type, ClassLoader classLoader) {
            this(new Class[]{type}, classLoader);
        }

        public ManagedProxyFactory(Class[] type, ClassLoader classLoader) {
            Enhancer enhancer = new Enhancer();
            if(type.length > 1) { // shrink first -- may reduce from many to one
                type = ClassLoading.reduceInterfaces(type);
            }
            if(type.length == 0) {
                throw new IllegalArgumentException("Cannot generate proxy for 0 interfaces!");
            } else if(type.length == 1) { // Unlikely (as a result of GeronimoManagedBean)
                enhancer.setSuperclass(type[0]);
            } else {
                if(type[0].isInterface()) {
                    enhancer.setSuperclass(Object.class);
                    enhancer.setInterfaces(type);
                } else { // there's a class and reduceInterfaces put the class in the first spot
                    Class[] intfs = new Class[type.length-1];
                    System.arraycopy(type, 1, intfs, 0, intfs.length);
                    enhancer.setSuperclass(type[0]);
                    enhancer.setInterfaces(intfs);
                }
            }
            enhancer.setClassLoader(classLoader);
            enhancer.setCallbackType(MethodInterceptor.class);
            enhancer.setUseFactory(false);
            proxyType = enhancer.createClass();
            fastClass = FastClass.create(proxyType);
        }
View Full Code Here

            // create method interceptors
            Callback callback = getPortMethodInterceptor();
            this.methodInterceptors = new Callback[] {NoOp.INSTANCE, callback};

            // create service class
            Enhancer enhancer = new Enhancer();
            enhancer.setClassLoader(new BundleClassLoader(bundle));
            enhancer.setSuperclass(superClass);
            enhancer.setCallbackFilter(new PortMethodFilter());
            enhancer.setCallbackTypes(new Class[] { NoOp.class, MethodInterceptor.class });
            enhancer.setUseFactory(false);
            enhancer.setUseCache(false);
            this.enhancedServiceClass = enhancer.createClass();

            // get constructor
            this.serviceConstructor =
                FastClass.create(this.enhancedServiceClass).getConstructor(URL_SERVICE_NAME_CONSTRUCTOR);
        }
View Full Code Here

        lookup.put(method.getName(), method);
      }
    }
   
      // MORE CGLIB magic!
      Enhancer ex = EnhancerFactory.getInstance().createEnhancer();
      ex.setSuperclass(Player.class);
      ex.setCallback(new MethodInterceptor() {
      @Override
      public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable {
       
        // There's no overloaded methods, so we don't care
        Method offlineMethod = lookup.get(method.getName());
       
        // Ignore all other methods
        if (offlineMethod == null) {
          throw new UnsupportedOperationException(
              "The method " + method.getName() + " is not supported for offline players.");
        }

        // Invoke our on method
        return offlineMethod.invoke(SerializedOfflinePlayer.this, args);
      }
      });
     
      return (Player) ex.create();
  }
View Full Code Here

    super(advised);
  }

  @Override
  public Object getProxy() {
    Enhancer enhancer = new Enhancer();
    enhancer.setSuperclass(advised.getTargetSource().getTargetClass());
    enhancer.setInterfaces(advised.getTargetSource().getInterfaces());
    enhancer.setCallback(new DynamicAdvisedInterceptor(advised));
    Object enhanced = enhancer.create();
    return enhanced;
  }
View Full Code Here

        assertFileExists(file);
        return file;
    }

    private static byte[] createClass(final String name) {
        Enhancer enhancer = new Enhancer();
        enhancer.setNamingPolicy(new NamingPolicy() {
            public String getClassName(String prefix, String source, Object key, Predicate names) {
                return name;
            }
        });
        enhancer.setClassLoader(new URLClassLoader(new URL[0]));
        enhancer.setSuperclass(Object.class);
        enhancer.setInterfaces(new Class[]{Serializable.class});
        enhancer.setCallbackTypes(new Class[]{NoOp.class});
        enhancer.setUseFactory(false);
        ByteCode byteCode = new ByteCode();
        enhancer.setStrategy(byteCode);
        enhancer.createClass();

        return byteCode.getByteCode();
    }
View Full Code Here

        //create a new ConnectionFactory
        connectionFactory = connectionManagerContainer.createConnectionFactory(managedConnectionFactory);

        //build proxy
        if (isProxyable) {
            Enhancer enhancer = new Enhancer();
            enhancer.setInterfaces(allImplementedInterfaces);
            enhancer.setCallbackType(net.sf.cglib.proxy.MethodInterceptor.class);
            enhancer.setUseFactory(false);//????
            interceptor = new ConnectorMethodInterceptor(kernel.getKernelName(), ObjectName.getInstance(objectName));
            enhancer.setCallbacks(new Callback[]{interceptor});
            proxy = enhancer.create(new Class[0], new Object[0]);
        } else {
            proxy = connectionFactory;
        }

        //connect proxy
View Full Code Here

TOP

Related Classes of net.sf.cglib.proxy.Enhancer

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.