use of org.exoplatform.management.annotations.ManagedBy in project kernel by exoplatform.
the class ManagementContextImpl method register.
public void register(Object o) {
Object resource = null;
// Apply managed by annotation
ManagedBy managedBy = o.getClass().getAnnotation(ManagedBy.class);
if (managedBy != null) {
try {
Class<?> managedByClass = managedBy.value();
Constructor<?> blah = managedByClass.getConstructor(o.getClass());
resource = blah.newInstance(o);
} catch (NoSuchMethodException e) {
LOG.error(e.getLocalizedMessage(), e);
} catch (InstantiationException e) {
LOG.error(e.getLocalizedMessage(), e);
} catch (IllegalAccessException e) {
LOG.error(e.getLocalizedMessage(), e);
} catch (InvocationTargetException e) {
LOG.error(e.getLocalizedMessage(), e);
}
} else {
resource = o;
}
//
if (resource != null) {
MetaDataBuilder builder = new MetaDataBuilder(resource.getClass());
if (builder.isBuildable()) {
ManagedTypeMetaData metaData = builder.build();
//
ManagementContextImpl managementContext;
if (resource instanceof Container) {
managementContext = (ManagementContextImpl) ((Container) resource).getManagementContext();
} else {
managementContext = new ManagementContextImpl(this, resource, metaData);
}
//
if (registrations.containsKey(resource)) {
LOG.debug("The component " + resource + " has already been registered");
return;
} else {
registrations.put(resource, managementContext);
}
//
ManageableContainer container = findContainer();
// Install for all the providers related
for (ManagementProvider provider : container.getProviders()) {
Object name = provider.manage(managementContext);
if (name != null) {
managementContext.managedSet.put(provider, name);
}
}
// Allow for more resource management
if (resource instanceof ManagementAware) {
((ManagementAware) resource).setContext(managementContext);
}
}
}
}
Aggregations