mirror of
https://github.com/jetty/jetty.project.git
synced 2025-03-03 12:29:31 +00:00
fix attribute issue when not assocated with fields
This commit is contained in:
parent
e987e954b0
commit
d6261cb714
@ -262,7 +262,7 @@ public class ObjectMBean implements DynamicMBean
|
||||
if ( fieldAnnotation != null )
|
||||
{
|
||||
LOG.debug("Field Annotation found for: " + field.getName() );
|
||||
attributes=LazyList.add(attributes, defineAttribute(field, fieldAnnotation));
|
||||
attributes=LazyList.add(attributes, defineAttribute(field.getName(), fieldAnnotation));
|
||||
}
|
||||
}
|
||||
|
||||
@ -274,8 +274,17 @@ public class ObjectMBean implements DynamicMBean
|
||||
|
||||
if ( methodAnnotation != null )
|
||||
{
|
||||
LOG.debug("Method Annotation found for: " + method.getName() );
|
||||
operations=LazyList.add(operations, defineOperation(method, methodAnnotation));
|
||||
if ( methodAnnotation.attribute() )
|
||||
{
|
||||
// TODO sort out how a proper name could get here, its a method name as an attribute at this point.
|
||||
LOG.debug("Attribute Annotation found for: " + method.getName() );
|
||||
attributes=LazyList.add(attributes,defineAttribute(method.getName(),methodAnnotation));
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG.debug("Method Annotation found for: " + method.getName() );
|
||||
operations=LazyList.add(operations, defineOperation(method, methodAnnotation));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -532,9 +541,9 @@ public class ObjectMBean implements DynamicMBean
|
||||
* </ul>
|
||||
* the access is either "RW" or "RO".
|
||||
*/
|
||||
public MBeanAttributeInfo defineAttribute(Field field, Managed fieldAnnotation)
|
||||
public MBeanAttributeInfo defineAttribute(String name, Managed fieldAnnotation)
|
||||
{
|
||||
String name = field.getName();
|
||||
//String name = field.getName();
|
||||
String description = fieldAnnotation.value();
|
||||
boolean writable = fieldAnnotation.readonly();
|
||||
boolean onMBean = fieldAnnotation.proxied();
|
||||
|
@ -69,7 +69,6 @@ import org.eclipse.jetty.util.StringUtil;
|
||||
import org.eclipse.jetty.util.TypeUtil;
|
||||
import org.eclipse.jetty.util.URIUtil;
|
||||
import org.eclipse.jetty.util.annotation.Managed;
|
||||
import org.eclipse.jetty.util.annotation.Name;
|
||||
import org.eclipse.jetty.util.component.AggregateLifeCycle;
|
||||
import org.eclipse.jetty.util.component.Dumpable;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
@ -1204,8 +1203,7 @@ public class ContextHandler extends ScopedHandler implements Attributes, Server.
|
||||
/*
|
||||
* @see javax.servlet.ServletContext#removeAttribute(java.lang.String)
|
||||
*/
|
||||
@Managed("Remove context attribute")
|
||||
public void removeAttribute( @Name(value = "name", description="attribute name") String name)
|
||||
public void removeAttribute(String name)
|
||||
{
|
||||
checkManagedAttribute(name,null);
|
||||
_attributes.removeAttribute(name);
|
||||
@ -1218,8 +1216,7 @@ public class ContextHandler extends ScopedHandler implements Attributes, Server.
|
||||
*
|
||||
* @see javax.servlet.ServletContext#setAttribute(java.lang.String, java.lang.Object)
|
||||
*/
|
||||
@Managed("Set context attribute")
|
||||
public void setAttribute(@Name(value = "name", description="attribute name") String name, @Name(value = "value", description="attribute value") Object value)
|
||||
public void setAttribute( String name, Object value)
|
||||
{
|
||||
checkManagedAttribute(name,value);
|
||||
_attributes.setAttribute(name,value);
|
||||
|
@ -19,6 +19,8 @@ import java.util.Map;
|
||||
|
||||
import org.eclipse.jetty.server.handler.ContextHandler;
|
||||
import org.eclipse.jetty.util.Attributes;
|
||||
import org.eclipse.jetty.util.annotation.Managed;
|
||||
import org.eclipse.jetty.util.annotation.Name;
|
||||
|
||||
public class ContextHandlerMBean extends AbstractHandlerMBean
|
||||
{
|
||||
@ -27,6 +29,7 @@ public class ContextHandlerMBean extends AbstractHandlerMBean
|
||||
super(managedObject);
|
||||
}
|
||||
|
||||
@Managed(value="Map of context attributes", readonly=true, attribute=true)
|
||||
public Map getContextAttributes()
|
||||
{
|
||||
Map map = new HashMap();
|
||||
@ -41,19 +44,22 @@ public class ContextHandlerMBean extends AbstractHandlerMBean
|
||||
return map;
|
||||
}
|
||||
|
||||
public void setContextAttribute(String name, Object value)
|
||||
@Managed(value="Set context attribute", impact="ACTION")
|
||||
public void setContextAttribute(@Name(value = "name", description="attribute name") String name, @Name(value = "value", description="attribute value") Object value)
|
||||
{
|
||||
Attributes attrs = ((ContextHandler)_managed).getAttributes();
|
||||
attrs.setAttribute(name,value);
|
||||
}
|
||||
|
||||
public void setContextAttribute(String name, String value)
|
||||
@Managed(value="Set context attribute", impact="ACTION")
|
||||
public void setContextAttribute(@Name(value = "name", description="attribute name") String name, @Name(value = "value", description="attribute value") String value)
|
||||
{
|
||||
Attributes attrs = ((ContextHandler)_managed).getAttributes();
|
||||
attrs.setAttribute(name,value);
|
||||
}
|
||||
|
||||
public void removeContextAttribute(String name)
|
||||
@Managed(value="Remove context attribute", impact="ACTION")
|
||||
public void removeContextAttribute(@Name(value = "name", description="attribute name") String name)
|
||||
{
|
||||
Attributes attrs = ((ContextHandler)_managed).getAttributes();
|
||||
attrs.removeAttribute(name);
|
||||
|
@ -87,4 +87,13 @@ public @interface Managed
|
||||
* @return the full name of the setter in question
|
||||
*/
|
||||
String setter() default "";
|
||||
|
||||
/**
|
||||
* Treat method as an attribute and not an operation
|
||||
*
|
||||
* NOTE: applies to METHOD
|
||||
*
|
||||
* @return true of the method should be treating as an attribute
|
||||
*/
|
||||
boolean attribute() default false;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user