List of usage examples for java.lang Class newInstance
@CallerSensitive @Deprecated(since = "9") public T newInstance() throws InstantiationException, IllegalAccessException
From source file:com.limegroup.gnutella.licenses.PublishedCCLicenseTest.java
/** * Returns the HTML parser as used by HTMLEditorKit. We could use * HTMLEditorKit to get an instance of it but HTMLEditorKit instantiates * some java.awt.Cursor objects internally that causes some problems * on OSX even in java.awt.headless mode! *//*from w ww . ja va 2s . c om*/ private static Parser getHTMLEditorKitParser() { try { Class c = Class.forName("javax.swing.text.html.parser.ParserDelegator"); return (Parser) c.newInstance(); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:com.yattatech.gcm.gui.GCMSender.java
public static void send(String channel, String message, String classKey) throws Exception { loadProperties();/*w ww . j ava 2s . co m*/ final HttpClient httpClient = new DefaultHttpClient(); final HttpPost httpPost = new HttpPost("https://android.googleapis.com/gcm/send"); final Class<?> formatClass = Class.forName(PROPERTIES.getProperty(classKey)); final RequestFormat format = (RequestFormat) formatClass.newInstance(); //HttpHost proxy = new HttpHost(PROPERTIES.getProperty("proxy.host"), Integer.parseInt(PROPERTIES.getProperty("proxy.port"))); //httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); httpPost.setHeader("Accept", "application/json"); httpPost.setHeader("Authorization", PROPERTIES.getProperty("auth.key")); httpPost.setEntity(format.getRequest(channel, message)); HttpResponse response = httpClient.execute(httpPost); final String content = IOUtils.toString(response.getEntity().getContent()); System.out.println("Response status " + response.getStatusLine().getStatusCode()); if (logCallback != null) { logCallback.message(content); } System.out.println("Response " + content); }
From source file:com.yahoo.pulsar.client.api.AuthenticationFactory.java
/** * Create an instance of the Authentication-Plugin * * @param authPluginClassName/*w w w .ja v a 2 s .com*/ * name of the Authentication-Plugin you want to use * @param authParams * map which represents parameters for the Authentication-Plugin * @return instance of the Authentication-Plugin * @throws UnsupportedAuthenticationException */ public static final Authentication create(String authPluginClassName, Map<String, String> authParams) throws UnsupportedAuthenticationException { try { if (isNotBlank(authPluginClassName)) { Class<?> authClass = Class.forName(authPluginClassName); Authentication auth = (Authentication) authClass.newInstance(); auth.configure(authParams); return auth; } else { return new AuthenticationDisabled(); } } catch (Throwable t) { throw new UnsupportedAuthenticationException(t); } }
From source file:adalid.commons.bundles.Bundle.java
private static Linguist getLinguist(ResourceBundle rb) { try {// w w w . ja v a2 s .c o m String name = rb.getString(Linguist.class.getName()); Class<?> clazz = Class.forName(name); return (Linguist) clazz.newInstance(); } catch (MissingResourceException | ClassNotFoundException | InstantiationException | IllegalAccessException e) { return null; } }
From source file:com.steelbridgelabs.oss.neo4j.structure.Neo4JGraphFactory.java
private static Neo4JElementIdProvider<?> loadProvider(String className) throws ClassNotFoundException, IllegalAccessException, InstantiationException { // check class name if (className != null) { // load class Class<?> type = Class.forName(className); // create instance return (Neo4JElementIdProvider<?>) type.newInstance(); }//ww w . ja v a2 s. c o m return null; }
From source file:org.arrow.util.DelegateUtil.java
/** * Creates a new {@link JavaDelegate} instance of the class with the given * name. Throws an IllegalArgumentException if the class could not be * instantiated.//from w w w.ja v a 2s .c o m * * @param className the java delegate class name * @return JavaDelegate */ public static JavaDelegate getJavaDelegate(String className) { Assert.notNull(className, "className must not be null"); try { if (cache.containsKey(className)) { return (JavaDelegate) cache.get(className); } Class<?> clazz = Class.forName(className); JavaDelegate delegate = (JavaDelegate) clazz.newInstance(); cache.put(className, delegate); return delegate; } catch (Exception e) { throw new IllegalArgumentException("Java delegation error", e); } }
From source file:dk.statsbiblioteket.doms.domsutil.surveillance.logappender.LogRegistryFactory.java
/** * Get the log registry singleton instance. As this produces a singleton, * a new instance will only be generated on the first call, after this the * same instance will be returned. If the configuration that defines the * implementing class is changed, though, a new instance of the new class * will be produced. This method is synchronized. * * @return Log registry singleton instance. * * @throws LogRegistryInstantiationException on trouble instantiating the * singleton./* ww w . ja v a 2 s.c o m*/ */ public static synchronized LogRegistry getLogRegistry() throws LogRegistryInstantiationException { log.trace("Enter getLogRegistry()"); String implementation = ConfigCollection.getProperties().getProperty(REGISTRYCLASS_CONFIGURATION_PARAMETER); if (implementation == null || implementation.equals("")) { implementation = DEFAULT_IMPLEMENTATION; } if ((logRegistry == null) || !logRegistry.getClass().getName().equals(implementation)) { log.info("Initializing log registry class '" + implementation + "'"); try { Class logRegistryClass = Class.forName(implementation); logRegistry = (LogRegistry) logRegistryClass.newInstance(); } catch (Exception e) { throw new LogRegistryInstantiationException( "Cannot instantiate LogRegistry class '" + implementation + "': " + e.getMessage(), e); } } return logRegistry; }
From source file:com.baomidou.framework.common.util.BeanUtil.java
/** * //from w ww . j a v a 2 s. c o m * * @param clazz * * @return */ @SuppressWarnings("unchecked") public static <T> T newInstance(Class<?> clazz) { try { return (T) clazz.newInstance(); } catch (InstantiationException e) { throw new RuntimeException(e); } catch (IllegalAccessException e) { throw new RuntimeException(e); } }
From source file:com.netflix.turbine.init.TurbineInit.java
private static InstanceDiscovery getInstanceDiscoveryImpl() { String className = InstanceDiscoveryClassProp.get(); if (className == null) { logger.info("Property " + InstanceDiscoveryClassProp.getName() + " is not defined, hence using " + ConfigPropertyBasedDiscovery.class.getSimpleName() + " as InstanceDiscovery impl"); return new ConfigPropertyBasedDiscovery(); }//from ww w .j a va2s .c o m try { Class clazz = Class.forName(className); return (InstanceDiscovery) clazz.newInstance(); } catch (Exception e) { logger.error("Could not load InstanceDiscovery impl class", e); throw new RuntimeException(e); } }
From source file:Main.java
/** * @param activity/*ww w . j a v a2 s .c o m*/ * @return > 0 success; <= 0 fail */ public static int getStatusHeight(Activity activity) { int statusHeight = 0; Rect localRect = new Rect(); activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(localRect); statusHeight = localRect.top; if (0 == statusHeight) { Class<?> localClass; try { localClass = Class.forName("com.android.internal.R$dimen"); Object localObject = localClass.newInstance(); int i5 = Integer.parseInt(localClass.getField("status_bar_height").get(localObject).toString()); statusHeight = activity.getResources().getDimensionPixelSize(i5); } catch (ClassNotFoundException | IllegalAccessException | InstantiationException | IllegalArgumentException | SecurityException | NoSuchFieldException e) { e.printStackTrace(); } } return statusHeight; }