[Bug 395168] fix unavailable attributes when return type has annotation
on super class
This commit is contained in:
parent
62ebbbac3c
commit
12075f7196
|
@ -372,16 +372,26 @@ public class ObjectMBean implements DynamicMBean
|
|||
}
|
||||
else
|
||||
{
|
||||
if ( r.getClass().isAnnotationPresent(ManagedObject.class))
|
||||
Class<?> clazz = r.getClass();
|
||||
|
||||
while (clazz != null)
|
||||
{
|
||||
ObjectName mbean = _mbeanContainer.findMBean(r);
|
||||
if (clazz.isAnnotationPresent(ManagedObject.class))
|
||||
{
|
||||
ObjectName mbean = _mbeanContainer.findMBean(r);
|
||||
|
||||
if (mbean == null)
|
||||
return null;
|
||||
r = mbean;
|
||||
}
|
||||
if (mbean != null)
|
||||
{
|
||||
return mbean;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
clazz = clazz.getSuperclass();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return r;
|
||||
|
@ -617,12 +627,10 @@ public class ObjectMBean implements DynamicMBean
|
|||
{
|
||||
returnType = returnType.getComponentType();
|
||||
}
|
||||
|
||||
if ( returnType.isAnnotationPresent(ManagedObject.class))
|
||||
{
|
||||
convert = true;
|
||||
}
|
||||
|
||||
|
||||
// Test to see if the returnType or any of its super classes are managed objects
|
||||
convert = isAnnotationPresent(returnType, ManagedObject.class);
|
||||
|
||||
String uName = name.substring(0, 1).toUpperCase(Locale.ENGLISH) + name.substring(1);
|
||||
Class<?> oClass = onMBean ? this.getClass() : _managed.getClass();
|
||||
|
||||
|
@ -631,7 +639,7 @@ public class ObjectMBean implements DynamicMBean
|
|||
Class<?> type = null;
|
||||
Method setter = null;
|
||||
|
||||
type = method.getReturnType();
|
||||
type = returnType;//method.getReturnType();
|
||||
|
||||
|
||||
// dig out a setter if one exists
|
||||
|
@ -727,7 +735,7 @@ public class ObjectMBean implements DynamicMBean
|
|||
}
|
||||
|
||||
_attributes.add(name);
|
||||
|
||||
|
||||
return info;
|
||||
}
|
||||
catch (Exception e)
|
||||
|
@ -867,6 +875,22 @@ public class ObjectMBean implements DynamicMBean
|
|||
|
||||
return variableName;
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected boolean isAnnotationPresent(Class<?> clazz, Class<? extends Annotation> annotation)
|
||||
{
|
||||
Class<?> test = clazz;
|
||||
|
||||
while (test != null )
|
||||
{
|
||||
if ( test.isAnnotationPresent(annotation))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
test = test.getSuperclass();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,6 +30,8 @@ public class Derived extends Base implements Signature
|
|||
|
||||
Managed managedInstance = new Managed();
|
||||
|
||||
SuperManaged superManagedInstance = new SuperManaged();
|
||||
|
||||
@ManagedAttribute(value="The full name of something", name="fname", setter="setFullName")
|
||||
public String getFullName()
|
||||
{
|
||||
|
@ -70,4 +72,10 @@ public class Derived extends Base implements Signature
|
|||
}
|
||||
|
||||
|
||||
@ManagedAttribute("sample super managed object")
|
||||
public SuperManaged getSuperManagedInstance()
|
||||
{
|
||||
return superManagedInstance;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2012 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
//
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
//
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
//
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
//
|
||||
|
||||
package com.acme;
|
||||
|
||||
public class SuperManaged extends Managed
|
||||
{
|
||||
|
||||
public String superized()
|
||||
{
|
||||
return "super";
|
||||
}
|
||||
|
||||
}
|
|
@ -87,7 +87,7 @@ public class ObjectMBeanTest
|
|||
/*
|
||||
* 2 attributes from lifecycle and 2 from Derived and 1 from MBean
|
||||
*/
|
||||
Assert.assertEquals("attribute count does not match", 5, info.getAttributes().length);
|
||||
Assert.assertEquals("attribute count does not match", 6, info.getAttributes().length);
|
||||
|
||||
Assert.assertEquals("attribute values does not match", "Full Name", mbean.getAttribute("fname") );
|
||||
|
||||
|
|
Loading…
Reference in New Issue