/*
 * Created on Sep 20, 2005
 * 
 * $Log$
 * Revision 1.1  2005/09/21 22:00:45  dsowen
 * Split out the access stuff into accesslib.
 * New Creator interface off-loads object creation to user.
 *
 */
package ws.fugue88.jpath;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

/**
 * @author dsowen
 */
public class DefaultCreator implements GraphCreator {

	public Object create(final Class type, final Object root,
			final PathPart part) throws IllegalAccessException,
			InstantiationException, InvocationTargetException
	{
		try {
			final Constructor ctor = type.getDeclaredConstructor(null);
			ctor.setAccessible(true);
			return ctor.newInstance(null);
		} catch(NoSuchMethodException e) {
			throw new InstantiationException("Class " + type.getName()
					+ " must have a no-argument constructor.");
		}
	}
}