2016-10-07 21:50:21 +02:00
|
|
|
package org.gcube.data_catalogue.grsf_publish_ws;
|
|
|
|
|
|
|
|
import java.beans.IntrospectionException;
|
|
|
|
import java.beans.PropertyDescriptor;
|
|
|
|
import java.lang.reflect.Field;
|
|
|
|
import java.lang.reflect.InvocationTargetException;
|
|
|
|
|
|
|
|
import org.gcube.data_catalogue.grsf_publish_ws.custom_annotations.Group;
|
|
|
|
import org.gcube.data_catalogue.grsf_publish_ws.custom_annotations.Tag;
|
2016-10-08 20:46:17 +02:00
|
|
|
import org.gcube.data_catalogue.grsf_publish_ws.json.input.FisheryRecord;
|
2016-10-07 21:50:21 +02:00
|
|
|
import org.gcube.data_catalogue.grsf_publish_ws.utils.groups.Source;
|
|
|
|
import org.gcube.data_catalogue.grsf_publish_ws.utils.groups.Type;
|
|
|
|
import org.junit.Test;
|
|
|
|
|
|
|
|
public class JTests {
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void test() throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, IntrospectionException {
|
|
|
|
|
|
|
|
// Common instance = new Common();
|
|
|
|
// instance.setType(Type.Assesment_Unit);
|
|
|
|
FisheryRecord recordFishery = new FisheryRecord();
|
|
|
|
recordFishery.setType(Type.Fishing_Description);
|
|
|
|
recordFishery.setDatabaseSources(Source.FIRMS);
|
|
|
|
// Class<Common> commonClass = Common.class;
|
|
|
|
Class<FisheryRecord> fisheryClass = FisheryRecord.class;
|
|
|
|
|
|
|
|
// bottom up, looks up for Tag fields
|
|
|
|
Class<?> current = fisheryClass;
|
|
|
|
do{
|
|
|
|
// do something with current's fields
|
|
|
|
System.out.println("Class is " + current.getCanonicalName());
|
|
|
|
Field[] fields = current.getDeclaredFields();
|
|
|
|
for (Field field : fields) {
|
|
|
|
if(field.isAnnotationPresent(Tag.class) || field.isAnnotationPresent(Group.class)){
|
|
|
|
System.out.println("Annotated field is " + field.getName());
|
|
|
|
Object f = new PropertyDescriptor(field.getName(), fisheryClass).getReadMethod().invoke(recordFishery);
|
|
|
|
System.out.println("Field is " + field.getName() + " and its value for instance is " + f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while((current = current.getSuperclass())!=null);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|