List of usage examples for java.lang Class getDeclaredConstructor
@CallerSensitive public Constructor<T> getDeclaredConstructor(Class<?>... parameterTypes) throws NoSuchMethodException, SecurityException
From source file:com.couchbase.sqoop.manager.CouchbaseFactory.java
@Override public ConnManager accept(JobData data) { SqoopOptions options = data.getSqoopOptions(); if (null != options.getConnManagerClassName()) { String className = options.getConnManagerClassName(); ConnManager connManager = null;/*w w w . ja v a 2s. c om*/ try { Class<ConnManager> cls = (Class<ConnManager>) Class.forName(className); Constructor<ConnManager> constructor = cls.getDeclaredConstructor(SqoopOptimnbons.class); connManager = constructor.newInstance(options); } catch (Exception e) { System.err.println("problem finding the connection manager for class name :" + className); // Log the stack trace for this exception LOG.debug(e.getMessage(), e); // Print exception message. System.err.println(e.getMessage()); } return connManager; } String connectStr = options.getConnectString(); // java.net.URL follows RFC-2396 literally, which does not allow a ':' // character in the scheme component (section 3.1). JDBC connect strings, // however, commonly have a multi-scheme addressing system. e.g., // jdbc:mysql://...; so we cannot parse the scheme component via URL // objects. Instead, attempt to pull out the scheme as best as we can. // First, see if this is of the form [scheme://hostname-and-etc..] int schemeStopIdx = connectStr.indexOf("//"); if (-1 == schemeStopIdx) { // If no hostname start marker ("//"), then look for the right-most ':' // character. schemeStopIdx = connectStr.lastIndexOf(':'); if (-1 == schemeStopIdx) { // Warn that this is nonstandard. But we should be as permissive // as possible here and let the ConnectionManagers themselves throw // out the connect string if it doesn't make sense to them. LOG.warn("Could not determine scheme component of connect string"); // Use the whole string. schemeStopIdx = connectStr.length(); } } String scheme = connectStr.substring(0, schemeStopIdx); if (null == scheme) { // We don't know if this is a mysql://, hsql://, etc. // Can't do anything with this. LOG.warn("Null scheme associated with connect string."); return null; } LOG.debug("Trying with scheme: " + scheme); if (scheme.equals("http:")) { return new CouchbaseManager(options); } else { return null; } }
From source file:harschware.collections.ranges.ValidRange.java
private Sequence<T> getSequence(T newStart) { Sequence<T> sequence = null; Class<? extends Comparable> startClazz = start.getClass(); String className = "harschware.collections.sequences." + startClazz.getSimpleName() + "Sequence"; logger.debug("Sequence strategy '" + className + "' chosen for '" + startClazz.getCanonicalName() + "'"); try {/* w ww .java 2 s . c o m*/ Class clazz = Class.forName(className); sequence = (Sequence<T>) clazz.getDeclaredConstructor(startClazz).newInstance(newStart); } catch (Exception e) { throw new UnsupportedOperationException("No Sequence found for type " + startClazz); } // end try/catch return sequence; }
From source file:org.dspace.EDMExport.service.EDMExportServiceXML.java
/** * Creacin del esquema EDM con la lista de los tems seleccionados * <p>Se usa jdom para crear el documento xml</p> * /* www . j a v a2 s . c o m*/ * @param edmExportBOFormEDMData POJO {@link EDMExportBOFormEDMData} con los datos del formulario * @param pat ruta fsica del edmexport desplegado * @return cadena con el contenido xml */ public String showEDMXML(EDMExportBOFormEDMData edmExportBOFormEDMData, String path) { this.edmExportBOFormEDMData = edmExportBOFormEDMData; String formatXml = edmExportBOFormEDMData.getXmlFormat(); logger.debug("Formato: " + formatXml); StringBuilder sb = new StringBuilder(path).append(fileSeparator).append("WEB-INF").append(fileSeparator) .append("classes").append(fileSeparator).append("org").append(fileSeparator).append("dspace") .append(fileSeparator).append("EDMExport").append(fileSeparator).append("service") .append(fileSeparator).append(formatXml).append("ExportXMLItem.class"); String formatClassStr = sb.toString(); File formatClassFile = new File(formatClassStr); if (formatClassFile.canRead()) { String formatClassName = "org.dspace.EDMExport.service." + formatXml + "ExportXMLItem"; try { Class<?> formatClass = Class.forName(formatClassName); Constructor<?> ctor = formatClass .getDeclaredConstructor(new Class[] { EDMExportServiceListItems.class }); edmExportXML = (EDMExportXML) ctor.newInstance(edmExportServiceListItems); return edmExportXML.showEDMXML(edmExportBOFormEDMData); } catch (ClassNotFoundException e) { logger.debug("EDMExportServiceXML.showEDMXML", e); } catch (InstantiationException e) { logger.debug("EDMExportServiceXML.showEDMXML", e); } catch (IllegalAccessException e) { logger.debug("EDMExportServiceXML.showEDMXML", e); } catch (InvocationTargetException e) { logger.debug("EDMExportServiceXML.showEDMXML", e); } catch (NoSuchMethodException e) { logger.debug("EDMExportServiceXML.showEDMXML", e); } } return ""; }
From source file:com.buaa.cfs.fs.AbstractFileSystem.java
/** * Create an object for the given class and initialize it from conf. * * @param theClass class of which an object is created * @param conf Configuration//from w ww .j a va 2 s.c o m * * @return a new object */ @SuppressWarnings("unchecked") static <T> T newInstance(Class<T> theClass, URI uri, Configuration conf) { T result; try { Constructor<T> meth = (Constructor<T>) CONSTRUCTOR_CACHE.get(theClass); if (meth == null) { meth = theClass.getDeclaredConstructor(URI_CONFIG_ARGS); meth.setAccessible(true); CONSTRUCTOR_CACHE.put(theClass, meth); } result = meth.newInstance(uri, conf); } catch (Exception e) { throw new RuntimeException(e); } return result; }
From source file:ome.formats.enums.IQueryEnumProvider.java
/** * Creates an unloaded copy of an enumeration object. * @param enumeration Enumeration to copy. * @return See above.//www . j av a2 s .c o m */ private IObject copyEnumeration(IObject enumeration) { Class<? extends IObject> klass = enumeration.getClass(); try { Constructor<? extends IObject> constructor = klass .getDeclaredConstructor(new Class[] { RLong.class, boolean.class }); return (IObject) constructor.newInstance(new Object[] { enumeration.getId(), false }); } catch (Exception e) { String m = "Unable to copy enumeration: " + enumeration; log.error(m, e); throw new EnumerationException(m, klass, getValue(enumeration)); } }
From source file:org.dspace.search.DSIndexer.java
/** * Get the Lucene analyzer to use according to current configuration (or * default). TODO: Should have multiple analyzers (and maybe indices?) for * multi-lingual DSpaces./* www .j a va 2s. co m*/ * * @return <code>Analyzer</code> to use * @throws IllegalStateException * if the configured analyzer can't be instantiated */ static Analyzer getAnalyzer() { if (analyzer == null) { // We need to find the analyzer class from the configuration String analyzerClassName = ConfigurationManager.getProperty("search.analyzer"); if (analyzerClassName == null) { // Use default analyzerClassName = "org.dspace.search.DSAnalyzer"; } try { Class analyzerClass = Class.forName(analyzerClassName); Constructor constructor = analyzerClass.getDeclaredConstructor(Version.class); constructor.setAccessible(true); analyzer = (Analyzer) constructor.newInstance(luceneVersion); } catch (Exception e) { log.fatal(LogManager.getHeader(null, "no_search_analyzer", "search.analyzer=" + analyzerClassName), e); throw new IllegalStateException(e.toString()); } } return analyzer; }
From source file:org.polymap.core.runtime.recordstore.RecordModel.java
/** * Allows to access the properties of the model (name, type(?)) in a static way. * * @param <M> The state model type. * @param cl The state model class./*from w w w.j a va 2 s . c om*/ * @return A new type instance with null state. */ public static <M extends RecordModel> M type(Class<M> cl) { IRecordState nullState = new IRecordState() { public IRecordState add(String key, Object value) { throw new RuntimeException("Not allowed for TYPE state."); } public <T> T get(String key) { throw new RuntimeException("Not allowed for TYPE state."); } public <T> List<T> getList(String key) { throw new RuntimeException("Not allowed for TYPE state."); } public Object id() { throw new RuntimeException("Not allowed for TYPE state."); } public Iterator<Entry<String, Object>> iterator() { throw new RuntimeException("Not allowed for TYPE state."); } public <T> IRecordState put(String key, T value) { throw new RuntimeException("Not allowed for TYPE state."); } public IRecordState remove(String key) { throw new RuntimeException("Not allowed for TYPE state."); } }; try { Constructor<M> ctor = cl.getDeclaredConstructor(new Class[] { IRecordState.class }); return ctor.newInstance(new Object[] { nullState }); } catch (Exception e) { // try no-arg ctor try { Constructor<M> ctor = cl.getDeclaredConstructor(ArrayUtils.EMPTY_CLASS_ARRAY); return ctor.newInstance(ArrayUtils.EMPTY_OBJECT_ARRAY); } catch (Exception e2) { throw new RuntimeException(e); } } }
From source file:zoedb.SQLStatementFactory.java
public SQLStatement getSQLStatement(String stmtType, String tableName) throws Exception { Class statementClass = (Class) registeredStatementTypes.get(stmtType); if (statementClass == null) { throw new TypeNotRegisteredException(stmtType, this.getClass()); }/*from w ww . j a v a 2 s. c o m*/ Constructor statementConstructor = statementClass.getDeclaredConstructor(new Class[] { String.class }); return (SQLStatement) statementConstructor.newInstance(tableName); }
From source file:zoedb.SQLStatementFactory.java
public SQLStatement getSQLStatement(String stmtType, JSONObject json) throws Exception { Class statementClass = (Class) registeredStatementTypes.get(stmtType); if (statementClass == null) { throw new TypeNotRegisteredException(stmtType, this.getClass()); }/*from w w w .ja va2 s .c o m*/ Constructor statementConstructor = statementClass.getDeclaredConstructor(new Class[] { JSONObject.class }); return (SQLStatement) statementConstructor.newInstance(json); }
From source file:com.pdi.hybridge.HybridgeWebChromeClient.java
@SuppressLint("DefaultLocale") @SuppressWarnings({ "unchecked", "rawtypes" }) private void executeJSONTask(String action, JSONObject json, JsPromptResult result, HybridgeBroadcaster hybridge, Activity activity) { final Class clazz = mActions.get(action); if (clazz != null && hybridge != null) { AsyncTask task = null;/*from w ww.ja v a2 s . c o m*/ try { task = (AsyncTask<JSONObject, Void, JSONObject>) clazz .getDeclaredConstructor(new Class[] { android.app.Activity.class }).newInstance(activity); } catch (final InstantiationException e) { e.printStackTrace(); } catch (final IllegalAccessException e) { e.printStackTrace(); } catch (final IllegalArgumentException e) { e.printStackTrace(); } catch (final InvocationTargetException e) { e.printStackTrace(); } catch (final NoSuchMethodException e) { e.printStackTrace(); } Log.v(mTag, "Execute action " + action); task.execute(json, result, hybridge); } else { result.confirm(json.toString()); Log.d(mTag, "Hybridge action not implemented: " + action); } }