Borrowed this code from jaxb-commons project

@param fieldOutline reference to a field
@return Getter for the given field or null
357823
static JMethod getter(FieldOutline fieldOutline) {
        final JDefinedClass theClass = fieldOutline.parent().implClass;
        final String publicName = fieldOutline.getPropertyInfo().getName(true);
        final JMethod getgetter = theClass.getMethod("get" + publicName, NONE);
        if (getgetter != null) {
            return getgetter;
        } else {
            final JMethod isgetter = theClass
                    .getMethod("is" + publicName, NONE);
            if (isgetter != null) {
                return isgetter;
            } else {
                return null;
            }
        }
    }
960255
private static MappedField checkGetAccessor(XML xml, Class<?> aClass, Field nestedField){
		
		MappedField field = new MappedField(nestedField);
		xml.fillMappedField(aClass, field);
		Annotation.fillMappedField(aClass,field);
		verifyGetterMethods(aClass,field);
		return field;
	}
993017
public static Method getGetterMethod(Class<?> clazz, Field field) {
        return getMethod(clazz, getGetterMethodName(field));
    }
837739
public static Field getField(Class<?> clazz, String fieldName)
      throws NoSuchFieldException {
    if (clazz == Object.class) {
      return null;
    }
    try {
      Field field = clazz.getDeclaredField(fieldName);
      return field;
    } catch (NoSuchFieldException e) {
      return getField(clazz.getSuperclass(), fieldName);
    }
  }
692333
public Field getField(String fieldName) {
		final PropDesc desc = this.propMap.get(fieldName);
		return null == desc ? null : desc.getField();
	}
1074129
public static FieldMarshaller getFieldMarshaller (Field field)
    {
        if (_marshallers == null) {
            // multiple threads may attempt to create the stock marshallers, but they'll just do
            // extra work and _marshallers will only ever contain a fully populated table
            _marshallers = createMarshallers();
        }

        // if necessary (we're running in a sandbox), look for custom field accessors
        if (useFieldAccessors()) {
            Method reader = null, writer = null;
            try {
                reader = field.getDeclaringClass().getMethod(
                    getReaderMethodName(field.getName()), READER_ARGS);
            } catch (NoSuchMethodException nsme) {
                // no problem
            }
            try {
                writer = field.getDeclaringClass().getMethod(
                    getWriterMethodName(field.getName()), WRITER_ARGS);
            } catch (NoSuchMethodException nsme) {
                // no problem
            }
            if (reader != null && writer != null) {
                return new MethodFieldMarshaller(reader, writer);
            }
            if ((reader == null && writer != null) || (writer == null && reader != null)) {
                log.warning("Class contains one but not both custom field reader and writer",
                            "class", field.getDeclaringClass().getName(), "field", field.getName(),
                            "reader", reader, "writer", writer);
                // fall through to using reflection on the fields...
            }
        }

        Class<?> ftype = field.getType();

        // use the intern marshaller for pooled strings
        if (ftype == String.class && field.isAnnotationPresent(Intern.class)) {
            return _internMarshaller;
        }

        // if we have an exact match, use that
        FieldMarshaller fm = _marshallers.get(ftype);
        if (fm == null) {
            Class<?> collClass = Streamer.getCollectionClass(ftype);
            if (collClass != null && !collClass.equals(ftype)) {
                log.warning("Specific field types are discouraged " +
                    "for Iterables/Collections and Maps. The implementation type may not be " +
                    "recreated on the other side.",
                    "class", field.getDeclaringClass(), "field", field.getName(),
                    "type", ftype, "shouldBe", collClass);
                fm = _marshallers.get(collClass);
            }

            // otherwise if the class is a pure interface or streamable,
            // use the streamable marshaller
            if (fm == null && (ftype.isInterface() || Streamer.isStreamable(ftype))) {
                fm = _marshallers.get(Streamable.class);
            }
        }

        return fm;
    }
632057
public @CheckForNull
    SourceLineRange getFieldLine(String className, String fieldName) {
        return fieldLineMap.get(new FieldDescriptor(className, fieldName));
    }
205318
public static Object getFieldValue(Object obj, Field field) {
        Object value = null;
        boolean accessible = field.isAccessible();
        //hack accessibility
        if (!accessible) {
            field.setAccessible(true);
        }
        try {
            value = field.get(obj);
        } catch (IllegalAccessException e) {
            //ignore should not happen as accessibility has been updated to suit assignment
            e.printStackTrace(); // $COVERAGE-IGNORE$
        }
        //restore accessibility
        field.setAccessible(accessible);
        return value;
    }
898729
public static Field getField(String fieldName, Class<?> clazz) {
    Field field = null;
    try {
      field = clazz.getDeclaredField(fieldName);
    }
    catch (SecurityException e) {
      throw LOG.unableToAccessField(field, clazz.getName());
    }
    catch (NoSuchFieldException e) {
      // for some reason getDeclaredFields doesnt search superclasses
      // (which getFields() does ... but that gives only public fields)
      Class<?> superClass = clazz.getSuperclass();
      if (superClass != null) {
        return getField(fieldName, superClass);
      }
    }
    return field;
  }
964057
public ClassBuilder<T> withField(String field, Class<?> fieldClass) {
		fields.put(field, fieldClass);
		return this;
	}
1257017
static BigqueryFieldMarshaller findMarshaller(Field field,
      Map<Field, BigqueryFieldMarshaller> marshallers) {
    BigqueryFieldMarshaller marshaller = null;
    if (marshallers != null) {
      marshaller = marshallers.get(field);
    }
    if (marshaller == null) {
      marshaller = BigqueryFieldMarshallers.getMarshaller(field.getType());
    }
    return marshaller;
  }
488104
public static Method getGetterMethod(Class<?> c, String field) {

        try {
            return c.getMethod(getMethodName(field, GET_METHOD_PREFIX), EMPTY_CLASS);
        } catch (NoSuchMethodException e) {
            try {
                return c.getMethod(getMethodName(field, IS_METHOD_PREFIX), EMPTY_CLASS);
            } catch (NoSuchMethodException e1) {
                //log.info("getter method not found : " + field);
                return null;
            }
        }
    }
473224
@XmlElementDecl(namespace = "http://www.schemas.conceptdraw.com/cdprj/document.xsd", name = "OutlineNumber") public JAXBElement<String> createOutlineNumber(String value)
   {
      return new JAXBElement<String>(_OutlineNumber_QNAME, String.class, null, value);
   }
1238328
public static Field lookupField( Class parentClass, String fieldName )
    {
        try {
            return parentClass.getDeclaredField( fieldName );
        }
        catch ( NoSuchFieldException e ) {
            Class superClass = parentClass.getSuperclass();
            return superClass != null ? lookupField( superClass, fieldName ) : null;
        }
    }
351678
public static Field getDeclaredField(final Class cls, final String fieldName) {
		return getField(cls, fieldName, true);
	}
73000
public Object getFieldValue(String fieldName) throws ReflectorException {
		if(object == null) {
			logger.error("object is null: did you specify it using the 'inspect()' method?");
			throw new ReflectorException("object is null: did you specify it using the 'inspect()' method?");
		}
		if(!Strings.isValid(fieldName)) {
			logger.error("field name is null or not valid");
			throw new ReflectorException("field name is null or not valid");
		}
		
		Object result = null;
		String name = fieldName.trim();
		if(useGetters) {
			logger.trace("accessing value using getter");
			String methodName = "get" + Character.toUpperCase(name.charAt(0)) + name.substring(1);			
			result = invoke(methodName);
		} else {
			logger.trace("accessing value through direct field access");
			Field field = null;			
			boolean needReprotect = false;
			try {
				field = object.getClass().getDeclaredField(name);				
				if(accessPrivateMembers) {
					needReprotect = unprotect(field);
				}
				result = field.get(object);
			} catch (Exception e) {
				String message = "error accessing field '" + fieldName + "'"; 
				logger.error(message, e);
				throw new ReflectorException(message, e);
			} finally {
				if(needReprotect) {				
					protect(field);
				}
			}
		}
		return result;		
	}
717149
public static String getString(Object from, Field field)
    {
        PropertyAccessor<?> accessor = PropertyAccessorFactory.getPropertyAccessor(field);
        Object object = getObject(from, field);
        return object != null ? accessor.toString(object) : null;
    }