* @return The transformed message.
* @throws IntegrationException If a transformation error occurs.
*/
public TransferObject transform(PropertyMap obj, Transformation transformation, Pair arguments) throws IntegrationException
{
Logger logger = transformation.getLogger();
m_output = new TransferObject();
m_listMap = new HashTab();
try
{
if (logger.isDebugEnabled())
{
logger.debug("Transforming a message with transformation " + transformation.getName());
logger.dump(obj);
}
Transformation oldTransformation = transformation;
if (!StringUtil.isEmpty(obj.getClassName()) && m_bPolymorphic)
{
TransformationEndpoint derivedEndpoint = transformation.getSource().getEndpoint(obj.getClassName());
Transformation derivedTransformation = findDerivedTransformation(transformation, derivedEndpoint);
if (oldTransformation.getDerivation() == Transformation.DERIVATION_FINAL && derivedTransformation != oldTransformation)
{
throw new IntegrationException("err.integration.messageTypeMismatch",
new Object[] {oldTransformation.toString(), oldTransformation.getSource().toString(), derivedEndpoint.toString()});
}
if (derivedTransformation != null && derivedTransformation != oldTransformation)
{
transformation = derivedTransformation;
if (logger.isDebugEnabled())
{
logger.debug("Using derived transformation \"" + derivedTransformation.getName() + "\"");
}
}
}
if (oldTransformation.getDerivation() == Transformation.DERIVATION_ABSTRACT)
{
if (transformation == oldTransformation)
{
throw new IntegrationException("err.integration.abstractTransformation",
new Object[]{oldTransformation.getName()});
}
}
m_sourceArray = new Object[SOURCE_SIZE * (transformation.getMaxLevel() + 1)];
if (transformation.getFunction() != null)
{
m_argList.clear();
m_argList.add(this);
m_argList.add(m_output);
m_argList.add(obj);
Pair head = arguments;
int nArgCount = transformation.getArgumentCount();
while (head != null)
{
nArgCount--;
m_argList.add(head.getHead());
head = head.getNext();
}
if (nArgCount != 0)
{
throw new IntegrationException("err.meta.transformation.argumentCount",
new Object[] {Primitive.createInteger(transformation.getArgumentCount()),
Primitive.createInteger(Pair.length(arguments))});
}
m_scriptArray = (Object[])m_context.getMachine().invoke(transformation.getFunction(), m_argList);
}
else
{
m_scriptArray = null;
}
transform(obj, transformation.getRoot());
if (m_scriptArray != null)
{
m_output = (TransferObject)m_context.getMachine().invoke((Function)m_scriptArray[0], (Pair)null);
}
if (m_output.getClassName() == null)
{
m_output.setClassName(transformation.getDestination().getName());
}
}
catch (Exception e)
{
throw new IntegrationException("err.integration.transformation",
new Object[]{transformation.getName()}, e);
}
if (logger.isDumpEnabled())
{
logger.dump("Transformation result:");
logger.dump(m_output);
}
return m_output;
}