private boolean marshalElement(String elementNs, String elementLocal, XSTypeDefinition type, boolean optional, boolean nillable, boolean declareNs, boolean declareXsiType) { Object value = stack.peek(); boolean result = value != null || value == null && (optional || nillable); boolean trace = log.isTraceEnabled() && result; if(trace) { String prefix = getPrefix(elementNs); log.trace("started element ns=" + elementNs + ", local=" + elementLocal + ", prefix=" + prefix); } if(value != null) { marshalElementType(elementNs, elementLocal, type, declareNs, nillable, declareXsiType); } else if(nillable) { writeNillable(elementNs, elementLocal, nillable); } if(trace) { log.trace("finished element ns=" + elementNs + ", local=" + elementLocal); } return result; }
/** * Adds xsi:type attribute and optionally declares namespaces for xsi and type's namespace. * @param type the type to declare xsi:type attribute for * @param attrs the attributes to add xsi:type attribute to * @return prefix for the type's ns if it was generated */ private String declareXsiType(XSTypeDefinition type, AttributesImpl attrs) { String result = null; String xsiPrefix = nsRegistry.getPrefix(Constants.NS_XML_SCHEMA_INSTANCE); if(xsiPrefix == null) { attrs.add(Constants.NS_XML_SCHEMA, "xmlns", "xmlns:xsi", null, Constants.NS_XML_SCHEMA_INSTANCE); xsiPrefix = "xsi"; } String pref = getPrefix(type.getNamespace()); if(pref == null) { // the ns is not declared result = pref = type.getName() + "_ns"; } String typeQName = pref == null ? type.getName() : pref + ':' + type.getName(); attrs.add(Constants.NS_XML_SCHEMA_INSTANCE, "type", xsiPrefix + ":type", null, typeQName); return result; }
String prefix = getPrefix(elementNsUri); boolean genPrefix = prefix == null && elementNsUri != null && elementNsUri.length() > 0; if(genPrefix) if(attrNs != null) attrPrefix = getPrefix(attrNs); if(attrPrefix == null && attrNs != null && attrNs.length() > 0) itemPrefix = getPrefix(itemNs); if(itemPrefix == null) if(ns != null && ns.length() > 0) qNamePrefix = getPrefix(ns); if(qNamePrefix == null)
if(value != null) String prefix = getPrefix(elementUri); boolean genPrefix = prefix == null && elementUri != null && elementUri.length() > 0; if(genPrefix)