use of io.atlasmap.java.test.StateEnumClassLong in project atlasmap by atlasmap.
the class JavaWriterUtilMock method setObjectOnParent.
/**
* Set the given object within the parentObject.
*
* @param field
* - provided if we need it, I don't think we will since we already
* have the value in hand?
* @param segmentContext
* - current segment for the field's path, this will be the last
* segment in the path.
* @param parentObject
* - the object we're setting the value in
* @param childObject
* - the childObject to set
*/
@SuppressWarnings({ "unchecked" })
@Override
public void setObjectOnParent(Field field, SegmentContext segmentContext, Object parentObject, Object childObject) throws AtlasException {
String segment = segmentContext.getSegment();
if (LOG.isDebugEnabled()) {
LOG.debug("Setting object '" + segmentContext.getSegmentPath() + "'.\n\tchildObject: " + childObject + "\n\tparentObject: " + parentObject);
}
// now the cleanedSegment is a cleaned name such as "addressLine1"
String cleanedSegment = AtlasPath.cleanPathSegment(segment);
if ("addressLine1".equals(cleanedSegment) && parentObject instanceof TargetAddress) {
((TargetAddress) parentObject).setAddressLine1((String) childObject);
} else if ("addressLine1".equals(cleanedSegment) && parentObject instanceof TargetAddress) {
((TargetAddress) parentObject).setAddressLine1((String) childObject);
} else if ("addressLine2".equals(cleanedSegment) && parentObject instanceof TargetAddress) {
((TargetAddress) parentObject).setAddressLine2((String) childObject);
} else if ("city".equals(cleanedSegment) && parentObject instanceof TargetAddress) {
((TargetAddress) parentObject).setCity((String) childObject);
} else if ("state".equals(cleanedSegment) && parentObject instanceof TargetAddress) {
((TargetAddress) parentObject).setState((String) childObject);
} else if ("zipCode".equals(cleanedSegment) && parentObject instanceof TargetAddress) {
((TargetAddress) parentObject).setZipCode((String) childObject);
} else if ("orders".equals(cleanedSegment) && parentObject instanceof TestListOrders) {
((TestListOrders) parentObject).setOrders((List<BaseOrder>) childObject);
} else if ("orders".equals(cleanedSegment) && parentObject instanceof TargetOrderArray) {
((TargetOrderArray) parentObject).setOrders((TargetOrder[]) childObject);
} else if ("address".equals(cleanedSegment) && parentObject instanceof TargetOrder) {
((TargetOrder) parentObject).setAddress((TargetAddress) childObject);
} else if ("name".equals(cleanedSegment) && parentObject instanceof TargetTestClass) {
((TargetTestClass) parentObject).setName((String) childObject);
} else if ("address".equals(cleanedSegment) && parentObject instanceof TargetTestClass) {
((TargetTestClass) parentObject).setAddress((TargetAddress) childObject);
} else if ("listOrders".equals(cleanedSegment) && parentObject instanceof TargetTestClass) {
((TargetTestClass) parentObject).setListOrders((TestListOrders) childObject);
} else if ("orderId".equals(cleanedSegment) && parentObject instanceof TargetOrder) {
((TargetOrder) parentObject).setOrderId((Integer) childObject);
} else if ("orderArray".equals(cleanedSegment) && parentObject instanceof TargetTestClass) {
((TargetTestClass) parentObject).setOrderArray((TargetOrderArray) childObject);
} else if ("numberOrders".equals(cleanedSegment) && parentObject instanceof TargetOrderArray) {
((TargetOrderArray) parentObject).setNumberOrders((Integer) childObject);
} else if ("contact".equals(cleanedSegment) && parentObject instanceof TargetOrder) {
((TargetOrder) parentObject).setContact((TargetContact) childObject);
} else if ("firstName".equals(cleanedSegment) && parentObject instanceof TargetContact) {
((TargetContact) parentObject).setFirstName((String) childObject);
} else if ("lastName".equals(cleanedSegment) && parentObject instanceof TargetContact) {
((TargetContact) parentObject).setLastName((String) childObject);
} else if ("primitives".equals(cleanedSegment) && parentObject instanceof TargetTestClass) {
((TargetTestClass) parentObject).setPrimitives((TargetFlatPrimitiveClass) childObject);
} else if ("intArrayField".equals(cleanedSegment) && parentObject instanceof TargetFlatPrimitiveClass) {
((TargetFlatPrimitiveClass) parentObject).setIntArrayField((int[]) childObject);
} else if ("boxedStringArrayField".equals(cleanedSegment) && parentObject instanceof TargetFlatPrimitiveClass) {
((TargetFlatPrimitiveClass) parentObject).setBoxedStringArrayField((String[]) childObject);
} else if ("statesLong".equals(cleanedSegment) && parentObject instanceof TargetTestClass) {
((TargetTestClass) parentObject).setStatesLong((StateEnumClassLong) childObject);
} else {
String clz = parentObject.getClass().getSimpleName();
String clz2 = childObject.getClass().getSimpleName();
String setter = "set" + cleanedSegment.substring(0, 1).toUpperCase() + cleanedSegment.substring(1);
String fix = "} else if (\"" + cleanedSegment + "\".equals(cleanedSegment) && parentObject instanceof " + clz + ") {\n " + "((" + clz + ") parentObject)." + setter + "((" + clz2 + ")childObject);";
LOG.error(fix);
throw new AtlasException("FIX: " + fix);
}
if (LOG.isDebugEnabled()) {
LOG.debug("Object after value written: " + parentObject);
}
}
Aggregations