use of io.atlasmap.v2.Field in project atlasmap by atlasmap.
the class ClassInspectionService method detectParameterizedTypes.
private List<String> detectParameterizedTypes(Field field, boolean onlyClasses) {
List<String> pTypes = null;
if (field == null || field.getGenericType() == null || !(field.getGenericType() instanceof ParameterizedType)) {
return null;
}
Type[] types = ((ParameterizedType) field.getGenericType()).getActualTypeArguments();
if (types.length == 0) {
return null;
}
for (Type t : types) {
if (pTypes == null) {
pTypes = new ArrayList<>();
}
if (!onlyClasses && t instanceof TypeVariable) {
TypeVariable<?> tv = (TypeVariable<?>) t;
// TODO: no current need, but we may want to have treatment for 'T'
// tv.getTypeName()
pTypes.add(((Class<?>) tv.getAnnotatedBounds()[0].getType()).getCanonicalName());
}
if (!onlyClasses && t instanceof WildcardType) {
WildcardType wc = (WildcardType) t;
Type[] upperBounds = wc.getUpperBounds();
Type[] lowerBounds = wc.getLowerBounds();
// wc.getTypeName()
if (upperBounds != null && upperBounds.length > 0) {
pTypes.add(wc.getUpperBounds()[0].getClass().getCanonicalName());
} else if (lowerBounds != null && lowerBounds.length > 0) {
pTypes.add(wc.getLowerBounds()[0].getClass().getCanonicalName());
}
}
if (t instanceof Class) {
pTypes.add(((Class<?>) t).getCanonicalName());
}
}
return pTypes;
}
use of io.atlasmap.v2.Field in project atlasmap by atlasmap.
the class BaseDocumentWriterTest method reset.
@Before
public void reset() {
classLoader = Thread.currentThread().getContextClassLoader();
writer = new DocumentJavaFieldWriter(conversionService);
writer.setTargetValueConverter(new TargetValueConverter(classLoader, conversionService) {
public Object convert(AtlasInternalSession session, LookupTable lookupTable, Field sourceField, Object parentObject, Field targetField) throws AtlasException {
return targetField.getValue();
}
});
field = null;
segmentContexts = new LinkedList<>();
targetTestClassInstance = new TargetTestClass();
targetTestClassInstance.setContact(new TargetContact());
targetTestClassInstance.setAddress(new TargetAddress());
targetOrderListInstance = new TestListOrders();
targetOrderListInstance.setOrders(new LinkedList<>());
targetOrderListInstance.getOrders().add(new TargetOrder());
targetOrderListInstance.getOrders().add(new TargetOrder());
targetTestClassInstance.setListOrders(targetOrderListInstance);
targetOrderArrayInstance = new TargetOrderArray();
targetOrderArrayInstance.setOrders(new BaseOrder[2]);
targetOrderArrayInstance.getOrders()[0] = new TargetOrder();
targetOrderArrayInstance.getOrders()[1] = new TargetOrder();
targetTestClassInstance.setOrderArray(targetOrderArrayInstance);
}
use of io.atlasmap.v2.Field in project atlasmap by atlasmap.
the class BaseDocumentWriterTest method write.
protected void write(String path, String targetValue) throws AtlasException {
Field field = createField(path, targetValue);
setTargetValue(targetValue);
write(field);
}
use of io.atlasmap.v2.Field in project atlasmap by atlasmap.
the class BaseDocumentWriterTest method write.
protected void write(String path, int targetValue) throws AtlasException {
Field field = createIntField(path, targetValue);
setTargetValue(targetValue);
write(field);
}
use of io.atlasmap.v2.Field in project atlasmap by atlasmap.
the class DocumentJavaFieldReader method getValueFromMemberField.
private Object getValueFromMemberField(AtlasInternalSession session, Object source, String fieldName) throws IllegalArgumentException, IllegalAccessException {
java.lang.reflect.Field reflectField = lookupJavaField(source, fieldName);
if (reflectField != null) {
reflectField.setAccessible(true);
return reflectField.get(source);
}
Field sourceField = session.head().getSourceField();
AtlasUtil.addAudit(session, sourceField.getDocId(), String.format("Field '%s' not found on object '%s'", fieldName, source), sourceField.getPath(), AuditStatus.ERROR, null);
return null;
}
Aggregations