List of usage examples for java.lang.reflect InvocationTargetException InvocationTargetException
public InvocationTargetException(Throwable target, String s)
From source file:ca.uvic.cs.tagsea.wizards.TagNetworkSender.java
public static synchronized void send(String xml, IProgressMonitor sendMonitor, int id) throws InvocationTargetException { sendMonitor.beginTask("Uploading Tags", 100); sendMonitor.subTask("Saving Temporary file..."); File location = TagSEAPlugin.getDefault().getStateLocation().toFile(); File temp = new File(location, "tagsea.temp.file.txt"); if (temp.exists()) { String message = "Unable to send tags. Unable to create temporary file."; IOException ex = new IOException(message); throw (new InvocationTargetException(ex, message)); }//from w w w . ja v a2 s . com try { FileWriter writer = new FileWriter(temp); writer.write(xml); writer.flush(); writer.close(); } catch (IOException e) { throw new InvocationTargetException(e); } sendMonitor.worked(5); sendMonitor.subTask("Uploading Tags..."); String uploadScript = "http://stgild.cs.uvic.ca/cgi-bin/tagSEAUpload.cgi"; PostMethod post = new PostMethod(uploadScript); String fileName = getToday() + ".txt"; try { Part[] parts = { new StringPart("KIND", "tag"), new FilePart("MYLAR" + id, fileName, temp) }; post.setRequestEntity(new MultipartRequestEntity(parts, post.getParams())); HttpClient client = new HttpClient(); int status = client.executeMethod(post); String resp = getData(post.getResponseBodyAsStream()); if (status != 200) { IOException ex = new IOException(resp); throw (ex); } } catch (IOException e) { throw new InvocationTargetException(e, e.getLocalizedMessage()); } finally { sendMonitor.worked(90); sendMonitor.subTask("Deleting Temporary File"); temp.delete(); sendMonitor.done(); } }
From source file:com.bluexml.side.clazz.alfresco.reverse.action.wizard.ReverseFromAlfrescoWizard.java
@Override public boolean performFinish() { try {/*from w ww. j ava 2 s. c o m*/ AbstractFieldsPage page = (AbstractFieldsPage) getPage(WelcomePage.ID); List<IResource> root = (List<IResource>) page.getFieldValue(WelcomePage.Fields.root.toString()); String output = page.getFieldValueString(WelcomePage.Fields.output.toString()); String libraryId = page.getFieldValueString(WelcomePage.Fields.library.toString()); final List<IFile> sideModels = new ArrayList<IFile>(); if (StringUtils.trimToNull(libraryId) != null) { // reverse may use some SIDE models (reversed) // import library ToolingUtils.importLibrary(libraryId); // models can be acceded in current workspace IConfigurationElement libFromLabel = ToolingUtils.getModelLibraryForId(libraryId); String projectId = libFromLabel.getAttribute(ToolingUtils.MODEL_LIBRARY_PROJECT_ID); IFolder iFolder = IFileHelper.getIFolder("/" + projectId + "/data"); sideModels.addAll(IFileHelper.getAllFiles(iFolder)); } final File sideModelRepo = new File(output); List<IFile> allFiles = new ArrayList<IFile>(); for (IResource entry : root) { IResource value = entry; if (value.getType() == IResource.FOLDER) { try { allFiles.addAll(IFileHelper.getAllFiles((IFolder) value)); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } else if (value.getType() == IResource.FILE) { allFiles.add((IFile) value); } } // Convert all Founded IFiles to System.io.File, and avoid duplicate entry Map<String, File> map = new HashMap<String, File>(); for (IFile iFile : allFiles) { map.put(iFile.toString(), IFileHelper.getFile(iFile)); } final Collection<File> files = map.values(); RunnableWithProgress myRunnable = new RunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { current = STATE.started; monitor.beginTask("reversing", -1); try { Reverser.executeReverse(files, sideModelRepo, sideModels, true); } catch (Exception e) { throw new InvocationTargetException(e, "Error while executing reverse"); } monitor.done(); current = STATE.finished; } }; this.getContainer().run(true, true, myRunnable); while (!myRunnable.getState().equals(RunnableWithState.STATE.finished)) { wait(1000); } } catch (Exception e) { e.printStackTrace(); WizardPage currentPage = (WizardPage) getContainer().getCurrentPage(); currentPage.setErrorMessage(e.getLocalizedMessage()); return false; } return true; }
From source file:com.bluexml.side.portal.alfresco.reverse.action.wizard.ReverseFromAlfrescoWizard.java
@Override public boolean performFinish() { try {/*www. java 2 s .c om*/ AbstractFieldsPage page = (AbstractFieldsPage) getPage(WelcomePage.ID); String root = page.getFieldValueString(WelcomePage.Fields.root.toString()); String output = page.getFieldValueString(WelcomePage.Fields.output.toString()); String libraryId = page.getFieldValueString(WelcomePage.Fields.library.toString()); final List<IFile> sideModels = new ArrayList<IFile>(); if (StringUtils.trimToNull(libraryId) != null) { // reverse may use some SIDE models (reversed) // import library ToolingUtils.importLibrary(libraryId); // models can be acceded in current workspace IConfigurationElement libFromLabel = ToolingUtils.getModelLibraryForId(libraryId); String projectId = libFromLabel.getAttribute(ToolingUtils.MODEL_LIBRARY_PROJECT_ID); IFolder iFolder = IFileHelper.getIFolder("/" + projectId + "/data"); sideModels.addAll(IFileHelper.getAllFiles(iFolder)); } final File sideModelRepo = new File(output); final File rootFile = new File(root); // Convert all Founded IFiles to System.io.File, and avoid duplicate entry RunnableWithProgress myRunnable = new RunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { current = STATE.started; monitor.beginTask("reversing", -1); try { if (rootFile.isFile()) { Portal createPortal = PortalFactory.eINSTANCE.createPortal(); LayoutReverser lr = new LayoutReverser(rootFile, createPortal, rootFile.getAbsolutePath()); lr.parse(); EResourceUtils.saveModel(new File( "/Users/davidabad/workspaces/runtime-New_configuration/Model-library-Alfresco-4.0.d-CE/portal/alfresco.portal"), createPortal); } else { ReversePortal rp = new ReversePortal(rootFile, sideModelRepo); rp.reverse(); rp.postChanges(); rp.persist(); } } catch (Exception e) { throw new InvocationTargetException(e, "Error while executing reverse"); } monitor.done(); current = STATE.finished; } }; this.getContainer().run(true, true, myRunnable); while (!myRunnable.getState().equals(RunnableWithState.STATE.finished)) { wait(1000); } } catch (Exception e) { e.printStackTrace(); WizardPage currentPage = (WizardPage) getContainer().getCurrentPage(); currentPage.setErrorMessage(e.getLocalizedMessage()); return false; } return true; }
From source file:games.strategy.engine.random.PropertiesDiceRoller.java
/** * /* w w w .j av a2s .c o m*/ * @throws IOException * if there was an error parsing the string */ public int[] getDice(final String string, final int count) throws IOException, InvocationTargetException { final String errorStartString = m_props.getProperty("error.start"); final String errorEndString = m_props.getProperty("error.end"); // if the error strings are defined if (errorStartString != null && errorStartString.length() > 0 && errorEndString != null && errorEndString.length() > 0) { final int startIndex = string.indexOf(errorStartString); if (startIndex >= 0) { final int endIndex = string.indexOf(errorEndString, (startIndex + errorStartString.length())); if (endIndex > 0) { final String error = string.substring(startIndex + errorStartString.length(), endIndex); throw new InvocationTargetException(null, error); } } } String rollStartString; String rollEndString; if (count == 1) { rollStartString = m_props.getProperty("roll.single.start"); rollEndString = m_props.getProperty("roll.single.end"); } else { rollStartString = m_props.getProperty("roll.multiple.start"); rollEndString = m_props.getProperty("roll.multiple.end"); } int startIndex = string.indexOf(rollStartString); if (startIndex == -1) { throw new IOException("Cound not find start index, text returned is:" + string); } startIndex += rollStartString.length(); final int endIndex = string.indexOf(rollEndString, startIndex); if (endIndex == -1) { throw new IOException("Cound not find end index"); } final StringTokenizer tokenizer = new StringTokenizer(string.substring(startIndex, endIndex), " ,", false); final int[] rVal = new int[count]; for (int i = 0; i < count; i++) { try { // -1 since we are 0 based rVal[i] = Integer.parseInt(tokenizer.nextToken()) - 1; } catch (final NumberFormatException ex) { ex.printStackTrace(); throw new IOException(ex.getMessage()); } } return rVal; }
From source file:br.com.kproj.salesman.infrastructure.helpers.BeanUtils.java
@SuppressWarnings({ "rawtypes", "unchecked" }) public void copyProperty(Object dest, String fieldName, Object value, Identifiable orig) throws IllegalAccessException, InvocationTargetException { if (log.isTraceEnabled()) { createLogCopyProperty(dest, fieldName, value); }//from w ww . jav a 2 s .co m if (!orig.getFields().contains(fieldName)) { return; } Object target = dest; int delim = fieldName.lastIndexOf(46); if (delim >= 0) { try { target = getPropertyUtils().getProperty(dest, fieldName.substring(0, delim)); } catch (NoSuchMethodException e) { return; } fieldName = fieldName.substring(delim + 1); if (log.isTraceEnabled()) { log.trace(" Target bean = " + target); log.trace(" Target name = " + fieldName); } } String propName = null; Class type = null; int index = -1; String key = null; propName = fieldName; int i = propName.indexOf(91); if (i >= 0) { int k = propName.indexOf(93); try { index = Integer.parseInt(propName.substring(i + 1, k)); } catch (NumberFormatException e) { } propName = propName.substring(0, i); } int j = propName.indexOf(40); if (j >= 0) { int k = propName.indexOf(41); try { key = propName.substring(j + 1, k); } catch (IndexOutOfBoundsException e) { } propName = propName.substring(0, j); } if (target instanceof DynaBean) { DynaClass dynaClass = ((DynaBean) target).getDynaClass(); DynaProperty dynaProperty = dynaClass.getDynaProperty(propName); if (dynaProperty == null) { return; } type = dynaProperty.getType(); } else { PropertyDescriptor descriptor = null; try { descriptor = getPropertyUtils().getPropertyDescriptor(target, fieldName); if (descriptor == null) return; } catch (NoSuchMethodException e) { return; } type = descriptor.getPropertyType(); if (type == null) { if (log.isTraceEnabled()) { log.trace(" target type for property '" + propName + "' is null, so skipping ths setter"); } return; } } if (log.isTraceEnabled()) { log.trace(" target propName=" + propName + ", type=" + type + ", index=" + index + ", key=" + key); } if (index >= 0) { Converter converter = getConvertUtils().lookup(type.getComponentType()); if (converter != null) { log.trace(" USING CONVERTER " + converter); value = converter.convert(type, value); } try { getPropertyUtils().setIndexedProperty(target, propName, index, value); } catch (NoSuchMethodException e) { throw new InvocationTargetException(e, "Cannot set " + propName); } } else if (key != null) { try { getPropertyUtils().setMappedProperty(target, propName, key, value); } catch (NoSuchMethodException e) { throw new InvocationTargetException(e, "Cannot set " + propName); } } else { Converter converter = getConvertUtils().lookup(type); if (converter != null && value != null) { log.trace(" USING CONVERTER " + converter); value = converter.convert(type, value); } try { if (value instanceof Map) { Map mapDest = (Map) getPropertyUtils().getSimpleProperty(dest, fieldName); if (mapDest != null) { Map mapOrig = (Map) value; Set entrySet = mapOrig.entrySet(); for (Object object : entrySet) { Entry entryOrig = (Entry) object; if (entryOrig.getValue() instanceof Identifiable) { if (mapDest.containsKey(entryOrig.getKey())) { Object destValue = mapDest.get(entryOrig.getKey()); new BeanUtils().copyProperties(destValue, entryOrig.getValue()); } else { mapDest.put(entryOrig.getKey(), entryOrig.getValue()); } } else { mapDest.put(entryOrig.getKey(), entryOrig.getValue()); } } } else { getPropertyUtils().setSimpleProperty(target, propName, value); } } else { getPropertyUtils().setSimpleProperty(target, propName, value); } } catch (NoSuchMethodException e) { throw new InvocationTargetException(e, "Cannot set " + propName); } } }
From source file:com.epam.catgenome.util.Utils.java
/** * Creates a temporary {@link FeatureFile} object, that is not registered int the system, but is used for * temporary processing, e.g. opening files by URL * * @param c class of a file to create/* w w w .j a va 2 s .co m*/ * @param fileUrl a URL of a file * @param indexUrl a URL of an index * @param chromosome a chromosome, that is being opened * @param <T> type of a {@link FeatureFile} * @return temporary {@link FeatureFile} object, that is not registered int the system * @throws InvocationTargetException */ public static <T extends FeatureFile> T createNonRegisteredFile(Class<T> c, String fileUrl, String indexUrl, Chromosome chromosome) throws InvocationTargetException { T notRegisteredFile; try { notRegisteredFile = c.getConstructor().newInstance(); } catch (InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) { throw new InvocationTargetException(e, "Cannot instantiate object of class " + c); } notRegisteredFile.setPath(fileUrl); notRegisteredFile.setCompressed(false); notRegisteredFile.setType(BiologicalDataItemResourceType.URL); notRegisteredFile.setReferenceId(chromosome.getReferenceId()); BiologicalDataItem index = new BiologicalDataItem(); index.setPath(indexUrl); notRegisteredFile.setIndex(index); return notRegisteredFile; }
From source file:com.sworddance.beans.ProxyMapperImpl.java
/** * @param method/* w ww . j a v a 2s. co m*/ * @param args * @param actualObject * @return * @throws IllegalAccessException * @throws InvocationTargetException */ private Object doInvoke(Method method, Object[] args) throws IllegalAccessException, InvocationTargetException { O actualObject; if ((method.getModifiers() & Modifier.STATIC) != Modifier.STATIC) { // not a static method actualObject = getRealObject(true, "need object to call a non-static method ", this, " method=", method, "(", join(args), ")"); } else { actualObject = null; } try { return method.invoke(actualObject, args); } catch (RuntimeException e) { // would like to log or annotate somehow .. // changing type of exception is bad so we will throw as an exception that will normally be unwrapped. throw new InvocationTargetException(e, this + " method=" + method + "(" + join(args) + ")"); } }
From source file:javadz.beanutils.BeanUtilsBean.java
/** * <p>Copy the specified property value to the specified destination bean, * performing any type conversion that is required. If the specified * bean does not have a property of the specified name, or the property * is read only on the destination bean, return without * doing anything. If you have custom destination property types, register * {@link Converter}s for them by calling the <code>register()</code> * method of {@link ConvertUtils}.</p> * * <p><strong>IMPLEMENTATION RESTRICTIONS</strong>:</p> * <ul>/* w w w. j av a2 s . co m*/ * <li>Does not support destination properties that are indexed, * but only an indexed setter (as opposed to an array setter) * is available.</li> * <li>Does not support destination properties that are mapped, * but only a keyed setter (as opposed to a Map setter) * is available.</li> * <li>The desired property type of a mapped setter cannot be * determined (since Maps support any data type), so no conversion * will be performed.</li> * </ul> * * @param bean Bean on which setting is to be performed * @param name Property name (can be nested/indexed/mapped/combo) * @param value Value to be set * * @exception IllegalAccessException if the caller does not have * access to the property accessor method * @exception InvocationTargetException if the property accessor method * throws an exception */ public void copyProperty(Object bean, String name, Object value) throws IllegalAccessException, InvocationTargetException { // Trace logging (if enabled) if (log.isTraceEnabled()) { StringBuffer sb = new StringBuffer(" copyProperty("); sb.append(bean); sb.append(", "); sb.append(name); sb.append(", "); if (value == null) { sb.append("<NULL>"); } else if (value instanceof String) { sb.append((String) value); } else if (value instanceof String[]) { String[] values = (String[]) value; sb.append('['); for (int i = 0; i < values.length; i++) { if (i > 0) { sb.append(','); } sb.append(values[i]); } sb.append(']'); } else { sb.append(value.toString()); } sb.append(')'); log.trace(sb.toString()); } // Resolve any nested expression to get the actual target bean Object target = bean; Resolver resolver = getPropertyUtils().getResolver(); while (resolver.hasNested(name)) { try { target = getPropertyUtils().getProperty(target, resolver.next(name)); name = resolver.remove(name); } catch (NoSuchMethodException e) { return; // Skip this property setter } } if (log.isTraceEnabled()) { log.trace(" Target bean = " + target); log.trace(" Target name = " + name); } // Declare local variables we will require String propName = resolver.getProperty(name); // Simple name of target property Class type = null; // Java type of target property int index = resolver.getIndex(name); // Indexed subscript value (if any) String key = resolver.getKey(name); // Mapped key value (if any) // Calculate the target property type if (target instanceof DynaBean) { DynaClass dynaClass = ((DynaBean) target).getDynaClass(); DynaProperty dynaProperty = dynaClass.getDynaProperty(propName); if (dynaProperty == null) { return; // Skip this property setter } type = dynaProperty.getType(); } else { PropertyDescriptor descriptor = null; try { descriptor = getPropertyUtils().getPropertyDescriptor(target, name); if (descriptor == null) { return; // Skip this property setter } } catch (NoSuchMethodException e) { return; // Skip this property setter } type = descriptor.getPropertyType(); if (type == null) { // Most likely an indexed setter on a POJB only if (log.isTraceEnabled()) { log.trace(" target type for property '" + propName + "' is null, so skipping ths setter"); } return; } } if (log.isTraceEnabled()) { log.trace(" target propName=" + propName + ", type=" + type + ", index=" + index + ", key=" + key); } // Convert the specified value to the required type and store it if (index >= 0) { // Destination must be indexed value = convert(value, type.getComponentType()); try { getPropertyUtils().setIndexedProperty(target, propName, index, value); } catch (NoSuchMethodException e) { throw new InvocationTargetException(e, "Cannot set " + propName); } } else if (key != null) { // Destination must be mapped // Maps do not know what the preferred data type is, // so perform no conversions at all // FIXME - should we create or support a TypedMap? try { getPropertyUtils().setMappedProperty(target, propName, key, value); } catch (NoSuchMethodException e) { throw new InvocationTargetException(e, "Cannot set " + propName); } } else { // Destination must be simple value = convert(value, type); try { getPropertyUtils().setSimpleProperty(target, propName, value); } catch (NoSuchMethodException e) { throw new InvocationTargetException(e, "Cannot set " + propName); } } }
From source file:org.locationtech.udig.processingtoolbox.tools.BoxPlotDialog.java
@SuppressWarnings("nls") @Override/*w w w . j a v a2 s. c o m*/ public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { monitor.beginTask(String.format(Messages.Task_Executing, windowTitle), 100); try { if (plotTab == null) { monitor.subTask("Preparing box plot..."); createGraphTab(inputTab.getParent()); } monitor.worked(increment); SimpleFeatureCollection features = MapUtils.getFeatures(inputLayer); if (chkStatistics.getSelection()) { if (outputTab == null) { createOutputTab(inputTab.getParent()); } ProgressListener subMonitor = GeoToolsAdapters .progress(SubMonitor.convert(monitor, Messages.Task_Internal, 20)); HtmlWriter writer = new HtmlWriter(inputLayer.getName()); DataStatisticsResult statistics = null; statistics = StatisticsFeaturesProcess.process(features, selectedFields, subMonitor); writer.writeDataStatistics(statistics); browser.setText(writer.getHTML()); } monitor.subTask("Updating box plot..."); // chartComposite.setLayer(inputLayer); updateChart(features, selectedFields.split(",")); plotTab.getParent().setSelection(plotTab); monitor.worked(increment); } catch (Exception e) { e.printStackTrace(); ToolboxPlugin.log(e.getMessage()); throw new InvocationTargetException(e.getCause(), e.getMessage()); } finally { ToolboxPlugin.log(String.format(Messages.Task_Completed, windowTitle)); monitor.done(); } }
From source file:org.locationtech.udig.processingtoolbox.tools.HistogramDialog.java
@SuppressWarnings("nls") @Override/*w w w . j a v a 2 s . c om*/ public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { monitor.beginTask(String.format(Messages.Task_Executing, windowTitle), 100); try { if (plotTab == null) { monitor.subTask("Preparing Histogram..."); createGraphTab(inputTab.getParent()); } monitor.worked(increment); String field = cboField.getText(); SimpleFeatureCollection features = MapUtils.getFeatures(inputLayer); if (chkStatistics.getSelection()) { monitor.subTask("Calculating Basic Statistics..."); if (outputTab == null) { createOutputTab(inputTab.getParent()); } ProgressListener subMonitor = GeoToolsAdapters .progress(SubMonitor.convert(monitor, Messages.Task_Internal, 20)); DataStatisticsResult statistics = StatisticsFeaturesProcess.process(features, field, subMonitor); HtmlWriter writer = new HtmlWriter(inputLayer.getName()); writer.writeDataStatistics(statistics); browser.setText(writer.getHTML()); } monitor.subTask("Updating Histogram..."); updateChart(features, field); plotTab.getParent().setSelection(plotTab); monitor.worked(increment); } catch (Exception e) { ToolboxPlugin.log(e.getMessage()); throw new InvocationTargetException(e.getCause(), e.getMessage()); } finally { ToolboxPlugin.log(String.format(Messages.Task_Completed, windowTitle)); monitor.done(); } }