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

org.docx4j.mce.ArrayListMce Maven / Gradle / Ivy

There is a newer version: 11.5.0
Show newest version
package org.docx4j.mce;


import java.util.ArrayList;

import jakarta.xml.bind.JAXBElement;

import org.jvnet.jaxb2_commons.ppp.Child;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @since 6.1.1
 */
public class ArrayListMce extends ArrayList {
	
	private static Logger log = LoggerFactory.getLogger(ArrayListMce.class);	
	
	public ArrayListMce(Object p) {
		this.parent = p;
	}
	
	private ArrayListMce() {
		
		log.error("ArrayListVml constructor invoked without arg");
		throw new RuntimeException();		
	}
	
	
	
	private Object parent = null;
	
	@Override
	public boolean add(E e) {
		
		if (parent==null) {
			
			log.warn("null parent. how?");
			if (log.isDebugEnabled()) {
				log.debug("Null parent", new Throwable());
			}
			
		} 
		
		if (e instanceof JAXBElement /* workaround */) {
			
			setParent( ((JAXBElement)e).getValue() );
			
		} else {
			
			setParent(e);
		}
		
    	
		return super.add(e);
    }
	
	private void setParent(Object o) {

		if (parent!=null) {
			
			if (o instanceof Child) {
				((Child)o).setParent(parent);
			} else {
				log.warn(o.getClass().getName() + " does not implement Child");
			}
		}
	}
	

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy