use of org.glassfish.api.admin.config.PropertiesDesc in project Payara by payara.
the class ConfigBeanJMXSupport method elementToMBeanAttributeInfo.
/**
* @Elements are represented as Attributes: getters for sub-elements are presented
* as ObjectName, Collection<String> presented as String[], Collection<? extends ConfigBeanProxy>
* represented as ObjectName[].
*/
public MBeanAttributeInfo elementToMBeanAttributeInfo(final Method m) {
// we assume that all getters are writeable for now, not true for sub-elements (ObjectName)
boolean isWriteable = true;
final ElementMethodInfo info = ElementMethodInfo.get(m);
if (info == null || info.anonymous()) {
return null;
}
// eg strip the "get"
final String name = info.attrName();
final String xmlName = info.xmlName();
// debug( m.getName() + " => " + name + " => " + xmlName );
final Class methodReturnType = info.returnType();
Class<?> returnType = null;
if (info.intf() != null) {
// some sub-type, which we must represent as an ObjectName
returnType = ObjectName.class;
isWriteable = false;
} else if (Collection.class.isAssignableFrom(methodReturnType)) {
final Type genericReturnType = m.getGenericReturnType();
if (genericReturnType instanceof ParameterizedType) {
final ParameterizedType pt = (ParameterizedType) genericReturnType;
final Type[] argTypes = pt.getActualTypeArguments();
if (argTypes.length == 1) {
final Type argType = argTypes[0];
if ((argType instanceof Class) && (Class) argType == String.class) {
returnType = String[].class;
} else {
returnType = ObjectName[].class;
isWriteable = false;
}
}
}
} else {
// some unknown type we cannot handle
}
MBeanAttributeInfo attrInfo = null;
if (returnType != null) {
final DescriptorSupport descriptor = descriptor(info.element());
descriptor.setField(DESC_ELEMENT_CLASS, returnType.getName());
descriptor.setField(DESC_XML_NAME, xmlName);
final ToDo toDo = info.method().getAnnotation(ToDo.class);
if (toDo != null) {
descriptor.setField(DESC_CONFIG_PREFIX + "toDo", toDo.priority() + ", " + toDo.details());
}
final PropertiesDesc props = info.method().getAnnotation(PropertiesDesc.class);
if (props != null) {
final String propType = props.systemProperties() ? "system-property" : "property";
for (final PropertyDesc p : props.props()) {
final String value = p.defaultValue() + " | " + p.dataType().getName() + " | " + p.description();
descriptor.setField(DESC_CONFIG_PREFIX + propType + "." + p.name(), value);
}
}
String description = "@Element " + name + " of interface " + mIntf.getName();
final boolean isReadable = true;
final boolean isIs = false;
attrInfo = new MBeanAttributeInfo(name, returnType.getName(), description, isReadable, isWriteable, isIs, descriptor);
}
return attrInfo;
}
use of org.glassfish.api.admin.config.PropertiesDesc in project Payara by payara.
the class AttributeMethodVisitor method visitAnnotation.
/**
* Visits an annotation of this method.
*
* @param desc the class descriptor of the annotation class.
* @param visible <tt>true</tt> if the annotation is visible at runtime.
*
* @return a visitor to visit the annotation values, or <tt>null</tt> if this visitor is not interested in visiting
* this annotation.
*/
@Override
public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
duckTyped |= "Lorg/jvnet/hk2/config/DuckTyped;".equals(desc);
AnnotationVisitor visitor = null;
if ("Lorg/jvnet/hk2/config/Attribute;".equals(desc) || "Lorg/jvnet/hk2/config/Element;".equals(desc)) {
try {
final Class<?> configurable = Thread.currentThread().getContextClassLoader().loadClass(def.getDef());
final Attribute annotation = configurable.getMethod(name).getAnnotation(Attribute.class);
def.addAttribute(name, annotation);
} catch (Exception e) {
throw new RuntimeException(e.getMessage(), e);
}
} else if ("Lorg/glassfish/api/admin/config/PropertiesDesc;".equals(desc)) {
try {
final Class<?> configurable = Thread.currentThread().getContextClassLoader().loadClass(def.getDef());
final PropertiesDesc annotation = configurable.getMethod(name).getAnnotation(PropertiesDesc.class);
final PropertyDesc[] propertyDescs = annotation.props();
for (PropertyDesc prop : propertyDescs) {
def.addProperty(prop);
}
} catch (Exception e) {
throw new RuntimeException(e.getMessage(), e);
}
}
return visitor;
}
Aggregations