private static void checkBeanTypeForWildcardsAndTypeVariables(Type beanType, Type type, BeanAttributes<?> attributes) { if (type instanceof TypeVariable<?>) { if (!attributes.getScope().equals(Dependent.class)) { throw MetadataLogger.LOG.beanWithParameterizedTypeContainingTypeVariablesMustBeDependentScoped(beanType, attributes); } } else if (type instanceof WildcardType) { throw MetadataLogger.LOG.parameterizedTypeContainingWildcardParameterIsNotAValidBeanType(beanType, attributes); } else if (type instanceof ParameterizedType) { ParameterizedType parameterizedType = (ParameterizedType) type; for (Type typeArgument : parameterizedType.getActualTypeArguments()) { checkBeanTypeForWildcardsAndTypeVariables(beanType, typeArgument, attributes); } } else if (type instanceof GenericArrayType) { GenericArrayType arrayType = (GenericArrayType) type; checkBeanTypeForWildcardsAndTypeVariables(beanType, arrayType.getGenericComponentType(), attributes); } }
private static void checkNotNull(Object expression, String methodName, Object target) { if (expression == null) { throw MetadataLogger.LOG.metadataSourceReturnedNull(methodName, target); } }
/** * Initializes the default scope type */ private void initDefaultScopeType(EnhancedAnnotation<T> annotatedAnnotation) { Set<Annotation> scopeTypes = new HashSet<Annotation>(); scopeTypes.addAll(annotatedAnnotation.getMetaAnnotations(Scope.class)); scopeTypes.addAll(annotatedAnnotation.getMetaAnnotations(NormalScope.class)); if (scopeTypes.size() > 1) { throw MetadataLogger.LOG.multipleScopes(annotatedAnnotation); } else if (scopeTypes.size() == 1) { this.defaultScopeType = scopeTypes.iterator().next(); } }
@Override public void addContext(Context context) { checkWithinObserverNotification(); Preconditions.checkArgumentNotNull(context, "context"); Class<? extends Annotation> scope = context.getScope(); if (scope == null) { throw ContextLogger.LOG.contextHasNullScope(context); } if (!getBeanManager().isScope(scope)) { MetadataLogger.LOG.contextGetScopeIsNotAScope(scope, context); } if (scope == ApplicationScoped.class || scope == Dependent.class) { throw ContextLogger.LOG.cannotRegisterContext(scope, context); } getBeanManager().addContext(context); BootstrapLogger.LOG.addContext(getReceiver(), context); }
private SlimAnnotatedType<?> tryToLoadUnknownBackedAnnotatedType() { if (identifier.getSuffix() != null || identifier.isModified()) { return null; // this is not a backed annotated type } // first, obtain the BeanManager for a given BDA final BeanManagerImpl manager = Container.instance(identifier).getBeanManager(identifier.getBdaId()); if (manager == null) { return null; } // second, try to load the class final ResourceLoader resourceLoader = manager.getServices().get(ResourceLoader.class); Class<?> clazz = null; try { clazz = resourceLoader.classForName(identifier.getClassName()); } catch (ResourceLoadingException e) { MetadataLogger.LOG.catchingDebug(e); return null; } // finally, try to load the annotated type try { return manager.getServices().get(ClassTransformer.class).getBackedAnnotatedType(clazz, identifier.getBdaId()); } catch (ResourceLoadingException e) { MetadataLogger.LOG.catchingDebug(e); return null; } } }
/** * Checks if the given AnnotatedType is sensible, otherwise provides warnings. */ private static void checkSensibility(AnnotatedType<?> type) { // check if it has a constructor if (type.getConstructors().isEmpty() && !type.getJavaClass().isInterface()) { MetadataLogger.LOG.noConstructor(type); } Set<Class<?>> hierarchy = new HashSet<Class<?>>(); for (Class<?> clazz = type.getJavaClass(); clazz != null; clazz = clazz.getSuperclass()) { hierarchy.add(clazz); hierarchy.addAll(Reflections.getInterfaceClosure(clazz)); } checkMembersBelongToHierarchy(type.getConstructors(), hierarchy, type); checkMembersBelongToHierarchy(type.getMethods(), hierarchy, type); checkMembersBelongToHierarchy(type.getFields(), hierarchy, type); }
private Object readResolve() throws ObjectStreamException { SlimAnnotatedType<?> type = Container.instance(identifier).services().get(ClassTransformer.class).getSlimAnnotatedTypeById(identifier); if (type == null) { type = tryToLoadUnknownBackedAnnotatedType(); } if (type == null) { throw MetadataLogger.LOG.annotatedTypeDeserializationFailure(identifier); } return type; }
static ImmutableSet.Builder<Type> omitIllegalBeanTypes(Set<Type> types, Object baseType) { ImmutableSet.Builder<Type> builder = ImmutableSet.builder(); for (Type type : types) { if (Types.isIllegalBeanType(type)) { MetadataLogger.LOG.illegalBeanTypeIgnored(type, baseType); } else { builder.add(type); } } return builder; }
public static void validateAnnotatedParameter(AnnotatedParameter<?> parameter) { validateAnnotated(parameter); if (parameter.getPosition() < 0) { throw MetadataLogger.LOG.invalidParameterPosition(parameter.getPosition(), parameter); } checkNotNull(parameter.getDeclaringCallable(), "getDeclaringCallable()", parameter); }
/** * Initializes the type */ protected void initType(EnhancedAnnotation<T> annotatedAnnotation) { if (!Annotation.class.isAssignableFrom(getRawType())) { throw MetadataLogger.LOG.metaAnnotationOnWrongType(getMetaAnnotationTypes(), getRawType()); } }
@Override public void addContext(Context context) { checkWithinObserverNotification(); Preconditions.checkArgumentNotNull(context, "context"); Class<? extends Annotation> scope = context.getScope(); if (scope == null) { throw ContextLogger.LOG.contextHasNullScope(context); } if (!getBeanManager().isScope(scope)) { MetadataLogger.LOG.contextGetScopeIsNotAScope(scope, context); } if (scope == ApplicationScoped.class || scope == Dependent.class) { throw ContextLogger.LOG.cannotRegisterContext(scope, context); } getBeanManager().addContext(context); BootstrapLogger.LOG.addContext(getReceiver(), context); }
private SlimAnnotatedType<?> tryToLoadUnknownBackedAnnotatedType() { if (identifier.getSuffix() != null || identifier.isModified()) { return null; // this is not a backed annotated type } // first, obtain the BeanManager for a given BDA final BeanManagerImpl manager = Container.instance(identifier).getBeanManager(identifier.getBdaId()); if (manager == null) { return null; } // second, try to load the class final ResourceLoader resourceLoader = manager.getServices().get(ResourceLoader.class); Class<?> clazz = null; try { clazz = resourceLoader.classForName(identifier.getClassName()); } catch (ResourceLoadingException e) { MetadataLogger.LOG.catchingDebug(e); return null; } // finally, try to load the annotated type try { return manager.getServices().get(ClassTransformer.class).getBackedAnnotatedType(clazz, identifier.getBdaId()); } catch (ResourceLoadingException e) { MetadataLogger.LOG.catchingDebug(e); return null; } } }
/** * Checks if the given AnnotatedType is sensible, otherwise provides warnings. */ private static void checkSensibility(AnnotatedType<?> type) { // check if it has a constructor if (type.getConstructors().isEmpty() && !type.getJavaClass().isInterface()) { MetadataLogger.LOG.noConstructor(type); } Set<Class<?>> hierarchy = new HashSet<Class<?>>(); for (Class<?> clazz = type.getJavaClass(); clazz != null; clazz = clazz.getSuperclass()) { hierarchy.add(clazz); hierarchy.addAll(Reflections.getInterfaceClosure(clazz)); } checkMembersBelongToHierarchy(type.getConstructors(), hierarchy, type); checkMembersBelongToHierarchy(type.getMethods(), hierarchy, type); checkMembersBelongToHierarchy(type.getFields(), hierarchy, type); }
private Object readResolve() throws ObjectStreamException { SlimAnnotatedType<?> type = Container.instance(identifier).services().get(ClassTransformer.class).getSlimAnnotatedTypeById(identifier); if (type == null) { type = tryToLoadUnknownBackedAnnotatedType(); } if (type == null) { throw MetadataLogger.LOG.annotatedTypeDeserializationFailure(identifier); } return type; }
static ImmutableSet.Builder<Type> omitIllegalBeanTypes(Set<Type> types, Object baseType) { ImmutableSet.Builder<Type> builder = ImmutableSet.builder(); for (Type type : types) { if (Types.isIllegalBeanType(type)) { MetadataLogger.LOG.illegalBeanTypeIgnored(type, baseType); } else { builder.add(type); } } return builder; }
public static void validateAnnotatedParameter(AnnotatedParameter<?> parameter) { validateAnnotated(parameter); if (parameter.getPosition() < 0) { throw MetadataLogger.LOG.invalidParameterPosition(parameter.getPosition(), parameter); } checkNotNull(parameter.getDeclaringCallable(), "getDeclaringCallable()", parameter); }
/** * Initializes the type */ protected void initType(EnhancedAnnotation<T> annotatedAnnotation) { if (!Annotation.class.isAssignableFrom(getRawType())) { throw MetadataLogger.LOG.metaAnnotationOnWrongType(getMetaAnnotationTypes(), getRawType()); } }
@Override public void addContext(Context context) { checkWithinObserverNotification(); Preconditions.checkArgumentNotNull(context, "context"); Class<? extends Annotation> scope = context.getScope(); if (scope == null) { throw ContextLogger.LOG.contextHasNullScope(context); } if (!getBeanManager().isScope(scope)) { MetadataLogger.LOG.contextGetScopeIsNotAScope(scope, context); } if (scope == ApplicationScoped.class || scope == Dependent.class) { throw ContextLogger.LOG.cannotRegisterContext(scope, context); } getBeanManager().addContext(context); BootstrapLogger.LOG.addContext(getReceiver(), context); }
private static void checkBeanTypeForWildcardsAndTypeVariables(Type beanType, Type type, BeanAttributes<?> attributes) { if (type instanceof TypeVariable<?>) { if (!attributes.getScope().equals(Dependent.class)) { throw MetadataLogger.LOG.beanWithParameterizedTypeContainingTypeVariablesMustBeDependentScoped(beanType, attributes); } } else if (type instanceof WildcardType) { throw MetadataLogger.LOG.parameterizedTypeContainingWildcardParameterIsNotAValidBeanType(beanType, attributes); } else if (type instanceof ParameterizedType) { ParameterizedType parameterizedType = (ParameterizedType) type; for (Type typeArgument : parameterizedType.getActualTypeArguments()) { checkBeanTypeForWildcardsAndTypeVariables(beanType, typeArgument, attributes); } } else if (type instanceof GenericArrayType) { GenericArrayType arrayType = (GenericArrayType) type; checkBeanTypeForWildcardsAndTypeVariables(beanType, arrayType.getGenericComponentType(), attributes); } }
private SlimAnnotatedType<?> tryToLoadUnknownBackedAnnotatedType() { if (identifier.getSuffix() != null || identifier.isModified()) { return null; // this is not a backed annotated type } // first, obtain the BeanManager for a given BDA final BeanManagerImpl manager = Container.instance(identifier).getBeanManager(identifier.getBdaId()); if (manager == null) { return null; } // second, try to load the class final ResourceLoader resourceLoader = manager.getServices().get(ResourceLoader.class); Class<?> clazz = null; try { clazz = resourceLoader.classForName(identifier.getClassName()); } catch (ResourceLoadingException e) { MetadataLogger.LOG.catchingDebug(e); return null; } // finally, try to load the annotated type try { return manager.getServices().get(ClassTransformer.class).getBackedAnnotatedType(clazz, identifier.getBdaId()); } catch (ResourceLoadingException e) { MetadataLogger.LOG.catchingDebug(e); return null; } } }