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:org.jboss.tools.ws.jaxrs.core.WorkbenchUtils.java

/**
 * @param monitor//from ww w.  j  a  va2  s  . c o  m
 * @param description
 * @param projectName
 * @param workspace
 * @param project
 * @throws InvocationTargetException
 */
static void createProject(IProgressMonitor monitor, IProjectDescription description, String projectName,
        IWorkspace workspace, IProject project) throws InvocationTargetException {
    // import from file system

    // import project from location copying files - use default project
    // location for this workspace
    // if location is null, project already exists in this location or
    // some error condition occured.
    IProjectDescription desc = workspace.newProjectDescription(projectName);
    desc.setBuildSpec(description.getBuildSpec());
    desc.setComment(description.getComment());
    desc.setDynamicReferences(description.getDynamicReferences());
    desc.setNatureIds(description.getNatureIds());
    desc.setReferencedProjects(description.getReferencedProjects());
    description = desc;

    try {
        monitor.beginTask(DataTransferMessages.WizardProjectsImportPage_CreateProjectsTask, 100);
        project.create(description, new SubProgressMonitor(monitor, 30));
        project.open(IResource.BACKGROUND_REFRESH, new SubProgressMonitor(monitor, 70));
    } catch (CoreException e) {
        throw new InvocationTargetException(e);
    } finally {
        monitor.done();
    }
}

From source file:org.jenkinsci.plugins.DependencyCheck.parser.ReportParser.java

@Override
public Collection<FileAnnotation> parse(final InputStream file, final String moduleName)
        throws InvocationTargetException {
    try {/*from w  w  w. j av  a 2  s. c om*/
        // Parse dependency-check-report.xml files compatible with DependencyCheck.xsd v.1.1
        Digester digester = new Digester();
        digester.setValidating(false);
        digester.setClassLoader(ReportParser.class.getClassLoader());

        digester.addObjectCreate("analysis", Analysis.class);

        String depXpath = "analysis/dependencies/dependency";
        digester.addObjectCreate(depXpath, Dependency.class);
        digester.addBeanPropertySetter(depXpath + "/fileName");
        digester.addBeanPropertySetter(depXpath + "/filePath");
        digester.addBeanPropertySetter(depXpath + "/md5", "md5sum");
        digester.addBeanPropertySetter(depXpath + "/sha1", "sha1sum");
        digester.addBeanPropertySetter(depXpath + "/description");
        digester.addBeanPropertySetter(depXpath + "/license");

        String vulnXpath = "analysis/dependencies/dependency/vulnerabilities/vulnerability";
        digester.addObjectCreate(vulnXpath, Vulnerability.class);
        digester.addBeanPropertySetter(vulnXpath + "/name");
        digester.addBeanPropertySetter(vulnXpath + "/cvssScore");
        digester.addBeanPropertySetter(vulnXpath + "/cwe");
        digester.addBeanPropertySetter(vulnXpath + "/description");

        String refXpath = "analysis/dependencies/dependency/vulnerabilities/vulnerability/references/reference";
        digester.addObjectCreate(refXpath, Reference.class);
        digester.addBeanPropertySetter(refXpath + "/source");
        digester.addBeanPropertySetter(refXpath + "/url");
        digester.addBeanPropertySetter(refXpath + "/name");

        digester.addSetNext(refXpath, "addReference");
        digester.addSetNext(vulnXpath, "addVulnerability");
        digester.addSetNext(depXpath, "addDependency");

        Analysis module = (Analysis) digester.parse(file);
        if (module == null) {
            throw new SAXException("Input stream is not a Dependency-Check report file.");
        }

        return convert(module, moduleName);

    } catch (IOException exception) {
        throw new InvocationTargetException(exception);
    } catch (SAXException exception) {
        throw new InvocationTargetException(exception);
    }
}

From source file:org.jsecurity.spring.remoting.SecureRemoteInvocationExecutor.java

@SuppressWarnings({ "unchecked" })
public Object invoke(RemoteInvocation invocation, Object targetObject)
        throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {

    try {/*w  w  w.  j a  v a 2 s  . c o m*/
        PrincipalCollection principals = null;
        boolean authenticated = false;
        InetAddress inetAddress = getInetAddress(invocation, targetObject);
        Session session = null;

        Serializable sessionId = invocation.getAttribute(SecureRemoteInvocationFactory.SESSION_ID_KEY);

        if (sessionId != null) {
            session = securityManager.getSession(sessionId);
            principals = getPrincipals(invocation, targetObject, session);
            authenticated = isAuthenticated(invocation, targetObject, session, principals);
        } else {
            if (log.isWarnEnabled()) {
                log.warn("RemoteInvocation object did not contain a JSecurity Session id under "
                        + "attribute name [" + SecureRemoteInvocationFactory.SESSION_ID_KEY
                        + "].  A Session will not "
                        + "be available to the method.  Ensure that clients are using a "
                        + "SecureRemoteInvocationFactory to prevent this problem.");
            }
        }

        Subject subject = new DelegatingSubject(principals, authenticated, inetAddress, session,
                securityManager);

        ThreadContext.bind(securityManager);
        ThreadContext.bind(subject);

        return super.invoke(invocation, targetObject);

    } catch (NoSuchMethodException nsme) {
        throw nsme;
    } catch (IllegalAccessException iae) {
        throw iae;
    } catch (InvocationTargetException ite) {
        throw ite;
    } catch (Throwable t) {
        throw new InvocationTargetException(t);
    } finally {
        ThreadContext.clear();
    }
}

From source file:org.kalypso.afgui.wizards.UnpackProjectTemplateOperation.java

@Override
public void execute(final IProgressMonitor monitor)
        throws CoreException, InvocationTargetException, InterruptedException {
    final IProject project = m_data.getProject();
    final ProjectTemplate template = m_data.getTemplate();
    final URL dataLocation = template.getData();

    final SubMonitor progress = SubMonitor.convert(monitor,
            Messages.getString("org.kalypso.afgui.wizards.NewProjectWizard.2"), 100); //$NON-NLS-1$
    try {//from   w ww .  j  a v  a2s. c  o  m
        // REMARK: we unpack into a closed project here (not using unzip(URL, IFolder)), as else
        // the project description will not be up-to-date in time, resulting in missing natures.
        project.close(progress.newChild(10));

        /* Unpack project from template */
        monitor.subTask(Messages.getString("UnpackProjectTemplateOperation.1")); //$NON-NLS-1$
        final File destinationDir = project.getLocation().toFile();
        unpackProjectData(dataLocation, destinationDir);
        ProgressUtilities.worked(progress, 30);

        /* Reset project to its own value, else we get the name from the zip, which leads to problems later. */
        ProjectUtilities.setProjectName(project, project.getName());

        project.open(progress.newChild(10));

        /* Necessary to remove all build specs from the data projects (we have at least the manifest builder now) */
        removeBuildspec(project);

        // IMPORTANT: As the project was already open once before, we need to refresh here, else
        // not all resources are up-to-date
        project.refreshLocal(IResource.DEPTH_INFINITE, progress.newChild(10));

        /* Let inherited wizards change the project */
        final INewProjectHandler handler = m_data.getHandler();
        if (handler == null)
            return;

        final IStatus postCreateStatus = handler.postCreateProject(project, template,
                progress.newChild(30, SubMonitor.SUPPRESS_NONE));
        if (!postCreateStatus.matches(IStatus.ERROR))
            handler.openProject(project);

        if (postCreateStatus != Status.OK_STATUS)
            throw new CoreException(postCreateStatus);

        /* Enforce and cleanup natures and description */
        final String moduleID = m_data.getModuleID();
        ModuleNature.enforceNature(project, moduleID);

        final String[] natureIds = cleanDescription(project, progress);
        configureNatures(project, natureIds, progress);
    } catch (final CoreException t) {
        final IStatus status = t.getStatus();
        if (status.matches(IStatus.ERROR | IStatus.CANCEL)) {
            // If anything went wrong, clean up the project
            // We use new monitor, else delete will not work if the monitor is already cancelled.
            project.delete(true, new NullProgressMonitor());
        }

        if (status.matches(IStatus.CANCEL))
            throw new InterruptedException(Messages.getString("UnpackProjectTemplateOperation.2")); //$NON-NLS-1$

        throw t;
    } catch (final Throwable t) {
        // If anything went wrong, clean up the project
        progress.setWorkRemaining(10);
        project.delete(true, progress);

        throw new InvocationTargetException(t);
    }
}

From source file:org.kalypso.gml.ui.internal.coverage.RemoveCoverageAction.java

@Override
public void runWithEvent(final Event event) {
    final Shell shell = event.display.getActiveShell();

    final ICoverage[] selectedCoverages = m_widget.getSelectedCoverages();
    final IKalypsoFeatureTheme selectedTheme = m_widget.getSelectedTheme();
    final Runnable refreshRunnable = m_widget.getRefreshRunnable();

    if (ArrayUtils.isEmpty(selectedCoverages) || selectedTheme == null)
        return;/*from w w w .j  a va 2 s  .c  om*/

    if (!MessageDialog.openConfirm(shell, getText(), Messages.getString("RemoveCoverageAction.1"))) //$NON-NLS-1$
        return;

    final ICoreRunnableWithProgress operation = new ICoreRunnableWithProgress() {
        @Override
        public IStatus execute(final IProgressMonitor monitor) throws InvocationTargetException {
            try {
                final CommandableWorkspace workspace = selectedTheme.getWorkspace();

                /* Delete coverage from collection */
                final DeleteFeatureCommand command = new DeleteFeatureCommand(selectedCoverages);
                selectedTheme.postCommand(command, refreshRunnable);

                /* save the model */
                final ResourcePool pool = KalypsoCorePlugin.getDefault().getPool();
                pool.saveObject(workspace, monitor);

                /*
                 * Delete underlying grid file: we do it in a job, later, in order to let the map give-up the handle to the
                 * file
                 */
                final Job job = new Job(
                        Messages.getString("org.kalypso.gml.ui.map.CoverageManagementWidget.20")) //$NON-NLS-1$
                {
                    @Override
                    protected IStatus run(final IProgressMonitor progress) {
                        final IStatusCollector log = new StatusCollector(KalypsoGmlUIPlugin.id());

                        for (final ICoverage coverage : selectedCoverages) {
                            final IStatus status = CoverageManagementHelper.deleteRangeSetFile(coverage);
                            log.add(status);
                        }

                        return log.asMultiStatusOrOK(Messages.getString("RemoveCoverageAction.0")); //$NON-NLS-1$
                    }
                };
                job.setUser(false);
                job.setSystem(true);
                job.schedule(5000);

                return Status.OK_STATUS;
            } catch (final LoaderException e) {
                e.printStackTrace();

                throw new InvocationTargetException(e);
            }
        }
    };

    final IStatus status = ProgressUtilities.busyCursorWhile(operation);
    ErrorDialog.openError(shell, Messages.getString("org.kalypso.gml.ui.map.CoverageManagementWidget.12"), //$NON-NLS-1$
            Messages.getString("org.kalypso.gml.ui.map.CoverageManagementWidget.22"), status); //$NON-NLS-1$
}

From source file:org.kalypso.kalypso1d2d.internal.importNet.shape.Import2dImportShapeOperation.java

@Override
protected Pair<IStatus, IPolygonWithName[]> readFileData(final File importFile, final int sourceSrid,
        final IProgressMonitor monitor) throws InvocationTargetException {
    String filePath = importFile.getAbsolutePath();
    if (filePath.endsWith(ShapeFile.EXTENSION_SHP))
        filePath = FilenameUtils.removeExtension(filePath);

    try (ShapeFile shapeFile = new ShapeFile(filePath, Charset.defaultCharset(), FileMode.READ)) {
        final ShapeType shapeType = shapeFile.getShapeType();
        if (!(shapeType == ShapeType.POLYGON || shapeType == ShapeType.POLYGONZ)) {
            final String message = String.format(Messages.getString("Import2dImportShapeOperation_1"), //$NON-NLS-1$
                    shapeType, ShapeType.POLYGON, ShapeType.POLYGONZ);
            final IStatus readStatus = new Status(IStatus.ERROR, Kalypso1d2dProjectPlugin.PLUGIN_ID, message);
            return Pair.of(readStatus, null);
        }/*from  w  w  w.  j a  v  a 2 s. c  o  m*/

        final int numRecords = shapeFile.getNumRecords();

        monitor.beginTask(String.format(Messages.getString("Import2dImportShapeOperation_2"), filePath), //$NON-NLS-1$
                numRecords);

        // TODO: potential heap exception here -> handle!
        final Collection<IPolygonWithName> polygons = new ArrayList<>(numRecords);

        for (int i = 0; i < numRecords; i++) {
            if (i % 100 == 0)
                monitor.subTask(String.format("%d/%d", i + 1, numRecords)); //$NON-NLS-1$

            final ISHPGeometry shape = shapeFile.getShape(i);
            addPolygons(polygons, i, shape);

            ProgressUtilities.worked(monitor, 1);
        }

        shapeFile.close();

        return Pair.of(Status.OK_STATUS, polygons.toArray(new IPolygonWithName[polygons.size()]));
    } catch (final IOException e) {
        throw new InvocationTargetException(e);
    } catch (final DBaseException e) {
        throw new InvocationTargetException(e);
    } finally {
        monitor.done();
    }
}

From source file:org.kalypso.kalypso1d2d.internal.importNet.twodm.Import2dImport2dmOperation.java

@Override
protected Pair<IStatus, IPolygonWithName[]> readFileData(final File importFile, final int sourceSrid,
        final IProgressMonitor monitor) throws InvocationTargetException {
    final SmsParser parser = new SmsParser(sourceSrid);

    try {//from  w  ww. ja  v  a  2 s  .  c  o  m
        final URL url = importFile.toURI().toURL();
        final IStatus parseStatus = parser.parse(url, new NullProgressMonitor());

        if (parseStatus.matches(IStatus.ERROR))
            return Pair.of(parseStatus, null);

        final ISmsModel model = parser.getModel();
        final SmsConverter converter = new SmsConverter(model);

        final SmsCollectorTarget target = new SmsCollectorTarget();
        converter.addTarget(target);

        converter.execute();

        final IPolygonWithName[] elements = target.getElements();

        return Pair.of(parseStatus, elements);
    } catch (final MalformedURLException e) {
        throw new InvocationTargetException(e);
    } catch (final IOException e) {
        throw new InvocationTargetException(e);
    }
}

From source file:org.kalypso.kalypso1d2d.pjt.map.HydrographManagementWidget.java

protected void saveModell() {

    // save the model
    final Runnable refreshRunnable = m_refreshHydrographViewerRunnable;
    final ICoreRunnableWithProgress operation = new ICoreRunnableWithProgress() {
        @Override//from  w  w w.  j  a v a  2  s .  c o m
        @SuppressWarnings("synthetic-access")
        public IStatus execute(final IProgressMonitor monitor) throws InvocationTargetException {
            if (m_theme == null)
                return new Status(IStatus.INFO, Kalypso1d2dProjectPlugin.PLUGIN_ID,
                        Messages.getString("org.kalypso.kalypso1d2d.pjt.map.HydrographManagementWidget.11")); //$NON-NLS-1$

            m_theme.postCommand(new EmptyCommand(StringUtils.EMPTY, false), refreshRunnable);

            try {
                /* save the model */
                final ResourcePool pool = KalypsoCorePlugin.getDefault().getPool();
                final CommandableWorkspace workspace = m_theme.getWorkspace();
                pool.saveObject(workspace, new NullProgressMonitor());

                return Status.OK_STATUS;
            } catch (final LoaderException e) {
                e.printStackTrace();

                throw new InvocationTargetException(e);
            }
        }
    };

    final IStatus status = ProgressUtilities.busyCursorWhile(operation);
    ErrorDialog.openError(m_hydrographViewer.getControl().getShell(),
            Messages.getString("org.kalypso.kalypso1d2d.pjt.map.HydrographManagementWidget.13"), //$NON-NLS-1$
            Messages.getString("org.kalypso.kalypso1d2d.pjt.map.HydrographManagementWidget.14"), status); //$NON-NLS-1$

}

From source file:org.kalypso.kalypso1d2d.pjt.map.HydrographManagementWidget.java

protected void handleListSelectionChanged(final Composite parent, final Group hydrographInfoGroup,
        final FeatureComposite featureComposite, final SelectionChangedEvent event) {
    final Runnable refreshRunnable = m_refreshHydrographViewerRunnable;
    final ICoreRunnableWithProgress operation = new ICoreRunnableWithProgress() {
        @Override/*from w  ww .  ja v  a 2s.  c  o m*/
        @SuppressWarnings("synthetic-access")
        public IStatus execute(final IProgressMonitor monitor) throws InvocationTargetException {
            m_theme.postCommand(new EmptyCommand(StringUtils.EMPTY, false), refreshRunnable);

            try {
                /* save the model */
                final ResourcePool pool = KalypsoCorePlugin.getDefault().getPool();
                final CommandableWorkspace workspace = m_theme.getWorkspace();
                pool.saveObject(workspace, new NullProgressMonitor());

                return Status.OK_STATUS;
            } catch (final LoaderException e) {
                e.printStackTrace();

                throw new InvocationTargetException(e);
            }
        }
    };

    final IStatus status = ProgressUtilities.busyCursorWhile(operation);
    ErrorDialog.openError(m_hydrographViewer.getControl().getShell(),
            Messages.getString("org.kalypso.kalypso1d2d.pjt.map.HydrographManagementWidget.20"), //$NON-NLS-1$
            Messages.getString("org.kalypso.kalypso1d2d.pjt.map.HydrographManagementWidget.21"), status); //$NON-NLS-1$

    final IStructuredSelection selection = (IStructuredSelection) event.getSelection();
    m_selectedHydrograph = (IHydrograph) selection.getFirstElement();

    featureComposite.disposeControl();

    if (m_selectedHydrograph != null) {
        featureComposite.setFeature(m_selectedHydrograph);
        featureComposite.createControl(hydrographInfoGroup, SWT.NONE);
        parent.layout(true, true);
    }

    // final Point size = panel.computeSize( SWT.DEFAULT, SWT.DEFAULT );
    // panel.setSize( size );
    // sc.setMinHeight( size.y );

    getMapPanel().repaintMap();

}

From source file:org.kalypso.kalypsomodel1d2d.ui.map.flowrel.FlowRelationshipCalcOperation.java

private QIntervallResult runCalculation(final TuhhCalculation templateCalculation,
        final IFlowRelation1D flowRel, final IProfile[] profiles, final IProgressMonitor monitor)
        throws InvocationTargetException {
    File tmpDir = null;/*from w w  w.  ja  v a2 s. c o m*/
    try {
        tmpDir = SimulationUtilitites.createSimulationTmpDir("" + System.currentTimeMillis()); //$NON-NLS-1$

        final TuhhCalculation calculation = createCalculation(flowRel, templateCalculation, profiles);

        // Prepare wspm model
        final File modelFile = new File(tmpDir, "modell.gml"); //$NON-NLS-1$
        final GMLWorkspace calcWorkspace = calculation.getWorkspace();
        GmlSerializer.serializeWorkspace(modelFile, calcWorkspace, Charset.defaultCharset().name());

        // prepare calcjob
        final WspmTuhhCalcJob wspmTuhhCalcJob = new WspmTuhhCalcJob(new PrintStream(m_outputStream));
        final DefaultSimulationDataProvider inputProvider = new DefaultSimulationDataProvider();
        inputProvider.put(WspmTuhhCalcJob.INPUT_MODELL_GML, modelFile.toURI().toURL());
        inputProvider.put(WspmTuhhCalcJob.INPUT_CALC_PATH, new GMLXPath(calculation).toString());
        // eps-thinning is big, as we do not need the tin result and bigger is faster
        inputProvider.put(WspmTuhhCalcJob.INPUT_EPS_THINNING, "100.0"); //$NON-NLS-1$

        final DefaultSimulationResultEater resultEater = new DefaultSimulationResultEater();
        final NullSimulationMonitorExtension simMonitor = new NullSimulationMonitorExtension(monitor);

        wspmTuhhCalcJob.run(tmpDir, inputProvider, resultEater, simMonitor);

        if (simMonitor.getFinishStatus() != IStatus.OK)
            throw new CoreException(new Status(simMonitor.getFinishStatus(), KalypsoModel1D2DPlugin.PLUGIN_ID,
                    simMonitor.getFinishText()));

        // read simulation log
        final File logFile = (File) resultEater.getResult(WspmTuhhCalcJob.OUTPUT_SIMULATION_LOG);
        m_consoleText = FileUtils.readFileToString(logFile, Charset.defaultCharset().name());

        // read interval results and remember them
        final File qintervallFile = (File) resultEater.getResult(WspmTuhhCalcJob.OUTPUT_QINTERVALL_RESULT);
        final GMLWorkspace qresultsWorkspace = GmlSerializer.createGMLWorkspace(qintervallFile,
                calcWorkspace.getFeatureProviderFactory());
        final QIntervallResultCollection qResultCollection = (QIntervallResultCollection) qresultsWorkspace
                .getRootFeature();

        final IFeatureBindingCollection<QIntervallResult> resultList = qResultCollection.getQIntervalls();
        for (final QIntervallResult qresult : resultList) {
            final BigDecimal flowStation = flowRel.getStation();
            if (flowStation == null) {
                final String message = String.format(Messages.getString("FlowRelationshipCalcOperation.0"), //$NON-NLS-1$
                        flowRel.getName());
                throw new CoreException(
                        new Status(IStatus.ERROR, KalypsoModel1D2DPlugin.PLUGIN_ID, message, null)); //$NON-NLS-1$
            }

            // HACK: we set a scale here in order to get a right comparison with the station value that was read from the
            // profile. if a rounded station value occurs in the flow relation, the result of the comparison is always
            // false, because the station value of the flow relation gets rounded and the one of the profile gets not
            // rounded (read from string with fixed length).
            // TODO: implement the right setting of the station value for the flow relation with a fixed scale of 4!
            final BigDecimal station = flowStation.setScale(4, BigDecimal.ROUND_HALF_UP);

            // FIXME: why do we use the station defined in the relation at all -> the calculation uses the station defined
            // in the profile anyways

            // REMARK: sometimes it could be, that the user wants to assign a profile to a new created flow relation. in
            // this case he is able to to this and to calculate the data, but the assignment will never happen, if the
            // station is not equal to the station of the assigned profile.
            if (ObjectUtils.equals(station, qresult.getStation()))
                return qresult;
        }

        final String message = Messages
                .getString("org.kalypso.kalypsomodel1d2d.ui.map.flowrel.FlowRelationshipCalcOperation.14"); //$NON-NLS-1$
        throw new CoreException(new Status(IStatus.ERROR, KalypsoModel1D2DPlugin.PLUGIN_ID, message));
    } catch (final InvocationTargetException e) {
        throw e;
    } catch (final GMLSchemaException e) {
        throw new InvocationTargetException(e);
    } catch (final IOException e) {
        throw new InvocationTargetException(e);
    } catch (final GmlSerializeException e) {
        throw new InvocationTargetException(e);
    } catch (final SimulationException e) {
        throw new InvocationTargetException(e);
    } catch (final GMLXPathException e) {
        throw new InvocationTargetException(e);
    } catch (final Exception e) {
        throw new InvocationTargetException(e);
    } finally {
        SimulationUtilitites.clearTmpDir(tmpDir);
    }
}