list = asList(value);
}
else
{
// todo: qname are also not yet supported
throw new JBossXBRuntimeException(
"Expected value for list type is an array or " + List.class.getName() + " but got: " + value
);
}
marshalled = SimpleTypeBindings.marshalList(itemType.getQName().getLocalPart(), list, null);
}
else
{
throw new JBossXBRuntimeException("Marshalling of list types with item types not from " +
Constants.NS_XML_SCHEMA + " is not supported."
);
}
}
else if(simpleTypeQName != null && Constants.NS_XML_SCHEMA.equals(simpleTypeQName.getNamespaceURI()))
{
String typeName = simpleTypeQName.getLocalPart();
String prefix = null;
boolean removePrefix = false;
if(SimpleTypeBindings.XS_QNAME_NAME.equals(typeName) ||
SimpleTypeBindings.XS_NOTATION_NAME.equals(typeName))
{
QName qNameValue = (QName)value;
if(qNameValue.getNamespaceURI() != null && qNameValue.getNamespaceURI().length() > 0)
{
prefix = nsRegistry.getPrefix(qNameValue.getNamespaceURI());
if(prefix == null)
{
prefix = qNameValue.getPrefix();
if(prefix == null || prefix.length() == 0)
{
prefix = qNameValue.getLocalPart() + "_ns";
}
nsRegistry.addPrefixMapping(prefix, qNameValue.getNamespaceURI());
ctx.declareNamespace(prefix, qNameValue.getNamespaceURI());
removePrefix = true;
}
}
}
marshalled = SimpleTypeBindings.marshal(typeName, value, nsRegistry);
if(removePrefix)
{
nsRegistry.removePrefixMapping(prefix);
}
}
// todo: this is a quick fix for boolean pattern (0|1 or true|false) should be refactored
else if(simpleType.getLexicalPattern() != null &&
simpleType.getBaseType() != null &&
Constants.QNAME_BOOLEAN.equals(simpleType.getBaseType().getQName()))
{
String item = (String)simpleType.getLexicalPattern().get(0);
if(item.indexOf('0') != -1 && item.indexOf('1') != -1)
{
marshalled = ((Boolean)value).booleanValue() ? "1" : "0";
}
else
{
marshalled = ((Boolean)value).booleanValue() ? "true" : "false";
}
}
else
{
if(simpleType.getLexicalEnumeration() != null)
{
Method getValue;
try
{
getValue = value.getClass().getMethod("value", null);
}
catch(NoSuchMethodException e)
{
try
{
getValue = value.getClass().getMethod("getValue", null);
}
catch(NoSuchMethodException e1)
{
throw new JBossXBRuntimeException("Failed to find neither value() nor getValue() in " +
value.getClass() +
" which is bound to enumeration type " + simpleTypeQName
);
}
}
try
{
value = getValue.invoke(value, null);
}
catch(Exception e)
{
throw new JBossXBRuntimeException(
"Failed to invoke getValue() on " + value + " to get the enumeration value", e
);
}
}