List of usage examples for java.lang Class newInstance
@CallerSensitive @Deprecated(since = "9") public T newInstance() throws InstantiationException, IllegalAccessException
From source file:monasca.common.util.SerializationTest.java
@SuppressWarnings("unchecked") private static <T> T proxyFor(Class<T> type) throws Exception { Enhancer enhancer = new Enhancer(); enhancer.setSuperclass(TestCommand.class); enhancer.setCallbackType(NoOp.class); Class<T> enhanced = enhancer.createClass(); return enhanced.newInstance(); }
From source file:Main.java
public static int getStatusBarHeight(Context context) { Class<?> c = null; Object obj = null;/*from w w w .ja v a 2 s . c om*/ Field field = null; int x = 0, statusBarHeight = 0; try { c = Class.forName("com.android.internal.R$dimen"); obj = c.newInstance(); field = c.getField("status_bar_height"); x = Integer.parseInt(field.get(obj).toString()); statusBarHeight = context.getResources().getDimensionPixelSize(x); } catch (Exception e1) { e1.printStackTrace(); } return statusBarHeight; }
From source file:br.com.renatoccosta.regexrenamer.element.base.ElementFactory.java
public static Element compile(String alias) throws ElementNotFoundException { Element ee = null;/*from ww w . j a v a 2 s . com*/ try { Class<Element> c = ElementsDirectory.getInstance().lookup(alias); if (c == null) { throw new ElementNotFoundException(alias); } ee = c.newInstance(); } catch (InstantiationException ex) { LOGGER.error(ex.getMessage(), ex); } catch (IllegalAccessException ex) { LOGGER.error(ex.getMessage(), ex); } return ee; }
From source file:cn.quickj.Setting.java
private static void createPlugin(Configuration config, String pluginClazz, int i) throws ClassNotFoundException, InstantiationException, IllegalAccessException { Configuration c = config.subset("plugins.plugin(" + i + ")"); Class<?> clazz = Class.forName(pluginClazz); Plugin plugin = (Plugin) clazz.newInstance(); plugin.init(c);//from ww w. ja v a 2 s . c o m log.info("?" + plugin.getName() + " id:" + plugin.getId()); plugins.add(plugin); }
From source file:com.asakusafw.testdriver.tools.runner.BatchTestTruncator.java
private static void resolveImporter(Conf conf, Class<? extends ImporterDescription> aClass) { try {/*from w ww .j av a 2s . com*/ conf.importers.add(aClass.newInstance()); } catch (Exception e) { throw new IllegalArgumentException( MessageFormat.format(Messages.getString("BatchTestTruncator.errorInvalidImporterClass"), //$NON-NLS-1$ aClass.getName()), e); } }
From source file:com.asakusafw.testdriver.tools.runner.BatchTestTruncator.java
private static void resolveExporter(Conf conf, Class<? extends ExporterDescription> aClass) { try {//from w w w . j ava2s . c om conf.exporters.add(aClass.newInstance()); } catch (Exception e) { throw new IllegalArgumentException( MessageFormat.format(Messages.getString("BatchTestTruncator.errorInvalidExporterClass"), //$NON-NLS-1$ aClass.getName()), e); } }
From source file:clearUp.Collections3.java
/** * mapbean// ww w. j av a 2s.com * * @param map * @param beanClass * @return */ public static Object map2Bean(Map map, Class<?> beanClass) { try { Object bean = beanClass.newInstance(); PropertyUtils.copyProperties(bean, map); return bean; } catch (Exception e) { throw new RuntimeException(beanClass.getCanonicalName() + "!"); } }
From source file:com.gohuinuo.common.utils.Collections3.java
/** * map?bean/*w w w . java2 s.c om*/ * * @param map * @param beanClass * @return */ public static Object map2Bean(Map map, Class<?> beanClass) { try { Object bean = beanClass.newInstance(); PropertyUtils.copyProperties(bean, map); return bean; } catch (Exception e) { throw new RuntimeException(beanClass.getCanonicalName() + "!"); } }
From source file:com.wavemaker.tools.project.LauncherHelper.java
/** * Invoke a method. It's expected that the ClassLoader cl will be the same as the context classloader, or else the * Spring init will likely fail (or otherwise be bad). *//* ww w. j av a 2s .c o m*/ public static Object invoke(ClassLoader cl, String fqClass, String methodName, Class<?>[] argTypes, Object[] args, boolean isStatic) throws ClassNotFoundException, SecurityException, NoSuchMethodException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { if (ResourceManager.getInstance() == null) { SpringUtils.initSpringConfig(); } Class<?> klass = cl.loadClass(fqClass); Method m = klass.getMethod(methodName, argTypes); Object o; if (isStatic) { o = null; } else { o = klass.newInstance(); } return m.invoke(o, args); }
From source file:com.carmanconsulting.cassidy.util.CassidyUtils.java
public static <T> T instantiate(Class<T> type) { try {//ww w . j av a 2 s .c o m LOGGER.debug("Instantiating object of type {}...", type.getCanonicalName()); return Validate.notNull(type.newInstance()); } catch (InstantiationException e) { throw new CassidyException(String.format("Unable to instantiate object of type %s.", type.getName()), e); } catch (IllegalAccessException e) { throw new CassidyException( String.format("Type %s has no accessible default constructor.", type.getName()), e); } }