targetWrapperHandler = getWrapperHandler(targetDataBinding, targetWrapped);
if ((!sourceWrapped) && targetWrapped) {
// Unwrapped --> Wrapped
WrapperInfo wrapper = targetOp.getWrapper();
ElementInfo wrapperElement = wrapper.getInputWrapperElement();
if (source == null) {
Object targetWrapper = targetWrapperHandler.create(wrapperElement, context);
return new Object[] {targetWrapper};
}
// If the source can be wrapped, wrapped it first
if (sourceWrapperHandler != null) {
DataType sourceWrapperType =
sourceWrapperHandler.getWrapperType(wrapperElement, wrapper.getInputChildElements(), context);
if (sourceWrapperType != null) {
Object sourceWrapper = sourceWrapperHandler.create(wrapperElement, context);
if (sourceWrapper != null) {
for (int i = 0; i < source.length; i++) {
ElementInfo argElement = wrapper.getInputChildElements().get(i);
sourceWrapperHandler.setChild(sourceWrapper, i, argElement, source[i]);
}
Object targetWrapper =
mediator.mediate(sourceWrapper, sourceWrapperType, targetType.getLogical().get(0), context
.getMetadata());
return new Object[] {targetWrapper};
}
}
}
// Fall back to child by child transformation
Object targetWrapper = targetWrapperHandler.create(wrapperElement, context);
List<DataType> argTypes = wrapper.getUnwrappedInputType().getLogical();
for (int i = 0; i < source.length; i++) {
ElementInfo argElement = wrapper.getInputChildElements().get(i);
DataType<XMLType> argType = argTypes.get(i);
Object child = source[i];
child = mediator.mediate(source[i], sourceType.getLogical().get(i), argType, context.getMetadata());
targetWrapperHandler.setChild(targetWrapper, i, argElement, child);
}
return new Object[] {targetWrapper};
} else if (sourceWrapped && (!targetWrapped)) {
// Wrapped to Unwrapped
Object sourceWrapper = source[0];
Object[] target = null;
List<ElementInfo> childElements = sourceOp.getWrapper().getInputChildElements();
if (targetWrapperHandler != null) {
ElementInfo wrapperElement = sourceOp.getWrapper().getInputWrapperElement();
// FIXME: This is a workaround for the wsdless support as it passes in child elements
// under the wrapper that only matches by position
if (sourceWrapperHandler.isInstance(sourceWrapper, wrapperElement, childElements, context)) {
DataType targetWrapperType =
targetWrapperHandler.getWrapperType(wrapperElement, childElements, context);