List of usage examples for java.lang IllegalAccessException getMessage
public String getMessage()
From source file:com.liferay.cli.support.util.ReflectionUtils.java
/** * Set the field represented by the supplied {@link Field field object} on * the specified {@link Object target object} to the specified * <code>value</code>. In accordance with {@link Field#set(Object, Object)} * semantics, the new value is automatically unwrapped if the underlying * field has a primitive type./* ww w. j a va2s . c o m*/ * <p> * Thrown exceptions are handled via a call to * {@link #handleReflectionException(Exception)}. * * @param field the field to set * @param target the target object on which to set the field * @param value the value to set; may be <code>null</code> */ public static void setField(final Field field, final Object target, final Object value) { try { field.set(target, value); } catch (final IllegalAccessException ex) { handleReflectionException(ex); throw new IllegalStateException( "Unexpected reflection exception - " + ex.getClass().getName() + ": " + ex.getMessage()); } }
From source file:fxts.stations.util.BrowserLauncher.java
/** * Attempts to open the default web browser to the given URL. * * @param url The URL to open//from w ww. jav a2 s. c o m * * @throws IOException If the web browser could not be located or does not run */ public static void openURL(String url) throws IOException { if (!loadedWithoutErrors) { throw new IOException("Exception in finding browser: " + errorMessage); } Object browser = locateBrowser(); if (browser == null) { throw new IOException("Unable to locate browser: " + errorMessage); } switch (jvm) { case MRJ_2_0: Object aeDesc = null; try { aeDesc = aeDescConstructor.newInstance(new Object[] { url }); putParameter.invoke(browser, new Object[] { keyDirectObject, aeDesc }); sendNoReply.invoke(browser, new Object[] {}); } catch (InvocationTargetException ite) { throw new IOException("InvocationTargetException while creating AEDesc: " + ite.getMessage()); } catch (IllegalAccessException iae) { throw new IOException("IllegalAccessException while building AppleEvent: " + iae.getMessage()); } catch (InstantiationException ie) { throw new IOException("InstantiationException while creating AEDesc: " + ie.getMessage()); } finally { aeDesc = null; // Encourage it to get disposed if it was created browser = null; // Ditto } break; case MRJ_2_1: Runtime.getRuntime().exec(new String[] { (String) browser, url }); break; case MRJ_3_0: int[] instance = new int[1]; int result = ICStart(instance, 0); if (result == 0) { int[] selectionStart = new int[] { 0 }; byte[] urlBytes = url.getBytes(); int[] selectionEnd = new int[] { urlBytes.length }; result = ICLaunchURL(instance[0], new byte[] { 0 }, urlBytes, urlBytes.length, selectionStart, selectionEnd); if (result == 0) { // Ignore the return value; the URL was launched successfully // regardless of what happens here. ICStop(instance); } else { throw new IOException("Unable to launch URL: " + result); } } else { throw new IOException("Unable to create an Internet Config instance: " + result); } break; case MRJ_3_1: try { openURL.invoke(null, new Object[] { url }); } catch (InvocationTargetException ite) { throw new IOException("InvocationTargetException while calling openURL: " + ite.getMessage()); } catch (IllegalAccessException iae) { throw new IOException("IllegalAccessException while calling openURL: " + iae.getMessage()); } break; case WINDOWS_NT: case WINDOWS_9x: // cmd = 'rundll32 url.dll,FileProtocolHandler http://...' Process process = Runtime.getRuntime().exec(WIN_PATH + " " + WIN_FLAG + " " + url); // This avoids a memory leak on some versions of Java on Windows. // That's hinted at in <http://developer.java.sun.com/developer/qow/archive/68/>. try { process.waitFor(); process.exitValue(); } catch (InterruptedException ie) { throw new IOException("InterruptedException while launching browser: " + ie.getMessage()); } break; case OTHER: // Assume that we're on Unix and that Netscape is installed // First, attempt to open the URL in a currently running session of Netscape process = Runtime.getRuntime().exec(new String[] { (String) browser, NETSCAPE_REMOTE_PARAMETER, NETSCAPE_OPEN_PARAMETER_START + url + NETSCAPE_OPEN_PARAMETER_END }); try { int exitCode = process.waitFor(); if (exitCode != 0) { // if Netscape was not open Runtime.getRuntime().exec(new String[] { (String) browser, url }); } } catch (InterruptedException ie) { throw new IOException("InterruptedException while launching browser: " + ie.getMessage()); } break; default: // This should never occur, but if it does, we'll try the simplest thing possible Runtime.getRuntime().exec(new String[] { (String) browser, url }); break; } }
From source file:Browser.java
/** * Open the specified URL in the client web browser. * /*from w w w .ja v a 2s.co m*/ * @param url URL to open. * @throws IOException If there is brwoser problem. */ public static void openUrl(String url) throws IOException { if (!loadedWithoutErrors) { throw new IOException("Exception in finding browser: " + errorMessage); } Object browser = locateBrowser(); if (browser == null) { throw new IOException("Unable to locate browser: " + errorMessage); } switch (jvm) { case MRJ_2_0: Object aeDesc = null; try { aeDesc = aeDescConstructor.newInstance(new Object[] { url }); putParameter.invoke(browser, new Object[] { keyDirectObject, aeDesc }); sendNoReply.invoke(browser, new Object[] {}); } catch (InvocationTargetException ite) { throw new IOException("InvocationTargetException while creating AEDesc: " + ite.getMessage()); } catch (IllegalAccessException iae) { throw new IOException("IllegalAccessException while building AppleEvent: " + iae.getMessage()); } catch (InstantiationException ie) { throw new IOException("InstantiationException while creating AEDesc: " + ie.getMessage()); } finally { aeDesc = null; // Encourage it to get disposed if it was created browser = null; // Ditto } break; case MRJ_2_1: Runtime.getRuntime().exec(new String[] { (String) browser, url }); break; case MRJ_3_0: int[] instance = new int[1]; int result = ICStart(instance, 0); if (result == 0) { int[] selectionStart = new int[] { 0 }; byte[] urlBytes = url.getBytes(); int[] selectionEnd = new int[] { urlBytes.length }; result = ICLaunchURL(instance[0], new byte[] { 0 }, urlBytes, urlBytes.length, selectionStart, selectionEnd); if (result == 0) { // Ignore the return value; the URL was launched successfully // regardless of what happens here. ICStop(instance); } else { throw new IOException("Unable to launch URL: " + result); } } else { throw new IOException("Unable to create an Internet Config instance: " + result); } break; case MRJ_3_1: try { openURL.invoke(null, new Object[] { url }); } catch (InvocationTargetException ite) { throw new IOException("InvocationTargetException while calling openURL: " + ite.getMessage()); } catch (IllegalAccessException iae) { throw new IOException("IllegalAccessException while calling openURL: " + iae.getMessage()); } break; case WINDOWS_NT: case WINDOWS_9x: // Add quotes around the URL to allow ampersands and other special // characters to work. Process process = Runtime.getRuntime().exec(new String[] { (String) browser, FIRST_WINDOWS_PARAMETER, SECOND_WINDOWS_PARAMETER, THIRD_WINDOWS_PARAMETER, '"' + url + '"' }); // This avoids a memory leak on some versions of Java on Windows. // That's hinted at in <http://developer.java.sun.com/developer/qow/ // archive/68/>. try { process.waitFor(); process.exitValue(); } catch (InterruptedException ie) { throw new IOException("InterruptedException while launching browser: " + ie.getMessage()); } break; case OTHER: // Assume that we're on Unix and that Netscape is installed // First, attempt to open the URL in a currently running session of // Netscape String command = browser.toString() + " -raise " + NETSCAPE_REMOTE_PARAMETER + " " + NETSCAPE_OPEN_PARAMETER_START + url + NETSCAPE_OPEN_PARAMETER_END; process = Runtime.getRuntime().exec(command); try { int exitCode = process.waitFor(); if (exitCode != 0) { // if Netscape was not open Runtime.getRuntime().exec(new String[] { (String) browser, url }); } } catch (InterruptedException exception) { exception.printStackTrace(); throw new IOException("InterruptedException while launching browser: " + exception.getMessage()); } break; default: // This should never occur, but if it does, we'll try the simplest // thing possible Runtime.getRuntime().exec(new String[] { (String) browser, url }); break; } }
From source file:com.sm.query.utils.QueryUtils.java
public static Collection collectObjectField(String fieldId, Collection collection, Map<String, FieldInfo> idMap, Map<String, ClassInfo> classInfoMap) { //first is object, second is field Collection list = new ArrayList(); Iterator iterator = collection.iterator(); while (iterator.hasNext()) { Pair<Object, FieldInfo> pair = findObjectId(fieldId, iterator.next(), classInfoMap); idMap.put(fieldId, pair.getSecond()); try {//from w ww . java 2 s.c o m list.add(pair.getSecond().getField().get(pair.getFirst())); } catch (IllegalAccessException e) { throw new ObjectIdException(e.getMessage(), e); } } return list; }
From source file:com.github.dactiv.common.utils.ReflectionUtils.java
/** * , private/protected, ??setter.//ww w. java 2 s .com * * @param target * Object * @param fieldName * ?? * @param value * */ public static void setFieldValue(final Object target, final String fieldName, final Object value) { Assert.notNull(target, "target?"); Assert.notNull(fieldName, "fieldName?"); Field field = getAccessibleField(target, fieldName); if (field == null) { throw new IllegalArgumentException( "? [" + fieldName + "] [" + target + "] "); } try { field.set(target, value); } catch (IllegalAccessException e) { logger.error("??:{}", e.getMessage()); } }
From source file:com.github.dactiv.common.utils.ReflectionUtils.java
/** * ?, private/protected, ??getter./* w w w. j av a 2 s . co m*/ * * @param target * Object * @param fieldName * ?? * * @return Object */ public static <T> T getFieldValue(final Object target, final String fieldName) { Assert.notNull(target, "target?"); Assert.notNull(fieldName, "fieldName?"); Field field = getAccessibleField(target, fieldName); if (field == null) { throw new IllegalArgumentException( "? [" + fieldName + "] [" + target + "] "); } Object result = null; try { result = field.get(target); } catch (IllegalAccessException e) { logger.error("??{}", e.getMessage()); } return (T) result; }
From source file:com.sm.query.utils.QueryUtils.java
public static Pair<Object, FieldInfo> findObjectId(String objectId, Object source, Map<String, ClassInfo> metaData) { if (source == null) { throw new ObjectIdException("source is null"); }/*from ww w .j a va2 s . co m*/ ClassInfo classInfo = findClassInfo(source, metaData); // String[] fields = objectId.split(DOT4R); if (fields.length == 1) { return findField(objectId, source, classInfo); } else { Pair<Object, FieldInfo> pair = findObjectId(fields[0], source, metaData); try { Object obj = pair.getSecond().getField().get(pair.getFirst()); if (obj != null) { String id = extract(fields); return findObjectId(id, obj, metaData); } else { return pair; } } catch (IllegalAccessException e) { throw new RuntimeException(e.getMessage(), e); } } }
From source file:com.concursive.connect.web.portal.PortalUtils.java
public static Object getFormBean(ActionRequest request, Class beanClass) { try {/*from w w w . ja va 2s .co m*/ // Construct the bean Object beanRef = beanClass.newInstance(); // The ActionRequest will auto-populate any values populateObject(beanRef, request); return beanRef; } catch (InstantiationException ie) { LOG.error("Instantiation Exception. MESSAGE = " + ie.getMessage(), ie); } catch (IllegalAccessException iae) { LOG.error("Illegal Access Exception. MESSAGE = " + iae.getMessage(), iae); } return null; }
From source file:br.com.lucasisrael.regra.reflections.TratamentoReflections.java
/** * Set the field represented by the supplied {@link Field field object} on the * specified {@link Object target object} to the specified {@code value}. * In accordance with {@link Field#set(Object, Object)} semantics, the new value * is automatically unwrapped if the underlying field has a primitive type. * <p>Thrown exceptions are handled via a call to {@link #handleReflectionException(Exception)}. * @param field the field to set/* w ww .j a va 2 s.c om*/ * @param target the target object on which to set the field * @param value the value to set; may be {@code null} */ public static void setField(Field field, Object target, Object value) { try { field.set(target, value); } catch (IllegalAccessException ex) { handleReflectionException(ex); throw new IllegalStateException( "Unexpected reflection exception - " + ex.getClass().getName() + ": " + ex.getMessage()); } }
From source file:br.com.lucasisrael.regra.reflections.TratamentoReflections.java
/** * Get the field represented by the supplied {@link Field field object} on the * specified {@link Object target object}. In accordance with {@link Field#get(Object)} * semantics, the returned value is automatically wrapped if the underlying field * has a primitive type.//from w ww . ja va2 s . c o m * <p>Thrown exceptions are handled via a call to {@link #handleReflectionException(Exception)}. * @param field the field to get * @param target the target object from which to get the field * @return the field's current value */ public static Object getField(Field field, Object target) { try { return field.get(target); } catch (IllegalAccessException ex) { handleReflectionException(ex); throw new IllegalStateException( "Unexpected reflection exception - " + ex.getClass().getName() + ": " + ex.getMessage()); } }