List of usage examples for java.lang Class getConstructor
@CallerSensitive public Constructor<T> getConstructor(Class<?>... parameterTypes) throws NoSuchMethodException, SecurityException
From source file:Main.java
public static Node applyXslToDocument2(Source xslt, Source doc, URIResolver resolver, Properties transformerProperties, HashMap<String, String> params, String transformerClassName) throws ClassNotFoundException, IllegalAccessException, InstantiationException, IOException, NoSuchMethodException, TransformerConfigurationException, TransformerException { TransformerFactory transformerFactory = null; if (transformerClassName == null) transformerFactory = TransformerFactory.newInstance(); else {//from w w w . ja v a 2s .c o m Class transformerClass = Class.forName(transformerClassName); Constructor defaultConstructor = transformerClass.getConstructor(null); transformerFactory = (TransformerFactory) transformerClass.newInstance(); } if (resolver != null) transformerFactory.setURIResolver(resolver); Transformer transformer = transformerFactory.newTransformer(xslt); if (transformerFactory != null) transformer.setOutputProperties(transformerProperties); if (params != null) { for (Map.Entry<String, String> cursor : params.entrySet()) { transformer.setParameter(cursor.getKey(), cursor.getValue()); } } DOMResult result = new DOMResult(); transformer.transform(doc, result); return (result.getNode()); }
From source file:indexer.Index.java
public static Index createIndex(Class<? extends Indexer> i, String indexDirectory) { try {/*from w ww . jav a 2 s .c o m*/ Indexer indexer = i.getConstructor(String.class).newInstance(indexDirectory); return getIndex(indexer); } catch (InstantiationException | NoSuchMethodException | InvocationTargetException | IllegalAccessException e) { LogFactory.getLog(Index.class).error("Could not create index.", e); return null; } }
From source file:Main.java
public static String applyXslToDocument(Source xslt, Source doc, URIResolver resolver, Properties transformerProperties, HashMap<String, String> params, String transformerClassName) throws ClassNotFoundException, IllegalAccessException, InstantiationException, IOException, NoSuchMethodException, TransformerConfigurationException, TransformerException { TransformerFactory transformerFactory = null; if (transformerClassName == null) transformerFactory = TransformerFactory.newInstance(); else {/*w w w . j a v a 2s .co m*/ Class transformerClass = Class.forName(transformerClassName); Constructor defaultConstructor = transformerClass.getConstructor(null); transformerFactory = (TransformerFactory) transformerClass.newInstance(); } if (resolver != null) transformerFactory.setURIResolver(resolver); Transformer transformer = transformerFactory.newTransformer(xslt); if (transformerFactory != null) transformer.setOutputProperties(transformerProperties); if (params != null) { for (Map.Entry<String, String> cursor : params.entrySet()) { transformer.setParameter(cursor.getKey(), cursor.getValue()); } } StringWriter strWriter = new StringWriter(); StreamResult result = new StreamResult(strWriter); transformer.transform(doc, result); return (strWriter.toString()); }
From source file:com.ibatis.common.logging.LogFactory.java
/** * This method will switch the logging implementation to Log4J if Log4J is available on the classpath. This is useful * in situations where you want to use Log4J to log iBATIS activity but commons logging is on the classpath. Note that * this method is only effective for log classes obtained after calling this method. If you intend to use this method * you should call it before calling any other iBATIS method. * *///from ww w . j av a2 s . co m public static synchronized void selectLog4JLogging() { try { Resources.classForName("org.apache.log4j.Logger"); Class implClass = Resources.classForName("com.ibatis.common.logging.log4j.Log4jImpl"); logConstructor = implClass.getConstructor(new Class[] { Class.class }); } catch (Throwable t) { } }
From source file:Main.java
public static Constructor<?> getConstructor(final Class<?> targetClass, final Class<?>... types) { if (targetClass == null || types == null) return null; try {//from w ww .j a v a2 s . c o m return targetClass.getConstructor(types); } catch (SecurityException e) { // ignore } catch (NoSuchMethodException e) { // ignore } return null; }
From source file:Main.java
public static <T> Constructor<T> getConstructor(Class<T> type, Class<?>[] paramTypes) throws NoSuchMethodException { return type.getConstructor(paramTypes); }
From source file:com.github.fge.jsonschema.library.validator.CommonValidatorDictionary.java
private static Constructor<? extends KeywordValidator> constructor(final Class<? extends KeywordValidator> c) { try {/*w ww. j a va 2 s . com*/ return c.getConstructor(JsonNode.class); } catch (NoSuchMethodException e) { throw new RuntimeException("No appropriate constructor", e); } }
From source file:com.ibatis.common.logging.LogFactory.java
/** * This method will switch the logging implementation to Java native logging if you are running in JRE 1.4 or above. * This is useful in situations where you want to use Java native logging to log iBATIS activity but commons logging * or Log4J is on the classpath. Note that this method is only effective for log classes obtained after calling this * method. If you intend to use this method you should call it before calling any other iBATIS method. *//*from ww w . j a v a 2s . c o m*/ public static synchronized void selectJavaLogging() { try { Resources.classForName("java.util.logging.Logger"); Class implClass = Resources.classForName("com.ibatis.common.logging.jdk14.Jdk14LoggingImpl"); logConstructor = implClass.getConstructor(new Class[] { Class.class }); } catch (Throwable t) { } }
From source file:Main.java
public static Constructor<?> getConstructor(final Class<?> targetClass, final Class<?>... types) { if (targetClass == null || types == null) { return null; }// ww w . j ava 2 s .c om try { return targetClass.getConstructor(types); } catch (final SecurityException | NoSuchMethodException e) { // ignore } return null; }
From source file:ee.ria.xroad.proxy.clientproxy.HandlerLoader.java
private static Handler instantiate(Class<? extends Handler> handlerClass, HttpClient client) throws Exception { try {/*from w w w . j av a 2 s .c o m*/ Constructor<? extends Handler> constructor = handlerClass.getConstructor(HttpClient.class); return constructor.newInstance(client); } catch (NoSuchMethodException e) { throw new Exception("Handler must have constructor taking " + "1 parameter (" + HttpClient.class + ")", e); } }