{
sName = message.getName();
}
}
XMLNamespace namespace = mapping.getNamespace();
Schema schema = (namespace == null) ? m_universe.getSchema(m_sNamespaceURI, null) :
m_universe.getSchema(namespace.getURI(), namespace.getName());
CompositeType type;
if (sName != null)
{
CompositeType existingType = (CompositeType)schema.findItem(sName, SchemaItem.COMPOSITE_TYPE);
if (existingType != null)
{
return existingType;
}
type = new CompositeType(sName);
schema.addItem(type);
}
else
{
type = new CompositeType(sName);
}
if (message != null)
{
type.setDescription(part.getDescription());
}
if (namespace != null)
{
m_sNamespaceURI = namespace.getURI();
}
switch (part.getAggregation())
{
case CompositeMessagePart.SEQUENTIAL:
type.setAggregation(CompositeType.AGGREGATION_SEQUENTIAL);
break;
case CompositeMessagePart.RANDOM:
type.setAggregation(CompositeType.AGGREGATION_RANDOM);
break;
case CompositeMessagePart.SINGLE:
type.setAggregation(CompositeType.AGGREGATION_CHOICE);
break;
default:
throw new IllegalStateException("Unknown aggregation");
}
type.setLax(part.isLax());
for (int i = 0, nCount = part.getPartCount(); i < nCount; i++)
{
MessagePart child = part.getPart(i);
// Omit parts declared in base message
if (message != null && child.getDeclarator() != message)
{
continue;
}
boolean bChildEnvelopeHeaders = child.getRoot() == part &&
child == ((RootXMLMessagePartMapping)mapping).getHeaderPart();
XMLMessagePartMapping childMapping = (XMLMessagePartMapping)child.getMapping();
if (child instanceof PrimitiveMessagePart)
{
if (bChildEnvelopeHeaders)
{
continue;
}
if (childMapping.getNodeType() == XMLMessagePartMapping.VALUE)
{
type.setValueType(getAtomicType((PrimitiveMessagePart)child));
}
else
{
Markup markup = createMarkup((PrimitiveMessagePart)child);
if (!isEnvelopeMarkup(markup))
{
type.addChild(markup);
}
if (bEnvelopeHeaders)
{
addEnvelopeHeader(child, (Element)markup, false);
}
}
}
else if (child instanceof CompositeMessagePart)
{
CompositeType childType;
Element childElement;
if (child instanceof CompositeMessagePartRef)
{
CompositeMessagePart referentPart = ((CompositeMessagePartRef)child).getRefPart();
Message referentMessage = ((RootXMLMessagePartMapping)referentPart.getMapping()).getRootMessage();
childType = createCompositeType(referentPart, referentMessage);
childElement = new Element(childMapping.getNodeName());
childElement.setType(childType);
childElement.setDescription(child.getDescription());
if (bEnvelopeHeaders)
{
addEnvelopeHeader(child, childElement, true);
}
}
else
{
XMLNamespace childNamespace = childMapping.getNamespace();
String sURI = (childNamespace == null) ? null : childNamespace.getURI();
if (sURI != null && !sURI.equals(m_sNamespaceURI))
{
// Element reference (different namespace)
String sCurrentNamespace = m_sNamespaceURI;
Schema otherNSSchema = m_universe.getSchema(sURI, childNamespace.getName());
m_sNamespaceURI = sURI;
childType = createCompositeType((CompositeMessagePart)child, null);
Element otherNSElement = new Element(childMapping.getNodeName());