Search in sources :

Example 21 with Property

use of org.jgroups.annotations.Property in project JGroups by belaban.

the class PropertiesToAsciidoc method convertProtocolToAsciidocTable.

private static void convertProtocolToAsciidocTable(Properties props, Class<Protocol> clazz) throws Exception {
    boolean isUnsupported = clazz.isAnnotationPresent(Unsupported.class);
    if (isUnsupported)
        return;
    Map<String, String> nameToDescription = new TreeMap<>();
    Field[] fields = clazz.getDeclaredFields();
    for (Field field : fields) {
        if (field.isAnnotationPresent(Property.class)) {
            String property = field.getName();
            Property annotation = field.getAnnotation(Property.class);
            String desc = annotation.description();
            nameToDescription.put(property, desc);
        }
    }
    // iterate methods
    Method[] methods = clazz.getDeclaredMethods();
    for (Method method : methods) {
        if (method.isAnnotationPresent(Property.class)) {
            Property annotation = method.getAnnotation(Property.class);
            String desc = annotation.description();
            if (desc == null || desc.isEmpty())
                desc = "n/a";
            String name = annotation.name();
            if (name.length() < 1) {
                name = Util.methodNameToAttributeName(method.getName());
            }
            nameToDescription.put(name, desc);
        }
    }
    // do we have more than one property (superclass Protocol has only one property (stats))
    if (nameToDescription.isEmpty())
        return;
    List<String[]> rows = new ArrayList<>(nameToDescription.size() + 1);
    rows.add(new String[] { "Name", "Description" });
    for (Map.Entry<String, String> entry : nameToDescription.entrySet()) rows.add(new String[] { entry.getKey(), entry.getValue() });
    String tmp = createAsciidocTable(rows, clazz.getSimpleName(), "[align=\"left\",width=\"90%\",cols=\"2,10\",options=\"header\"]");
    props.put(clazz.getSimpleName(), tmp);
}
Also used : Method(java.lang.reflect.Method) Field(java.lang.reflect.Field) Property(org.jgroups.annotations.Property)

Aggregations

Property (org.jgroups.annotations.Property)21 Field (java.lang.reflect.Field)7 DeprecatedProperty (org.jgroups.annotations.DeprecatedProperty)7 Method (java.lang.reflect.Method)5 InetAddress (java.net.InetAddress)3 ManagedAttribute (org.jgroups.annotations.ManagedAttribute)3 Protocol (org.jgroups.stack.Protocol)3 ProtocolConfiguration (org.jgroups.conf.ProtocolConfiguration)2 InetSocketAddress (java.net.InetSocketAddress)1 StringTokenizer (java.util.StringTokenizer)1 XmlAttribute (org.jgroups.annotations.XmlAttribute)1 XmlElement (org.jgroups.annotations.XmlElement)1 PropertyConverter (org.jgroups.conf.PropertyConverter)1 Element (org.w3c.dom.Element)1