Type typeParameter = type.getActualTypeArguments()[0]; if (typeParameter instanceof Class<?>) { this.observers.put(observer, new ExactTypePredicate(Reflections.getRawType(typeParameter))); } else if (typeParameter instanceof ParameterizedType) { checkBounds(observer, wildCard.getUpperBounds()); this.observers.put(observer, CompositePredicate.assignable(Types.getRawTypes(wildCard.getUpperBounds()))); } else if (typeParameter instanceof TypeVariable<?>) { checkBounds(observer, variable.getBounds()); this.observers.put(observer, CompositePredicate.assignable(Types.getRawTypes(variable.getBounds()))); defaultRules(observer, observedType);
/** * Resolves a set of {@code ProcessAnnotatedType} observer methods for the specified class. If no observer methods are resolved, an * empty set is returned. * * @param className the specified class name * @return the set of resolved ProcessAnnotatedType observer methods */ public Set<ContainerLifecycleEventObserverMethod<?>> resolveProcessAnnotatedTypeObservers(ClassFileServices classFileServices, String className) { Set<ContainerLifecycleEventObserverMethod<?>> result = new HashSet<ContainerLifecycleEventObserverMethod<?>>(); result.addAll(catchAllObservers); ClassFileInfo classInfo = classFileServices.getClassFileInfo(className); for (Map.Entry<ContainerLifecycleEventObserverMethod<?>, Predicate<ClassFileInfo>> entry : observers.entrySet()) { ContainerLifecycleEventObserverMethod<?> observer = entry.getKey(); if (containsRequiredAnnotation(classInfo, observer) && entry.getValue().test(classInfo)) { result.add(observer); } } return result; }
public FastProcessAnnotatedTypeResolver(Iterable<ObserverMethod<?>> observers) throws UnsupportedObserverMethodException { this.catchAllObservers = new HashSet<>(); this.observers = new LinkedHashMap<ContainerLifecycleEventObserverMethod<?>, Predicate<ClassFileInfo>>(); for (ObserverMethod<?> o : observers) { if (o instanceof ContainerLifecycleEventObserverMethod<?>) { final Set<Annotation> qualifiers = o.getObservedQualifiers(); // only process observer methods with no qualifiers or with @Any if (qualifiers.isEmpty() || (qualifiers.size() == 1 && Any.class.equals(qualifiers.iterator().next().annotationType()))) { process((ContainerLifecycleEventObserverMethod<?>) o, o.getObservedType()); } } } }
private void defaultRules(ContainerLifecycleEventObserverMethod<?> observer, Type observedType) throws UnsupportedObserverMethodException { if (ProcessAnnotatedType.class.equals(observedType)) { catchAllObservers.add(observer); } else if (observedType instanceof ParameterizedType) { ParameterizedType parameterizedType = (ParameterizedType) observedType; if (ProcessAnnotatedType.class.equals(parameterizedType.getRawType())) { Type argument = parameterizedType.getActualTypeArguments()[0]; if (argument instanceof Class<?>) { this.observers.put(observer, new ExactTypePredicate(Reflections.getRawType(argument))); } else { throw new UnsupportedObserverMethodException(observer); } } } else if (observedType instanceof TypeVariable) { final TypeVariable<?> typeVariable = (TypeVariable<?>) observedType; if (Reflections.isUnboundedTypeVariable(observedType)) { // <T> void observe(T event) catchAllObservers.add(observer); } else { if (typeVariable.getBounds().length == 1) { // here we expect that a PAT impl only implements the PAT interface defaultRules(observer, typeVariable.getBounds()[0]); } } } }
@Override public <T> SlimAnnotatedTypeContext<T> loadAnnotatedType(String className, String bdaId) { try { final ClassFileInfo classFileInfo = classFileServices.getClassFileInfo(className); observerMethods = resolver.resolveProcessAnnotatedTypeObservers(classFileServices, className); if (!observerMethods.isEmpty()) { BootstrapLogger.LOG.decoratorWithNonCdiConstructor(classFileInfo.getClassName()); BootstrapLogger.LOG.exceptionLoadingAnnotatedType(e.getMessage()); return fallback.loadAnnotatedType(className, bdaId);
private void installFastProcessAnnotatedTypeResolver(ServiceRegistry services) { ClassFileServices classFileServices = services.get(ClassFileServices.class); if (classFileServices != null) { final GlobalObserverNotifierService observers = services.get(GlobalObserverNotifierService.class); try { final FastProcessAnnotatedTypeResolver resolver = new FastProcessAnnotatedTypeResolver(observers.getAllObserverMethods()); services.add(FastProcessAnnotatedTypeResolver.class, resolver); } catch (UnsupportedObserverMethodException e) { BootstrapLogger.LOG.notUsingFastResolver(e.getObserver()); return; } } }
private void defaultRules(ExtensionObserverMethodImpl<?, ?> observer, Type observedType) throws UnsupportedObserverMethodException { if (ProcessAnnotatedType.class.equals(observedType)) { catchAllObservers.add(observer); } else if (observedType instanceof ParameterizedType) { ParameterizedType parameterizedType = (ParameterizedType) observedType; if (ProcessAnnotatedType.class.equals(parameterizedType.getRawType())) { Type argument = parameterizedType.getActualTypeArguments()[0]; if (argument instanceof Class<?>) { this.observers.put(observer, new ExactTypePredicate(Reflections.getRawType(argument))); } else { throw new UnsupportedObserverMethodException(observer); } } } else if (observedType instanceof TypeVariable) { final TypeVariable<?> typeVariable = (TypeVariable<?>) observedType; if (Reflections.isUnboundedTypeVariable(observedType)) { // <T> void observe(T event) catchAllObservers.add(observer); } else { if (typeVariable.getBounds().length == 1) { // here we expect that a PAT impl only implements the PAT interface defaultRules(observer, typeVariable.getBounds()[0]); } } } }
@Override public <T> SlimAnnotatedTypeContext<T> loadAnnotatedType(String className, String bdaId) { try { final ClassFileInfo classFileInfo = classFileServices.getClassFileInfo(className); observerMethods = resolver.resolveProcessAnnotatedTypeObservers(classFileServices, className); if (!observerMethods.isEmpty()) { BootstrapLogger.LOG.decoratorWithNonCdiConstructor(classFileInfo.getClassName()); BootstrapLogger.LOG.exceptionLoadingAnnotatedType(e.getMessage()); return fallback.loadAnnotatedType(className, bdaId);
private void installFastProcessAnnotatedTypeResolver(ServiceRegistry services) { ClassFileServices classFileServices = services.get(ClassFileServices.class); if (classFileServices != null) { final GlobalObserverNotifierService observers = services.get(GlobalObserverNotifierService.class); try { final FastProcessAnnotatedTypeResolver resolver = new FastProcessAnnotatedTypeResolver(observers.getAllObserverMethods()); services.add(FastProcessAnnotatedTypeResolver.class, resolver); } catch (UnsupportedObserverMethodException e) { BootstrapLogger.LOG.notUsingFastResolver(e.getObserver()); return; } } }
private void defaultRules(ContainerLifecycleEventObserverMethod<?> observer, Type observedType) throws UnsupportedObserverMethodException { if (ProcessAnnotatedType.class.equals(observedType)) { catchAllObservers.add(observer); } else if (observedType instanceof ParameterizedType) { ParameterizedType parameterizedType = (ParameterizedType) observedType; if (ProcessAnnotatedType.class.equals(parameterizedType.getRawType())) { Type argument = parameterizedType.getActualTypeArguments()[0]; if (argument instanceof Class<?>) { this.observers.put(observer, new ExactTypePredicate(Reflections.getRawType(argument))); } else { throw new UnsupportedObserverMethodException(observer); } } } else if (observedType instanceof TypeVariable) { final TypeVariable<?> typeVariable = (TypeVariable<?>) observedType; if (Reflections.isUnboundedTypeVariable(observedType)) { // <T> void observe(T event) catchAllObservers.add(observer); } else { if (typeVariable.getBounds().length == 1) { // here we expect that a PAT impl only implements the PAT interface defaultRules(observer, typeVariable.getBounds()[0]); } } } }
Type typeParameter = type.getActualTypeArguments()[0]; if (typeParameter instanceof Class<?>) { this.observers.put(observer, new ExactTypePredicate(Reflections.getRawType(typeParameter))); } else if (typeParameter instanceof ParameterizedType) { checkBounds(observer, wildCard.getUpperBounds()); this.observers.put(observer, CompositePredicate.assignable(Types.getRawTypes(wildCard.getUpperBounds()))); } else if (typeParameter instanceof TypeVariable<?>) { checkBounds(observer, variable.getBounds()); this.observers.put(observer, CompositePredicate.assignable(Types.getRawTypes(variable.getBounds()))); defaultRules(observer, observedType);
@Override public <T> SlimAnnotatedTypeContext<T> loadAnnotatedType(String className, String bdaId) { try { final ClassFileInfo classFileInfo = classFileServices.getClassFileInfo(className); observerMethods = resolver.resolveProcessAnnotatedTypeObservers(classFileServices, className); if (!observerMethods.isEmpty()) { BootstrapLogger.LOG.decoratorWithNonCdiConstructor(classFileInfo.getClassName()); BootstrapLogger.LOG.exceptionLoadingAnnotatedType(e.getMessage()); return fallback.loadAnnotatedType(className, bdaId);
private void installFastProcessAnnotatedTypeResolver(ServiceRegistry services) { ClassFileServices classFileServices = services.get(ClassFileServices.class); if (classFileServices != null) { final GlobalObserverNotifierService observers = services.get(GlobalObserverNotifierService.class); try { final FastProcessAnnotatedTypeResolver resolver = new FastProcessAnnotatedTypeResolver(observers.getAllObserverMethods()); services.add(FastProcessAnnotatedTypeResolver.class, resolver); } catch (UnsupportedObserverMethodException e) { BootstrapLogger.LOG.notUsingFastResolver(e.getObserver()); return; } } }
/** * Resolves a set of {@code ProcessAnnotatedType} observer methods for the specified class. If no observer methods are resolved, an * empty set is returned. * * @param className the specified class name * @return the set of resolved ProcessAnnotatedType observer methods */ public Set<ContainerLifecycleEventObserverMethod<?>> resolveProcessAnnotatedTypeObservers(ClassFileServices classFileServices, String className) { Set<ContainerLifecycleEventObserverMethod<?>> result = new HashSet<ContainerLifecycleEventObserverMethod<?>>(); result.addAll(catchAllObservers); ClassFileInfo classInfo = classFileServices.getClassFileInfo(className); for (Map.Entry<ContainerLifecycleEventObserverMethod<?>, Predicate<ClassFileInfo>> entry : observers.entrySet()) { ContainerLifecycleEventObserverMethod<?> observer = entry.getKey(); if (containsRequiredAnnotation(classInfo, observer) && entry.getValue().test(classInfo)) { result.add(observer); } } return result; }
public FastProcessAnnotatedTypeResolver(Iterable<ObserverMethod<?>> observers) throws UnsupportedObserverMethodException { this.catchAllObservers = new HashSet<>(); this.observers = new LinkedHashMap<ContainerLifecycleEventObserverMethod<?>, Predicate<ClassFileInfo>>(); for (ObserverMethod<?> o : observers) { if (o instanceof ContainerLifecycleEventObserverMethod<?>) { final Set<Annotation> qualifiers = o.getObservedQualifiers(); // only process observer methods with no qualifiers or with @Any if (qualifiers.isEmpty() || (qualifiers.size() == 1 && Any.class.equals(qualifiers.iterator().next().annotationType()))) { process((ContainerLifecycleEventObserverMethod<?>) o, o.getObservedType()); } } } }
private void defaultRules(ContainerLifecycleEventObserverMethod<?> observer, Type observedType) throws UnsupportedObserverMethodException { if (ProcessAnnotatedType.class.equals(observedType)) { catchAllObservers.add(observer); } else if (observedType instanceof ParameterizedType) { ParameterizedType parameterizedType = (ParameterizedType) observedType; if (ProcessAnnotatedType.class.equals(parameterizedType.getRawType())) { Type argument = parameterizedType.getActualTypeArguments()[0]; if (argument instanceof Class<?>) { this.observers.put(observer, new ExactTypePredicate(Reflections.getRawType(argument))); } else { throw new UnsupportedObserverMethodException(observer); } } } else if (observedType instanceof TypeVariable) { final TypeVariable<?> typeVariable = (TypeVariable<?>) observedType; if (Reflections.isUnboundedTypeVariable(observedType)) { // <T> void observe(T event) catchAllObservers.add(observer); } else { if (typeVariable.getBounds().length == 1) { // here we expect that a PAT impl only implements the PAT interface defaultRules(observer, typeVariable.getBounds()[0]); } } } }
Type typeParameter = type.getActualTypeArguments()[0]; if (typeParameter instanceof Class<?>) { this.observers.put(observer, new ExactTypePredicate(Reflections.getRawType(typeParameter))); } else if (typeParameter instanceof ParameterizedType) { checkBounds(observer, wildCard.getUpperBounds()); this.observers.put(observer, CompositePredicate.assignable(Types.getRawTypes(wildCard.getUpperBounds()))); } else if (typeParameter instanceof TypeVariable<?>) { checkBounds(observer, variable.getBounds()); this.observers.put(observer, CompositePredicate.assignable(Types.getRawTypes(variable.getBounds()))); defaultRules(observer, observedType);
@Override public <T> SlimAnnotatedTypeContext<T> loadAnnotatedType(String className, String bdaId) { try { final ClassFileInfo classFileInfo = classFileServices.getClassFileInfo(className); observerMethods = resolver.resolveProcessAnnotatedTypeObservers(classFileServices, className); if (!observerMethods.isEmpty()) { BootstrapLogger.LOG.decoratorWithNonCdiConstructor(classFileInfo.getClassName()); BootstrapLogger.LOG.exceptionLoadingAnnotatedType(e.getMessage()); return fallback.loadAnnotatedType(className, bdaId);
private void installFastProcessAnnotatedTypeResolver(ServiceRegistry services) { ClassFileServices classFileServices = services.get(ClassFileServices.class); if (classFileServices != null) { final GlobalObserverNotifierService observers = services.get(GlobalObserverNotifierService.class); try { final FastProcessAnnotatedTypeResolver resolver = new FastProcessAnnotatedTypeResolver(observers.getAllObserverMethods()); services.add(FastProcessAnnotatedTypeResolver.class, resolver); } catch (UnsupportedObserverMethodException e) { BootstrapLogger.LOG.notUsingFastResolver(e.getObserver()); return; } } }
/** * Resolves a set of {@code ProcessAnnotatedType} observer methods for the specified class. If no observer methods are resolved, an * empty set is returned. * * @param className the specified class name * @return the set of resolved ProcessAnnotatedType observer methods */ public Set<ContainerLifecycleEventObserverMethod<?>> resolveProcessAnnotatedTypeObservers(ClassFileServices classFileServices, String className) { Set<ContainerLifecycleEventObserverMethod<?>> result = new HashSet<ContainerLifecycleEventObserverMethod<?>>(); result.addAll(catchAllObservers); ClassFileInfo classInfo = classFileServices.getClassFileInfo(className); for (Map.Entry<ContainerLifecycleEventObserverMethod<?>, Predicate<ClassFileInfo>> entry : observers.entrySet()) { ContainerLifecycleEventObserverMethod<?> observer = entry.getKey(); if (containsRequiredAnnotation(classInfo, observer) && entry.getValue().test(classInfo)) { result.add(observer); } } return result; }