}
// If the source can be wrapped, wrapped it first
if (sourceWrapperHandler != null) {
WrapperInfo sourceWrapperInfo = sourceOp.getWrapper();
DataType sourceWrapperType = sourceWrapperInfo != null ? sourceWrapperInfo.getInputWrapperType() : null;
// We only do wrapper to wrapper transformation if the source has a wrapper and both sides
// match by XML structure
if (sourceWrapperType != null && matches(sourceOp.getWrapper(), targetOp.getWrapper())) {
Class<?> sourceWrapperClass = sourceWrapperType.getPhysical();
// Create the source wrapper
Object sourceWrapper = sourceWrapperHandler.create(sourceOp, true);
// Populate the source wrapper
if (sourceWrapper != null) {
sourceWrapperHandler.setChildren(sourceWrapper,
source,
sourceOp,
true);
// Transform the data from source wrapper to target wrapper
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(targetOp, true);
List<DataType> argTypes = wrapper.getUnwrappedInputType().getLogical();
Object[] targetChildren = new Object[source.length];
for (int i = 0; i < source.length; i++) {
// ElementInfo argElement = wrapper.getInputChildElements().get(i);
DataType<XMLType> argType = argTypes.get(i);
targetChildren[i] =
mediator.mediate(source[i], sourceType.getLogical().get(i), argType, context.getMetadata());
}
targetWrapperHandler.setChildren(targetWrapper,
targetChildren,
targetOp,
true);
return new Object[] {targetWrapper};
} else if (sourceWrapped && (!targetWrapped && !targetNotSubjectToWrapping)) {
// 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, sourceOp, true)) {
WrapperInfo targetWrapperInfo = targetOp.getWrapper();
DataType targetWrapperType =
targetWrapperInfo != null ? targetWrapperInfo.getInputWrapperType() : null;
if (targetWrapperType != null && matches(sourceOp.getWrapper(), targetOp.getWrapper())) {
Object targetWrapper =
mediator.mediate(sourceWrapper, sourceType.getLogical().get(0), targetWrapperType, context
.getMetadata());