List of usage examples for java.lang InstantiationException InstantiationException
public InstantiationException()
From source file:org.jtransfo.internal.NewInstanceObjectFinderTest.java
@Test public void testInstantiationException() throws Exception { when(reflectionHelper.newInstance(SimpleClassDomain.class)).thenThrow(new InstantiationException()); exception.expect(JTransfoException.class); exception.expectMessage("Cannot create instance for domain class org.jtransfo.object.SimpleClassDomain."); newInstanceObjectFinder.getObject(SimpleClassDomain.class, new SimpleClassNameTo()); }
From source file:egovframework.rte.fdl.string.EgovObjectUtil.java
/** * ? ? ? ./* w w w . ja v a2s . co m*/ * @param className * @return * @throws ClassNotFoundException * @throws InstantiationException * @throws IllegalAccessException * @throws Exception */ public static Object instantiate(String className) throws ClassNotFoundException, InstantiationException, IllegalAccessException, Exception { Class<?> clazz; try { clazz = loadClass(className); return clazz.newInstance(); } catch (ClassNotFoundException e) { if (log.isErrorEnabled()) log.error(className + " : Class is can not instantialized."); throw new ClassNotFoundException(); } catch (InstantiationException e) { if (log.isErrorEnabled()) log.error(className + " : Class is can not instantialized."); throw new InstantiationException(); } catch (IllegalAccessException e) { if (log.isErrorEnabled()) log.error(className + " : Class is not accessed."); throw new IllegalAccessException(); } catch (Exception e) { if (log.isErrorEnabled()) log.error(className + " : Class is not accessed."); throw new Exception(e); } }
From source file:com.anaplan.client.transport.JCIFSEngine.java
JCIFSEngine() throws InstantiationException { if (0 == TYPE_1_FLAGS) { throw new InstantiationException(); } }
From source file:org.openxdata.server.service.impl.SerializationServiceImpl.java
/** * Gets the value of data stream serializer. * /*from w ww . jav a2s . c o m*/ * @param name the name of the setting that points to the class * @param settingName the default name of the setting to use in case null is passed for the first parameter. * @param defaultValue the default value to return incase no setting with the given name exists. * @return the class name including its full pack. * * @throws InstantiationException If the specified Serializer could not be loaded. */ private Object getSerializer(String name, String settingName, String defaultValue) throws InstantiationException { String key = name; if (key == null || key.trim().length() == 0) key = settingName; String serializer = settingDAO.getSetting(key, defaultValue); try { Object obj = Class.forName(serializer).newInstance(); return obj; } catch (Exception e) { throw new InstantiationException(); } }
From source file:br.ufpr.gres.core.classpath.ClassDetails.java
public Class getClassInstance() throws ClassNotFoundException, InstantiationException, IllegalAccessException { // initialization of the test set class if (clazz.newInstance() == null) { throw new InstantiationException(); }/*from www . j ava 2 s . co m*/ return clazz; }
From source file:org.jtransfo.JTransfoImplTest.java
@Test public void testConvertInstantiationException() throws Exception { when(reflectionHelper.newInstance(SimpleClassDomain.class)).thenThrow(new InstantiationException()); exception.expect(JTransfoException.class); exception.expectMessage("Cannot create instance for domain class org.jtransfo.object.SimpleClassDomain."); jTransfo.convert(new SimpleClassNameTo()); }
From source file:org.jtransfo.JTransfoImplTest.java
@Test public void testConvertToInstantiationException() throws Exception { when(reflectionHelper.newInstance(SimpleClassDomain.class)).thenThrow(new InstantiationException()); exception.expect(JTransfoException.class); exception.expectMessage("Cannot create instance for domain class org.jtransfo.object.SimpleClassDomain."); jTransfo.convertTo(new SimpleClassNameTo(), SimpleClassDomain.class); }
From source file:org.jtransfo.JTransfoImplTest.java
@Test public void testFindTargetInstantiationException() throws Exception { when(reflectionHelper.newInstance(SimpleClassDomain.class)).thenThrow(new InstantiationException()); exception.expect(JTransfoException.class); exception.expectMessage("Cannot create instance for domain class org.jtransfo.object.SimpleClassDomain."); jTransfo.findTarget(new SimpleClassNameTo(), SimpleClassDomain.class); }
From source file:egovframework.rte.fdl.string.EgovObjectUtil.java
/** * ? ? ?? ?? ? . ) Class <?>// www . ja v a 2 s . c om * clazz = EgovObjectUtil.loadClass(this.mapClass); * Constructor <?> constructor = * clazz.getConstructor(new Class * []{DataSource.class, String.class}); Object [] * params = new Object []{getDataSource(), * getUsersByUsernameQuery()}; * this.usersByUsernameMapping = * (EgovUsersByUsernameMapping) * constructor.newInstance(params); * @param className * @return * @throws ClassNotFoundException * @throws InstantiationException * @throws IllegalAccessException * @throws Exception */ public static Object instantiate(String className, String[] types, Object[] values) throws ClassNotFoundException, InstantiationException, IllegalAccessException, Exception { Class<?> clazz; Class<?>[] classParams = new Class[values.length]; Object[] objectParams = new Object[values.length]; try { clazz = loadClass(className); for (int i = 0; i < values.length; i++) { classParams[i] = loadClass(types[i]); objectParams[i] = values[i]; } Constructor<?> constructor = clazz.getConstructor(classParams); return constructor.newInstance(values); } catch (ClassNotFoundException e) { if (log.isErrorEnabled()) log.error(className + " : Class is can not instantialized."); throw new ClassNotFoundException(); } catch (InstantiationException e) { if (log.isErrorEnabled()) log.error(className + " : Class is can not instantialized."); throw new InstantiationException(); } catch (IllegalAccessException e) { if (log.isErrorEnabled()) log.error(className + " : Class is not accessed."); throw new IllegalAccessException(); } catch (Exception e) { if (log.isErrorEnabled()) log.error(className + " : Class is not accessed."); throw new Exception(e); } }
From source file:egovframework.rte.itl.webservice.service.impl.MessageConverterImpl.java
@SuppressWarnings("unchecked") public Object convertToValueObject(Object source, Type type) throws ClassNotFoundException, IllegalAccessException, InstantiationException, NoSuchFieldException { LOG.debug("convertToValueObject(source = " + source + ", type = " + type + ")"); if (type instanceof PrimitiveType) { LOG.debug("Type is a Primitive Type"); return source; } else if (type instanceof ListType) { LOG.debug("Type is a List Type"); ListType listType = (ListType) type; Object[] components = ((Collection<?>) source).toArray(); Class<?> arrayClass = classLoader.loadClass(listType); Object array = Array.newInstance(arrayClass.getComponentType(), components.length); for (int i = 0; i < components.length; i++) { Array.set(array, i, convertToValueObject(components[i], listType.getElementType())); }// w ww .j a v a 2s. co m return array; } else if (type instanceof RecordType) { LOG.debug("Type is a Record(Map) Type"); RecordType recordType = (RecordType) type; Map<String, Object> map = (Map<String, Object>) source; Class<?> recordClass = classLoader.loadClass(recordType); Object record = recordClass.newInstance(); for (Entry<String, Object> entry : map.entrySet()) { Object fieldValue = convertToValueObject(entry.getValue(), recordType.getFieldType(entry.getKey())); recordClass.getField(entry.getKey()).set(record, fieldValue); } return record; } LOG.error("Type is invalid"); throw new InstantiationException(); }