Example usage for java.lang.reflect InvocationTargetException InvocationTargetException

List of usage examples for java.lang.reflect InvocationTargetException InvocationTargetException

Introduction

In this page you can find the example usage for java.lang.reflect InvocationTargetException InvocationTargetException.

Prototype

public InvocationTargetException(Throwable target) 

Source Link

Document

Constructs a InvocationTargetException with a target exception.

Usage

From source file:net.sf.webissues.ui.wizard.WebIssuesQueryPage.java

private void updateClient(final boolean force) {
    try {/*from  ww w.  ja v a  2s.c om*/
        IRunnableWithProgress runnable = new IRunnableWithProgress() {
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                try {
                    final WebIssuesClient client = getClient();
                    try {
                        client.updateAttributes(monitor, force);
                    } finally {
                        types = client.getEnvironment().getTypes();
                    }
                    PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
                        public void run() {
                            rebuildTypeList();
                        }
                    });
                } catch (Exception e) {
                    throw new InvocationTargetException(e);
                }
            }
        };

        if (getContainer() != null) {
            getContainer().run(true, true, runnable);
        } else if (getSearchContainer() != null) {
            getSearchContainer().getRunnableContext().run(true, true, runnable);
        } else {
            IProgressService service = PlatformUI.getWorkbench().getProgressService();
            service.busyCursorWhile(runnable);
        }
    } catch (InvocationTargetException e) {
        LOG.log(Level.SEVERE, "Failed to get client for query.", e);
        setErrorMessage(WebIssuesCorePlugin.toStatus(e.getCause(), getTaskRepository()).getMessage());
        return;
    } catch (InterruptedException e) {
        return;
    }
}

From source file:com.twinsoft.convertigo.eclipse.wizards.new_project.NewProjectWizard.java

/**
 * This method is called when 'Finish' button is pressed in the wizard. We
 * will create an operation and run it using wizard as execution context.
 *//*w  ww  .j av  a  2 s  .c o m*/
public boolean performFinish() {
    IRunnableWithProgress op = new IRunnableWithProgress() {
        public void run(IProgressMonitor monitor) throws InvocationTargetException {
            try {
                doFinish(monitor);
            } catch (CoreException e) {
                throw new InvocationTargetException(e);
            } finally {
                monitor.done();
            }
        }
    };

    try {
        getContainer().run(true, false, op);
    } catch (InterruptedException e) {
        return false;
    } catch (InvocationTargetException e) {
        Throwable realException = e.getTargetException();
        MessageDialog.openError(getShell(), "Error", realException.getMessage());
        return false;
    }

    // refresh the project explorer treeview
    IWorkbenchPart iwbPart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
            .findView("com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView");

    if (iwbPart instanceof ProjectExplorerView) {
        ProjectExplorerView view = (ProjectExplorerView) iwbPart;

        try {
            if (projectName != null) {
                view.importProjectTreeObject(projectName);
            }
        } catch (CoreException e) {
            ConvertigoPlugin.logException(e, "An error occured while refreshing the tree view");
        }
        view.viewer.refresh();
    }

    return true;
}

From source file:eu.numberfour.n4js.npmexporter.ui.NpmExportWizard.java

/**
 *
 *//*from w  ww.j ava2s  .c  om*/
protected void udpatePackagJasonComparison() {
    try {
        getContainer().run(true, true, new IRunnableWithProgress() {
            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                try {
                    System.out.println("called to synch the package.jason-compareview");
                    // prepare merge
                    final List<MergeResult> mergeResults = new ArrayList<>();
                    for (IN4JSProject p : requiresMerge) {
                        mergeResults.add(npmExporter.readExistingAndMerge(p));
                    }

                    Display.getDefault().asyncExec(new Runnable() {

                        @Override
                        public void run() {
                            comparePage.updateOn(mergeResults);
                        }
                    });

                } catch (Exception e) {
                    throw new InvocationTargetException(e);
                }
            }
        });
    } catch (InvocationTargetException | InterruptedException e) {
        e.printStackTrace();
    }
}

From source file:es.bsc.servicess.ide.editors.deployers.LicenseTokensTableComposite.java

/**
 * Invoke the runnable to generate the license token
 * @param selectionIndex Index of selected license in the license token table
 *//*  w  ww . j  ava2s .co m*/
protected void generateToken(final int selectionIndex) {
    ProgressMonitorDialog dialog = new ProgressMonitorDialog(shell);
    try {
        dialog.run(false, false, new IRunnableWithProgress() {

            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                try {
                    String token = deployer.executeTokenGeneration(kvTable.getItem(selectionIndex).getText(0),
                            monitor);
                    if (token != null && token.length() > 0) {
                        String name = LicenseTokenUtils.getName(token);
                        if (name.equalsIgnoreCase(kvTable.getItem(selectionIndex).getText(0).trim())) {
                            kvTable.getItem(selectionIndex).setText(1, token);
                        } else {
                            throw (new Exception("Token license identifier " + name
                                    + " is not the specified in the constraints ("
                                    + kvTable.getItem(selectionIndex).getText(0).trim() + ")"));
                        }
                    } else {
                        log.debug("Generated token is invalid");
                        throw (new Exception("Generated token is invalid"));
                    }
                } catch (Exception e) {
                    log.debug("Exception:" + e.getMessage());
                    throw (new InvocationTargetException(e));

                }
            }
        });
    } catch (InterruptedException e) {
        log.error("Exception generating licenses", e);
        ErrorDialog.openError(shell, "Exception Generating license token ", e.getMessage(),
                new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getLocalizedMessage(), e));
    } catch (InvocationTargetException e) {
        log.error("Exception generating licenses", e);
        ErrorDialog.openError(shell, "Exception Generating license token ", e.getMessage(),
                new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getLocalizedMessage(), e));
    }
}

From source file:org.toobsframework.data.beanutil.BeanMonkey.java

private static Object evaluatePropertyValue(String name, String className, String namespace, Object value,
        Map properties, Object bean)
        throws InvocationTargetException, IllegalAccessException, NoSuchMethodException, PermissionException {
    // Perform the assignment for this property
    if (className.startsWith(configuration.getProperty("toobs.beanmonkey.dataPackage"))) {
        className = className.substring(className.lastIndexOf(".") + 1);

        IObjectLoader odao = null;/*  w  w  w. j a  v a2s  . c o m*/
        ICollectionLoader cdao = null;
        Object daoObject = beanFactory.getBean(Introspector.decapitalize(className) + "Dao");
        if (daoObject == null) {
            throw new InvocationTargetException(new Exception(
                    "DAO class " + Introspector.decapitalize(className) + "Dao could not be loaded"));
        }
        if (daoObject instanceof IObjectLoader) {
            odao = (IObjectLoader) daoObject;
        } else {
            cdao = (ICollectionLoader) daoObject;
        }

        String guid = null;
        if (value != null && value.getClass().isArray()) {
            if (properties.containsKey(PlatformConstants.MULTI_ACTION_INSTANCE)) {
                Object[] oldValue = (Object[]) value;
                Integer instance = (Integer) properties.get(PlatformConstants.MULTI_ACTION_INSTANCE);
                if (oldValue.length >= instance + 1) {
                    guid = ((String[]) oldValue)[instance];
                } else {
                    throw new RuntimeException("Instance " + instance + " not found in " + oldValue + " for: "
                            + name + " class: " + className + " in: " + bean);
                }
            } else {
                guid = ((String[]) value)[0];
            }
        } else {
            guid = (String) value;
        }
        if (guid != null && guid.length() > 0) {
            String personId = (String) properties.get("personId");
            try {
                if (odao != null) {
                    value = odao.load(guid);
                } else {
                    value = cdao.load(Integer.parseInt(guid));
                }
            } catch (PermissionException pe) {
                log.error("PermissionException loading object " + className + "." + name + " with guid " + guid
                        + " by person " + personId);
                throw pe;
            } finally {
            }
        } else {
            value = null;
        }
    } else if ((className.equals("java.util.ArrayList") || className.equals("java.util.List"))
            && !(value instanceof java.util.List)) {
        Object[] values = null;
        if (value != null && value.getClass().isArray()) {
            values = ((Object[]) value);
        } else {
            values = new Object[1];
            values[0] = (Object) value;
        }
        value = new ArrayList();
        for (int aa = 0; aa < values.length; aa++) {
            if (!"".equals(values[aa]))
                ((ArrayList) value).add(values[aa]);
        }
        if (((ArrayList) value).size() == 0)
            value = null;
    } else if (className.equals("java.util.Collection")) {
        className = null;
        String typeProp = (namespace != null ? namespace : "") + name + "-Type";
        if (properties.get(typeProp) != null && properties.get(typeProp).getClass().isArray()) {
            className = ((String[]) properties.get(typeProp))[0];
        } else {
            className = (String) properties.get(typeProp);
        }

        if (className == null) {
            throw new InvocationTargetException(new Exception("Missing collection type for " + name));
        }

        IObjectLoader odao = null;
        ICollectionLoader cdao = null;
        Object daoObject = beanFactory.getBean(Introspector.decapitalize(className) + "Dao");
        if (daoObject == null) {
            throw new InvocationTargetException(new Exception(
                    "DAO class " + Introspector.decapitalize(className) + "Dao could not be loaded"));
        }
        if (daoObject instanceof IObjectLoader) {
            odao = (IObjectLoader) daoObject;
        } else {
            cdao = (ICollectionLoader) daoObject;
        }

        Object[] guids = null;
        if (value != null && value.getClass().isArray()) {
            guids = ((Object[]) value);
        } else if (value != null && value instanceof ArrayList) {
            guids = new Object[((ArrayList) value).size()];
            for (int i = 0; i < guids.length; i++) {
                guids[i] = (Object) ((ArrayList) value).get(i);
            }
        } else {
            guids = new Object[1];
            guids[0] = (Object) value;
        }

        String personId = (String) properties.get("personId");

        java.util.Collection valueList = (java.util.Collection) PropertyUtils.getProperty(bean, name);
        valueList.clear();

        for (int i = 0; i < guids.length; i++) {
            if (odao != null) {
                if (((String) guids[i]).length() == 0)
                    continue;
                value = odao.load((String) guids[i]);
            } else if (cdao != null) {
                value = cdao.load((Integer) guids[i]);
            }
            if (value != null) {
                valueList.add(value);
            } else {
                if (beanFactory.containsBean(className + "CollectionCreator")) {
                    ICollectionCreator collectionCreator = (ICollectionCreator) beanFactory
                            .getBean(className + "CollectionCreator");
                    try {
                        collectionCreator.addCollectionElements(guids[i], valueList, properties, personId,
                                namespace);
                    } catch (Exception e) {
                        throw new InvocationTargetException(e);
                    }
                }
            }
        }
        value = valueList;
    } else if (className.equals("java.lang.String") && value != null && value.getClass().isArray()
            && ((Object[]) value).length > 1
            && properties.containsKey(PlatformConstants.MULTI_ACTION_INSTANCE)) {
        Object[] oldValue = (Object[]) value;
        Integer instance = (Integer) properties.get(PlatformConstants.MULTI_ACTION_INSTANCE);
        if (oldValue.length >= instance + 1) {
            value = oldValue[instance];
        } else {
            throw new RuntimeException("Instance " + instance + " not found in " + oldValue + " for: " + name
                    + " class: " + className + " in: " + bean);
        }
    } else if (className.equals("java.lang.String") && value != null && value.getClass().isArray()
            && ((Object[]) value).length > 1) {
        Object[] oldValue = (Object[]) value;
        String newValue = new String();
        for (int i = 0; i < oldValue.length; i++) {
            if (i > 0) {
                newValue = newValue + ";";
            }
            newValue = newValue + oldValue[i];
        }
        value = newValue;
    } else if ((className.equals("java.lang.Integer") || className.equals("java.lang.Boolean"))
            && value != null) {
        if (value.getClass().isArray() && ((Object[]) value).length == 1 && ((Object[]) value)[0].equals("")) {
            value = null;
        } else if (!value.getClass().isArray() && String.valueOf(value).equals("")) {
            value = null;
        }
    } else if (className.equals("java.util.Date") && value != null) {
        if (value.getClass().isArray()) {
            value = StringToDateConverter.convert(value);
        }
    }

    return value;
}

From source file:es.bsc.servicess.ide.editors.deployers.LicenseTokensTableComposite.java

/**
 * Execute the runnable to generate all the license tokens
 *//*from   w  w w .j a  v a 2  s . c o  m*/
protected void generateAllTokens() {

    ProgressMonitorDialog dialog = new ProgressMonitorDialog(shell);
    try {
        dialog.run(false, false, new IRunnableWithProgress() {

            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                try {
                    if (kvTable.getItemCount() > 0) {
                        for (int index = 0; index < kvTable.getItemCount(); index++) {
                            String token = deployer.executeTokenGeneration(kvTable.getItem(index).getText(0),
                                    monitor);
                            if (token != null && token.length() > 0) {
                                String name = LicenseTokenUtils.getName(token);
                                if (name.equalsIgnoreCase(kvTable.getItem(index).getText(0).trim())) {
                                    kvTable.getItem(index).setText(1, token);
                                } else {
                                    throw (new Exception("Token license identifier " + name
                                            + " is not the specified in the constraints ("
                                            + kvTable.getItem(index).getText(0).trim() + ")"));
                                }

                            } else
                                throw (new Exception("Generated token for " + kvTable.getItem(index).getText(0)
                                        + " is invalid"));
                        }
                    }
                } catch (Exception e) {
                    log.debug("Exception during generation:" + e.getMessage());
                    throw (new InvocationTargetException(e));
                }
            }
        });
    } catch (InterruptedException e) {
        ErrorDialog.openError(shell, "Exception Generating license ", e.getMessage(),
                new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getLocalizedMessage(), e));
        log.error("Exception Generating License tokens", e);
    } catch (InvocationTargetException e) {
        ErrorDialog.openError(shell, "Exception Generating license", e.getMessage(),
                new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getLocalizedMessage(), e));
        log.error("Exception Generating License tokens", e);
    }
}

From source file:net.rim.ejde.internal.ui.wizards.BasicBlackBerryProjectWizardPageTwo.java

private final void doRemoveProject(IProgressMonitor monitor) throws InvocationTargetException {
    final boolean noProgressMonitor = (fCurrProjectLocation == null); // inside
    // workspace//from   www. ja  v  a  2s .c  o m
    if (monitor == null || noProgressMonitor) {
        monitor = new NullProgressMonitor();
    }
    monitor.beginTask(Messages.NewBlackBerryProjectWizardPageTwo_operation_remove, 3);
    try {
        try {
            URI projLoc = fCurrProject.getLocationURI();

            boolean removeContent = !fKeepContent && fCurrProject.isSynchronized(IResource.DEPTH_INFINITE);
            if (!removeContent) {
                restoreExistingFolders(projLoc);
            }
            fCurrProject.delete(removeContent, false, new SubProgressMonitor(monitor, 2));

            restoreExistingFiles(projLoc, new SubProgressMonitor(monitor, 1));
        } finally {
            CoreUtility.setAutoBuilding(fIsAutobuild.booleanValue()); // fIsAutobuild
            // must
            // be
            // set
            fIsAutobuild = null;
        }
    } catch (CoreException e) {
        throw new InvocationTargetException(e);
    } finally {
        monitor.done();
        fCurrProject = null;
        fKeepContent = false;
    }
}

From source file:net.lightbody.bmp.proxy.jetty.xml.XmlConfiguration.java

private Object value(Object obj, XmlParser.Node node) throws NoSuchMethodException, ClassNotFoundException,
        InvocationTargetException, IllegalAccessException {
    Object value = null;//from  w ww  .  j  a v  a2 s.  c om

    // Get the type
    String type = node.getAttribute("type");

    // Try a ref lookup
    String ref = node.getAttribute("ref");
    if (ref != null) {
        value = _idMap.get(ref);
    } else {
        // handle trivial case
        if (node.size() == 0) {
            if ("String".equals(type))
                return "";
            return null;
        }

        // Trim values
        int first = 0;
        int last = node.size() - 1;

        // Handle default trim type
        if (type == null || !"String".equals(type)) {
            // Skip leading white
            Object item = null;
            while (first <= last) {
                item = node.get(first);
                if (!(item instanceof String))
                    break;
                item = ((String) item).trim();
                if (((String) item).length() > 0)
                    break;
                first++;
            }

            // Skip trailing white
            while (first < last) {
                item = node.get(last);
                if (!(item instanceof String))
                    break;
                item = ((String) item).trim();
                if (((String) item).length() > 0)
                    break;
                last--;
            }

            // All white, so return null
            if (first > last)
                return null;
        }

        if (first == last)
            //  Single Item value
            value = itemValue(obj, node.get(first));
        else {
            // Get the multiple items as a single string
            StringBuffer buf = new StringBuffer();
            synchronized (buf) {
                for (int i = first; i <= last; i++) {
                    Object item = node.get(i);
                    buf.append(itemValue(obj, item));
                }
                value = buf.toString();
            }
        }
    }

    // Untyped or unknown
    if (value == null) {
        if ("String".equals(type))
            return "";
        return null;
    }

    // Try to type the object
    if (type == null) {
        if (value != null && value instanceof String)
            return ((String) value).trim();
        return value;
    }

    if ("String".equals(type) || "java.lang.String".equals(type))
        return value.toString();

    Class pClass = TypeUtil.fromName(type);
    if (pClass != null)
        return TypeUtil.valueOf(pClass, value.toString());

    if ("URL".equals(type) || "java.net.URL".equals(type)) {
        if (value instanceof URL)
            return value;
        try {
            return new URL(value.toString());
        } catch (MalformedURLException e) {
            throw new InvocationTargetException(e);
        }
    }

    if ("InetAddress".equals(type) || "java.net.InetAddress".equals(type)) {
        if (value instanceof InetAddress)
            return value;
        try {
            return InetAddress.getByName(value.toString());
        } catch (UnknownHostException e) {
            throw new InvocationTargetException(e);
        }
    }

    if ("InetAddrPort".equals(type) || "net.lightbody.bmp.proxy.jetty.util.InetAddrPort".equals(type)) {
        if (value instanceof InetAddrPort)
            return value;
        try {
            return new InetAddrPort(value.toString());
        } catch (UnknownHostException e) {
            throw new InvocationTargetException(e);
        }
    }

    throw new IllegalStateException("Unknown type " + type);
}

From source file:de.blizzy.backup.restore.RestoreDialog.java

private void restore(final Collection<Entry> entries) {
    String folder = null;//www  .ja  va 2 s. c  om
    for (;;) {
        DirectoryDialog dlg = new DirectoryDialog(getShell(), SWT.SAVE);
        dlg.setText(Messages.Title_SelectOutputFolder);
        dlg.setFilterPath(folder);
        folder = dlg.open();
        if (folder == null) {
            break;
        }

        if (new File(folder).list().length > 0) {
            MessageDialog.openError(getShell(), Messages.Title_FolderNotEmpty, NLS.bind(Messages.FolderNotEmpty,
                    Utils.getSimpleName(new FileSystemFileOrFolder(new File(folder)))));
            continue;
        }

        break;
    }

    if (folder != null) {
        alwaysRestoreFromOlderBackups = null;

        final String myFolder = folder;
        Backup backup = (Backup) ((IStructuredSelection) backupsViewer.getSelection()).getFirstElement();
        final int backupId = backup.id;
        final int numEntries = backup.numEntries;
        final ProgressMonitorDialog dlg = new ProgressMonitorDialog(getShell());
        IRunnableWithProgress runnable = new IRunnableWithProgress() {
            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {

                try {
                    monitor.beginTask(Messages.Title_RestoreFromBackup, numEntries);
                    for (Entry entry : entries) {
                        restoreEntry(entry, new File(myFolder), settings.getOutputFolder(), backupId, monitor,
                                dlg.getShell());
                    }
                } catch (IOException e) {
                    throw new InvocationTargetException(e);
                } finally {
                    monitor.done();
                }
            }
        };
        try {
            dlg.run(true, true, runnable);
        } catch (InvocationTargetException e) {
            // TODO
            BackupPlugin.getDefault().logError("error while restoring from backup", e.getCause()); //$NON-NLS-1$
        } catch (InterruptedException e) {
            // okay
        }
    }
}

From source file:com.safi.workshop.util.SafletPersistenceManager.java

public IProject createNewProject(SafletProject sr) throws CoreException {
    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    final IProject project = root.getProject(sr.getName());
    // project.create(null);
    // project.open(null);
    final IProjectDescription desc = ResourcesPlugin.getWorkspace().newProjectDescription(project.getName());
    // final IProjectDescription desc = project.getDescription();
    desc.setLocation(null);/*from   w w  w  .  j a va  2s.  c  o m*/

    // String[] natures = description.getNatureIds();
    // String[] newNatures = new String[natures.length + 1];
    // System.arraycopy(natures, 0, newNatures, 0, natures.length);
    // newNatures[natures.length] = SafiProjectNature.NATURE_ID;
    // description.setNatureIds(newNatures);

    String[] natures = desc.getNatureIds();
    String[] newNatures = new String[natures.length + 1];
    System.arraycopy(natures, 0, newNatures, 0, natures.length);
    newNatures[natures.length] = SafiProjectNature.NATURE_ID;
    desc.setNatureIds(newNatures);

    // desc.setNatureIds(new String[] { SafiProjectNature.NATURE_ID });
    // project.setDescription(desc, null);

    IRunnableWithProgress op = new IRunnableWithProgress() {
        public void run(IProgressMonitor monitor) throws InvocationTargetException {
            CreateProjectOperation op = new CreateProjectOperation(desc,
                    ResourceMessages.NewProject_windowTitle);
            try {
                PlatformUI.getWorkbench().getOperationSupport().getOperationHistory().execute(op, monitor,
                        WorkspaceUndoUtil.getUIInfoAdapter(SafiWorkshopEditorUtil.getActiveShell()));
            } catch (ExecutionException e) {
                throw new InvocationTargetException(e);
            }
        }
    };

    ProgressMonitorDialog pd = new ProgressMonitorDialog(SafiWorkshopEditorUtil.getActiveShell());
    // run the new project creation operation
    try {
        pd.run(false, true, op);
    } catch (InterruptedException e) {
        return null;
    } catch (InvocationTargetException e) {
        Throwable t = e.getTargetException();
        if (t instanceof ExecutionException && t.getCause() instanceof CoreException) {
            CoreException cause = (CoreException) t.getCause();
            StatusAdapter status;
            if (cause.getStatus().getCode() == IResourceStatus.CASE_VARIANT_EXISTS) {
                status = new StatusAdapter(StatusUtil.newStatus(IStatus.WARNING,
                        NLS.bind(ResourceMessages.NewProject_caseVariantExistsError, project.getName()),
                        cause));
            } else {
                status = new StatusAdapter(StatusUtil.newStatus(cause.getStatus().getSeverity(),
                        ResourceMessages.NewProject_errorMessage, cause));
            }
            status.setProperty(StatusAdapter.TITLE_PROPERTY, ResourceMessages.NewProject_errorMessage);
            StatusManager.getManager().handle(status, StatusManager.BLOCK);
        } else {
            StatusAdapter status = new StatusAdapter(
                    new Status(IStatus.WARNING, IDEWorkbenchPlugin.IDE_WORKBENCH, 0,
                            NLS.bind(ResourceMessages.NewProject_internalError, t.getMessage()), t));
            status.setProperty(StatusAdapter.TITLE_PROPERTY, ResourceMessages.NewProject_errorMessage);
            StatusManager.getManager().handle(status, StatusManager.LOG | StatusManager.BLOCK);
        }
    }
    return project;
}