use of org.jboss.weld.resolution.QualifierInstance in project core by weld.
the class Parsers method createQualifierInstance.
/**
* @param qualifier
* @param resourceLoader
* @param beanManager
* @return the qualifier instance or null
*/
@SuppressWarnings("unchecked")
static QualifierInstance createQualifierInstance(String qualifier, ResourceLoader resourceLoader, BeanManager beanManager) {
String qualifierType = qualifier.contains("(") ? qualifier.substring(0, qualifier.indexOf("(")) : qualifier;
Class<?> qualifierClass = tryLoadClass(qualifierType, resourceLoader);
if (qualifierClass != null) {
Class<? extends Annotation> qualifierAnnotationClass;
try {
qualifierAnnotationClass = (Class<? extends Annotation>) qualifierClass;
} catch (Exception e) {
return null;
}
if (beanManager.isQualifier(qualifierAnnotationClass)) {
Map<String, Object> values;
Method[] qualifierMembers = SecurityActions.getDeclaredMethods(qualifierAnnotationClass);
if (qualifierMembers.length == 0) {
values = Collections.emptyMap();
} else {
Map<String, String> memberValues = parseMemberValues(qualifier);
values = new HashMap<>();
for (Method method : qualifierMembers) {
if (!method.isAnnotationPresent(Nonbinding.class)) {
String value = memberValues.get(method.getName());
if (value == null) {
Object defaultValue = method.getDefaultValue();
if (defaultValue == null) {
return null;
}
values.put(method.getName(), defaultValue);
} else {
Object extracted = extractValue(method, value);
if (extracted == null) {
return null;
}
values.put(method.getName(), extracted);
}
}
}
}
return new QualifierInstance(qualifierAnnotationClass, Collections.unmodifiableMap(values));
}
}
return null;
}
use of org.jboss.weld.resolution.QualifierInstance in project core by weld.
the class Bindings method areQualifiersEquivalent.
public static boolean areQualifiersEquivalent(Annotation qualifier1, Annotation qualifier2, MetaAnnotationStore store) {
checkQualifier(qualifier1, store);
checkQualifier(qualifier2, store);
QualifierInstance q1 = QualifierInstance.of(qualifier1, store);
QualifierInstance q2 = QualifierInstance.of(qualifier2, store);
return q1.equals(q2);
}
use of org.jboss.weld.resolution.QualifierInstance in project core by weld.
the class DefaultJsonDataProvider method receiveAvailableBeans.
@Override
public String receiveAvailableBeans(int pageIndex, int pageSize, String filters, String representation) {
Map<String, String> filterValues = Queries.Filters.parseFilters(filters);
// First validate input
if (!filterValues.containsKey(BDA_ID)) {
return getError("Bean deployment archive id (bdaId) must be specified: " + filters);
}
// Find the bean deployment archive
BeanManagerImpl beanManager = probe.getBeanManager(filterValues.get(BDA_ID));
if (beanManager == null) {
return getError("Unable to find the bean deployment archive for: " + filterValues.get(BDA_ID));
}
Set<Bean<?>> beans = null;
// Parse required type
Type requiredType;
if (filterValues.get(REQUIRED_TYPE) != null) {
requiredType = Parsers.parseType(filterValues.get(REQUIRED_TYPE), beanManager.getServices().get(ResourceLoader.class));
} else {
requiredType = Object.class;
}
if (requiredType == null) {
return getError("Invalid required type: parsing error or the type is not accessible from the specified bean archive!");
}
ResolvableBuilder resolvableBuilder = new ResolvableBuilder(requiredType, beanManager);
// Parse qualifiers
List<QualifierInstance> qualifierInstances;
if (filterValues.get(QUALIFIERS) != null) {
qualifierInstances = Parsers.parseQualifiers(filterValues.get(QUALIFIERS), beanManager.getServices().get(ResourceLoader.class), beanManager);
} else {
qualifierInstances = Collections.singletonList(QualifierInstance.DEFAULT);
}
for (QualifierInstance qualifierInstance : qualifierInstances) {
if (qualifierInstance == null) {
return getError("Invalid qualifiers: parsing error or one of the qualifier types is not accessible from the specified bean archive!");
}
resolvableBuilder.addQualifierUnchecked(qualifierInstance);
}
Resolvable resolvable = resolvableBuilder.create();
// Lookup beans
beans = beanManager.getBeanResolver().resolve(resolvable, false);
if (Boolean.valueOf(filterValues.get(RESOLVE))) {
// Apply resolution rules
beans = beanManager.getBeanResolver().resolve(beans);
}
return JsonObjects.createBeansJson(Queries.find(probe.getOrderedBeans(beans), pageIndex, pageSize, null), probe, beanManager, Representation.from(representation));
}
use of org.jboss.weld.resolution.QualifierInstance in project core by weld.
the class Bindings method areInterceptorBindingsEquivalent.
public static boolean areInterceptorBindingsEquivalent(Annotation qualifier1, Annotation qualifier2, MetaAnnotationStore store) {
checkInterceptorBinding(qualifier1, store);
checkInterceptorBinding(qualifier2, store);
QualifierInstance q1 = QualifierInstance.of(qualifier1, store);
QualifierInstance q2 = QualifierInstance.of(qualifier2, store);
return q1.equals(q2);
}
use of org.jboss.weld.resolution.QualifierInstance in project core by weld.
the class MetaAnnotationStore method getQualifierInstances.
/**
* @param annotations
* @return the set of qualifier instances, uses caches if possible
*/
public Set<QualifierInstance> getQualifierInstances(final Set<Annotation> annotations) {
if (annotations == null || annotations.isEmpty()) {
return Collections.emptySet();
}
ImmutableSet.Builder<QualifierInstance> builder = ImmutableSet.builder();
boolean useSharedCache = true;
for (Annotation annotation : annotations) {
if (isCacheAllowed(annotation)) {
builder.add(qualifierInstanceCache.getValue(annotation));
} else {
builder.add(QualifierInstance.of(annotation, this));
// Don't use shared object cache if there's some qualifier instance which should not be cached
useSharedCache = false;
}
}
return useSharedCache ? sharedObjectCache.getSharedSet(builder.build()) : builder.build();
}
Aggregations