(Protocol prot)
| 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 |
no test coverage detected