soot.plugins.internal.ReflectionClassLoadingStrategy Maven / Gradle / Ivy
package soot.plugins.internal;
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 2018 Bernhard J. Berger
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* .
* #L%
*/
/**
* Class loading strategy that uses traditional reflection for instantiation.
*
* @author Bernhard J. Berger
*/
public class ReflectionClassLoadingStrategy implements ClassLoadingStrategy {
@Override
public Object create(final String className) throws ClassNotFoundException, InstantiationException {
final Class clazz = Class.forName(className);
try {
return clazz.newInstance();
} catch (final IllegalAccessException e) {
throw new InstantiationException("Failed to create instance of " + className + " due to access restrictions.");
}
}
}