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

org.dspace.app.itemupdate.ActionManager Maven / Gradle / Ivy

/**
 * The contents of this file are subject to the license and copyright
 * detailed in the LICENSE and NOTICE files at the root of the source
 * tree and available online at
 *
 * http://www.dspace.org/license/
 */
package org.dspace.app.itemupdate;

import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;

/**
 * 	 Container for UpdateActions      
 *    Order of actions is very import for correct processing.  This implementation
 *     supports an iterator that returns the actions in the order in which they are
 *     put in.  Adding the same action a second time has no effect on this order.
 * 
 *
 */
public class ActionManager implements Iterable {
	
	private Map, UpdateAction> registry 
                     = new LinkedHashMap, UpdateAction>();
	
	public UpdateAction getUpdateAction(Class actionClass) 
	throws InstantiationException, IllegalAccessException
	{
		UpdateAction action =  registry.get(actionClass);
		
		if (action == null)
		{
			action = actionClass.newInstance();
			registry.put(actionClass, action);
		}
		
		return action;		
	}
	
	/**
	 * 
	 * @return whether any actions have been registered with this manager
	 */
	public boolean hasActions()
	{
		return !registry.isEmpty();
	}
	
	/**
	 * 	 This implementation guarantees the iterator order is the same as the order
	 *   in which updateActions have been added
	 * 
	 * @return iterator for UpdateActions
	 */
	public Iterator iterator()
	{
		return new Iterator() 
		{ 			
			private Iterator> itr = registry.keySet().iterator();
			
			public boolean hasNext()
			{
				return itr.hasNext();
			}
			
			public UpdateAction next()
			{
				return registry.get(itr.next());
			}
			
			//not supported
			public void remove()
			{
				throw new UnsupportedOperationException();
			}
		};
		
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy