public Object[] transform(Object[] source, TransformationContext context) {
DataType<List<DataType<?>>> sourceType = context.getSourceDataType();
Operation<?> sourceOp = (Operation<?>)sourceType.getMetadata(Operation.class.getName());
boolean sourceWrapped = sourceOp != null && sourceOp.isWrapperStyle();
WrapperHandler sourceWrapperHandler = null;
if (sourceWrapped) {
sourceWrapperHandler = getWapperHandler(sourceType.getLogical().get(0).getDataBinding(), true);
}
DataType<List<DataType<QName>>> targetType = context.getTargetDataType();
Operation<?> targetOp = (Operation<?>)targetType.getMetadata(Operation.class.getName());
boolean targetWrapped = targetOp != null && targetOp.isWrapperStyle();
WrapperHandler targetWrapperHandler = null;
if (targetWrapped) {
targetWrapperHandler = getWapperHandler(targetType.getLogical().get(0).getDataBinding(), true);
}
if ((!sourceWrapped) && targetWrapped) {
// Unwrapped --> Wrapped
WrapperInfo wrapper = targetOp.getWrapper();
ElementInfo wrapperElement = wrapper.getInputWrapperElement();
// If the source can be wrapped, wrapped it first
if (sourceWrapperHandler != null) {
Object sourceWrapper = sourceWrapperHandler.create(wrapperElement, context);
for (int i = 0; i < source.length; i++) {
ElementInfo argElement = wrapper.getInputChildElements().get(i);
sourceWrapperHandler.setChild(sourceWrapper, i, argElement, source[0]);
}
}
Object targetWrapper = targetWrapperHandler.create(wrapperElement, context);
if (source == null) {
return new Object[] {targetWrapper};
}
List<DataType<QName>> argTypes = wrapper.getUnwrappedInputType().getLogical();
for (int i = 0; i < source.length; i++) {
ElementInfo argElement = wrapper.getInputChildElements().get(i);
DataType<QName> 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];
List<ElementInfo> childElements = sourceOp.getWrapper().getInputChildElements();
Object[] target = new Object[childElements.size()];
targetWrapperHandler = getWapperHandler(targetType.getLogical().get(0).getDataBinding(), false);
if (targetWrapperHandler != null) {
ElementInfo wrapperElement = sourceOp.getWrapper().getInputWrapperElement();
// Object targetWrapper =
// targetWrapperHandler.create(wrapperElement, context);
DataType<QName> targetWrapperType =
new DataType<QName>(targetType.getLogical().get(0).getDataBinding(), Object.class,
wrapperElement.getQName());
Object targetWrapper =
mediator.mediate(sourceWrapper,
sourceType.getLogical().get(0),
targetWrapperType,
context.getMetadata());
for (int i = 0; i < childElements.size(); i++) {
ElementInfo childElement = childElements.get(i);
target[i] = targetWrapperHandler.getChild(targetWrapper, i, childElement);
}
} else {
for (int i = 0; i < childElements.size(); i++) {
ElementInfo childElement = childElements.get(i);
Object child = sourceWrapperHandler.getChild(sourceWrapper, i, childElement);