/** * This <code>writeSection</code> method is used to perform serialization * of the given source object. Serialization is performed by appending * elements and attributes from the source object to the provided XML * element object. How the objects contacts are serialized is * determined by the XML schema class that the source object is an * instance of. If a required contact is null an exception is thrown. * * @param source this is the source object to be serialized * @param node the XML element the object is to be serialized to * @param section this is the section that defines the XML structure */ private void writeSection(OutputNode node, Object source, Section section) throws Exception { NamespaceMap scope = node.getNamespaces(); String prefix = section.getPrefix(); if(prefix != null) { String reference = scope.getReference(prefix); if(reference == null) { throw new ElementException("Namespace prefix '%s' in %s is not in scope", prefix, type); } else { node.setReference(reference); } } writeAttributes(node, source, section); writeElements(node, source, section); writeText(node, source, section); }
/** * This is use to apply for <code>NamespaceList</code> annotations * on the node. If there is no namespace list then this will return * and the node will be left unchanged. If however the namespace * list is not empty the the namespaces are added. * * @param node this is the node to apply the namespace list to */ private void scope(OutputNode node) { NamespaceMap map = node.getNamespaces(); for(Namespace next : scope) { String reference = next.reference(); String prefix = next.prefix(); map.setReference(reference, prefix); } }