List of usage examples for java.lang Class getConstructor
@CallerSensitive public Constructor<T> getConstructor(Class<?>... parameterTypes) throws NoSuchMethodException, SecurityException
From source file:com.xpn.xwiki.plugin.charts.plots.LinePlotFactory.java
public Plot create(DataSource dataSource, ChartParams params) throws GenerateException, DataSourceException { Class rendererClass = params.getClass(ChartParams.RENDERER); if (rendererClass == null || XYItemRenderer.class.isAssignableFrom(rendererClass)) { XYItemRenderer renderer;/*from ww w .j a v a2s . c om*/ if (rendererClass != null) { try { Constructor ctor = rendererClass.getConstructor(new Class[] {}); renderer = (XYItemRenderer) ctor.newInstance(new Object[] {}); } catch (Throwable e) { throw new GenerateException(e); } } else { renderer = new XYLineAndShapeRenderer(); } ChartCustomizer.customizeXYItemRenderer(renderer, params); return XYPlotFactory.getInstance().create(dataSource, renderer, params); } else if (CategoryItemRenderer.class.isAssignableFrom(rendererClass)) { CategoryItemRenderer renderer; if (rendererClass != null) { try { Constructor ctor = rendererClass.getConstructor(new Class[] {}); renderer = (CategoryItemRenderer) ctor.newInstance(new Object[] {}); } catch (Throwable e) { throw new GenerateException(e); } } else { renderer = new LineAndShapeRenderer(); } ChartCustomizer.customizeCategoryItemRenderer(renderer, params); return CategoryPlotFactory.getInstance().create(dataSource, renderer, params); } else { throw new GenerateException("Incompatible renderer class: " + rendererClass); } }
From source file:com.adaptris.core.management.ManagementComponentFactory.java
private Object resolve(final String name, BootstrapProperties bootstrapProperties) throws Exception { final ClassLoader originalContectClassLoader = Thread.currentThread().getContextClassLoader(); ClassLoader classLoader = getClass().getClassLoader(); try (final InputStream in = classLoader.getResourceAsStream(RESOURCE_PATH + name)) { if (in != null) { final Properties p = new Properties(); p.load(in);//ww w . j ava 2 s . c om final String classloaderProperty = p.getProperty(CLASSLOADER_KEY); if (classloaderProperty != null) { log.debug("Using custom class loader " + classloaderProperty); final Class<ClassLoaderFactory> classLoaderFactoryClass = (Class<ClassLoaderFactory>) Class .forName(classloaderProperty); final Constructor<ClassLoaderFactory> constructor = classLoaderFactoryClass .getConstructor(BootstrapProperties.class); final ClassLoaderFactory classLoaderFactory = constructor.newInstance(bootstrapProperties); classLoader = classLoaderFactory.create(classLoader); Thread.currentThread().setContextClassLoader(classLoader); } final Object component = Class.forName(p.getProperty(PROPERTY_KEY), true, classLoader) .newInstance(); if (classloaderProperty != null) { invokeMethod(component, "setClassLoader", new Class[] { ClassLoader.class }, new ClassLoader[] { classLoader }); } return component; } return Class.forName(name).newInstance(); } finally { Thread.currentThread().setContextClassLoader(originalContectClassLoader); } }
From source file:info.magnolia.module.admininterface.DialogHandlerManager.java
protected DialogMVCHandler instantiateHandler(String name, HttpServletRequest request, HttpServletResponse response, Object[] handlerConfig) { try {//w ww . java2 s . c o m Class dialogHandlerClass = (Class) handlerConfig[0]; Content configNode = (Content) handlerConfig[1]; if (configNode != null) { try { Constructor constructor = dialogHandlerClass.getConstructor(new Class[] { String.class, HttpServletRequest.class, HttpServletResponse.class, Content.class }); return (DialogMVCHandler) constructor .newInstance(new Object[] { name, request, response, configNode }); } catch (NoSuchMethodException e) { Constructor constructor = dialogHandlerClass.getConstructor( new Class[] { String.class, HttpServletRequest.class, HttpServletResponse.class }); return (DialogMVCHandler) constructor.newInstance(new Object[] { name, request, response }); } } Constructor constructor = dialogHandlerClass.getConstructor( new Class[] { String.class, HttpServletRequest.class, HttpServletResponse.class }); return (DialogMVCHandler) constructor.newInstance(new Object[] { name, request, response }); } catch (Exception e) { throw new InvalidDialogHandlerException(name, e); } }