{
ObjectMessagePartMapping mapping = (ObjectMessagePartMapping)composite.getMapping();
CompositeMessagePart derivedComposite = getPolymorphic(composite, tobj);
ObjectMessagePartMapping derivedMapping = ((ObjectMessagePartMapping)derivedComposite.getMapping());
Metaclass derivedMetaclass = derivedMapping.getMetaclass();
Pair where = null;
if (!bRoot)
{
assoc = new Pair(mapping.getAttribute().getSymbol(), assoc);
if (!mapping.isLocal())
{
Instance instance = (Instance)m_instanceByTobjMap.get(tobj);
if (instance == null)
{
if (!m_instanceByTobjMap.contains(tobj) && !mapping.isSubKeyParent())
{
instance = findInstance1(tobj, composite, parent, parentComposite);
}
if (instance == null && !mapping.isSubKeyParent())
{
return EMPTY;
}
}
if (instance != null && !mapping.isSubKeyParent())
{
return getComparison(assoc, instance);
}
}
}
if (tobj == null || isInstanceRead(tobj, derivedMapping))
{
return EMPTY;
}
if (tobj.getOID() != null)
{
where = new Pair(getComparison(assoc, tobj.getOID()), where);
}
else
{
for (int i = 0, n = derivedComposite.getPartCount(); i != n; ++i)
{
MessagePart part = derivedComposite.getPart(i);
ObjectMessagePartMapping partMapping = (ObjectMessagePartMapping)part.getMapping();
if (bRoot && partMapping.isKey() || !bRoot && partMapping.isSubKey())
{
if (!tobj.hasValue(part.getName()))
{
return EMPTY;
}
Object obj = tobj.getValue(part.getName());
Pair expr = null;
if (part instanceof CompositeMessagePart)
{
expr = getWhere(obj, (CompositeMessagePart)part, tobj, composite, assoc, false);
if (expr == EMPTY)
{
return EMPTY;
}
}
else if (partMapping.getSystemAttribute() == ObjectMessagePartMapping.ATTR_OID)
{
expr = getComparison(assoc, obj);
}
else if (partMapping.getAttribute() != null)
{
expr = getComparison(new Pair(partMapping.getAttribute().getSymbol(), assoc),
partMapping.getAttribute().getType().convert(obj));
}
if (expr != null)
{
where = new Pair(expr, where);
}
}
}
if (!bRoot && derivedMetaclass != mapping.getAttribute().getType())
{
where = new Pair(Pair.binary(Symbol.INSTANCE_P, getAssociation(assoc),
derivedMetaclass.getSymbol()), where);
}
if (mapping.getWhere() != Boolean.TRUE)
{
where = new Pair(mapping.getWhere(), where);
}
}
if (where != null)
{
if (where.getTail() == null)
{
return (Pair)where.getHead();
}
where = new Pair(Symbol.AND, where);
}
return where;
}