MCPcopy Create free account
hub / github.com/belaban/JGroups / getProps

Method getProps

src/org/jgroups/stack/ProtocolStack.java:383–438  ·  view source on GitHub ↗
(Protocol prot)

Source from the content-addressed store, hash-verified

381 }
382
383 private static Map<String,String> getProps(Protocol prot) {
384 Map<String,String> retval=new HashMap<>();
385
386 for(Class<?> clazz=prot.getClass(); clazz != null; clazz=clazz.getSuperclass()) {
387
388 // copy all fields marked with @Property
389 Field[] fields=clazz.getDeclaredFields();
390 Property annotation;
391 for(Field field: fields) {
392 if(field.isAnnotationPresent(Property.class)) {
393 Object value=Util.getField(field, prot);
394 if(value != null) {
395 annotation=field.getAnnotation(Property.class);
396 Class<? extends PropertyConverter> conv_class=annotation.converter();
397 PropertyConverter conv=null;
398 try {
399 conv=conv_class.getDeclaredConstructor().newInstance();
400 }
401 catch(Exception e) {
402 }
403 String tmp=conv != null? conv.toString(value) : value.toString();
404 retval.put(field.getName(), tmp);
405 }
406 }
407 }
408
409 // copy all setters marked with @Property
410 Method[] methods=clazz.getDeclaredMethods();
411 for(Method method: methods) {
412 String methodName=method.getName();
413 if(method.isAnnotationPresent(Property.class) && Configurator.isSetPropertyMethod(method, clazz)) {
414 annotation=method.getAnnotation(Property.class);
415 List<String> possible_names=new LinkedList<>();
416 if(annotation.name() != null)
417 possible_names.add(annotation.name());
418 possible_names.add(Util.methodNameToAttributeName(methodName));
419 Field field=Util.findField(prot, possible_names);
420 if(field != null) {
421 Object value=Util.getField(field, prot);
422 if(value != null) {
423 Class<?> conv_class=annotation.converter();
424 PropertyConverter conv=null;
425 try {
426 conv=(PropertyConverter)conv_class.getDeclaredConstructor().newInstance();
427 }
428 catch(Exception e) {
429 }
430 String tmp=conv != null? conv.toString(value) : value.toString();
431 retval.put(field.getName(), tmp);
432 }
433 }
434 }
435 }
436 }
437 return retval;
438 }
439
440

Callers 3

printProtocolSpecMethod · 0.95

Calls 10

getFieldMethod · 0.95
toStringMethod · 0.95
isSetPropertyMethodMethod · 0.95
findFieldMethod · 0.95
getAnnotationMethod · 0.80
getNameMethod · 0.65
putMethod · 0.45
nameMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected