Search in sources :

Example 6 with JavaEnumField

use of io.atlasmap.java.v2.JavaEnumField in project atlasmap by atlasmap.

the class TargetValueConverter method resolveTargetSetMethod.

private Method resolveTargetSetMethod(Object sourceObject, Field field, Class<?> targetType) throws AtlasException {
    AtlasPath atlasPath = new AtlasPath(field.getPath());
    Object parentObject = sourceObject;
    List<Class<?>> classTree = resolveMappableClasses(parentObject.getClass());
    if (field instanceof JavaField) {
        JavaField javaField = (JavaField) field;
        for (Class<?> clazz : classTree) {
            try {
                String setterMethodName = javaField.getSetMethod();
                if (setterMethodName == null) {
                    setterMethodName = "set" + capitalizeFirstLetter(atlasPath.getLastSegment());
                }
                return ClassHelper.detectSetterMethod(clazz, setterMethodName, targetType);
            } catch (NoSuchMethodException e) {
            // method does not exist
            }
            // Try the boxUnboxed version
            if (conversionService.isPrimitive(targetType) || conversionService.isBoxedPrimitive(targetType)) {
                try {
                    String setterMethodName = javaField.getSetMethod();
                    if (setterMethodName == null) {
                        setterMethodName = "set" + capitalizeFirstLetter(atlasPath.getLastSegment());
                    }
                    return ClassHelper.detectSetterMethod(clazz, setterMethodName, conversionService.boxOrUnboxPrimitive(targetType));
                } catch (NoSuchMethodException e) {
                // method does not exist
                }
            }
        }
    } else if (field instanceof JavaEnumField) {
        for (Class<?> clazz : classTree) {
            try {
                String setterMethodName = "set" + capitalizeFirstLetter(atlasPath.getLastSegment());
                return ClassHelper.detectSetterMethod(clazz, setterMethodName, targetType);
            } catch (NoSuchMethodException e) {
            // method does not exist
            }
        }
    }
    throw new AtlasException(String.format("Unable to resolve setter for path=%s", field.getPath()));
}
Also used : JavaEnumField(io.atlasmap.java.v2.JavaEnumField) JavaField(io.atlasmap.java.v2.JavaField) AtlasPath(io.atlasmap.core.AtlasPath) AtlasException(io.atlasmap.api.AtlasException)

Example 7 with JavaEnumField

use of io.atlasmap.java.v2.JavaEnumField in project atlasmap by atlasmap.

the class BaseDocumentWriterTest method createEnumField.

public JavaEnumField createEnumField(String path, Enum<?> value) {
    JavaEnumField f = new JavaEnumField();
    f.setPath(path);
    f.setName(value.name());
    f.setOrdinal(value.ordinal());
    f.setFieldType(FieldType.NONE);
    f.setValue(value);
    return f;
}
Also used : JavaEnumField(io.atlasmap.java.v2.JavaEnumField)

Aggregations

JavaEnumField (io.atlasmap.java.v2.JavaEnumField)7 AtlasException (io.atlasmap.api.AtlasException)5 JavaField (io.atlasmap.java.v2.JavaField)5 FieldType (io.atlasmap.v2.FieldType)3 Method (java.lang.reflect.Method)3 AtlasPath (io.atlasmap.core.AtlasPath)2 Field (io.atlasmap.v2.Field)2 AtlasConversionException (io.atlasmap.api.AtlasConversionException)1 AtlasFieldActionService (io.atlasmap.api.AtlasFieldActionService)1 SegmentContext (io.atlasmap.core.AtlasPath.SegmentContext)1 ModifierList (io.atlasmap.java.v2.ModifierList)1 LookupTable (io.atlasmap.v2.LookupTable)1 ParameterizedType (java.lang.reflect.ParameterizedType)1 Type (java.lang.reflect.Type)1