List of usage examples for java.lang Class getConstructor
@CallerSensitive public Constructor<T> getConstructor(Class<?>... parameterTypes) throws NoSuchMethodException, SecurityException
From source file:ezbake.thrift.ThriftUtils.java
@SuppressWarnings("unchecked") public static <Y extends TServiceClient> Y getClient(Class<Y> clazz, HostAndPort hostAndPort, Properties properties) throws NoSuchMethodException, TException, Exception { final Constructor<?> constructor = clazz.getConstructor(TProtocol.class); final Object ds = constructor.newInstance(getProtocol(hostAndPort, properties)); return (Y) ds; }
From source file:it.unimi.di.big.mg4j.document.PropertyBasedDocumentFactory.java
public static PropertyBasedDocumentFactory getInstance(final Class<?> klass, final String[] property) throws InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException {//from w w w . j a v a 2 s . c o m return (PropertyBasedDocumentFactory) (klass.getConstructor(new Class[] { String[].class }) .newInstance(new Object[] { property })); }
From source file:it.unimi.di.big.mg4j.document.PropertyBasedDocumentFactory.java
public static PropertyBasedDocumentFactory getInstance(final Class<?> klass, final Properties properties) throws InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException {/*from w ww . jav a 2 s .c o m*/ return (PropertyBasedDocumentFactory) (klass.getConstructor(Properties.class).newInstance(properties)); }
From source file:com.cloudbees.eclipse.core.util.Utils.java
public static <T> T createInstance(final Class<T> clazz, final Class<?>[] types, final Object[] params) { try {// w w w. j a v a2 s . c o m Constructor<T> cnst; cnst = clazz.getConstructor(types); return cnst.newInstance(params); } catch (SecurityException e) { } catch (NoSuchMethodException e) { } catch (IllegalArgumentException e) { } catch (InstantiationException e) { } catch (IllegalAccessException e) { } catch (InvocationTargetException e) { } return null; }
From source file:edu.cwru.sepia.environment.Environment.java
/** * Do some reflection to read the type of tracker to use and call its constructor with a random if possible, * and failing that, no argument.//from w ww . ja v a2 s. c om * @param seed * @return */ private static TurnTracker readTurnTrackerFromPrefs(int seed, Configuration configuration) { TurnTracker toReturn = null; String trackerName = configuration.getString("TurnTracker", "edu.cwru.sepia.environment.SimultaneousTurnTracker"); Class<?> trackerClass = null; try { trackerClass = Class.forName(trackerName); } catch (ClassNotFoundException e) { logger.log(Level.SEVERE, "Unable to find class for TurnTracker " + trackerName, e); } try { toReturn = (TurnTracker) trackerClass.getConstructor(Random.class).newInstance(new Random(seed)); } catch (Exception e) { try { toReturn = (TurnTracker) trackerClass.getConstructor().newInstance(); } catch (Exception e1) { logger.log(Level.SEVERE, "Unable to create an instance of TurnTracker " + trackerName, e); } } if (toReturn == null) { logger.info("No TurnTracker was specified or instantiation failed; using SimultaneousTurnTracker"); return new SimultaneousTurnTracker(new Random(seed)); } else return toReturn; }
From source file:com.open.cas.shiro.util.ReflectionUtils.java
public static Object newInstance(Class clazz, Object[] args, Class[] argsClass) { try {/* w w w . j av a2 s. c o m*/ Constructor cons = clazz.getConstructor(argsClass); return cons.newInstance(args); } catch (Exception e) { throw convertReflectionExceptionToUnchecked(e); } }
From source file:fr.mby.saml2.sp.impl.helper.SecurityHelper.java
/** * Build a private Key from DER resource. * //from w w w. j a va2 s . co m * @param certificate * the DER resource * @param pkSpecClass * the java key specification class * @param type * the certificate type * @return the java.security.cert.Certificate * @throws NoSuchMethodException * @throws SecurityException * @throws InvocationTargetException * @throws IllegalAccessException * @throws InstantiationException * @throws IllegalArgumentException * @throws NoSuchAlgorithmException * @throws InvalidKeySpecException * @throws IOException */ public static PrivateKey buildPrivateKey(final Resource privateKey, final Class<EncodedKeySpec> pkSpecClass, final String type) throws SecurityException, NoSuchMethodException, IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchAlgorithmException, InvalidKeySpecException, IOException { PrivateKey result = null; final Constructor<EncodedKeySpec> keySpecConstructor = pkSpecClass.getConstructor(byte[].class); final byte[] keyBytes = SecurityHelper.readBytesFromFilePath(privateKey); if (keyBytes != null) { final EncodedKeySpec keySpec = keySpecConstructor.newInstance(keyBytes); final KeyFactory pkFactory = KeyFactory.getInstance(type); result = pkFactory.generatePrivate(keySpec); } return result; }
From source file:com.inmobi.messaging.consumer.databus.AbstractMessagingDatabusConsumer.java
public static CheckpointProvider createCheckpointProvider(String checkpointProviderClassName, String chkpointDir) {/*from www. ja v a 2 s. c om*/ CheckpointProvider chkProvider = null; try { Class<?> clazz = Class.forName(checkpointProviderClassName); Constructor<?> constructor = clazz.getConstructor(String.class); chkProvider = (CheckpointProvider) constructor.newInstance(new Object[] { chkpointDir }); } catch (Exception e) { throw new IllegalArgumentException( "Could not create checkpoint provider " + checkpointProviderClassName, e); } return chkProvider; }
From source file:info.papdt.blacklight.api.BaseApi.java
protected static <T> T request(String token, String url, WeiboParameters params, String method, Class<T> jsonClass) throws Exception { if (token == null) { return null; } else {//from w ww . j a v a2s.c o m params.put("access_token", token); String jsonData = HttpUtility.doRequest(url, params, method); if (DEBUG) { Log.d(TAG, "jsonData = " + jsonData); } if (jsonData != null && (jsonData.contains("{") || jsonData.contains("["))) { return jsonClass.getConstructor(String.class).newInstance(jsonData); } else { return null; } } }
From source file:ezbake.thrift.ThriftUtils.java
@SuppressWarnings("unchecked") public static <Y extends TServiceClient> Y getClient(Class<Y> clazz, HostAndPort hostAndPort, String securityId, Properties properties) throws NoSuchMethodException, TException, Exception { final Constructor<?> constructor = clazz.getConstructor(TProtocol.class); final Object ds = constructor.newInstance(getProtocol(hostAndPort, securityId, properties)); return (Y) ds; }