private void marshallInternal(Object root, SchemaBinding schema, Writer writer)
throws IOException, SAXException
{
if(schema == null)
{
throw new JBossXBRuntimeException("XSModel is not available!");
}
this.schema = schema;
this.root = root;
content.startDocument();
if(rootTypeQName != null)
{
if(rootQNames.isEmpty())
{
throw new JBossXBRuntimeException("If type name (" +
rootTypeQName +
") for the root element is specified then the name for the root element is required!"
);
}
QName rootQName = (QName)rootQNames.get(0);
TypeBinding type = schema.getType(rootTypeQName);
if(type == null)
{
throw new JBossXBRuntimeException("Global type definition is not found: " + rootTypeQName);
}
if(isArrayWrapper(type))
{
stack.push(root);
marshalComplexType(rootQName, type, true, false);
stack.pop();
}
else
{
ElementBinding element = new ElementBinding(schema, rootQName, type);
ctx.particle = new ParticleBinding(element);
marshalElementOccurence(element, root, false, true);
}
}
else if(rootQNames.isEmpty())
{
Iterator elements = schema.getElementParticles();
if(!elements.hasNext())
{
throw new JBossXBRuntimeException("The schema doesn't contain global element declarations.");
}
while(elements.hasNext())
{
ParticleBinding element = (ParticleBinding)elements.next();