/** * Indicates if a class is proxyable * * @param type The class to test * @return True if proxyable, false otherwise */ public static boolean isTypeProxyable(Type type, ServiceRegistry services) { return getUnproxyableTypeException(type, services) == null; }
public static UnproxyableResolutionException getUnproxyableTypeException(Type type, Bean<?> declaringBean, ServiceRegistry services, boolean ignoreFinalMethods) { if (type instanceof Class<?> || type instanceof ParameterizedType || type instanceof GenericArrayType) { return getUnproxyableClassException(Reflections.getRawType(type), declaringBean, services, ignoreFinalMethods); } return ValidatorLogger.LOG.notProxyableUnknown(type, getDeclaringBeanInfo(declaringBean)); }
/** * Indicates if a set of types are all proxyable * * @param types The types to test * @return True if proxyable, false otherwise */ public static boolean isTypesProxyable(Iterable<? extends Type> types, ServiceRegistry services) { return getUnproxyableTypesException(types, services) == null; }
private static void processSuperinterface(Class<?> superinterface, Set<Class<?>> interfaces, LinkedHashSet<Class<?>> sorted) { for (Class<?> interfaceClass : interfaces) { if (isInterfaceExtending(interfaceClass, superinterface)) { processSuperinterface(interfaceClass, interfaces, sorted); sorted.add(interfaceClass); } } }
for (Type type : input.bean.getTypes()) { if (Reflections.getRawType(type).isInterface()) { types.add(type); if (input.bean instanceof RIBean) { RIBean<?> riBean = (RIBean<?>) input.bean; beanType = riBean.getType(); } else { beanType = input.bean.getBeanClass(); if (Proxies.isTypeProxyable(beanType, services())) { return createClientProxy(input.bean, types.add(beanType).build()); if (Proxies.isTypeProxyable(input.requestedType, services())) { return createClientProxy(input.bean, types.add(input.requestedType).build()); Class<?> requestedRawType = Reflections.getRawType(input.requestedType); for (Type type : input.bean.getTypes()) { if (requestedRawType.isAssignableFrom(Reflections.getRawType(type)) && Proxies.isTypeProxyable(type, services())) { return createClientProxy(input.bean, types.add(type).build());
this.contextId = contextId; this.proxiedBeanType = proxiedBeanType; this.configuration = Container.instance(contextId).deploymentManager().getServices().get(WeldConfiguration.class); addInterfacesFromTypeClosure(typeClosure, proxiedBeanType); TypeInfo typeInfo = TypeInfo.of(typeClosure); this.classLoader = resolveClassLoaderForBeanProxy(contextId, bean.getBeanClass(), typeInfo); } else { this.classLoader = resolveClassLoaderForBeanProxy(contextId, proxiedBeanType, typeInfo); LinkedHashSet<Class<?>> sorted = Proxies.sortInterfacesHierarchy(additionalInterfaces); additionalInterfaces.clear(); additionalInterfaces.addAll(sorted); this.proxyInstantiator = Container.instance(contextId).services().get(ProxyInstantiator.class);
/** * Indicates if a bean is proxyable * * @param bean The bean to test * @return True if proxyable, false otherwise */ public static boolean isBeanProxyable(Bean<?> bean, BeanManagerImpl manager) { if (bean instanceof RIBean<?>) { return ((RIBean<?>) bean).isProxyable(); } else { return Proxies.isTypesProxyable(bean.getTypes(), manager.getServices()); } }
public static UnproxyableResolutionException getUnproxyableTypesException(Bean<?> declaringBean, ServiceRegistry services) { if (declaringBean == null) { throw new java.lang.IllegalArgumentException("Null declaring bean!"); } return getUnproxyableTypesExceptionInt(declaringBean.getTypes(), declaringBean, services); }
return; // do not validate delegate injection points as these are special Set<?> resolvedBeans = beanManager.getBeanResolver().resolve(beanManager.getBeans(ij)); if (!isInjectionPointSatisfied(ij, resolvedBeans, beanManager)) { throw ValidatorLogger.LOG.injectionPointHasUnsatisfiedDependencies( ij, Formats.formatAnnotations(ij.getQualifiers()), throw ValidatorLogger.LOG.injectionPointHasAmbiguousDependencies( ij, Formats.formatAnnotations(ij.getQualifiers()), if (beanManager.isNormalScope(resolvedBean.getScope())) { UnproxyableResolutionException ue = Proxies.getUnproxyableTypeException(ij.getType(), resolvedBean, beanManager.getServices()); if (ue != null) { throw ValidatorLogger.LOG.injectionPointHasNonProxyableDependencies(ij, Formats.formatAsStackTraceElement(ij), ue);
return ValidatorLogger.LOG.notProxyablePrimitive(clazz, getDeclaringBeanInfo(declaringBean)); } else if (Reflections.isArrayType(clazz)) { return ValidatorLogger.LOG.notProxyableArrayType(clazz, getDeclaringBeanInfo(declaringBean)); } else if (Reflections.isFinal(clazz)) { return ValidatorLogger.LOG.notProxyableFinalType(clazz, getDeclaringBeanInfo(declaringBean)); } else { Method finalMethod = Reflections.getNonPrivateNonStaticFinalMethod(clazz); if (finalMethod != null) { if (services.get(WeldConfiguration.class).isFinalMethodIgnored(clazz.getName())) { ValidatorLogger.LOG.notProxyableFinalMethodIgnored(finalMethod, getDeclaringBeanInfo(declaringBean)); } else { return ValidatorLogger.LOG.notProxyableFinalMethod(clazz, finalMethod, getDeclaringBeanInfo(declaringBean)); UnproxyableResolutionException exception = services.get(ProxyInstantiator.class).validateNoargConstructor(constructor, clazz, declaringBean); if (exception != null) { return exception;
public ExtensionBean(BeanManagerImpl manager, EnhancedAnnotatedType<E> enhancedAnnotatedType, Metadata<E> instance) { super(new StringBeanIdentifier(BeanIdentifiers.forExtension(enhancedAnnotatedType)), manager, enhancedAnnotatedType.getJavaClass()); this.annotatedType = enhancedAnnotatedType.slim(); this.instance = instance; this.passivationCapable = enhancedAnnotatedType.isSerializable(); this.proxiable = Proxies.isTypeProxyable(enhancedAnnotatedType.getBaseType(), manager.getServices()); checkPublicFields(enhancedAnnotatedType); }
super(attributes, new StringBeanIdentifier(BeanIdentifiers.forProducerField(field, declaringBean)), declaringBean, manager, services); this.enhancedAnnotatedField = field; this.annotatedField = field.slim(); initType(); this.proxiable = Proxies.isTypesProxyable(field.getTypeClosure(), beanManager.getServices()); setProducer(new ProducerFieldProducer<X, T>(field, disposalMethod) {
@Override public T createInterceptedInstance(T instance) { if (used) { throw InterceptorLogger.LOG.interceptionFactoryNotReusable(); } if (instance instanceof ProxyObject) { InterceptorLogger.LOG.interceptionFactoryInternalContainerConstruct(instance.getClass()); return instance; } UnproxyableResolutionException exception = Proxies.getUnproxyableTypeException(annotatedType.getBaseType(), null, beanManager.getServices(), ignoreFinalMethods); if (exception != null) { throw exception; } used = true; Optional<InterceptionFactoryData<T>> cached = beanManager.getServices().get(InterceptionFactoryDataCache.class) .getInterceptionFactoryData(configurator != null ? configurator.complete() : annotatedType); if (!cached.isPresent()) { InterceptorLogger.LOG.interceptionFactoryNotRequired(annotatedType.getJavaClass().getSimpleName()); return instance; } InterceptionFactoryData<T> data = cached.get(); InterceptedProxyMethodHandler methodHandler = new InterceptedProxyMethodHandler(instance); methodHandler.setInterceptorMethodHandler(new InterceptorMethodHandler( InterceptionContext.forNonConstructorInterception(data.getInterceptionModel(), creationalContext, beanManager, data.getSlimAnnotatedType()))); T proxy = (System.getSecurityManager() == null) ? data.getInterceptedProxyFactory().run() : AccessController.doPrivileged(data.getInterceptedProxyFactory()); ((ProxyObject) proxy).weld_setHandler(methodHandler); return proxy; }
/** * Constructor * * @param type The type of the bean * @param beanManager The Bean manager */ protected ManagedBean(BeanAttributes<T> attributes, EnhancedAnnotatedType<T> type, BeanIdentifier identifier, BeanManagerImpl beanManager) { super(attributes, type, identifier, beanManager); this.proxiable = Proxies.isTypesProxyable(getTypes(), beanManager.getServices()); setProducer(beanManager.getLocalInjectionTargetFactory(getEnhancedAnnotated()).createInjectionTarget(getEnhancedAnnotated(), this, false)); }
@Override public <T> UnproxyableResolutionException validateNoargConstructor(Constructor<T> constructor, Class<?> clazz, Bean<?> declaringBean) throws UnproxyableResolutionException { if (constructor == null) { return ValidatorLogger.LOG.notProxyableNoConstructor(clazz, Proxies.getDeclaringBeanInfo(declaringBean)); } else if (Modifier.isPrivate(constructor.getModifiers())) { return new UnproxyableResolutionException(ValidatorLogger.LOG.notProxyablePrivateConstructor(clazz.getName(), constructor, Proxies.getDeclaringBeanInfo(declaringBean))); } return null; }
public static UnproxyableResolutionException getUnproxyableTypesException(Iterable<? extends Type> types, ServiceRegistry services) { return getUnproxyableTypesExceptionInt(types, null, services); }
/** * * @param interfaces * @return the sorted set of interfaces */ public static LinkedHashSet<Class<?>> sortInterfacesHierarchy(Set<Class<?>> interfaces) { LinkedHashSet<Class<?>> sorted = new LinkedHashSet<>(interfaces.size()); processSuperinterface(null, interfaces, sorted); if (interfaces.size() != sorted.size()) { // Interface may not processed due to incomplete type closure Set<Class<?>> unprocessed = new HashSet<>(interfaces); unprocessed.removeAll(sorted); for (Class<?> unprocessedInterface : unprocessed) { processSuperinterface(unprocessedInterface, interfaces, sorted); sorted.add(unprocessedInterface); } } return sorted; }
@Override public Object apply(Bean<Object> from) { if (Proxies.isTypesProxyable(from, services())) { return createClientProxy(from); } else { return BEAN_NOT_PROXYABLE_MARKER; } } }
for (Type type : input.bean.getTypes()) { if (Reflections.getRawType(type).isInterface()) { types.add(type); if (input.bean instanceof RIBean) { RIBean<?> riBean = (RIBean<?>) input.bean; beanType = riBean.getType(); } else { beanType = input.bean.getBeanClass(); if (Proxies.isTypeProxyable(beanType, services())) { return createClientProxy(input.bean, types.add(beanType).build()); if (Proxies.isTypeProxyable(input.requestedType, services())) { return createClientProxy(input.bean, types.add(input.requestedType).build()); Class<?> requestedRawType = Reflections.getRawType(input.requestedType); for (Type type : input.bean.getTypes()) { if (requestedRawType.isAssignableFrom(Reflections.getRawType(type)) && Proxies.isTypeProxyable(type, services())) { return createClientProxy(input.bean, types.add(type).build());
this.contextId = contextId; this.proxiedBeanType = proxiedBeanType; this.configuration = Container.instance(contextId).deploymentManager().getServices().get(WeldConfiguration.class); addInterfacesFromTypeClosure(typeClosure, proxiedBeanType); TypeInfo typeInfo = TypeInfo.of(typeClosure); proxyServices = Container.instance(contextId).services().get(ProxyServices.class); if (!proxyServices.supportsClassDefining()) { if (bean != null) { this.classLoader = resolveClassLoaderForBeanProxy(contextId, bean.getBeanClass(), typeInfo, proxyServices); } else { this.classLoader = resolveClassLoaderForBeanProxy(contextId, proxiedBeanType, typeInfo, proxyServices); LinkedHashSet<Class<?>> sorted = Proxies.sortInterfacesHierarchy(additionalInterfaces); additionalInterfaces.clear(); additionalInterfaces.addAll(sorted); this.proxyInstantiator = Container.instance(contextId).services().get(ProxyInstantiator.class);