All Downloads are FREE. Search and download functionalities are using the official Maven repository.

de.retest.ui.descriptors.RenderContainedElementsAdapter Maven / Gradle / Ivy

There is a newer version: 6.0.0
Show newest version
package de.retest.ui.descriptors;

import java.util.HashMap;
import java.util.Map;

import javax.xml.bind.annotation.adapters.XmlAdapter;

public class RenderContainedElementsAdapter extends XmlAdapter {

	private final boolean renderLightweightXml;

	public RenderContainedElementsAdapter() {
		renderLightweightXml = false;
	}

	public RenderContainedElementsAdapter( final boolean renderLightweightXml ) {
		this.renderLightweightXml = renderLightweightXml;
	}

	@Override
	public Element marshal( final Element descriptor ) throws Exception {
		if ( descriptor instanceof RootElement ) {
			return descriptor;
		}
		return renderLightweightXml ? null : descriptor;
	}

	private final Map elements = new HashMap();

	@Override
	public Element unmarshal( final Element descriptor ) throws Exception {
		if ( descriptor.identifyingAttributes == null ) {
			return descriptor;
		}

		if ( elements.containsKey( descriptor ) ) {
			return elements.get( descriptor );
		}

		elements.put( descriptor, descriptor );
		return descriptor;
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy