net.sf.cglib.proxy.NoOp Java Examples

The following examples show how to use net.sf.cglib.proxy.NoOp. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SeiFactoryImpl.java    From tomee with Apache License 2.0 6 votes vote down vote up
public Remote createServiceEndpoint() throws ServiceException {
        //TODO figure out why this can't be called in readResolve!
//        synchronized (this) {
//            if (!initialized) {
//                initialize();
//                initialized = true;
//            }
//        }
        Service service = ((ServiceImpl) serviceImpl).getService();
        GenericServiceEndpoint serviceEndpoint = new GenericServiceEndpoint(portQName, service, location);
        Callback callback = new ServiceEndpointMethodInterceptor(serviceEndpoint, sortedOperationInfos, credentialsName);
        Callback[] callbacks = new Callback[]{NoOp.INSTANCE, callback};
        Enhancer.registerCallbacks(serviceEndpointClass, callbacks);
        try {
            return (Remote) constructor.newInstance(new Object[]{serviceEndpoint});
        } catch (InvocationTargetException e) {
            throw (ServiceException) new ServiceException("Could not construct service instance", e.getTargetException()).initCause(e);
        }
    }
 
Example #2
Source File: GenericDaoBase.java    From cosmic with Apache License 2.0 6 votes vote down vote up
@DB()
protected T toEntityBean(final ResultSet result, final boolean cache) throws SQLException {
    final T entity = (T) _factory.newInstance(new Callback[]{NoOp.INSTANCE, new UpdateBuilder(this)});

    toEntityBean(result, entity);

    if (cache && _cache != null) {
        try {
            _cache.put(new Element(_idField.get(entity), entity));
        } catch (final Exception e) {
            s_logger.debug("Can't put it in the cache", e);
        }
    }

    return entity;
}
 
Example #3
Source File: ClassByImplementationBenchmark.java    From byte-buddy with Apache License 2.0 6 votes vote down vote up
/**
 * Performs a benchmark of an interface implementation using cglib.
 *
 * @return The created instance, in order to avoid JIT removal.
 */
@Benchmark
public ExampleInterface benchmarkCglib() {
    Enhancer enhancer = new Enhancer();
    enhancer.setUseCache(false);
    enhancer.setClassLoader(newClassLoader());
    enhancer.setSuperclass(baseClass);
    CallbackHelper callbackHelper = new CallbackHelper(Object.class, new Class[]{baseClass}) {
        protected Object getCallback(Method method) {
            if (method.getDeclaringClass() == baseClass) {
                return new FixedValue() {
                    public Object loadObject() {
                        return null;
                    }
                };
            } else {
                return NoOp.INSTANCE;
            }
        }
    };
    enhancer.setCallbackFilter(callbackHelper);
    enhancer.setCallbacks(callbackHelper.getCallbacks());
    return (ExampleInterface) enhancer.create();
}
 
Example #4
Source File: GenericDaoBase.java    From cloudstack with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@DB()
protected T toEntityBean(final ResultSet result, final boolean cache) throws SQLException {
    final T entity = (T)_factory.newInstance(new Callback[] {NoOp.INSTANCE, new UpdateBuilder(this)});

    toEntityBean(result, entity);

    if (cache && _cache != null) {
        try {
            _cache.put(new Element(_idField.get(entity), entity));
        } catch (final Exception e) {
            s_logger.debug("Can't put it in the cache", e);
        }
    }

    return entity;
}
 
Example #5
Source File: SerializationTest.java    From monasca-common with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private static <T> T proxyFor(Class<T> type) throws Exception {
  Enhancer enhancer = new Enhancer();
  enhancer.setSuperclass(TestCommand.class);
  enhancer.setCallbackType(NoOp.class);
  Class<T> enhanced = enhancer.createClass();
  return enhanced.newInstance();
}
 
Example #6
Source File: ConcurrentGetInstantiator.java    From objenesis with Apache License 2.0 5 votes vote down vote up
@Setup
public void setUp() {
   for(int i = 0; i < COUNT; i++) {
      Enhancer enhancer = new Enhancer();
      enhancer.setUseCache(false); // deactivate the cache to get a new instance each time
      enhancer.setCallbackType(NoOp.class);
      Class<?> c = enhancer.createClass();
      toInstantiate[i] = c;
   }
}
 
Example #7
Source File: SeiFactoryImpl.java    From tomee with Apache License 2.0 5 votes vote down vote up
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();
}
 
Example #8
Source File: TrivialClassCreationBenchmark.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
/**
 * Performs a benchmark for a trivial class creation using cglib.
 *
 * @return The created instance, in order to avoid JIT removal.
 */
@Benchmark
public Class<?> benchmarkCglib() {
    Enhancer enhancer = new Enhancer();
    enhancer.setUseCache(false);
    enhancer.setClassLoader(newClassLoader());
    enhancer.setSuperclass(baseClass);
    enhancer.setCallbackType(NoOp.class);
    return enhancer.createClass();
}
 
Example #9
Source File: ComponentInstantiationPostProcessor.java    From cloudstack with Apache License 2.0 5 votes vote down vote up
public ComponentInstantiationPostProcessor() {
    _callbacks = new Callback[2];
    _callbacks[0] = NoOp.INSTANCE;
    _callbacks[1] = new InterceptorDispatcher();

    _callbackFilter = new InterceptorFilter();
}
 
Example #10
Source File: TypesTest.java    From monasca-common with Apache License 2.0 5 votes vote down vote up
public void shouldDeProxyCGLibProxy() throws Exception {
  Enhancer enhancer = new Enhancer();
  enhancer.setSuperclass(ArrayList.class);
  enhancer.setCallbackTypes(new Class[] { NoOp.class });
  Class<?> proxy = enhancer.createClass();

  assertEquals(Types.deProxy(proxy), ArrayList.class);
}
 
Example #11
Source File: DalTransactionManager.java    From das with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public static <T> T create(Class<T> targetClass) throws InstantiationException, IllegalAccessException {
    Enhancer enhancer = new Enhancer();
    enhancer.setSuperclass(targetClass);
    enhancer.setClassLoader(targetClass.getClassLoader());
    enhancer.setCallbackFilter(new TransactionalCallbackFilter());
    Callback[] callbacks = new Callback[] {new DasTransactionInterceptor(), NoOp.INSTANCE};
    enhancer.setCallbacks(callbacks);
    enhancer.setInterfaces(new Class[] {TransactionalIntercepted.class});
    return (T) enhancer.create();
}
 
Example #12
Source File: ProxyFactoryFactoryImpl.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public Object getProxy() {
	try {
		return factory.newInstance(
				new Callback[] { new PassThroughInterceptor( proxyClass.getName() ), NoOp.INSTANCE }
		);
	}
	catch ( Throwable t ) {
		throw new HibernateException( "Unable to instantiate proxy instance" );
	}
}
 
Example #13
Source File: CGLIBLazyInitializer.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static Class getProxyFactory(Class persistentClass, Class[] interfaces)
		throws HibernateException {
	Enhancer e = new Enhancer();
	e.setSuperclass( interfaces.length == 1 ? persistentClass : null );
	e.setInterfaces(interfaces);
	e.setCallbackTypes(new Class[]{
		InvocationHandler.class,
		NoOp.class,
  		});
 		e.setCallbackFilter(FINALIZE_FILTER);
 		e.setUseFactory(false);
	e.setInterceptDuringConstruction( false );
	return e.createClass();
}
 
Example #14
Source File: ProxyEventCallbackFilter.java    From flux with Apache License 2.0 5 votes vote down vote up
@Override
protected Object getCallback(Method method) {
    if(method.getName().equals("name") && method.getReturnType().equals(String.class)) {
        return getNameCallback();
    }
    if (method.getName().equals("getRealClassName") && method.getReturnType().equals(String.class)) {
        return getRealClassName();
    }
    return NoOp.INSTANCE;
}
 
Example #15
Source File: DalTransactionManager.java    From dal with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public static <T> T create(Class<T> targetClass) throws InstantiationException, IllegalAccessException {
    Enhancer enhancer = new Enhancer();
    enhancer.setSuperclass(targetClass);
    enhancer.setClassLoader(targetClass.getClassLoader());
    enhancer.setCallbackFilter(new TransactionalCallbackFilter());
    Callback[] callbacks = new Callback[] {new DalTransactionInterceptor(), NoOp.INSTANCE};
    enhancer.setCallbacks(callbacks);
    enhancer.setInterfaces(new Class[] {TransactionalIntercepted.class});
    return (T) enhancer.create();
}
 
Example #16
Source File: ComponentInstantiationPostProcessor.java    From cosmic with Apache License 2.0 5 votes vote down vote up
public ComponentInstantiationPostProcessor() {
    _callbacks = new Callback[2];
    _callbacks[0] = NoOp.INSTANCE;
    _callbacks[1] = new InterceptorDispatcher();

    _callbackFilter = new InterceptorFilter();
}
 
Example #17
Source File: CGLIBEnhancedConverter.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private void readCallback(HierarchicalStreamReader reader, UnmarshallingContext context,
    List callbacksToEnhance, List callbacks) {
    Callback callback = (Callback)context.convertAnother(null, mapper.realClass(reader
        .getNodeName()));
    callbacks.add(callback);
    if (callback == null) {
        callbacksToEnhance.add(NoOp.INSTANCE);
    } else {
        callbacksToEnhance.add(callback);
    }
}
 
Example #18
Source File: ReactorDebugAgentTest.java    From reactor-core with Apache License 2.0 4 votes vote down vote up
@Test
public void cglibProxies() {
	ProxyMe proxy = (ProxyMe) Enhancer.create(ProxyMe.class, NoOp.INSTANCE);

	assertThat(proxy.doSomething()).isInstanceOf(ProxyMe.MyMono.class);
}
 
Example #19
Source File: GenericDaoBase.java    From cloudstack with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
protected GenericDaoBase() {
    super();
    Type t = getClass().getGenericSuperclass();
    if (t instanceof ParameterizedType) {
        _entityBeanType = (Class<T>)((ParameterizedType)t).getActualTypeArguments()[0];
    } else if (((Class<?>)t).getGenericSuperclass() instanceof ParameterizedType) {
        _entityBeanType = (Class<T>)((ParameterizedType)((Class<?>)t).getGenericSuperclass()).getActualTypeArguments()[0];
    } else {
        _entityBeanType = (Class<T>)((ParameterizedType)((Class<?>)((Class<?>)t).getGenericSuperclass()).getGenericSuperclass()).getActualTypeArguments()[0];
    }

    s_daoMaps.put(_entityBeanType, this);
    Class<?>[] interphaces = _entityBeanType.getInterfaces();
    if (interphaces != null) {
        for (Class<?> interphace : interphaces) {
            s_daoMaps.put(interphace, this);
        }
    }

    _table = DbUtil.getTableName(_entityBeanType);

    final SqlGenerator generator = new SqlGenerator(_entityBeanType);
    _partialSelectSql = generator.buildSelectSql(false);
    _count = generator.buildCountSql();
    _distinctIdSql= generator.buildDistinctIdSql();
    _partialQueryCacheSelectSql = generator.buildSelectSql(true);
    _embeddedFields = generator.getEmbeddedFields();
    _insertSqls = generator.buildInsertSqls();
    final Pair<StringBuilder, Map<String, Object>> dc = generator.buildDiscriminatorClause();
    _discriminatorClause = dc.first().length() == 0 ? null : dc.first();
    _discriminatorValues = dc.second();

    _idAttributes = generator.getIdAttributes();
    _idField = _idAttributes.get(_table).length > 0 ? _idAttributes.get(_table)[0].field : null;

    _tables = generator.buildTableReferences();

    _allAttributes = generator.getAllAttributes();
    _allColumns = generator.getAllColumns();

    _selectByIdSql = buildSelectByIdSql(createPartialSelectSql(null, true));
    _removeSql = generator.buildRemoveSql();
    _deleteSqls = generator.buildDeleteSqls();
    _removed = generator.getRemovedAttribute();
    _tgs = generator.getTableGenerators();
    _ecAttributes = generator.getElementCollectionAttributes();

    TableGenerator tg = this.getClass().getAnnotation(TableGenerator.class);
    if (tg != null) {
        _tgs.put(tg.name(), tg);
    }
    tg = this.getClass().getSuperclass().getAnnotation(TableGenerator.class);
    if (tg != null) {
        _tgs.put(tg.name(), tg);
    }

    Callback[] callbacks = new Callback[] {NoOp.INSTANCE, new UpdateBuilder(this)};

    _enhancer = new Enhancer();
    _enhancer.setSuperclass(_entityBeanType);
    _enhancer.setCallbackFilter(s_callbackFilter);
    _enhancer.setCallbacks(callbacks);
    _factory = (Factory)_enhancer.create();

    _searchEnhancer = new Enhancer();
    _searchEnhancer.setSuperclass(_entityBeanType);
    _searchEnhancer.setCallback(new UpdateBuilder(this));

    if (s_logger.isTraceEnabled()) {
        s_logger.trace("Select SQL: " + _partialSelectSql.first().toString());
        s_logger.trace("Remove SQL: " + (_removeSql != null ? _removeSql.first() : "No remove sql"));
        s_logger.trace("Select by Id SQL: " + _selectByIdSql);
        s_logger.trace("Table References: " + _tables);
        s_logger.trace("Insert SQLs:");
        for (final Pair<String, Attribute[]> insertSql : _insertSqls) {
            s_logger.trace(insertSql.first());
        }

        s_logger.trace("Delete SQLs");
        for (final Pair<String, Attribute[]> deletSql : _deleteSqls) {
            s_logger.trace(deletSql.first());
        }

        s_logger.trace("Collection SQLs");
        for (Attribute attr : _ecAttributes) {
            EcInfo info = (EcInfo)attr.attache;
            s_logger.trace(info.insertSql);
            s_logger.trace(info.selectSql);
        }
    }

    setRunLevel(ComponentLifecycle.RUN_LEVEL_SYSTEM);
}
 
Example #20
Source File: GenericDaoBase.java    From cosmic with Apache License 2.0 4 votes vote down vote up
protected GenericDaoBase() {
    super();
    final Type t = getClass().getGenericSuperclass();
    if (t instanceof ParameterizedType) {
        _entityBeanType = (Class<T>) ((ParameterizedType) t).getActualTypeArguments()[0];
    } else if (((Class<?>) t).getGenericSuperclass() instanceof ParameterizedType) {
        _entityBeanType = (Class<T>) ((ParameterizedType) ((Class<?>) t).getGenericSuperclass()).getActualTypeArguments()[0];
    } else {
        _entityBeanType = (Class<T>) ((ParameterizedType) ((Class<?>) ((Class<?>) t).getGenericSuperclass()).getGenericSuperclass()).getActualTypeArguments()[0];
    }

    s_daoMaps.put(_entityBeanType.getCanonicalName(), this);
    final Class<?>[] interfaceClasses = _entityBeanType.getInterfaces();
    if (interfaceClasses != null) {
        for (final Class<?> interfaceClass : interfaceClasses) {
            s_daoMaps.put(interfaceClass.getCanonicalName(), this);
        }
    }
    logDetectedDaos();

    _table = DbUtil.getTableName(_entityBeanType);

    final SqlGenerator generator = new SqlGenerator(_entityBeanType);
    _partialSelectSql = generator.buildSelectSql(false);
    _count = generator.buildCountSql();
    _distinctIdSql = generator.buildDistinctIdSql();
    _partialQueryCacheSelectSql = generator.buildSelectSql(true);
    _embeddedFields = generator.getEmbeddedFields();
    _insertSqls = generator.buildInsertSqls();
    final Pair<StringBuilder, Map<String, Object>> dc = generator.buildDiscriminatorClause();
    _discriminatorClause = dc.first().length() == 0 ? null : dc.first();
    _discriminatorValues = dc.second();

    _idAttributes = generator.getIdAttributes();
    _idField = _idAttributes.get(_table).length > 0 ? _idAttributes.get(_table)[0].field : null;

    _tables = generator.buildTableReferences();

    _allAttributes = generator.getAllAttributes();
    _allColumns = generator.getAllColumns();

    _selectByIdSql = buildSelectByIdSql(createPartialSelectSql(null, true));
    _removeSql = generator.buildRemoveSql();
    _deleteSqls = generator.buildDeleteSqls();
    _removed = generator.getRemovedAttribute();
    _tgs = generator.getTableGenerators();
    _ecAttributes = generator.getElementCollectionAttributes();

    TableGenerator tg = this.getClass().getAnnotation(TableGenerator.class);
    if (tg != null) {
        _tgs.put(tg.name(), tg);
    }
    tg = this.getClass().getSuperclass().getAnnotation(TableGenerator.class);
    if (tg != null) {
        _tgs.put(tg.name(), tg);
    }

    final Callback[] callbacks = new Callback[]{NoOp.INSTANCE, new UpdateBuilder(this)};

    _enhancer = new Enhancer();
    _enhancer.setSuperclass(_entityBeanType);
    _enhancer.setCallbackFilter(s_callbackFilter);
    _enhancer.setCallbacks(callbacks);
    _factory = (Factory) _enhancer.create();

    _searchEnhancer = new Enhancer();
    _searchEnhancer.setSuperclass(_entityBeanType);
    _searchEnhancer.setCallback(new UpdateBuilder(this));

    if (s_logger.isTraceEnabled()) {
        s_logger.trace("Select SQL: " + _partialSelectSql.first().toString());
        s_logger.trace("Remove SQL: " + (_removeSql != null ? _removeSql.first() : "No remove sql"));
        s_logger.trace("Select by Id SQL: " + _selectByIdSql);
        s_logger.trace("Table References: " + _tables);
        s_logger.trace("Insert SQLs:");
        for (final Pair<String, Attribute[]> insertSql : _insertSqls) {
            s_logger.trace(insertSql.first());
        }

        s_logger.trace("Delete SQLs");
        for (final Pair<String, Attribute[]> deletSql : _deleteSqls) {
            s_logger.trace(deletSql.first());
        }

        s_logger.trace("Collection SQLs");
        for (final Attribute attr : _ecAttributes) {
            final EcInfo info = (EcInfo) attr.attache;
            s_logger.trace(info.insertSql);
            s_logger.trace(info.selectSql);
        }
    }

    setRunLevel(ComponentLifecycle.RUN_LEVEL_SYSTEM);
}