Search in sources :

Example 1 with TypeInfo

use of org.jboss.weld.util.Proxies.TypeInfo in project core by weld.

the class ProxyFactory method getProxyName.

static String getProxyName(String contextId, Class<?> proxiedBeanType, Set<? extends Type> typeClosure, Bean<?> bean) {
    TypeInfo typeInfo = TypeInfo.of(typeClosure);
    String proxyPackage;
    if (proxiedBeanType.equals(Object.class)) {
        Class<?> superInterface = typeInfo.getSuperInterface();
        if (superInterface == null) {
            throw new IllegalArgumentException("Proxied bean type cannot be java.lang.Object without an interface");
        } else {
            String reason = getDefaultPackageReason(superInterface);
            if (reason != null) {
                proxyPackage = DEFAULT_PROXY_PACKAGE;
                BeanLogger.LOG.generatingProxyToDefaultPackage(superInterface, DEFAULT_PROXY_PACKAGE, reason);
            } else {
                proxyPackage = superInterface.getPackage().getName();
            }
        }
    } else {
        String reason = getDefaultPackageReason(proxiedBeanType);
        if (reason != null && reason.equals(NULL)) {
            proxyPackage = DEFAULT_PROXY_PACKAGE;
            BeanLogger.LOG.generatingProxyToDefaultPackage(proxiedBeanType, DEFAULT_PROXY_PACKAGE, reason);
        } else {
            proxyPackage = proxiedBeanType.getPackage().getName();
        }
    }
    final String className;
    if (typeInfo.getSuperClass() == Object.class) {
        final StringBuilder name = new StringBuilder();
        // interface only bean.
        className = createCompoundProxyName(contextId, bean, typeInfo, name) + PROXY_SUFFIX;
    } else {
        boolean typeModified = false;
        for (Class<?> iface : typeInfo.getInterfaces()) {
            if (!iface.isAssignableFrom(typeInfo.getSuperClass())) {
                typeModified = true;
                break;
            }
        }
        if (typeModified) {
            // this bean has interfaces that the base type is not assignable to
            // which can happen with some creative use of the SPI
            // interface only bean.
            StringBuilder name = new StringBuilder(typeInfo.getSuperClass().getSimpleName() + "$");
            className = createCompoundProxyName(contextId, bean, typeInfo, name) + PROXY_SUFFIX;
        } else {
            className = typeInfo.getSuperClass().getSimpleName() + PROXY_SUFFIX;
        }
    }
    return proxyPackage + '.' + getEnclosingPrefix(proxiedBeanType) + className;
}
Also used : TypeInfo(org.jboss.weld.util.Proxies.TypeInfo)

Example 2 with TypeInfo

use of org.jboss.weld.util.Proxies.TypeInfo in project core by weld.

the class AbstractBeanInstance method computeInstanceType.

protected static Class<?> computeInstanceType(Set<Type> types) {
    TypeInfo typeInfo = TypeInfo.of(types);
    Class<?> superClass = typeInfo.getSuperClass();
    if (superClass.equals(Object.class)) {
        superClass = typeInfo.getSuperInterface();
    }
    return superClass;
}
Also used : TypeInfo(org.jboss.weld.util.Proxies.TypeInfo)

Example 3 with TypeInfo

use of org.jboss.weld.util.Proxies.TypeInfo in project core by weld.

the class ClientProxyProvider method createClientProxy.

private <T> T createClientProxy(Bean<T> bean, Set<Type> types) {
    BeanIdentifier id = Container.instance(contextId).services().get(ContextualStore.class).putIfAbsent(bean);
    if (id == null) {
        throw BeanLogger.LOG.beanIdCreationFailed(bean);
    }
    BeanInstance beanInstance = new ContextBeanInstance<T>(bean, id, contextId);
    TypeInfo typeInfo = TypeInfo.of(types);
    T proxy = new ClientProxyFactory<T>(contextId, typeInfo.getSuperClass(), types, bean).create(beanInstance);
    BeanLogger.LOG.createdNewClientProxyType(proxy.getClass(), bean, id);
    return proxy;
}
Also used : ContextualStore(org.jboss.weld.serialization.spi.ContextualStore) BeanIdentifier(org.jboss.weld.serialization.spi.BeanIdentifier) TypeInfo(org.jboss.weld.util.Proxies.TypeInfo)

Aggregations

TypeInfo (org.jboss.weld.util.Proxies.TypeInfo)3 BeanIdentifier (org.jboss.weld.serialization.spi.BeanIdentifier)1 ContextualStore (org.jboss.weld.serialization.spi.ContextualStore)1