return marshalled;
}
private boolean marshalWildcard(XSParticle particle, boolean declareNs)
{
XSWildcard wildcard = (XSWildcard)particle.getTerm();
Object o = stack.peek();
ClassMapping mapping = getClassMapping(o.getClass());
if(mapping == null)
{
// todo: YAH (yet another hack)
QName autoType = SimpleTypeBindings.typeQName(o.getClass());
if(autoType != null)
{
String marshalled = SimpleTypeBindings.marshal(autoType.getLocalPart(), o, null);
content.characters(marshalled.toCharArray(), 0, marshalled.length());
return true;
}
else
{
if(ignoreUnresolvedWildcard)
{
log.warn("Failed to marshal wildcard. Class mapping not found for " +
o.getClass() +
"@" +
o.hashCode() +
": " + o
);
return true;
}
else
{
throw new IllegalStateException("Failed to marshal wildcard. Class mapping not found for " +
o.getClass() +
"@" +
o.hashCode() +
": " + o
);
}
}
}
GenericObjectModelProvider parentProvider = this.provider;
Object parentRoot = this.root;
Stack parentStack = this.stack;
XSModel parentModel = this.model;
this.root = o;
this.stack = new StackImpl();
this.model = mapping.schemaUrl == null ? this.model : Util.loadSchema(mapping.schemaUrl, schemaResolver);
if(mapping.provider != null)
{
this.provider = mapping.provider;
}
boolean marshalled;
if(mapping.elementName != null)
{
XSElementDeclaration elDec = model.getElementDeclaration(mapping.elementName.getLocalPart(),
mapping.elementName.getNamespaceURI()
);
if(elDec == null)
{
throw new JBossXBRuntimeException("Element " + mapping.elementName + " is not declared in the schema.");
}
Object elementValue = provider.getRoot(root, null, elDec.getNamespace(), elDec.getName());
marshalled = marshalElementOccurence(elDec.getNamespace(),
elDec.getName(),
elDec.getTypeDefinition(),
elementValue,
elDec.getNillable(),
particle.getMinOccurs() == 0,
declareNs
);
}
else if(mapping.typeName != null)
{
XSTypeDefinition typeDef = model.getTypeDefinition(mapping.typeName.getLocalPart(),
mapping.typeName.getNamespaceURI()
);
if(typeDef == null)
{
List typeNames = new ArrayList();
XSNamedMap types = model.getComponents(XSConstants.TYPE_DEFINITION);
for(int i = 0; i < types.getLength(); ++i)
{
XSObject type = types.item(i);
if(!Constants.NS_XML_SCHEMA.equals(type.getNamespace()))
{
typeNames.add(new QName(type.getNamespace(), type.getName()));
}
}
throw new JBossXBRuntimeException("Type " +
mapping.typeName +
" is not defined in the schema." +
" Defined types are: " + typeNames
);
}
Object elementValue = provider.getRoot(root, null, wildcard.getNamespace(), wildcard.getName());
marshalled =
marshalElementOccurence(wildcard.getNamespace(),
wildcard.getName(),
typeDef,
elementValue,
true,
particle.getMinOccurs() == 0,
declareNs