Skip to content
This repository has been archived by the owner on Apr 8, 2019. It is now read-only.

Commit

Permalink
Only allow one value for the Managed annotation as before it was conf…
Browse files Browse the repository at this point in the history
…using and I don't think it's really needed.
  • Loading branch information
nscavell committed Apr 1, 2013
1 parent 126c966 commit 5aaa0ae
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 48 deletions.
Expand Up @@ -35,12 +35,13 @@
public @interface Managed
{
/**
* The value of the path (address) of the resource/operation
* The value of the path of the managed resource. ie: '/foo/bar' will be registered at address
* <code>PathAddress.pathAddress("foo", "bar")</code>
*/
String[] value() default "";
String value() default "";

/**
* The description of the resource/operation
* The description of the managed resource
*/
String description() default "";
}
Expand Up @@ -112,32 +112,23 @@ public ComponentRegistration registerManagedComponent(Class<?> component)
Managed managed = component.getAnnotation(Managed.class);
if (managed == null) throw new RuntimeException(Managed.class + " annotation not present on " + component);

//ManagedPath componentPath = component.getAnnotation(ManagedPath.class);
String[] componentPath = managed.value();
if (componentPath == null || componentPath.length == 0) throw new RuntimeException(Managed.class + " annotation must have a value other then default on " + component);
String componentName = managed.value();
if ("".equals(componentName)) throw new RuntimeException(Managed.class + " annotation must have a value (path) for component class " + component);
if (debug) log.debug("Registering managed component " + componentName);

// Register component
ComponentRegistration registration = null;
for (String path : componentPath)
{
PathAddress address = PathAddress.pathAddress(path);
String componentName = address.iterator().next();
if (debug) log.debug("Registering managed component " + componentName);

registration = registerManagedComponent(componentName);
registration.registerManagedResource(description(managed.description()));
ComponentRegistration registration = registerManagedComponent(componentName);
registration.registerManagedResource(description(managed.description()));

// Register operations
AbstractManagedResource resource = registerManaged(managed, rootResource);
Method[] methods = component.getMethods();
for (Method method : methods)
// Register operations
AbstractManagedResource resource = registerManaged(managed, rootResource);
Method[] methods = component.getMethods();
for (Method method : methods)
{
Managed managedMethod = method.getAnnotation(Managed.class);
if (managedMethod != null)
{
Managed managedMethod = method.getAnnotation(Managed.class);
if (managedMethod != null)
{
if (debug) log.debug("Processing managed method " + getMethodName(method));
registerManagedOperation(registerManaged(managedMethod, resource), method, component, componentName);
}
if (debug) log.debug("Processing managed method " + getMethodName(method));
registerManagedOperation(registerManaged(managedMethod, resource), method, component, componentName);
}
}

Expand All @@ -146,32 +137,25 @@ public ComponentRegistration registerManagedComponent(Class<?> component)

private AbstractManagedResource registerManaged(Managed managed, AbstractManagedResource resource)
{
String[] managedPaths = managed.value();
if (managedPaths != null && managedPaths.length != 0)
PathAddress address = PathAddress.pathAddress(managed.value());
for (Iterator<String> iterator = address.iterator(); iterator.hasNext();)
{
for (String managedPath : managedPaths)
String path = iterator.next();
String description = "";
if (iterator.hasNext())
{
PathAddress address = PathAddress.pathAddress(managedPath);
Iterator<String> iterator = address.iterator();
while (iterator.hasNext())
{
String path = iterator.next();
String description = "";
if (iterator.hasNext())
{
description = managed.description();
}
AbstractManagedResource child = (AbstractManagedResource) resource.getSubResource(path);
if (child == null)
{
if (log.isDebugEnabled()) log.debug("Registering sub resource " + path);
child = (AbstractManagedResource) resource.registerSubResource(path, description(description));
}

resource = child;
}
description = managed.description();
}
AbstractManagedResource child = (AbstractManagedResource) resource.getSubResource(path);
if (child == null)
{
if (log.isDebugEnabled()) log.debug("Registering sub resource " + path);
child = (AbstractManagedResource) resource.registerSubResource(path, description(description));
}

resource = child;
}

return resource;
}

Expand Down

0 comments on commit 5aaa0ae

Please sign in to comment.