1 17 package org.apache.servicemix.beanflow.support; 18 19 import org.apache.commons.logging.Log; 20 import org.apache.commons.logging.LogFactory; 21 import org.apache.servicemix.beanflow.State; 22 23 import java.lang.reflect.Field ; 24 import java.util.ArrayList ; 25 import java.util.Iterator ; 26 import java.util.List ; 27 28 33 public class FieldIntrospector implements Introspector { 34 35 private static final Log log = LogFactory.getLog(FieldIntrospector.class); 36 37 public Iterator <State> iterator(Object owner) { 38 List <State> list = new ArrayList <State>(); 39 for (Class type = owner.getClass(); type != null && type != Object .class; type = type.getSuperclass()) { 40 Field [] fields = type.getDeclaredFields(); 41 for (int i = 0; i < fields.length; i++) { 42 Field field = fields[i]; 43 Object value = null; 44 try { 45 field.setAccessible(true); 46 value = field.get(owner); 47 } 48 catch (Exception e) { 49 if (log.isDebugEnabled()) { 50 log.debug("Could not access field: " + field + " reason: " + e, e); 51 } 52 } 53 State state = toState(value); 54 if (state != null) { 55 list.add(state); 56 } 57 } 58 } 59 return list.iterator(); 60 } 61 62 66 protected State toState(Object value) { 67 if (value instanceof State) { 68 return (State) value; 69 } 70 return null; 71 } 72 } 73 | Popular Tags |