List of usage examples for java.lang InstantiationException InstantiationException
public InstantiationException(String s)
From source file:ORG.oclc.os.SRW.Lucene.SRWLuceneDatabase.java
@Override public void addRenderer(String schemaName, String schemaID, Properties props) throws InstantiationException { RecordResolver resolver = null;//from w w w. j av a 2 s . co m String resolverName = dbProperties.getProperty(schemaName + ".resolver"); if (resolverName == null) { log.debug("creating BasicLuceneRecordResolver"); resolver = new BasicLuceneRecordResolver(); resolver.init(props); } else { try { log.debug("creating resolver " + resolverName); Class resolverClass = Class.forName(resolverName); log.debug("creating instance of class " + resolverClass); resolver = (RecordResolver) resolverClass.newInstance(); resolver.init(dbProperties); } catch (Exception e) { log.error("Unable to create RecordResolver class " + resolverName + " for database " + dbname); log.error(e, e); throw new InstantiationException(e.getMessage()); } } resolvers.put(schemaName, resolver); resolvers.put(schemaID, resolver); }
From source file:org.apache.torque.adapter.AdapterFactory.java
/** * Creates a new instance of the Torque database adapter based on * the JDBC meta-data// w ww . ja v a 2 s . c o m * * @param con a database connection * @return An instance of a Torque database adapter, or null if * no adapter could be detected. * @throws InstantiationException if the adapter could not be * instantiated * @throws SQLException if there are problems getting the JDBC meta data */ public static Adapter autoDetectAdapter(Connection con) throws InstantiationException, SQLException { DatabaseMetaData dmd = con.getMetaData(); String dbmsName = dmd.getDatabaseProductName(); Class<? extends Adapter> adapterClass = adapters.get(dbmsName); if (adapterClass == null) { throw new InstantiationException("Could not detect adapter for database: " + dbmsName); } log.info("Mapped database product " + dbmsName + " to adapter " + adapterClass.getSimpleName()); try { Adapter adapter = adapterClass.newInstance(); return adapter; } catch (IllegalAccessException e) { throw new InstantiationException("Could not instantiate adapter for database: " + dbmsName + ": Assure that adapter classes are in your classpath"); } }
From source file:com.spokentech.speechdown.server.util.pool.AbstractPoolableObjectFactory.java
/** * Initializes an {@link org.apache.commons.pool.ObjectPool} by borrowing each object from the * pool (thereby triggering activation) and then returning all the objects back to the pool. * @param pool the object pool to be initialized. * @throws InstantiationException if borrowing (or returning) an object from the pool triggers an exception. *///from www .j a v a 2s .c o m public static void initPool(ObjectPool pool) throws InstantiationException { try { List<Object> objects = new ArrayList<Object>(); while (true) try { objects.add(pool.borrowObject()); } catch (NoSuchElementException e) { // ignore, max active reached break; } for (Object obj : objects) { pool.returnObject(obj); } } catch (Exception e) { try { pool.close(); } catch (Exception e1) { _logger.warn("Encounter expception while attempting to close object pool!", e1); } throw (InstantiationException) new InstantiationException(e.getMessage()).initCause(e); } }
From source file:ReflectUtil.java
/** * Attempts to determine an implementing class for the interface provided and instantiate * it using a default constructor.//from www . j a va 2s .co m * * @param interfaceType an interface (or abstract class) to make an instance of * @return an instance of the interface type supplied * @throws InstantiationException if no implementation type has been configured * @throws IllegalAccessException if thrown by the JVM during class instantiation */ @SuppressWarnings("unchecked") public static <T> T getInterfaceInstance(Class<T> interfaceType) throws InstantiationException, IllegalAccessException { Class impl = getImplementingClass(interfaceType); if (impl == null) { throw new InstantiationException("Stripes needed to instantiate a property who's declared type as an " + "interface (which obviously cannot be instantiated. The interface is not " + "one that Stripes is aware of, so no implementing class was known. The " + "interface type was: '" + interfaceType.getName() + "'. To fix this " + "you'll need to do one of three things. 1) Change the getter/setter methods " + "to use a concrete type so that Stripes can instantiate it. 2) in the bean's " + "setContext() method pre-instantiate the property so Stripes doesn't have to. " + "3) Bug the Stripes author ;) If the interface is a JDK type it can easily be " + "fixed. If not, if enough people ask, a generic way to handle the problem " + "might get implemented."); } else { return (T) impl.newInstance(); } }
From source file:org.jboss.dashboard.security.PermissionDescriptor.java
public Principal getPrincipal() throws InstantiationException { if (principalClass == null) return null; try {//from ww w. j av a 2s. c o m Class prpalClass = Class.forName(principalClass); Constructor constr = prpalClass.getConstructor(_prpalConstructorTypes); return (Principal) constr.newInstance(new Object[] { principalName }); } catch (Exception ignored) { } // If Permission can't be instantiated then throw an exception. throw new InstantiationException("Principal class not supported (" + principalClass + ")."); }
From source file:org.cesecore.keys.token.PKCS11CryptoToken.java
/** * @param providerClass/*from w ww. j a va 2s . c om*/ * @throws InstantiationException */ public PKCS11CryptoToken() throws InstantiationException { super(); try { Thread.currentThread().getContextClassLoader().loadClass(Pkcs11SlotLabel.SUN_PKCS11_CLASS); } catch (ClassNotFoundException t) { throw new InstantiationException( "PKCS11 provider class " + Pkcs11SlotLabel.SUN_PKCS11_CLASS + " not found."); } }
From source file:org.sglover.alfrescoextensions.common.MongoDbFactory.java
public DB createInstance() throws Exception { DB db = null;//w w w. ja v a 2 s. co m try { if (enabled) { if (embedded) { Mongo mongo = newMongo(); // Mongo mongo = mongoFactory.newMongo(); if (dbName != null) { db = mongo.getDB(dbName); } else { db = mongo.getDB(UUID.randomUUID().toString()); } } else { if (mongoURI == null || dbName == null) { throw new RuntimeException("Must provide mongoURI and dbName or a mongo object"); } MongoClientURI uri = new MongoClientURI(mongoURI); MongoClient mongoClient = new MongoClient(uri); db = mongoClient.getDB(dbName); } if (db == null) { throw new InstantiationException("Could not instantiate a Mongo DB instance"); } if (logger.isDebugEnabled()) { logger.debug("Instatiated DB object for dbName '" + db.getName() + "'"); } CommandResult stats = db.getStats(); if (logger.isTraceEnabled()) { stats = db.getStats(); for (String key : stats.keySet()) { logger.trace("\t" + key + " = " + stats.get(key).toString()); } } } } catch (MongoException.Network e) { throw new MongoDbUnavailableException("Mongo network exception, database down?", e); } catch (UnknownHostException e) { throw new MongoDbUnavailableException("Mongo host not found", e); } return db; }
From source file:org.candlepin.pinsetter.core.PinsetterKernel.java
/** * Kernel main driver behind Pinsetter//from w ww . j a v a2 s . co m * @param conf Configuration to use * @throws InstantiationException thrown if this.scheduler can't be * initialized. */ @Inject public PinsetterKernel(Configuration conf, JobFactory jobFactory, JobListener listener, JobCurator jobCurator, StdSchedulerFactory fact) throws InstantiationException { this.config = conf; this.jobCurator = jobCurator; /* * Did your unit test get an NPE here? * this will help: * when(config.subset(eq("org.quartz"))).thenReturn( * new MapConfiguration(ConfigProperties.DEFAULT_PROPERTIES)); * * TODO: We should probably be clearing up what's happening here. Not a fan of a comment * explaining what should be handled by something like an illegal arg or illegal state * exception. -C */ Properties props = config.subset("org.quartz").toProperties(); // create a schedulerFactory try { fact.initialize(props); scheduler = fact.getScheduler(); scheduler.setJobFactory(jobFactory); if (listener != null) { scheduler.getListenerManager().addJobListener(listener); } } catch (SchedulerException e) { throw new InstantiationException("this.scheduler failed: " + e.getMessage()); } }
From source file:org.mule.module.wsdlproc.WSDLProcModule.java
private Class<?> findInputClass() throws InstantiationException { ClientImpl clientImpl = (ClientImpl) client; Endpoint endpoint = clientImpl.getEndpoint(); ServiceInfo serviceInfo = endpoint.getService().getServiceInfos().get(0); Collection<BindingInfo> bindings = serviceInfo.getBindings(); BindingMessageInfo bindingMessageInfo = null; for (BindingInfo b : bindings) { for (BindingOperationInfo o : b.getOperations()) { if (o.getName().getLocalPart().equals(operationName)) { bindingMessageInfo = o.getInput(); boi = o;/*from w w w .j a va 2s . c om*/ } } } if (bindingMessageInfo == null) { throw new InstantiationException("Could not find specified operation"); } List<MessagePartInfo> parts = bindingMessageInfo.getMessageParts(); // only one part. MessagePartInfo partInfo = parts.get(0); Class<?> partClass = partInfo.getTypeClass(); System.out.println(boi.isUnwrapped()); return partClass; }
From source file:de.xaniox.simpletrading.i18n.YMLControl.java
@Override public ResourceBundle newBundle(String baseName, Locale locale, String format, ClassLoader loader, boolean reload) throws IllegalAccessException, InstantiationException, IOException { Validate.notNull(baseName);//from ww w . j a va 2 s. c om Validate.notNull(locale); Validate.notNull(format); Validate.notNull(loader); ResourceBundle bundle = null; if (YML_FORMAT.equals(format)) { String bundleName = toBundleName(baseName, locale); String resourceName = toResourceName(bundleName, format); URL url = null; if (mode == I18N.LoadingMode.CLASSPATH) { //The mode forces us to load the resource from classpath url = getClass().getResource(classpathDir + resourceName); } else if (mode == I18N.LoadingMode.FILE_SYSTEM) { //If we use the file system mode, try to load the resource from file first //and load it from classpath if it fails File resourceFile = new File(localeDir, resourceName); if (resourceFile.exists() && resourceFile.isFile()) { url = resourceFile.toURI().toURL(); } else { url = getClass().getResource(classpathDir + resourceName); } } if (url == null) { return null; } URLConnection connection = url.openConnection(); if (reload) { connection.setUseCaches(false); } InputStream stream = connection.getInputStream(); if (stream != null) { Reader reader = new InputStreamReader(stream, I18N.UTF8_CHARSET); YamlConfiguration config = new YamlConfiguration(); StringBuilder builder; try (BufferedReader bufferedReader = new BufferedReader(reader)) { builder = new StringBuilder(); String read; while ((read = bufferedReader.readLine()) != null) { builder.append(read); builder.append('\n'); } } try { config.loadFromString(builder.toString()); } catch (InvalidConfigurationException e) { throw new InstantiationException(e.getMessage()); } bundle = new YMLResourceBundle(config); } } else { bundle = super.newBundle(baseName, locale, format, loader, reload); } return bundle; }