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

com.dooapp.gaedo.finders.repository.InheriterRepository Maven / Gradle / Ivy

package com.dooapp.gaedo.finders.repository;

import com.dooapp.gaedo.finders.FinderCrudService;
import com.dooapp.gaedo.finders.Informer;

/**
 * Subclass of simple service repository allowing subclasses usage
 * @author ndx
 *
 */
public class InheriterRepository extends SimpleServiceRepository {
	/**
	 * Override parent method to perform superclass lookup
	 * @param arg0
	 * @return
	 * @see com.dooapp.gaedo.finders.repository.SimpleServiceRepository#containsKey(java.lang.Class)
	 */
	@Override
	public boolean containsKey(Class arg0) {
		if(super.containsKey(arg0))
			return true;
		else {
			if(arg0==null) {
				return false;
			} else if(!Object.class.equals(arg0)) {
				return containsKey(arg0.getSuperclass());
			} else {
				return false;
			}
		}
	}

	@Override
	public > FinderCrudService get(Class dataType) {
		return get(dataType, dataType);
	}

	public > FinderCrudService get(Class dataType, Class original) {
		if(super.containsKey(dataType))
			return super.get((Class)dataType);
		else {
			if(!Object.class.equals(dataType)) {
				return get(dataType.getSuperclass(), original);
			} else {
				throw new NoSuchServiceException("class "+original.getName()+" appears as not managed by a service of this repository");
			}
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy