List of usage examples for java.lang InstantiationException getMessage
public String getMessage()
From source file:hudson.lifecycle.Lifecycle.java
/** * Gets the singleton instance.//from w ww . j a v a2 s . com * * @return never null */ public synchronized static Lifecycle get() { if (INSTANCE == null) { String p = System.getProperty("hudson.lifecycle"); if (p != null) { try { ClassLoader cl = Hudson.getInstance().getPluginManager().uberClassLoader; INSTANCE = (Lifecycle) cl.loadClass(p).newInstance(); } catch (InstantiationException e) { InstantiationError x = new InstantiationError(e.getMessage()); x.initCause(e); throw x; } catch (IllegalAccessException e) { IllegalAccessError x = new IllegalAccessError(e.getMessage()); x.initCause(e); throw x; } catch (ClassNotFoundException e) { NoClassDefFoundError x = new NoClassDefFoundError(e.getMessage()); x.initCause(e); throw x; } } else { // if run on Unix, we can do restart if (!Hudson.isWindows()) { try { INSTANCE = new UnixLifecycle(); } catch (IOException e) { LOGGER.log(Level.WARNING, "Failed to install embedded lifecycle implementation", e); } } // use the default one. final fallback. if (INSTANCE == null) INSTANCE = new Lifecycle() { }; } } return INSTANCE; }
From source file:org.onesun.atomator.adaptors.AdaptorFactory.java
public static Adaptor newAdaptor(Channel channel, String feedURL, boolean fullText) { Adaptor adaptor = null;/*from ww w . j a v a 2 s . c o m*/ String type = channel.getEntry().getChannelType(); if (adaptors.containsKey(type) == false) { type = GENERIC_ADAPTOR_NAME; } logger.info("Resolving class [asked]: " + channel + " [giving]: " + type); Class<?> clazz = adaptors.get(type); if (clazz != null) { try { adaptor = (Adaptor) clazz.newInstance(); adaptor.setChannel(channel); if (feedURL != null) { adaptor.setFeedURL(feedURL); } adaptor.setFullText(fullText); } catch (InstantiationException e) { logger.error("Instantiation Exception while loading adaptors : " + e.getMessage()); e.printStackTrace(); } catch (IllegalAccessException e) { logger.error("Illegal Access Exception while loading adaptors : " + e.getMessage()); e.printStackTrace(); } } return adaptor; }
From source file:org.dspace.app.cris.discovery.CrisItemEnhancerUtility.java
private static List<String[]> getCrisMetadata(Item item, CrisItemEnhancer enh, String qualifier) { List<String> mdList = enh.getMetadata(); Set<String> validAuthorities = new HashSet<String>(); MetadataAuthorityManager mam = MetadataAuthorityManager.getManager(); for (String md : mdList) { DCValue[] dcvalues = item.getMetadata(md); for (DCValue dc : dcvalues) { try { if (dc.authority != null && dc.authority.startsWith(enh.getClazz().newInstance().getAuthorityPrefix())) { if (mam.getMinConfidence(dc.schema, dc.element, dc.qualifier) <= dc.confidence) { validAuthorities.add(dc.authority); }/*from w w w. j a va2 s . co m*/ } } catch (InstantiationException e) { log.error(e.getMessage(), e); } catch (IllegalAccessException e) { log.error(e.getMessage(), e); } } } List<String[]> result = new ArrayList<String[]>(); if (validAuthorities.size() > 0) { DSpace dspace = new DSpace(); String path = enh.getQualifiers2path().get(qualifier); ApplicationService as = dspace.getServiceManager().getServiceByName("applicationService", ApplicationService.class); for (String authKey : validAuthorities) { result.addAll( getPathAsMetadata(as, as.get(enh.getClazz(), ResearcherPageUtils.getRealPersistentIdentifier(authKey, enh.getClazz())), path)); } } return result; }
From source file:org.apache.myfaces.custom.graphicimagedynamic.util.GraphicsImageDynamicHelper.java
/** * This method is used for getting the ImageRenderer * from the image render class./*from ww w .j av a 2s. co m*/ * @param imageRendererClassName * @return the image renderer */ public static ImageRenderer getImageRendererFromClassName(String imageRendererClassName) { ImageRenderer imageRenderer; try { Class rendererClass = ClassUtils.classForName(imageRendererClassName); if (!ImageRenderer.class.isAssignableFrom(rendererClass)) { throw new FacesException("Image renderer class [" + imageRendererClassName + "] does not implement " + ImageRenderer.class.getName()); } try { imageRenderer = (ImageRenderer) rendererClass.newInstance(); } catch (InstantiationException e) { throw new FacesException("could not instantiate image renderer class " + imageRendererClassName + " : " + e.getMessage(), e); } catch (IllegalAccessException e) { throw new FacesException("could not instantiate image renderer class " + imageRendererClassName + " : " + e.getMessage(), e); } } catch (ClassNotFoundException e) { throw new FacesException("image renderer class not found: " + e.getMessage(), e); } return imageRenderer; }
From source file:org.onehippo.forge.jcrshell.CommandHelper.java
public static Command getCommandInstanceForClass(final String clazz) { try {//from ww w .ja v a 2 s . c o m return (Command) Class.forName(clazz).newInstance(); } catch (InstantiationException e) { log.error("Unable to instantiate class '{}': {}", clazz, e.getMessage()); } catch (IllegalAccessException e) { log.error("No access to class '{}': {}", clazz, e.getMessage()); } catch (ClassNotFoundException e) { log.error("Class not found '{}': {}", clazz, e.getMessage()); } return null; }
From source file:com.impetus.ankush.common.utils.JsonMapperUtil.java
/** * Method to Convert the given json string into the specified class object. * // w ww. j a v a2s .c o m * @param <S> * the generic type * @param jsonString * the json string * @param targetClass * the target class * @return Object of the class formed using the JSON string. */ public static <S> S objectFromString(String jsonString, Class<S> targetClass) { S object = null; try { /* Creating the target class object */ object = targetClass.newInstance(); } catch (InstantiationException e) { LOG.error(e.getMessage(), e); } catch (IllegalAccessException e) { LOG.error(e.getMessage(), e); } try { /* Populating the object with json string values. */ object = mapper.readValue(jsonString, targetClass); } catch (Exception e) { LOG.error(e.getMessage(), e); } return object; }
From source file:com.opengamma.util.ReflectionUtils.java
/** * Creates an instance of a class from a constructor. * //from www . j a v a 2s . c om * @param <T> the type * @param constructor the constructor to call, not null * @param args the arguments, not null * @return the constructor, not null * @throws RuntimeException if the class cannot be loaded */ public static <T> T newInstance(final Constructor<T> constructor, final Object... args) { try { return constructor.newInstance(args); } catch (InstantiationException ex) { throw new OpenGammaRuntimeException(ex.getMessage(), ex); } catch (IllegalAccessException ex) { throw new OpenGammaRuntimeException(ex.getMessage(), ex); } catch (InvocationTargetException ex) { if (ex.getCause() instanceof RuntimeException) { throw (RuntimeException) ex.getCause(); } throw new OpenGammaRuntimeException(ex.getMessage(), ex); } }
From source file:com.vk.sdk.api.model.ParseUtils.java
/** * Parses array from given JSONArray.//from w w w.j a v a2 s . c om * Supports parsing of primitive types and {@link com.vk.sdk.api.model.VKApiModel} instances. * @param array JSONArray to parse * @param arrayClass type of array field in class. * @return object to set to array field in class * @throws JSONException if given array have incompatible type with given field. */ private static Object parseArrayViaReflection(JSONArray array, Class arrayClass) throws JSONException { Object result = Array.newInstance(arrayClass.getComponentType(), array.length()); Class<?> subType = arrayClass.getComponentType(); for (int i = 0; i < array.length(); i++) { try { Object item = array.opt(i); if (VKApiModel.class.isAssignableFrom(subType) && item instanceof JSONObject) { VKApiModel model = (VKApiModel) subType.newInstance(); item = model.parse((JSONObject) item); } Array.set(result, i, item); } catch (InstantiationException e) { throw new JSONException(e.getMessage()); } catch (IllegalAccessException e) { throw new JSONException(e.getMessage()); } catch (IllegalArgumentException e) { throw new JSONException(e.getMessage()); } } return result; }
From source file:org.jahia.services.image.ImageJImageService.java
protected static boolean save(int type, ImagePlus ip, File outputFile) { switch (type) { case Opener.TIFF: return new FileSaver(ip).saveAsTiff(outputFile.getPath()); case Opener.GIF: return new FileSaver(ip).saveAsGif(outputFile.getPath()); case Opener.JPEG: return new FileSaver(ip).saveAsJpeg(outputFile.getPath()); case Opener.TEXT: return new FileSaver(ip).saveAsText(outputFile.getPath()); case Opener.LUT: return new FileSaver(ip).saveAsLut(outputFile.getPath()); case Opener.ZIP: return new FileSaver(ip).saveAsZip(outputFile.getPath()); case Opener.BMP: return new FileSaver(ip).saveAsBmp(outputFile.getPath()); case Opener.PNG: ImagePlus tempImage = WindowManager.getTempCurrentImage(); WindowManager.setTempCurrentImage(ip); PlugIn p = null;// ww w .jav a2 s .c o m try { p = (PlugIn) Class.forName("ij.plugin.PNG_Writer").newInstance(); p.run(outputFile.getPath()); } catch (InstantiationException e) { logger.error(e.getMessage(), e); } catch (IllegalAccessException e) { logger.error(e.getMessage(), e); } catch (ClassNotFoundException e) { logger.error(e.getMessage(), e); } WindowManager.setTempCurrentImage(tempImage); return true; case Opener.PGM: return new FileSaver(ip).saveAsPgm(outputFile.getPath()); } return false; }
From source file:com.vk.sdk.api.model.ParseUtils.java
/** * Parses object with follow rules://from ww w .j a v a2 s .com * * 1. All fields should had a public access. * 2. The name of the filed should be fully equal to name of JSONObject key. * 3. Supports parse of all Java primitives, all {@link String}, * arrays of primitive types, {@link String}s and {@link com.vk.sdk.api.model.VKApiModel}s, * list implementation line {@link com.vk.sdk.api.model.VKList}, {@link com.vk.sdk.api.model.VKAttachments.VKAttachment} or {@link com.vk.sdk.api.model.VKPhotoSizes}, * {@link com.vk.sdk.api.model.VKApiModel}s. * * 4. Boolean fields defines by vk_int == 1 expression. * @param object object to initialize * @param source data to read values * @return initialized according with given data object * @throws JSONException if source object structure is invalid */ @SuppressWarnings({ "rawtypes", "unchecked" }) public static <T> T parseViaReflection(T object, JSONObject source) throws JSONException { if (source.has("response")) { source = source.optJSONObject("response"); } if (source == null) { return object; } for (Field field : object.getClass().getFields()) { field.setAccessible(true); String fieldName = field.getName(); Class<?> fieldType = field.getType(); Object value = source.opt(fieldName); if (value == null) { continue; } try { if (fieldType.isPrimitive() && value instanceof Number) { Number number = (Number) value; if (fieldType.equals(int.class)) { field.setInt(object, number.intValue()); } else if (fieldType.equals(long.class)) { field.setLong(object, number.longValue()); } else if (fieldType.equals(float.class)) { field.setFloat(object, number.floatValue()); } else if (fieldType.equals(double.class)) { field.setDouble(object, number.doubleValue()); } else if (fieldType.equals(boolean.class)) { field.setBoolean(object, number.intValue() == 1); } else if (fieldType.equals(short.class)) { field.setShort(object, number.shortValue()); } else if (fieldType.equals(byte.class)) { field.setByte(object, number.byteValue()); } } else { Object result = field.get(object); if (value.getClass().equals(fieldType)) { result = value; } else if (fieldType.isArray() && value instanceof JSONArray) { result = parseArrayViaReflection((JSONArray) value, fieldType); } else if (VKPhotoSizes.class.isAssignableFrom(fieldType) && value instanceof JSONArray) { Constructor<?> constructor = fieldType.getConstructor(JSONArray.class); result = constructor.newInstance((JSONArray) value); } else if (VKAttachments.class.isAssignableFrom(fieldType) && value instanceof JSONArray) { Constructor<?> constructor = fieldType.getConstructor(JSONArray.class); result = constructor.newInstance((JSONArray) value); } else if (VKList.class.equals(fieldType)) { ParameterizedType genericTypes = (ParameterizedType) field.getGenericType(); Class<?> genericType = (Class<?>) genericTypes.getActualTypeArguments()[0]; if (VKApiModel.class.isAssignableFrom(genericType) && Parcelable.class.isAssignableFrom(genericType) && Identifiable.class.isAssignableFrom(genericType)) { if (value instanceof JSONArray) { result = new VKList((JSONArray) value, genericType); } else if (value instanceof JSONObject) { result = new VKList((JSONObject) value, genericType); } } } else if (VKApiModel.class.isAssignableFrom(fieldType) && value instanceof JSONObject) { result = ((VKApiModel) fieldType.newInstance()).parse((JSONObject) value); } field.set(object, result); } } catch (InstantiationException e) { throw new JSONException(e.getMessage()); } catch (IllegalAccessException e) { throw new JSONException(e.getMessage()); } catch (NoSuchMethodException e) { throw new JSONException(e.getMessage()); } catch (InvocationTargetException e) { throw new JSONException(e.getMessage()); } catch (NoSuchMethodError e) { // ?????????? ???????: // ?? ?? ????????, ?? ? ????????? ???????? getFields() ???????? ??? ???. // ?????? ? ??????? ???????????, ????????? ?? ? ????????, ?????? Android ? ???????? ????????? ??????????. throw new JSONException(e.getMessage()); } } return object; }