package org.gcube.common.resources.gcore.common; import java.util.ArrayList; import java.util.List; import javax.xml.bind.Marshaller; import javax.xml.bind.Unmarshaller; import javax.xml.bind.annotation.XmlAnyElement; import org.gcube.common.resources.gcore.utils.Utils; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class AnyWrapper { //this is the element we return to client for modifications private Element root = Utils.newDocument().getDocumentElement(); //these are the elements we deserialise @XmlAnyElement private List elements; public Element root() { return root; } //after deserialisation, we link the elements to the root @SuppressWarnings("unused") private void afterUnmarshal(Unmarshaller unmarshaller, Object parent) { if (elements!=null) for (Element e: elements) root.appendChild(root.getOwnerDocument().adoptNode(e)); elements=null; } //before serialisation we copy the child elements of the root @SuppressWarnings("unused") private void beforeMarshal(Marshaller marshaller) { elements = new ArrayList(); NodeList list = root.getChildNodes(); for (int i=0;i