in broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredObjectTypeRegistry.java [208:350]
public ConfiguredObjectTypeRegistry(Iterable<ConfiguredObjectRegistration> configuredObjectRegistrations,
final Iterable<ConfiguredObjectAttributeInjector> attributeInjectors,
Collection<Class<? extends ConfiguredObject>> categoriesRestriction,
final ConfiguredObjectFactory objectFactory)
{
_objectFactory = objectFactory;
_attributeInjectors = attributeInjectors;
Set<Class<? extends ConfiguredObject>> categories = new HashSet<>();
Set<Class<? extends ConfiguredObject>> types = new HashSet<>();
for (ConfiguredObjectRegistration registration : configuredObjectRegistrations)
{
for (Class<? extends ConfiguredObject> configuredObjectClass : registration.getConfiguredObjectClasses())
{
if (categoriesRestriction.isEmpty()
|| categoriesRestriction.contains(getCategory(configuredObjectClass)))
{
try
{
process(configuredObjectClass);
ManagedObject annotation = configuredObjectClass.getAnnotation(ManagedObject.class);
if (annotation.category())
{
categories.add(configuredObjectClass);
}
else
{
Class<? extends ConfiguredObject> category = getCategory(configuredObjectClass);
if (category != null)
{
categories.add(category);
}
}
if (!"".equals(annotation.type()))
{
types.add(configuredObjectClass);
}
}
catch (NoClassDefFoundError ncdfe)
{
LOGGER.warn("A class definition could not be found while processing the model for '"
+ configuredObjectClass.getName()
+ "': "
+ ncdfe.getMessage());
}
}
}
}
for (Class<? extends ConfiguredObject> categoryClass : categories)
{
_knownTypes.put(categoryClass, new HashSet<>());
}
for (Class<? extends ConfiguredObject> typeClass : types)
{
for (Class<? extends ConfiguredObject> categoryClass : categories)
{
if (categoryClass.isAssignableFrom(typeClass))
{
ManagedObject annotation = typeClass.getAnnotation(ManagedObject.class);
String annotationType = annotation.type();
if (ModelRoot.class.isAssignableFrom(categoryClass) || factoryExists(categoryClass, annotationType))
{
_knownTypes.get(categoryClass).add(typeClass);
}
}
}
}
for (Class<? extends ConfiguredObject> categoryClass : categories)
{
Set<Class<? extends ConfiguredObject>> typesForCategory = _knownTypes.get(categoryClass);
if (typesForCategory.isEmpty())
{
typesForCategory.add(categoryClass);
_typeSpecificAttributes.put(categoryClass, Set.of());
_typeSpecificStatistics.put(categoryClass, Set.of());
}
else
{
Set<String> commonAttributes = new HashSet<>();
for (ConfiguredObjectAttribute<?, ?> attribute : _allAttributes.get(categoryClass))
{
commonAttributes.add(attribute.getName());
}
Set<String> commonStatistics = new HashSet<>();
for (ConfiguredObjectStatistic<?, ?> statistic : _allStatistics.get(categoryClass))
{
commonStatistics.add(statistic.getName());
}
for (Class<? extends ConfiguredObject> typeClass : typesForCategory)
{
Set<ConfiguredObjectAttribute<?, ?>> attributes = new HashSet<>();
for (ConfiguredObjectAttribute<?, ?> attr : _allAttributes.get(typeClass))
{
if (!commonAttributes.contains(attr.getName()))
{
attributes.add(attr);
}
}
_typeSpecificAttributes.put(typeClass, attributes);
Set<ConfiguredObjectStatistic<?, ?>> statistics = new HashSet<>();
for (ConfiguredObjectStatistic<?, ?> statistic : _allStatistics.get(typeClass))
{
if (!commonStatistics.contains(statistic.getName()))
{
statistics.add(statistic);
}
}
_typeSpecificStatistics.put(typeClass, statistics);
}
}
}
for (Class<? extends ConfiguredObject> type : types)
{
final ManagedObject annotation = type.getAnnotation(ManagedObject.class);
String validChildren = annotation.validChildTypes();
if (!"".equals(validChildren))
{
Method validChildTypesMethod = getValidChildTypesFunction(validChildren, type);
if (validChildTypesMethod != null)
{
try
{
_validChildTypes.put(type,
(Map<String, Collection<String>>) validChildTypesMethod.invoke(null));
}
catch (IllegalAccessException | InvocationTargetException e)
{
throw new IllegalArgumentException("Exception while evaluating valid child types for "
+ type.getName(), e);
}
}
}
}
validateContextDependencies();
}