verifyNotReadOnly();
m_part = part;
CompositeMessagePart parentPart = part.getParent();
XMLMessagePartMapping parentMapping = (parentPart == null) ? null : (XMLMessagePartMapping)parentPart.getMapping();
PrimitiveMessagePart primitivePart = null;
CompositeMessagePart compositePart = null;
if (part instanceof PrimitiveMessagePart)
{
primitivePart = (PrimitiveMessagePart)part;
}
if (part instanceof CompositeMessagePart)
{
compositePart = (CompositeMessagePart)part;
}
switch (m_nNodeType)
{
case ATTRIBUTE:
if (parentPart == null)
{
throw new MetadataException("err.meta.integration.xml.rootNotElement",
new Object[]{part.getFullPath()});
}
if (compositePart != null)
{
throw new MetadataException("err.meta.integration.xml.compositeAttribute",
new Object[]{part.getFullPath()});
}
if (part.isCollection())
{
throw new MetadataException("err.meta.integration.xml.collectionAttribute",
new Object[]{part.getFullPath()});
}
if (m_bNillable)
{
throw new MetadataException("err.meta.integration.xml.misplacedNillable",
new Object[]{part.getFullPath()});
}
break;
case VALUE:
if (parentPart == null)
{
throw new MetadataException("err.meta.integration.xml.rootNotElement",
new Object[]{part.getFullPath()});
}
if (compositePart != null)
{
throw new MetadataException("err.meta.integration.xml.compositeValue",
new Object[]{part.getFullPath()});
}
if (part.isCollection() && primitivePart.getType() != Primitive.ANY)
{
throw new MetadataException("err.meta.integration.xml.collectionValue",
new Object[]{part.getFullPath()});
}
if (parentMapping.getValuePart() != null)
{
throw new MetadataException("err.meta.integration.xml.duplicateElementValueMapping",
new Object[]{part.getFullPath()});
}
parentMapping.m_valuePart = primitivePart;
if (m_bNillable)
{
throw new MetadataException("err.meta.integration.xml.misplacedNillable",
new Object[]{part.getFullPath()});
}
break;
case ELEMENT:
if (m_bNillable && part.isRequired())
{
throw new MetadataException("err.meta.integration.xml.requiredNillable",
new Object[]{part.getFullPath()});
}
break;
}
if (m_nSubtype != SUBTYPE_DEFAULT && m_sFormat != null)
{
throw new MetadataException("err.meta.integration.xml.formatSubtype",
new Object[]{part.getFullPath()});
}
boolean bSubtypeValid;
if (primitivePart != null)
{
switch (primitivePart.getType().getOrdinal())
{
case Primitive.BINARY_ORDINAL:
switch (m_nSubtype)
{
case SUBTYPE_DEFAULT:
m_nSubtype = SUBTYPE_BASE64;
case SUBTYPE_BASE64:
case SUBTYPE_HEX:
bSubtypeValid = true;
break;
default:
bSubtypeValid = false;
break;
}
break;
case Primitive.TIMESTAMP_ORDINAL:
switch (m_nSubtype)
{
case SUBTYPE_DEFAULT:
m_nSubtype = SUBTYPE_DATETIME;
case SUBTYPE_DATE:
case SUBTYPE_TIME:
case SUBTYPE_DATETIME:
bSubtypeValid = true;
break;
default:
bSubtypeValid = false;
break;
}
break;
case Primitive.ANY_ORDINAL:
bSubtypeValid = m_nSubtype == SUBTYPE_DEFAULT || m_nSubtype == SUBTYPE_XSI && m_nNodeType == ELEMENT;
break;
default:
bSubtypeValid = m_nSubtype == SUBTYPE_DEFAULT;
break;
}
}
else
{
bSubtypeValid = m_nSubtype == SUBTYPE_DEFAULT;
if (m_sFormat != null)
{
throw new MetadataException("err.meta.integration.formatComposite",
new Object[]{part.getFullPath()});
}
}
if (!bSubtypeValid)
{
throw new MetadataException("err.meta.integration.xml.inapplicableSubtype",
new Object[]{SUBTYPE_NAMES[m_nSubtype], part.getFullPath()});
}
MessagePart rootPart = part.getRoot();
RootXMLMessagePartMapping rootMapping = (RootXMLMessagePartMapping)rootPart.getMapping();
// Ensure XSI namespace is used on message root if nillable elements are used
if (m_bNillable && rootMapping != null)
{
rootMapping.addNamespace(XMLNamespace.XSI_NAME, XMLNamespace.XSI, null, false);
}
// ANY-typed part with polymorphic typing
if (primitivePart != null && primitivePart.getType() == Primitive.ANY &&
m_nSubtype == XMLMessagePartMapping.SUBTYPE_XSI)
{
rootMapping.addNamespace(XMLNamespace.XSI_NAME, XMLNamespace.XSI, null, false);
rootMapping.addNamespace(XMLNamespace.XSD_NAME, XMLNamespace.XSD, null, false);
}