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

org.robobinding.widgetaddon.DefaultViewAddOnFactory Maven / Gradle / Ivy

There is a newer version: 0.8.14
Show newest version
package org.robobinding.widgetaddon;

import java.lang.reflect.InvocationTargetException;

import org.robobinding.util.ConstructorUtils;


/**
 * @since 1.0
 * @author Cheng Wei
 *
 */
public class DefaultViewAddOnFactory implements ViewAddOnFactory {
	private final Class viewAddOnType;
	
	public DefaultViewAddOnFactory(Class viewAddOnType) {
		this.viewAddOnType = viewAddOnType;
	}
	
	@Override
	public ViewAddOn create(Object view) {
		try {
			return ConstructorUtils.invokeConstructor(viewAddOnType, view);
		} catch (NoSuchMethodException e) {
			throw new RuntimeException("ViewAddOn class " + viewAddOnType.getName() + " does not have a constructor with a view parameter");
		} catch (InvocationTargetException e) {
			throw new RuntimeException(e);
		} catch (InstantiationException e) {
			throw new RuntimeException("ViewAddOn class " + viewAddOnType.getName() + " could not be instantiated: " + e);
		} catch (IllegalAccessException e) {
			throw new RuntimeException("ViewAddOn class " + viewAddOnType.getName() + " is not public");
		}

	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy