List of usage examples for java.lang InstantiationException getMessage
public String getMessage()
From source file:net.firejack.platform.core.utils.Factory.java
private <T extends AbstractDTO> T convertTo0(Class<?> clazz, Object entity) { if (entity == null) return null; if (entity instanceof HibernateProxy) entity = ((HibernateProxy) entity).getHibernateLazyInitializer().getImplementation(); Object dto = null;//from ww w . j ava2 s .c om try { dto = clazz.newInstance(); List<FieldInfo> infos = fields.get(clazz); if (infos == null) { infos = getAllField(clazz, clazz, new ArrayList<FieldInfo>()); fields.put(clazz, infos); } for (FieldInfo info : infos) { Class<?> type = info.getType(); String fieldName = info.getField().getName(); Object value = get(entity, info.name(), type); if (value != null) { if (value instanceof AbstractModel || value.getClass().isAnnotationPresent(XmlAccessorType.class)) { if (contains(value)) { Object convert = get(value); set(dto, fieldName, convert); } else { add(value, null); Object convert = convertTo0(type, value); add(value, convert); set(dto, fieldName, convert); } } else if (value instanceof Collection) { Collection result = (Collection) value; Class<?> arrayType = info.getGenericType(); if (arrayType == null && result.size() != 0) { arrayType = result.iterator().next().getClass(); info.setGenericType(arrayType); } if (AbstractDTO.class.isAssignableFrom(arrayType)) { try { if (value instanceof PersistentCollection) { result = new ArrayList(); } else { result = (Collection) value.getClass().newInstance(); } } catch (InstantiationException e) { result = new ArrayList(); } for (Object o : (Collection) value) { Object convert = convertTo0(arrayType, o); result.add(convert); } } set(dto, fieldName, result); } else { set(dto, fieldName, value); } } } } catch (Exception e) { logger.warn(e.getMessage()); } return (T) dto; }
From source file:jmdbtools.JMdbTools.java
private Connection connectToMySQL(String dbName, String user, String pass) { // Initialize MYSQL java driver try {// ww w . j a v a 2 s . c om Class.forName("com.mysql.jdbc.Driver").newInstance(); } catch (InstantiationException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } catch (IllegalAccessException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } catch (ClassNotFoundException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } Connection conn = null; try { String connectionString = "jdbc:mysql://" + dbName + "?user=" + user; if (pass != null) { connectionString = connectionString + "&password=" + pass; } conn = DriverManager.getConnection(connectionString); } catch (SQLException e) { log("SQLException: " + e.getMessage(), "error"); log("SQLState: " + e.getSQLState(), "error"); log("VendorError: " + e.getErrorCode(), "error"); } return conn; }
From source file:edu.duke.cabig.c3pr.web.ajax.CommonAjaxFacade.java
@SuppressWarnings("unchecked") private <T> T buildReduced(T src, List<String> properties) { T dst = null;/*from www . ja va 2 s . c om*/ try { dst = (T) src.getClass().newInstance(); } catch (InstantiationException e) { throw new RuntimeException("Failed to instantiate " + src.getClass().getName(), e); } catch (IllegalAccessException e) { throw new RuntimeException("Failed to instantiate " + src.getClass().getName(), e); } BeanWrapper source = new BeanWrapperImpl(src); BeanWrapper destination = new BeanWrapperImpl(dst); for (String property : properties) { // only for nested props String[] individualProps = property.split("\\."); String temp = ""; for (int i = 0; i < individualProps.length - 1; i++) { temp += (i != 0 ? "." : "") + individualProps[i]; Object o = source.getPropertyValue(temp); if (destination.getPropertyValue(temp) == null) { try { destination.setPropertyValue(temp, o.getClass().newInstance()); } catch (BeansException e) { log.error(e.getMessage()); } catch (InstantiationException e) { log.error(e.getMessage()); } catch (IllegalAccessException e) { log.error(e.getMessage()); } } } destination.setPropertyValue(property, source.getPropertyValue(property)); } return dst; }
From source file:ch.rgw.tools.JdbcLink.java
/** * Verbindung zur Datenbank herstellen//www. ja v a2 s . c o m * * TODO return value is always true because exception is thrown on error * * @param user * Username, kann null sein * @param password * Passwort, kann null sein * @return errcode * * @throws JdbcLinkException */ public boolean connect(String user, String password) { Exception cause = null; try { sUser = user; sPwd = password; Driver driver = (Driver) Class.forName(sDrv).newInstance(); verMajor = driver.getMajorVersion(); verMinor = driver.getMinorVersion(); log.log(Level.INFO, "Loading database driver " + sDrv); log.log(Level.INFO, "Connecting with database " + sConn); // // First, we'll create a ConnectionFactory that the // pool will use to create Connections. // Properties properties = new Properties(); properties.put("user", user); properties.put("password", password); ConnectionFactory connectionFactory = new DriverConnectionFactory(driver, sConn, properties); // // Next we'll create the PoolableConnectionFactory, which wraps // the "real" Connections created by the ConnectionFactory with // the classes that implement the pooling functionality. // connectionPool = new GenericObjectPool<Connection>(null); // configure the connection pool connectionPool.setMaxActive(32); connectionPool.setMinIdle(2); connectionPool.setMaxWait(10000); connectionPool.setTestOnBorrow(true); new PoolableConnectionFactory(connectionFactory, connectionPool, null, VALIDATION_QUERY, false, true); dataSource = new PoolingDataSource(connectionPool); // test establishing a connection Connection conn = dataSource.getConnection(); conn.close(); lastErrorCode = CONNECT_SUCCESS; lastErrorString = "Connect successful"; log.log("Connect successful", Log.DEBUGMSG); return true; } catch (ClassNotFoundException ex) { lastErrorCode = CONNECT_CLASSNOTFOUND; lastErrorString = "Class not found exception: " + ex.getMessage(); cause = ex; } catch (InstantiationException e) { lastErrorCode = CONNECT_UNKNOWN_ERROR; lastErrorString = "Instantiation exception: " + e.getMessage(); cause = e; } catch (IllegalAccessException e) { lastErrorCode = CONNECT_UNKNOWN_ERROR; lastErrorString = "Illegal access exception: " + e.getMessage(); cause = e; } catch (SQLException e) { lastErrorCode = CONNECT_UNKNOWN_ERROR; lastErrorString = "SQL exception: " + e.getMessage(); cause = e; } catch (IllegalStateException e) { lastErrorCode = CONNECT_UNKNOWN_ERROR; lastErrorString = "Illegal state exception: " + e.getMessage(); cause = e; } throw JdbcLinkExceptionTranslation.translateException("Connect failed: " + lastErrorString, cause); }
From source file:net.firejack.platform.core.utils.Factory.java
private <T> T convertFrom0(Class<?> clazz, Object dto) { if (dto == null) return null; Object bean = null;// www . j a v a 2 s . c o m try { bean = clazz.newInstance(); List<FieldInfo> infos = fields.get(dto.getClass()); if (infos == null) { infos = getAllField(dto.getClass(), dto.getClass(), new ArrayList<FieldInfo>()); fields.put(dto.getClass(), infos); } for (FieldInfo info : infos) { if (info.readonly()) { continue; } String name = info.name(); Object entity = bean; clazz = entity.getClass(); String[] lookup = name.split("\\."); if (lookup.length > 1) { if (isNullValue(dto, info.getField().getName())) continue; for (int i = 0; i < lookup.length - 1; i++) { Object instance = get(entity, lookup[i], null); if (instance == null) { FieldInfo fieldInfo = getField(clazz, lookup[i]); Class<?> type = fieldInfo.getType(); if (!type.isInterface() && !Modifier.isAbstract(type.getModifiers())) { instance = type.newInstance(); set(entity, lookup[i], instance); entity = instance; clazz = type; } } else { entity = instance; clazz = instance.getClass(); } } name = lookup[lookup.length - 1]; } FieldInfo distField = getField(clazz, name); if (distField != null) { Class<?> type = distField.getType(); Object value = get(dto, info.getField().getName(), type); if (value != null) { if (value instanceof AbstractDTO) { if (contains(value)) { Object convert = get(value); set(entity, name, convert); } else { add(value, null); Object convert = convertFrom0(type, value); add(value, convert); set(entity, name, convert); } } else if (value instanceof Collection) { Collection result = (Collection) value; Class<?> arrayType = distField.getGenericType(); if (AbstractModel.class.isAssignableFrom(arrayType) || arrayType.isAnnotationPresent(XmlAccessorType.class)) { try { result = (Collection) value.getClass().newInstance(); } catch (InstantiationException e) { result = new ArrayList(); } for (Object o : (Collection) value) { Object convert = convertFrom0(arrayType, o); result.add(convert); } } set(entity, name, result); } else { set(entity, name, value); } } } } } catch (Exception e) { logger.warn(e.getMessage()); } return (T) bean; }
From source file:com.jaspersoft.jasperserver.api.metadata.user.service.impl.ObjectPermissionServiceImpl.java
/** * Constructs an individual <code>BasicAclEntry</code> from the passed * <code>ObjectPermission</code> and <code>InternalURI</code>. * * <P>// w w w .j a va 2 s. com * Guarantees to never return <code>null</code> (exceptions are thrown in * the event of any issues). * </p> * * @param propertiesInformation mandatory information about which instance * to create, the object identity, and the parent object identity * (<code>null</code> or empty <code>String</code>s prohibited for * <code>aclClass</code> and <code>aclObjectIdentity</code> * @param aclInformation optional information about the individual ACL * record (if <code>null</code> only an "inheritence marker" * instance is returned; if not <code>null</code>, it is prohibited * to present <code>null</code> or an empty <code>String</code> for * <code>recipient</code>) * * @return a fully populated instance suitable for use by external objects * * @throws IllegalArgumentException if the indicated ACL class could not be * created */ BasicAclEntry createBasicAclEntry(String targetURI, ObjectPermission aclInformation) { BasicAclEntry entry; try { entry = (BasicAclEntry) SimpleAclEntry.class.newInstance(); } catch (InstantiationException ie) { throw new IllegalArgumentException(ie.getMessage()); } catch (IllegalAccessException iae) { throw new IllegalArgumentException(iae.getMessage()); } entry.setAclObjectIdentity(new URIObjectIdentity(targetURI)); entry.setAclObjectParentIdentity(new URIObjectIdentity(getParentURI(targetURI))); if (aclInformation == null) { // this is an inheritance marker instance only entry.setMask(0); entry.setRecipient(RECIPIENT_USED_FOR_INHERITANCE_MARKER); } else { // this is an individual ACL entry entry.setMask(aclInformation.getPermissionMask()); entry.setRecipient(aclInformation.getPermissionRecipient()); } return entry; }
From source file:org.lsc.service.AbstractJdbcService.java
/** * Override default AbstractJdbcSrcService to get a SimpleBean * @throws LscServiceException /* w w w. j av a 2 s . c o m*/ */ @SuppressWarnings("unchecked") @Override public IBean getBean(String id, LscDatasets attributes, boolean fromSameService) throws LscServiceException { IBean srcBean = null; try { srcBean = beanClass.newInstance(); List<?> records = sqlMapper.queryForList(getRequestNameForObjectOrClean(fromSameService), getAttributesMap(attributes)); if (records.size() > 1) { throw new LscServiceException("Only a single record can be returned from a getObject request ! " + "For id=" + id + ", there are " + records.size() + " records !"); } else if (records.size() == 0) { return null; } Map<String, Object> record = (Map<String, Object>) records.get(0); for (Entry<String, Object> entry : record.entrySet()) { if (entry.getValue() != null) { srcBean.setDataset(entry.getKey(), SetUtils.attributeToSet(new BasicAttribute(entry.getKey(), entry.getValue()))); } else { srcBean.setDataset(entry.getKey(), SetUtils.attributeToSet(new BasicAttribute(entry.getKey()))); } } srcBean.setMainIdentifier(id); return srcBean; } catch (InstantiationException e) { LOGGER.error( "Unable to get static method getInstance on {} ! This is probably a programmer's error ({})", beanClass.getName(), e.toString()); LOGGER.debug(e.toString(), e); } catch (IllegalAccessException e) { LOGGER.error( "Unable to get static method getInstance on {} ! This is probably a programmer's error ({})", beanClass.getName(), e.toString()); LOGGER.debug(e.toString(), e); } catch (SQLException e) { LOGGER.warn("Error while looking for a specific entry with id={} ({})", id, e); LOGGER.debug(e.toString(), e); // TODO This SQLException may mean we lost the connection to the DB // This is a dirty hack to make sure we stop everything, and don't risk deleting everything... throw new LscServiceException(new CommunicationException(e.getMessage())); } catch (NamingException e) { LOGGER.error("Unable to get handle cast: " + e.toString()); LOGGER.debug(e.toString(), e); } return null; }
From source file:org.unitime.timetable.solver.studentsct.StudentSolver.java
@Override public <X extends OnlineSectioningAction> X createAction(Class<X> clazz) { try {//from w ww . j a va 2 s .c o m return clazz.newInstance(); } catch (InstantiationException e) { throw new SectioningException(e.getMessage(), e); } catch (IllegalAccessException e) { throw new SectioningException(e.getMessage(), e); } }
From source file:org.broadinstitute.sting.commandline.ArgumentTypeDescriptor.java
@Override @SuppressWarnings("unchecked") public Object parse(ParsingEngine parsingEngine, ArgumentSource source, Type fulltype, ArgumentMatches matches) {/* w ww .j ava 2 s . c om*/ Class type = makeRawTypeIfNecessary(fulltype); Type componentType; Object result; if (Collection.class.isAssignableFrom(type)) { // If this is a generic interface, pick a concrete implementation to create and pass back. // Because of type erasure, don't worry about creating one of exactly the correct type. if (Modifier.isInterface(type.getModifiers()) || Modifier.isAbstract(type.getModifiers())) { if (java.util.List.class.isAssignableFrom(type)) type = ArrayList.class; else if (java.util.Queue.class.isAssignableFrom(type)) type = java.util.ArrayDeque.class; else if (java.util.Set.class.isAssignableFrom(type)) type = java.util.TreeSet.class; } componentType = getCollectionComponentType(source.field); ArgumentTypeDescriptor componentArgumentParser = parsingEngine .selectBestTypeDescriptor(makeRawTypeIfNecessary(componentType)); Collection collection; try { collection = (Collection) type.newInstance(); } catch (InstantiationException e) { logger.fatal( "ArgumentParser: InstantiationException: cannot convert field " + source.field.getName()); throw new ReviewedStingException( "constructFromString:InstantiationException: Failed conversion " + e.getMessage()); } catch (IllegalAccessException e) { logger.fatal( "ArgumentParser: IllegalAccessException: cannot convert field " + source.field.getName()); throw new ReviewedStingException( "constructFromString:IllegalAccessException: Failed conversion " + e.getMessage()); } for (ArgumentMatch match : matches) { for (ArgumentMatch value : match) { Object object = componentArgumentParser.parse(parsingEngine, source, componentType, new ArgumentMatches(value)); collection.add(object); // WARNING: Side effect! parsingEngine.addTags(object, value.tags); } } result = collection; } else if (type.isArray()) { componentType = type.getComponentType(); ArgumentTypeDescriptor componentArgumentParser = parsingEngine .selectBestTypeDescriptor(makeRawTypeIfNecessary(componentType)); // Assemble a collection of individual values used in this computation. Collection<ArgumentMatch> values = new ArrayList<ArgumentMatch>(); for (ArgumentMatch match : matches) for (ArgumentMatch value : match) values.add(value); result = Array.newInstance(makeRawTypeIfNecessary(componentType), values.size()); int i = 0; for (ArgumentMatch value : values) { Object object = componentArgumentParser.parse(parsingEngine, source, componentType, new ArgumentMatches(value)); Array.set(result, i++, object); // WARNING: Side effect! parsingEngine.addTags(object, value.tags); } } else throw new ReviewedStingException("Unsupported compound argument type: " + type); return result; }
From source file:com.moviejukebox.MovieJukebox.java
public static synchronized MovieImagePlugin getImagePlugin(String className) { try {/* w ww . j a va 2s. c o m*/ Thread t = Thread.currentThread(); ClassLoader cl = t.getContextClassLoader(); Class<? extends MovieImagePlugin> pluginClass = cl.loadClass(className) .asSubclass(MovieImagePlugin.class); return pluginClass.newInstance(); } catch (InstantiationException ex) { LOG.error("Failed instanciating ImagePlugin: {} - Error: {}", className, ex.getMessage()); LOG.error(SystemTools.getStackTrace(ex)); } catch (IllegalAccessException ex) { LOG.error("Failed accessing ImagePlugin: {} - Error: {}", className, ex.getMessage()); LOG.error(SystemTools.getStackTrace(ex)); } catch (ClassNotFoundException ex) { LOG.error("ImagePlugin class not found: {} - Error: {}", className, ex.getMessage()); LOG.error(SystemTools.getStackTrace(ex)); } LOG.error("Default poster plugin will be used instead."); return new DefaultImagePlugin(); }