protected Object transfer1(Object obj, MessagePart msg) throws IntegrationException
{
MessagePart processedPart = msg;
String sMessageName = null;
Metaclass metaclass;
Instance instance = (obj instanceof Instance) ? (Instance)obj : null;
TransferObject srcTobj = (obj instanceof TransferObject) ? (TransferObject)obj : null;
Message message = null;
if (instance != null || srcTobj != null)
{
if (msg instanceof CompositeMessagePartRef)
{
CompositeMessagePartRef ref = (CompositeMessagePartRef)msg;
CompositeMessagePart referencedPart = ref.getRefPart();
message = ((ObjectMessagePartMapping)referencedPart.getMapping()).getMessage();
}
else if (msg.getParent() == null)
{
message = ((ObjectMessagePartMapping)msg.getRoot().getMapping()).getMessage();
}
}
// Process inheritance
if (message != null)
{
metaclass = (instance != null) ? instance.getMetaclass() :
m_context.getMetadata().getMetaclass(srcTobj.getClassName());
Message derivedMessage = findDerivedMessage(message, metaclass);
if (derivedMessage == null)
{
throw new IntegrationException("err.integration.object.missingMapping",
new Object[]{metaclass.getName(), message.getName(), msg.getFullPath()});
}
Message.validatePolymorphism(message, derivedMessage, msg);
msg = derivedMessage.getRoot();
message = derivedMessage;
sMessageName = message.getName();
}
ObjectMessagePartMapping mapping = (ObjectMessagePartMapping)msg.getMapping();
if (m_context.isSecure())
{
if (mapping.getAttribute() != null)
{
mapping.getAttribute().checkReadAccess(m_context.getPrivilegeSet());
}
else
{
mapping.getMetaclass().checkReadAccess(m_context.getPrivilegeSet());
}
}
if (obj == null)
{
if (msg.isRequired())
{
throw new IntegrationException("err.integration.minPartCount", new Object[]{msg.getFullPath()});
}
return null;
}
if (msg instanceof PrimitiveMessagePart)
{
return ((PrimitiveMessagePart)msg).convertValue(obj);
}
CompositeMessagePart composite = (CompositeMessagePart)msg;
int nCount = composite.getPartCount();
if (obj instanceof TransferObject)
{
if (isFetchInstance())
{
instance = (Instance)RPCUtil.instantiateClean(srcTobj, new HashTab(), m_context);
}
else
{
TransferObject tobj = new TransferObject(sMessageName, composite.getPartCount());
tobj.setEventName(srcTobj.getEventName());
tobj.setOID(srcTobj.getOID());
for (int i = 0; i < nCount; ++i)
{
MessagePart part = composite.getPart(i);
ObjectMessagePartMapping objectMessagePartMapping = (ObjectMessagePartMapping)part.getMapping();
Attribute attribute = objectMessagePartMapping.getAttribute();
Object value = null;
if (attribute != null)
{
value = transfer(srcTobj.findValue(attribute.getName()), part);
}
else
{
switch (objectMessagePartMapping.getSystemAttribute())
{
case ObjectMessagePartMapping.ATTR_OID:
value = srcTobj.getOID().toBinary();
break;
case ObjectMessagePartMapping.ATTR_CLASS:
value = srcTobj.getClassName();
break;
case ObjectMessagePartMapping.ATTR_EVENT:
value = srcTobj.getEventName();
break;
}
}
tobj.setValue(part.getName(), value);
}
return tobj;
}
}
if (m_context.isSecure() && !instance.isReadable())
{
return null;
}
metaclass = instance.getMetaclass();
TransferObject tobj = new TransferObject(sMessageName, composite.getPartCount());
if (!mapping.getMetaclass().isUpcast(metaclass))
{
throw new IntegrationException("err.integration.object.partClass",
new Object[]{mapping.getMetaclass().getName(), composite.getFullPath()});
}
String sEvent = null;
boolean bProcessed = m_processedSet.put(instance, processedPart, Boolean.TRUE) != null;
m_instanceMap.put(instance, tobj);
tobj.setOID(instance.getOID());
if (srcTobj != null)
{
sEvent = srcTobj.getEventName();
}
else
{
switch (instance.getState())
{
case Instance.NEW:
sEvent = "create";
break;
case Instance.DIRTY:
sEvent = "update";
break;
case Instance.DELETED:
sEvent = "delete";
break;
}
}
tobj.setEventName(sEvent);
for (int i = 0; i < nCount; ++i)
{
MessagePart part = composite.getPart(i);
ObjectMessagePartMapping objectMessagePartMapping = (ObjectMessagePartMapping)part.getMapping();
Attribute attribute = objectMessagePartMapping.getAttribute();
Object value = null;
if (attribute != null)
{
if (bProcessed && objectMessagePartMapping.isKey() && !(part instanceof PrimitiveMessagePart))
{
throw new IntegrationException("err.integration.object.recursive", new Object[]{msg.getName()});
}
if (!bProcessed || objectMessagePartMapping.isKey())
{
value = transfer(instance.getValue(attribute.getOrdinal()), part);
tobj.setValue(part.getName(), value);
}
}
else
{
switch (objectMessagePartMapping.getSystemAttribute())
{
case ObjectMessagePartMapping.ATTR_OID:
value = (instance.getOID() == null) ? null : instance.getOID().toBinary();
break;
case ObjectMessagePartMapping.ATTR_CLASS:
value = instance.getMetaclass().getName();
break;
case ObjectMessagePartMapping.ATTR_EVENT:
value = sEvent;
break;