if(value != null) String prefix = getPrefix(elementUri); boolean genPrefix = prefix == null && elementUri != null && elementUri.length() > 0; if(genPrefix) String marshalled = marshalCharacters(elementUri, prefix, type, value, attrs); declareNs(attrs); declareXsiType(type, attrs); String qName = prefixLocalName(prefix, elementLocal); writeNillable(elementUri, elementLocal, nillable);
i = o != null && isRepeatable(particle) ? getIterator(o) : null; if(i != null) marshalled = marshalModelGroup(particle, declareNs); stack.pop(); marshalled = marshalModelGroup(particle, declareNs); i = o != null && isRepeatable(particle) ? getIterator(o) : null; if(i != null) marshalled = marshalWildcardOccurence(particle, marshaller, value, declareNs); marshalled = marshalWildcardOccurence(particle, marshaller, o, declareNs); XSElementDeclaration element = (XSElementDeclaration)term; XSTypeDefinition type = element.getTypeDefinition(); o = getElementValue(element.getNamespace(), element.getName(), type); i = o != null && isRepeatable(particle) ? getIterator(o) : null; if(i != null) marshalElementOccurence(element.getNamespace(), element.getName(), type, marshalElementOccurence(element.getNamespace(), element.getName(), type,
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; }
String prefix = getPrefix(elementNs); if(prefix == null && elementNs != null && elementNs.length() > 0) String xsiPrefix = getPrefix(Constants.NS_XML_SCHEMA_INSTANCE); if(xsiPrefix == null) attrs.add(Constants.NS_XML_SCHEMA_INSTANCE, "nil", nilQName, null, "1"); String qName = prefixLocalName(prefix, elementLocal); content.startElement(elementNs, elementLocal, qName, attrs); content.endElement(elementNs, elementLocal, qName);
declareNs(attrs); generatedPrefix = declareXsiType(type, attrs); if(generatedPrefix != null) declareNs(attrs, generatedPrefix, typeNsWithGeneratedPrefix); declareNamespace(generatedPrefix, typeNsWithGeneratedPrefix); String prefix = getPrefix(elementNsUri); boolean genPrefix = prefix == null && elementNsUri != null && elementNsUri.length() > 0; if(genPrefix) declareNamespace(prefix, elementNsUri); if(attrs == null) attrPrefix = getPrefix(attrNs); if(attrPrefix == null && attrNs != null && attrNs.length() > 0) itemPrefix = getPrefix(itemNs); if(itemPrefix == null) declareNs(attrs, itemPrefix, itemNs); qNamePrefix = getPrefix(ns); if(qNamePrefix == null) declareNs(attrs, qNamePrefix, ns); nsRegistry.addPrefixMapping(qNamePrefix, ns); declarePrefix = true;
if(isArrayWrapper(type)) marshalComplexType(rootQName.getNamespaceURI(), rootQName.getLocalPart(), (XSComplexTypeDefinition)type, marshalElementOccurence(rootQName.getNamespaceURI(), rootQName.getLocalPart(), type, marshalElementOccurence(element.getNamespace(), element.getName(), element.getTypeDefinition(), marshalElementOccurence(element.getNamespace(), element.getName(), element.getTypeDefinition(), writeXmlVersion(writer); propertyIsTrueOrNotSet(Marshaller.PROP_OUTPUT_INDENTATION) ); content.handleContent(contentWriter); propertyIsTrueOrNotSet(Marshaller.PROP_OUTPUT_INDENTATION) ); content.handleContent(contentWriter);
list = asList(value); declareNs(attrs, prefix, qName.getNamespaceURI()); marshalled = marshalCharacters(elementUri, elementPrefix, (XSSimpleTypeDefinition)type.getBaseType(),
ClassMapping mapping = getClassMapping(o.getClass()); if(mapping == null) marshalled = marshalElementOccurence(elDec.getNamespace(), elDec.getName(), elDec.getTypeDefinition(), marshalElementOccurence(wildcard.getNamespace(), wildcard.getName(), typeDef,
/** * 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; }