Refine search
private TypeInfo add(Type type) { if (type instanceof Class<?>) { Class<?> clazz = (Class<?>) type; if (clazz.isInterface()) { interfaces.add(clazz); } else { classes.add(clazz); } } else if (type instanceof ParameterizedType) { add(((ParameterizedType) type).getRawType()); } else { throw UtilLogger.LOG.cannotProxyNonClassType(type); } return this; }
private static String createCompoundProxyName(String contextId, Bean<?> bean, TypeInfo typeInfo, StringBuilder name) { String className; final List<String> interfaces = new ArrayList<String>(); for (Class<?> type : typeInfo.getInterfaces()) { interfaces.add(type.getSimpleName()); } Collections.sort(interfaces); for (final String iface : interfaces) { name.append(iface); name.append('$'); } //there is a remote chance that this could generate the same //proxy name for two interfaces with the same simple name. //append the hash code of the bean id to be sure // However, it is safe to share a proxy class for built-in beans of the same type (e.g. Event) if (bean != null && !(bean instanceof AbstractBuiltInBean)) { final BeanIdentifier id = Container.instance(contextId).services().get(ContextualStore.class).putIfAbsent(bean); int idHash = id.hashCode(); name.append(Math.abs(idHash == Integer.MIN_VALUE ? 0 : idHash)); } className = name.toString(); return className; }
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; }
this.contextId = contextId; this.proxiedBeanType = proxiedBeanType; this.configuration = Container.instance(contextId).deploymentManager().getServices().get(WeldConfiguration.class); addInterfacesFromTypeClosure(typeClosure, proxiedBeanType); TypeInfo typeInfo = TypeInfo.of(typeClosure); Class<?> superClass = typeInfo.getSuperClass(); superClass = superClass == null ? Object.class : superClass; if (forceSuperClass || (superClass.equals(Object.class) && additionalInterfaces.isEmpty())) { proxyServices = Container.instance(contextId).services().get(ProxyServices.class); if (!proxyServices.supportsClassDefining()) { if (bean != null) { this.proxyInstantiator = Container.instance(contextId).services().get(ProxyInstantiator.class);
/** * Figures out the correct class loader to use for a proxy for a given bean */ public static ClassLoader resolveClassLoaderForBeanProxy(String contextId, Class<?> proxiedType, TypeInfo typeInfo) { Class<?> superClass = typeInfo.getSuperClass(); if (superClass.getName().startsWith(JAVA)) { ClassLoader cl = Container.instance(contextId).services().get(ProxyServices.class).getClassLoader(proxiedType); if (cl == null) { cl = Thread.currentThread().getContextClassLoader(); } return cl; } return Container.instance(contextId).services().get(ProxyServices.class).getClassLoader(superClass); }
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"); if (reason != null) { proxyPackage = DEFAULT_PROXY_PACKAGE; BeanLogger.LOG.generatingProxyToDefaultPackage(superInterface, DEFAULT_PROXY_PACKAGE, reason); } else { proxyPackage = superInterface.getPackage().getName(); if (typeInfo.getSuperClass() == Object.class) { final StringBuilder name = new StringBuilder(); } else { boolean typeModified = false; for (Class<?> iface : typeInfo.getInterfaces()) { if (!iface.isAssignableFrom(typeInfo.getSuperClass())) { typeModified = true; break; StringBuilder name = new StringBuilder(typeInfo.getSuperClass().getSimpleName() + "$"); className = createCompoundProxyName(contextId, bean, typeInfo, name) + PROXY_SUFFIX; } else { className = typeInfo.getSuperClass().getSimpleName() + PROXY_SUFFIX;
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; } }
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; } }
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; } }
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; } }
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; } }
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; } }
private TypeInfo add(Type type) { if (type instanceof Class<?>) { Class<?> clazz = (Class<?>) type; if (clazz.isInterface()) { interfaces.add(clazz); } else { classes.add(clazz); } } else if (type instanceof ParameterizedType) { add(((ParameterizedType) type).getRawType()); } else { throw UtilLogger.LOG.cannotProxyNonClassType(type); } return this; }
private TypeInfo add(Type type) { if (type instanceof Class<?>) { Class<?> clazz = (Class<?>) type; if (clazz.isInterface()) { interfaces.add(clazz); } else { classes.add(clazz); } } else if (type instanceof ParameterizedType) { add(((ParameterizedType) type).getRawType()); } else { throw UtilLogger.LOG.cannotProxyNonClassType(type); } return this; }