キーの候補を生成する。
<p>コンテキストのキーの形式として、次の優先順位に一致したものを返す。

@param code 元となるメッセージのコード
@param objectName オブジェクト名（クラスのフルパス）
@param field フィールド名 （指定しない場合はnullを設定する）
@param fieldType フィールドのクラスタイプ（指定しない場合はnullを設定する）
@return
437640
public String[] generateCodes(final String code, final String objectName, final String field, final Class<?> fieldType) {
        
        final String baseCode = getPrefix().isEmpty() ? code : getPrefix() + code;
        final List<String> codeList = new ArrayList<>();
        
        final List<String> objectNameList = Arrays.asList(generateObjectNameCodes(objectName));
        final List<String> fieldList = new ArrayList<>();
        buildFieldList(field, fieldList);
        
        if(Utils.isNotEmpty(field)) {
            // 最後のフィールド名のみを取得する
            int dotIndex = field.lastIndexOf('.');
            if(dotIndex > 0) {
                buildFieldList(field.substring(dotIndex + 1), fieldList);
            }
        }
        
        for(final String name : objectNameList) {
            addCodes(codeList, baseCode, name, fieldList);
        }
        
        addCodes(codeList, code, null, fieldList);
        
        if(fieldType != null) {
            addCode(codeList, code, null, fieldType.getName());
            
            if(Enum.class.isAssignableFrom(fieldType)) {
                // 列挙型の場合は、java.lang.Enumとしてクラスタイプを追加する。
                addCode(codeList, code, null, Enum.class.getName());
                
            } else if(fieldType.isArray()) {
                // 配列の場合は、"配列のクラスタイプ+[]"を追加する。
                Class<?> componentType = fieldType.getComponentType();
                addCode(codeList, code, null, componentType.getName() + "[]");
                addCode(codeList, code, null, "java.lang.Object[]");
            }
        }
        
        addCode(codeList, code, null, null);
        
        return codeList.toArray(new String[codeList.size()]);
    }
332937
public static ObjectFields convertGenObjectFieldsToObjectFields(org.fcrepo.server.types.gen.ObjectFields source) {
        if (source == null) {
            return null;
        }
        ObjectFields result = new ObjectFields();
        result.setPid(source.getPid() != null ? source.getPid().getValue() : null);
        result.setLabel(source.getLabel() != null ? source.getLabel().getValue() : null);
        result.setState(source.getState() != null ? source.getState().getValue() : null);
        result.setOwnerId(source.getOwnerId() != null ? source.getOwnerId().getValue() : null);
        result.setCDate(source.getCDate() != null ? DateUtility.convertStringToDate(source.getCDate().getValue()) : null);
        result.setMDate(source.getMDate() != null ? DateUtility.convertStringToDate(source.getMDate().getValue()) : null);
        result.setDCMDate(source.getDcmDate() != null ? DateUtility.convertStringToDate(source.getDcmDate().getValue()) : null);
        result.titles().addAll(convertStringArray(source.getTitle()));
        result.subjects().addAll(convertStringArray(source.getSubject()));
        result.descriptions()
                .addAll(convertStringArray(source.getDescription()));
        result.publishers().addAll(convertStringArray(source.getPublisher()));
        result.contributors()
                .addAll(convertStringArray(source.getContributor()));
        result.dates().addAll(convertStringArray(source.getDate()));
        result.types().addAll(convertStringArray(source.getType()));
        result.formats().addAll(convertStringArray(source.getFormat()));
        result.identifiers().addAll(convertStringArray(source.getIdentifier()));
        result.sources().addAll(convertStringArray(source.getSource()));
        result.languages().addAll(convertStringArray(source.getLanguage()));
        result.relations().addAll(convertStringArray(source.getRelation()));
        result.coverages().addAll(convertStringArray(source.getCoverage()));
        result.rights().addAll(convertStringArray(source.getRights()));
        return result;
    }
419082
public static Field getField(final Class clazz, final String fieldName) {
		Validate.notNull(clazz, "clazz can't be null");
		Validate.notEmpty(fieldName, "fieldName can't be blank");
		for (Class<?> superClass = clazz; superClass != Object.class; superClass = superClass.getSuperclass()) {
			try {
				Field field = superClass.getDeclaredField(fieldName);
				makeAccessible(field);
				return field;
			} catch (NoSuchFieldException e) {// NOSONAR
				// Field不在当前类定义,继续向上转型
			}
		}
		return null;
	}
729177
public static String toMMCIF(String categoryName, Object o) {

		StringBuilder sb = new StringBuilder();

		Class<?> c = o.getClass();


		Field[] fields = getFields(c);
		String[] names = getFieldNames(fields);

		int maxFieldNameLength = getMaxStringLength(names);

		for (int i=0;i<fields.length;i++) {
			Field f = fields[i];
			String name = names[i];

			sb.append(categoryName).append(".").append(name);

			int spacing = maxFieldNameLength - name.length() + 3;

			try {
				Object obj = f.get(o);
				String val;
				if (obj==null) {
					logger.debug("Field {} is null, will write it out as {}",name,MMCIF_MISSING_VALUE);
					val = MMCIF_MISSING_VALUE;
				} else {
					val = (String) obj;
				}
				for (int j=0;j<spacing;j++) sb.append(' ');
				sb.append(addMmCifQuoting(val));
				sb.append(newline);

			} catch (IllegalAccessException e) {
				logger.warn("Field {} is inaccessible", name);
				continue;
			} catch (ClassCastException e) {
				logger.warn("Could not cast value to String for field {}",name);
				continue;
			}

		}

		sb.append(SimpleMMcifParser.COMMENT_CHAR+newline);

		return sb.toString();
	}
333508
public Class<?> getActualFieldType(final String field) {
        
        final Object fieldValue = getFieldValue(field);
        return fieldValue == null ? null : fieldValue.getClass();
        
    }
71848
public static Object serializeField(ObjectMapper objectMapper, Object value) {
        if (value == null || BASIC_TYPES.contains(value.getClass())) {
            // Return as is
            return value;
        } else if (value instanceof DBObject) {
            return serializeFields(objectMapper, (DBObject) value);
        } else if (value instanceof Collection) {
            Collection<?> coll = (Collection<?>) value;
            List<Object> copy = null;
            int position = 0;
            for (Object item : coll) {
                Object returned = serializeField(objectMapper, item);
                if (returned != item) {
                    if (copy == null) {
                        copy = new ArrayList<Object>(coll);
                    }
                    copy.set(position, returned);
                }
                position++;
            }
            if (copy != null) {
                return copy;
            } else {
                return coll;
            }
        } else if (value.getClass().isArray()) {
            if (BASIC_TYPES.contains(value.getClass().getComponentType())) {
                return value;
            }
            Object[] array = (Object[]) value;
            Object[] copy = null;
            for (int i = 0; i < array.length; i++) {
                Object returned = serializeField(objectMapper, array[i]);
                if (returned != array[i]) {
                    if (copy == null) {
                        copy = new Object[array.length];
                        System.arraycopy(array, 0, copy, 0, array.length);
                    }
                    copy[i] = returned;
                }
            }
            if (copy != null) {
                return copy;
            } else {
                return array;
            }
        } else {
            // We don't know what it is, serialise it
            BsonObjectGenerator generator = new BsonObjectGenerator();
            try {
                objectMapper.writeValue(generator, value);
            } catch (JsonMappingException e) {
                throw new MongoJsonMappingException(e);
            } catch (IOException e) {
                throw new RuntimeException("Somehow got an IOException writing to memory", e);
            }
            return generator.getValue();
        }
    }
82025
public static <T> T getFieldValue(final Object obj, final String fieldName) {
		Field field = getField(obj.getClass(), fieldName);
		if (field == null) {
			throw new IllegalArgumentException("Could not find field [" + fieldName + "] on target [" + obj + ']');
		}
		return getFieldValue(obj, field);
	}
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;		
	}
1339858
public FieldAccessor create(final Field field) {

        ArgUtils.notNull(field, "field");

        final FieldAccessor accessor = new FieldAccessor();

        // 共通情報の設定
        accessor.name = field.getName();
        accessor.targetType = field.getType();
        accessor.declaringClass = field.getDeclaringClass();

        // フィールド情報の設定
        setupWithFiled(accessor, field);

        // getter情報の設定
        if(ClassUtils.isPrimitiveBoolean(accessor.getType())) {
            ClassUtils.extractBooleanGetter(accessor.getDeclaringClass(), accessor.getName())
                    .ifPresent(getter -> setupWithGetter(accessor, getter));

        } else {
            ClassUtils.extractGetter(accessor.getDeclaringClass(), accessor.getName(), accessor.getType())
                    .ifPresent(getter -> setupWithGetter(accessor, getter));
        }

        // setter情報の設定
        ClassUtils.extractSetter(accessor.getDeclaringClass(), accessor.getName(), accessor.getType())
                .ifPresent(setter -> setupWithSetter(accessor, setter));

        // コンポーネントタイプの設定
        if(Collection.class.isAssignableFrom(accessor.getType())) {
            ParameterizedType type = (ParameterizedType) field.getGenericType();
            accessor.componentType = Optional.of((Class<?>) type.getActualTypeArguments()[0]);

        } else if(accessor.getType().isArray()) {
            accessor.componentType = Optional.of(accessor.getType().getComponentType());

        } else if(Map.class.isAssignableFrom(accessor.getType())) {
            ParameterizedType type = (ParameterizedType) field.getGenericType();
            accessor.componentType = Optional.of((Class<?>) type.getActualTypeArguments()[1]);
        }

        // 位置・ラベル情報のアクセッサの設定
        if(accessor.hasAnnotation(XlsMapColumns.class)) {
            // マップ形式の場合
            accessor.mapPositionSetter = mapPositionSetterFactory.create(accessor.getDeclaringClass(), accessor.getName());
            accessor.mapLabelSetter = mapLabelSetterFactory.create(accessor.getDeclaringClass(), accessor.getName());

        } else if(accessor.hasAnnotation(XlsArrayColumns.class)
                || accessor.hasAnnotation(XlsArrayCells.class)
                || accessor.hasAnnotation(XlsLabelledArrayCells.class)
                || accessor.hasAnnotation(XlsIterateTables.class)){
            // リストや配列形式の場合
            accessor.arrayPositionSetter = arrayPositionSetterFactory.create(accessor.getDeclaringClass(), accessor.getName());
            accessor.arrayLabelSetter = arrayLabelSetterFactory.create(accessor.getDeclaringClass(), accessor.getName());

            if(accessor.hasAnnotation(XlsArrayColumns.class)
                    || accessor.hasAnnotation(XlsLabelledArrayCells.class)) {
                // インデックスが付いていないラベルの設定
                accessor.labelSetter = labelSetterFactory.create(accessor.getDeclaringClass(), accessor.getName());
            }

        } else {
            // リストやMapではない通常のプロパティの場合
            accessor.positionSetter = positionSetterFactory.create(accessor.getDeclaringClass(), accessor.getName());
            accessor.positionGetter = positionGetterFactory.create(accessor.getDeclaringClass(), accessor.getName());

            accessor.labelSetter = labelSetterFactory.create(accessor.getDeclaringClass(), accessor.getName());
            accessor.labelGetter = labelGetterFactory.create(accessor.getDeclaringClass(), accessor.getName());

        }

        return accessor;
    }
344226
public String[] generateTypeMismatchCodes(final String objectName, final String field, final Class<?> filedType) {
        return generateCodes(getTypeMismatchCode(), objectName, field, filedType);
    }
1190510
public static Field getAccessibleField(final Object obj, final String fieldName) {
		if(obj == null)
			throw new IllegalArgumentException("object cannot be null.");
		if(fieldName == null || fieldName.trim().length() == 0)
			throw new IllegalArgumentException("fieldName cannot be null.");
		for (Class<?> superClass = obj.getClass(); superClass != Object.class; superClass = superClass.getSuperclass()) {
			try {
				Field field = superClass.getDeclaredField(fieldName);
				field.setAccessible(true);
				return field;
			} catch (NoSuchFieldException e) {//NOSONAR
				// Field不在当前类定义,继续向上转型
			}
		}
		return null;
	}
912310
private Object getObjectValue(Node node, String fieldName) {
        // we have to take into account the fact that fieldName will be in the lower case
        if (node != null) {
            String name = node.getLocalName();
            switch (node.getNodeType()) {
                case Node.ATTRIBUTE_NODE:
                    return name.equalsIgnoreCase(fieldName) ? node : null;
                case Node.ELEMENT_NODE: {
                    if (name.equalsIgnoreCase(fieldName)) {
                        return new NodeArray(node.getChildNodes());
                    } else {
                        NamedNodeMap namedNodeMap = node.getAttributes();
                        for (int attributeIndex = 0; attributeIndex < namedNodeMap.getLength(); ++attributeIndex) {
                            Node attribute = namedNodeMap.item(attributeIndex);
                            if (attribute.getLocalName().equalsIgnoreCase(fieldName)) {
                                return attribute;
                            }
                        }
                        return null;
                    }
                }
                default:
                    return null;
            }
        }
        return null;
    }
164688
public String[] generateParentNameCodes(final String objectName, final String field) {
        
        if(Utils.isEmpty(field) || !field.contains(".")) {
            return generateObjectNameCodes(objectName);
        }
        
        // フィールド名の前の値を取得する
        final int dotIndex = field.lastIndexOf('.');
        final String subName = field.substring(0, dotIndex);
        return generateFieldNameCodes(objectName, subName);
        
    }
617231
public static Class<?> getGenericTypeOfCollectionField(Field field) {
        Type genericType = field.getGenericType();

        if (!(genericType instanceof ParameterizedType)) {
            throw new IllegalArgumentException("Field is not a ParameterizedType.");
        }

        Type[] genericTypes = ((ParameterizedType) genericType).getActualTypeArguments();


        if (genericTypes.length != 1) {
            throw new IllegalArgumentException("Field does not have a single generic type.");
        }

        if (!(genericTypes[0] instanceof Class)) {
            throw new IllegalArgumentException("Field's generic type is not a class?");
        }

        return (Class<?>) genericTypes[0];
    }
776109
public static Field getDeclaredField(Object object, String fieldName) {
        Field field = null;
        Class<?> clazz = object.getClass();
        for (; clazz != Object.class; clazz = clazz.getSuperclass()) {
            try {
                field = clazz.getDeclaredField(fieldName);
                return field;
            } catch (Exception e) {
                //这里甚么都不要做！并且这里的异常必须这样写，不能抛出去。
                //如果这里的异常打印或者往外抛，则就不会执行clazz = clazz.getSuperclass(),最后就不会进入到父类中了
            }
        }
        return null;
    }
626647
public static JavaType of(final Class<?> implementClass, final Field field) {
		return of(new ImplementClass(implementClass), field);
	}
15563
public static Object getFieldValue(Object object, String fieldName) {
        try {
            return getDeclaredFieldInHierarchy(object.getClass(), fieldName).get(object);
        } catch (IllegalArgumentException e) {
            throw new RuntimeException(e);
        } catch (IllegalAccessException e) {
            throw new RuntimeException(e);
        }
    }