Example usage for javax.xml.bind JAXBException printStackTrace

List of usage examples for javax.xml.bind JAXBException printStackTrace

Introduction

In this page you can find the example usage for javax.xml.bind JAXBException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

Prints this JAXBException and its stack trace (including the stack trace of the linkedException if it is non-null) to System.err .

Usage

From source file:net.itransformers.postDiscoverer.core.ReportManager.java

public static void main(String[] args) throws IOException {

    File projectDir = new File(".");
    File scriptPath = new File("postDiscoverer/src/main/resources/postDiscoverer/conf/groovy/");

    ResourceManagerFactory resourceManagerFactory = new XmlResourceManagerFactory(
            "iDiscover/resourceManager/xmlResourceManager/src/main/resources/xmlResourceManager/conf/xml/resource.xml");
    Map<String, String> resourceManagerParams = new HashMap<>();
    resourceManagerParams.put("projectPath", projectDir.getAbsolutePath());
    ResourceManager resourceManager = resourceManagerFactory.createResourceManager("xml",
            resourceManagerParams);/*from   ww w  . j a va  2  s .  co  m*/

    Map<String, String> params = new HashMap<String, String>();
    params.put("protocol", "telnet");
    params.put("deviceName", "R1");
    params.put("deviceType", "CISCO");
    params.put("address", "10.17.1.5");
    params.put("port", "23");

    ResourceType resource = resourceManager.findFirstResourceBy(params);
    List connectParameters = resource.getConnectionParams();

    for (int i = 0; i < connectParameters.size(); i++) {
        ConnectionParamsType connParamsType = (ConnectionParamsType) connectParameters.get(i);

        String connectionType = connParamsType.getConnectionType();
        if (connectionType.equalsIgnoreCase(params.get("protocol"))) {

            for (ParamType param : connParamsType.getParam()) {
                params.put(param.getName(), param.getValue());
            }

        }
    }

    File postDiscoveryConfing = new File(
            projectDir + "/postDiscoverer/src/main/resources/postDiscoverer/conf/xml/reportGenerator.xml");
    if (!postDiscoveryConfing.exists()) {
        System.out.println("File missing: " + postDiscoveryConfing.getAbsolutePath());
        return;
    }

    ReportGeneratorType reportGenerator = null;

    FileInputStream is = new FileInputStream(postDiscoveryConfing);
    try {
        reportGenerator = JaxbMarshalar.unmarshal(ReportGeneratorType.class, is);
    } catch (JAXBException e) {
        logger.info(e); //To change body of catch statement use File | Settings | File Templates.
    } finally {
        is.close();
    }

    ReportManager reportManager = new ReportManager(reportGenerator, scriptPath.getPath(), projectDir,
            "postDiscoverer/conf/xslt/table_creator.xslt");
    StringBuffer report = null;

    HashMap<String, Object> groovyExecutorParams = new HashMap<String, Object>();

    for (String s : params.keySet()) {
        groovyExecutorParams.put(s, params.get(s));
    }

    try {
        report = reportManager.reportExecutor(
                new File("/Users/niau/Projects/Projects/netTransformer10/version1/post-discovery"),
                groovyExecutorParams);
    } catch (ParserConfigurationException e) {
        e.printStackTrace();
    } catch (SAXException e) {
        e.printStackTrace();
    }
    if (report != null) {
        System.out.println(report.toString());

    } else {
        System.out.println("Report generation failed!");

    }
}

From source file:de.prozesskraft.pkraft.Createdoc.java

public static void main(String[] args) throws org.apache.commons.cli.ParseException, IOException {

    Createdoc tmp = new Createdoc();
    /*----------------------------
      get options from ini-file//www. ja  v a2  s. c om
    ----------------------------*/
    File installDir = new java.io.File(WhereAmI.getInstallDirectoryAbsolutePath(Createdoc.class) + "/..");

    File inifile = new java.io.File(installDir.getAbsolutePath() + "/etc/pkraft-createdoc.ini");

    if (inifile.exists()) {
        try {
            ini = new Ini(inifile);
        } catch (InvalidFileFormatException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        } catch (IOException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
    } else {
        System.err.println("ini file does not exist: " + inifile.getAbsolutePath());
        System.exit(1);
    }

    /*----------------------------
      create boolean options
    ----------------------------*/
    Option ohelp = new Option("help", "print this message");
    Option ov = new Option("v", "prints version and build-date");

    /*----------------------------
      create argument options
    ----------------------------*/
    Option odefinition = OptionBuilder.withArgName("definition").hasArg()
            .withDescription("[mandatory] process definition file")
            //            .isRequired()
            .create("definition");

    Option oformat = OptionBuilder.withArgName("format").hasArg()
            .withDescription("[mandatory, default=pdf] output format (pdf|pptx) ").create("format");

    Option ooutput = OptionBuilder.withArgName("output").hasArg().withDescription(
            "[mandatory, default=out.<format>] output file with full documentation of process definition")
            //            .isRequired()
            .create("output");

    ////      Option property = OptionBuilder.withArgName( "property=value" )
    ////            .hasArgs(2)
    ////            .withValueSeparator()
    ////            .withDescription( "use value for given property" )
    ////            .create("D");
    //      
    //      /*----------------------------
    //        create options object
    //      ----------------------------*/
    Options options = new Options();

    options.addOption(ohelp);
    options.addOption(ov);
    options.addOption(odefinition);
    options.addOption(oformat);
    options.addOption(ooutput);

    /*----------------------------
      create the parser
    ----------------------------*/
    CommandLineParser parser = new GnuParser();
    // parse the command line arguments
    line = parser.parse(options, args);

    /*----------------------------
      usage/help
    ----------------------------*/
    if (line.hasOption("help")) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("createdoc", options);
        System.exit(0);
    }

    if (line.hasOption("v")) {
        System.out.println("web:     www.prozesskraft.de");
        System.out.println("version: [% version %]");
        System.out.println("date:    [% date %]");
        System.exit(0);
    }

    /*----------------------------
      die variablen festlegen
    ----------------------------*/
    int error = 0;
    String definition = null;
    String format = null;
    String output = null;

    // festlegen von definition
    if (line.hasOption("definition")) {
        definition = line.getOptionValue("definition");
        if (!(new java.io.File(definition).exists())) {
            System.err.println("file does not exist " + definition);
        }
    } else {
        System.err.println("parameter -definition is mandatory");
        error++;
    }

    // festlegen von format
    if (line.hasOption("format")) {
        if (line.getOptionValue("format").matches("pdf|pptx")) {
            format = line.getOptionValue("format");
        } else {
            System.err.println("for -format use only pdf|pptx");
            error++;
        }
    } else {
        format = "pdf";
    }

    // festlegen von output
    if (line.hasOption("output")) {
        output = line.getOptionValue("output");
    } else {
        output = "out." + format;
    }

    // feststellen ob output bereits existiert
    if (new java.io.File(output).exists()) {
        System.err.println("output already exists: " + output);
        error++;
    }

    // aussteigen, falls fehler aufgetaucht sind
    if (error > 0) {
        System.err.println("error(s) occured. try -help for help.");
        System.exit(1);
    }

    /*----------------------------
      die lizenz ueberpruefen und ggf abbrechen
    ----------------------------*/

    // check for valid license
    ArrayList<String> allPortAtHost = new ArrayList<String>();
    allPortAtHost.add(ini.get("license-server", "license-server-1"));
    allPortAtHost.add(ini.get("license-server", "license-server-2"));
    allPortAtHost.add(ini.get("license-server", "license-server-3"));

    MyLicense lic = new MyLicense(allPortAtHost, "1", "user-edition", "0.1");

    // lizenz-logging ausgeben
    for (String actLine : (ArrayList<String>) lic.getLog()) {
        System.err.println(actLine);
    }

    // abbruch, wenn lizenz nicht valide
    if (!lic.isValid()) {
        System.exit(1);
    }

    /*----------------------------
      die eigentliche business logic
    ----------------------------*/

    Process process = new Process();
    Reporter report;

    process.setInfilexml(definition);

    System.out.println("info: reading process definition " + definition);

    try {
        process.readXml();
        process.setStepRanks();
    }

    catch (JAXBException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    //festlegen des temporaeren verzeichnisses fuer die Daten und Pfade erzeugen
    long jetztMillis = System.currentTimeMillis();
    String randomPathJasperFilled = "/tmp/" + jetztMillis + "_jasperFilled";
    String randomPathPng = "/tmp/" + jetztMillis + "_png";
    String randomPathPdf = "/tmp/" + jetztMillis + "_pdf";
    String randomPathPptx = "/tmp/" + jetztMillis + "_pptx";

    new File(randomPathJasperFilled).mkdirs();
    new File(randomPathPng).mkdirs();
    new File(randomPathPdf).mkdirs();
    new File(randomPathPptx).mkdirs();

    //////////////////////////////////////////

    // erstellen der Bilder

    // konfigurieren der processing ansicht
    //      PmodelViewPage page = new PmodelViewPage(process);
    PmodelViewPage page = new PmodelViewPage();
    page.einstellungen.getProcess().setStepRanks();
    page.einstellungen.setSize(100);
    page.einstellungen.setZoom(100);
    //      page.einstellungen.setZoom(8 * 100/process.getMaxLevel());
    page.einstellungen.setTextsize(0);
    page.einstellungen.setRanksize(7);
    page.einstellungen.setWidth(2500);
    page.einstellungen.setHeight(750);
    page.einstellungen.setGravx(10);
    page.einstellungen.setGravy(0);
    page.einstellungen.setRootpositionratiox((float) 0.05);
    page.einstellungen.setRootpositionratioy((float) 0.5);
    page.einstellungen.setProcess(process);

    createContents(page);

    // mit open kann die page angezeigt werden
    if (!(produktiv)) {
        open();
    }

    //      // warten
    //      System.out.println("stabilisierung ansicht: 5 sekunden warten gravitation = "+page.einstellungen.getGravx());
    //      long jetzt5 = System.currentTimeMillis();
    //      while (System.currentTimeMillis() < jetzt5 + 5000)
    //      {
    //         
    //      }
    //
    //      page.einstellungen.setGravx(10);
    //
    // warten
    int wartezeitSeconds = 1;
    if (produktiv) {
        wartezeitSeconds = page.einstellungen.getProcess().getStep().size() * 2;
    }
    System.out.println("stabilisierung ansicht: " + wartezeitSeconds + " sekunden warten gravitation = "
            + page.einstellungen.getGravx());
    long jetzt6 = System.currentTimeMillis();
    while (System.currentTimeMillis() < jetzt6 + (wartezeitSeconds * 1000)) {

    }

    page.einstellungen.setFix(true);

    // VORBEREITUNG) bild speichern
    processTopologyImagePath = randomPathPng + "/processTopology.png";
    page.savePic(processTopologyImagePath);
    // zuerst 1 sekunde warten, dann autocrop
    long jetzt = System.currentTimeMillis();
    while (System.currentTimeMillis() < jetzt + 1000) {

    }
    new AutoCropBorder(processTopologyImagePath);

    // VORBEREITUNG) fuer jeden step ein bild speichern
    for (Step actualStep : process.getStep()) {

        // root ueberspringen
        //         if (actualStep.isRoot());

        String stepImagePath = randomPathPng + "/step_" + actualStep.getName() + "_Topology.png";

        // Farbe des Steps auf finished (gruen) aendern
        page.einstellungen.getProcess().getRootStep().setStatusOverwrite("waiting");
        actualStep.setStatusOverwrite("finished");

        // etwas warten, bis die farbe bezeichnet wurde
        long jetzt4 = System.currentTimeMillis();
        while (System.currentTimeMillis() < jetzt4 + 500) {

        }

        page.savePic(stepImagePath);
        // zuerst 1 sekunde warten, dann autocrop
        long jetzt3 = System.currentTimeMillis();
        while (System.currentTimeMillis() < jetzt3 + 1000) {

        }
        new AutoCropBorder(stepImagePath);

        stepTopologyImagePath.put(actualStep.getName(), stepImagePath);

        // farbe wieder auf grau aendern
        actualStep.setStatusOverwrite(null);

        System.out.println("erstelle bild fuer step: " + actualStep.getName());

        long jetzt2 = System.currentTimeMillis();
        while (System.currentTimeMillis() < jetzt2 + 1000) {

        }
    }

    page.destroy();

    //////////////////////////////////////////
    report = new Reporter();

    // P03) erstellen des p03
    System.out.println("info: generating p03.");

    String pdfPathP03 = null;
    String pptxPathP03 = null;
    String jasperPathP03 = null;
    String jasperFilledPathP03 = null;

    // P03) feststellen, welches jasperreports-template fuer den angeforderten typ verwendet werden soll
    if (ini.get("pkraft-createdoc", "p03") != null) {
        pdfPathP03 = randomPathPdf + "/p03.pdf";
        pptxPathP03 = randomPathPptx + "/p03.pptx";
        jasperPathP03 = installDir.getAbsolutePath() + "/" + ini.get("pkraft-createdoc", "p03");
        jasperFilledPathP03 = (randomPathJasperFilled + "/p03.jasperFilled");

        pdfRankFiles.put("0.0.03", pdfPathP03);
        pptxRankFiles.put("0.0.03", pptxPathP03);
    } else {
        System.err.println("no entry 'p03' found in ini file");
        System.exit(1);
    }

    DateFormat dateFormat = new SimpleDateFormat("dd. MM. yyyy");
    Date date = new Date();

    report.setParameter("processName", process.getName());
    report.setParameter("processVersion", process.getVersion());
    report.setParameter("processDatum", dateFormat.format(date));
    report.setParameter("processArchitectLogoImagePath",
            installDir.getAbsolutePath() + "/" + ini.get("pkraft-createdoc", "logo"));
    report.setParameter("processArchitectCompany", process.getArchitectCompany());
    report.setParameter("processArchitectName", process.getArchitectName());
    report.setParameter("processArchitectMail", process.getArchitectMail());
    report.setParameter("processCustomerCompany", process.getCustomerCompany());
    report.setParameter("processCustomerName", process.getCustomerName());
    report.setParameter("processCustomerMail", process.getCustomerMail());

    try {
        report.fillReportFileToFile(jasperPathP03, jasperFilledPathP03);
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (JRException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    // export to pdf
    try {
        report.convertFileToPdf(jasperFilledPathP03, pdfPathP03);
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (JRException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    // export to pptx
    try {
        report.convertFileToPptx(jasperFilledPathP03, pptxPathP03);
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (JRException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    report = null;

    //System.exit(0);

    //////////////////////////////////////////
    report = new Reporter();

    // P05) erstellen des p05
    System.out.println("info: generating p05.");

    String pdfPathP05 = null;
    String pptxPathP05 = null;
    String jasperPathP05 = null;
    String jasperFilledPathP05 = null;

    // P05) feststellen, welches jasperreports-template fuer den angeforderten typ verwendet werden soll
    if (ini.get("pkraft-createdoc", "p05") != null) {
        pdfPathP05 = randomPathPdf + "/p05.pdf";
        pptxPathP05 = randomPathPptx + "/p05.pptx";
        jasperPathP05 = installDir.getAbsolutePath() + "/" + ini.get("pkraft-createdoc", "p05");
        jasperFilledPathP05 = (randomPathJasperFilled + "/p05.jasperFilled");

        pdfRankFiles.put("0.0.05", pdfPathP05);
        pptxRankFiles.put("0.0.05", pptxPathP05);
    }

    else {
        System.err.println("no entry 'p05' found in ini file");
        System.exit(1);
    }

    report.setParameter("processName", process.getName());
    report.setParameter("processVersion", process.getVersion());
    report.setParameter("processArchitectCompany", process.getArchitectCompany());
    report.setParameter("processArchitectName", process.getArchitectName());
    report.setParameter("processArchitectMail", process.getArchitectMail());
    report.setParameter("processCustomerCompany", process.getCustomerCompany());
    report.setParameter("processCustomerName", process.getCustomerName());
    report.setParameter("processCustomerMail", process.getCustomerMail());

    try {
        report.fillReportFileToFile(jasperPathP05, jasperFilledPathP05);
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (JRException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    // export to pdf
    try {
        report.convertFileToPdf(jasperFilledPathP05, pdfPathP05);
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (JRException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    // export to pptx
    try {
        report.convertFileToPptx(jasperFilledPathP05, pptxPathP05);
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (JRException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    report = null;

    //System.exit(0);

    //////////////////////////////////////////
    report = new Reporter();

    // P08) erstellen des p08
    System.out.println("info: generating p08.");

    String pdfPathP08 = null;
    String pptxPathP08 = null;
    String jasperPathP08 = null;
    String jasperFilledPathP08 = null;

    // P08) feststellen, welches jasperreports-template fuer den angeforderten typ verwendet werden soll
    if (ini.get("pkraft-createdoc", "p08") != null) {
        pdfPathP08 = randomPathPdf + "/p08.pdf";
        pptxPathP08 = randomPathPptx + "/p08.pptx";
        jasperPathP08 = installDir.getAbsolutePath() + "/" + ini.get("pkraft-createdoc", "p08");
        jasperFilledPathP08 = (randomPathJasperFilled + "/p08.jasperFilled");

        pdfRankFiles.put("0.0.08", pdfPathP08);
        pptxRankFiles.put("0.0.08", pptxPathP08);
    } else {
        System.err.println("no entry 'p08' found in ini file");
        System.exit(1);
    }

    report.setParameter("processName", process.getName());
    report.setParameter("processVersion", process.getVersion());
    report.setParameter("processArchitectCompany", process.getArchitectCompany());
    report.setParameter("processArchitectName", process.getArchitectName());
    report.setParameter("processArchitectMail", process.getArchitectMail());
    report.setParameter("processCustomerCompany", process.getCustomerCompany());
    report.setParameter("processCustomerName", process.getCustomerName());
    report.setParameter("processCustomerMail", process.getCustomerMail());
    report.setParameter("processDescription", process.getDescription());

    try {
        report.fillReportFileToFile(jasperPathP08, jasperFilledPathP08);
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (JRException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    // export to pdf
    try {
        report.convertFileToPdf(jasperFilledPathP08, pdfPathP08);
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (JRException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    // export to pptx
    try {
        report.convertFileToPptx(jasperFilledPathP08, pptxPathP08);
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (JRException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    report = null;

    //System.exit(0);

    //////////////////////////////////////////

    report = new Reporter();

    // P10) erstellen des p10
    System.out.println("info: generating p10.");

    String pdfPathP10 = null;
    String pptxPathP10 = null;
    String jasperPathP10 = null;
    String jasperFilledPathP10 = null;

    // P10) feststellen, welches jasperreports-template fuer den angeforderten typ verwendet werden soll
    if (ini.get("pkraft-createdoc", "p10") != null) {
        pdfPathP10 = randomPathPdf + "/p10.pdf";
        pptxPathP10 = randomPathPptx + "/p10.pptx";
        jasperPathP10 = installDir.getAbsolutePath() + "/" + ini.get("pkraft-createdoc", "p10");
        jasperFilledPathP10 = (randomPathJasperFilled + "/p10.jasperFilled");

        pdfRankFiles.put("0.0.10", pdfPathP10);
        pptxRankFiles.put("0.0.10", pptxPathP10);
    } else {
        System.err.println("no entry 'p10' found in ini file");
        System.exit(1);
    }

    report.setParameter("processName", process.getName());
    report.setParameter("processVersion", process.getVersion());
    report.setParameter("processArchitectCompany", process.getArchitectCompany());
    report.setParameter("processArchitectName", process.getArchitectName());
    report.setParameter("processArchitectMail", process.getArchitectMail());
    report.setParameter("processCustomerCompany", process.getCustomerCompany());
    report.setParameter("processCustomerName", process.getCustomerName());
    report.setParameter("processCustomerMail", process.getCustomerMail());

    // rootstep holen
    Step rootStep = process.getStep(process.getRootstepname());

    // ueber alle commit iterieren
    for (Commit actualCommit : rootStep.getCommit()) {

        // ueber alle files iterieren
        for (de.prozesskraft.pkraft.File actualFile : actualCommit.getFile()) {
            HashMap<String, Object> row = new HashMap<String, Object>();

            // Spalte 'origin'
            row.put("origin", "user/cb2");

            // Spalte 'objectType'
            row.put("objectType", "file");

            // Spalte 'minOccur'
            row.put("minOccur", "" + actualFile.getMinoccur());

            // Spalte 'maxOccur'
            row.put("maxOccur", "" + actualFile.getMaxoccur());

            // Spalte 'objectKey'
            row.put("objectKey", actualFile.getKey());

            // die steps herausfinden, die dieses file benoetigen
            ArrayList<Step> allStepsThatNeedThisFileFromRoot = process.getStepWhichNeedFromRoot("file",
                    actualFile.getKey());
            String stepnameListe = "";
            for (Step actStep : allStepsThatNeedThisFileFromRoot) {
                stepnameListe += "\n=> " + actStep.getName();
            }

            // Spalte 'objectDescription'
            row.put("objectDescription", actualFile.getDescription() + stepnameListe);

            // Datensatz dem report hinzufuegen
            report.addField(row);
        }

        // ueber alle variablen iterieren
        for (de.prozesskraft.pkraft.Variable actualVariable : actualCommit.getVariable()) {
            HashMap<String, Object> row = new HashMap<String, Object>();

            // Spalte 'origin'
            row.put("origin", "user/cb2");

            // Spalte 'objectType'
            row.put("objectType", "variable");

            // Spalte 'minOccur'
            row.put("minOccur", "" + actualVariable.getMinoccur());

            // Spalte 'maxOccur'
            row.put("maxOccur", "" + actualVariable.getMaxoccur());

            // Spalte 'objectKey'
            row.put("objectKey", actualVariable.getKey());

            // die steps herausfinden, die dieses file benoetigen
            ArrayList<Step> allStepsThatNeedThisObjectFromRoot = process.getStepWhichNeedFromRoot("variable",
                    actualVariable.getKey());
            String stepnameListe = "";
            for (Step actStep : allStepsThatNeedThisObjectFromRoot) {
                stepnameListe += "\n=> " + actStep.getName();
            }

            // Spalte 'objectDescription'
            row.put("objectDescription", actualVariable.getDescription() + stepnameListe);

            // Datensatz dem report hinzufuegen
            report.addField(row);
        }

    }

    try {
        report.fillReportFileToFile(jasperPathP10, jasperFilledPathP10);
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (JRException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    // export to pdf
    try {
        report.convertFileToPdf(jasperFilledPathP10, pdfPathP10);
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (JRException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    // export to pptx
    try {
        report.convertFileToPptx(jasperFilledPathP10, pptxPathP10);
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (JRException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    report = null;

    //////////////////////////////////////////

    report = new Reporter();

    // P20) erstellen des p20
    System.out.println("info: generating p20.");

    String pdfPathP20 = null;
    String pptxPathP20 = null;
    String jasperPathP20 = null;
    String jasperFilledPathP20 = null;

    // P20) feststellen, welches jasperreports-template fuer den angeforderten typ verwendet werden soll
    if (ini.get("pkraft-createdoc", "p20") != null) {
        pdfPathP20 = randomPathPdf + "/p20.pdf";
        pptxPathP20 = randomPathPptx + "/p20.pptx";
        jasperPathP20 = installDir.getAbsolutePath() + "/" + ini.get("pkraft-createdoc", "p20");
        jasperFilledPathP20 = (randomPathJasperFilled + "/p20.jasperFilled");

        pdfRankFiles.put("0.0.20", pdfPathP20);
        pptxRankFiles.put("0.0.20", pptxPathP20);
    } else {
        System.err.println("no entry 'p20' found in ini file");
        System.exit(1);
    }

    report.setParameter("processName", process.getName());
    report.setParameter("processVersion", process.getVersion());
    report.setParameter("processArchitectCompany", process.getArchitectCompany());
    report.setParameter("processArchitectName", process.getArchitectName());
    report.setParameter("processArchitectMail", process.getArchitectMail());
    report.setParameter("processCustomerCompany", process.getCustomerCompany());
    report.setParameter("processCustomerName", process.getCustomerName());
    report.setParameter("processCustomerMail", process.getCustomerMail());

    // ueber alle steps iterieren (ausser root)
    for (Step actualStep : (ArrayList<Step>) process.getStep()) {

        // ueberspringen wenn es sich um root handelt
        if (!(actualStep.getName().equals(process.getRootstepname()))) {
            // ueber alle commit iterieren
            for (Commit actualCommit : actualStep.getCommit()) {

                // nur die, die toroot=true ( und spaeter auch tosdm=true)
                if (actualCommit.isTorootPresent()) {
                    // ueber alle files iterieren
                    for (de.prozesskraft.pkraft.File actualFile : actualCommit.getFile()) {

                        HashMap<String, Object> row = new HashMap<String, Object>();

                        // Spalte 'destination'
                        row.put("destination", "user/cb2");

                        // Spalte 'objectType'
                        row.put("objectType", "file");

                        // Spalte 'minOccur'
                        row.put("minOccur", "" + actualFile.getMinoccur());

                        // Spalte 'maxOccur'
                        row.put("maxOccur", "" + actualFile.getMaxoccur());

                        // Spalte 'objectKey'
                        row.put("objectKey", actualFile.getKey());

                        // Spalte 'objectDescription'
                        row.put("objectDescription",
                                actualFile.getDescription() + "\n<= " + actualStep.getName());

                        // Datensatz dem report hinzufuegen
                        report.addField(row);
                    }

                    // ueber alle variablen iterieren
                    for (de.prozesskraft.pkraft.Variable actualVariable : actualCommit.getVariable()) {
                        HashMap<String, Object> row = new HashMap<String, Object>();

                        // Spalte 'objectType'
                        row.put("destination", "user/cb2");

                        // Spalte 'objectType'
                        row.put("objectType", "variable");

                        // Spalte 'minOccur'
                        row.put("minOccur", "" + actualVariable.getMinoccur());

                        // Spalte 'maxOccur'
                        row.put("maxOccur", "" + actualVariable.getMaxoccur());

                        // Spalte 'objectKey'
                        row.put("objectKey", actualVariable.getKey());

                        // Spalte 'objectDescription'
                        row.put("objectDescription",
                                actualVariable.getDescription() + "\n<= " + actualStep.getName());

                        // Datensatz dem report hinzufuegen
                        report.addField(row);
                    }
                }
            }
        }

    }

    try {
        report.fillReportFileToFile(jasperPathP20, jasperFilledPathP20);
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (JRException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    // export to pdf
    try {
        report.convertFileToPdf(jasperFilledPathP20, pdfPathP20);
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (JRException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    // export to pptx
    try {
        report.convertFileToPptx(jasperFilledPathP20, pptxPathP20);
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (JRException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    report = null;

    //////////////////////////////////////////

    report = new Reporter();

    // P30) erstellen des p30
    System.out.println("info: generating p30.");

    String pdfPathP30 = null;
    String pptxPathP30 = null;
    String jasperPathP30 = null;
    String jasperFilledPathP30 = null;

    // P30) feststellen, welches jasperreports-template fuer den angeforderten typ verwendet werden soll
    if (ini.get("pkraft-createdoc", "p30") != null) {
        pdfPathP30 = randomPathPdf + "/p30.pdf";
        pptxPathP30 = randomPathPptx + "/p30.pptx";
        jasperPathP30 = installDir.getAbsolutePath() + "/" + ini.get("pkraft-createdoc", "p30");
        jasperFilledPathP30 = (randomPathJasperFilled + "/p30.jasperFilled");

        pdfRankFiles.put("0.0.30", pdfPathP30);
        pptxRankFiles.put("0.0.30", pptxPathP30);
    } else {
        System.err.println("no entry 'p30' found in ini file");
        System.exit(1);
    }

    report.setParameter("processName", process.getName());
    report.setParameter("processVersion", process.getVersion());
    report.setParameter("processArchitectCompany", process.getArchitectCompany());
    report.setParameter("processArchitectName", process.getArchitectName());
    report.setParameter("processArchitectMail", process.getArchitectMail());
    report.setParameter("processCustomerCompany", process.getCustomerCompany());
    report.setParameter("processCustomerName", process.getCustomerName());
    report.setParameter("processCustomerMail", process.getCustomerMail());

    // P1) bild an report melden
    report.setParameter("processTopologyImagePath", processTopologyImagePath);

    try {
        report.fillReportFileToFile(jasperPathP30, jasperFilledPathP30);
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (JRException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    // export to pdf
    try {
        report.convertFileToPdf(jasperFilledPathP30, pdfPathP30);
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (JRException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    // export to pptx
    try {
        report.convertFileToPptx(jasperFilledPathP30, pptxPathP30);
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (JRException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    report = null;

    //      System.exit(0);
    //////////////////////////////////////////

    report = new Reporter();

    // P40) erstellen des p40
    System.out.println("info: generating p40.");

    String pdfPathP40 = null;
    String pptxPathP40 = null;
    String jasperPathP40 = null;
    String jasperFilledPathP40 = null;

    // P40) feststellen, welches jasperreports-template fuer den angeforderten typ verwendet werden soll
    if (ini.get("pkraft-createdoc", "p40") != null) {
        pdfPathP40 = randomPathPdf + "/p40.pdf";
        pptxPathP40 = randomPathPptx + "/p40.pptx";
        jasperPathP40 = installDir.getAbsolutePath() + "/" + ini.get("pkraft-createdoc", "p40");
        jasperFilledPathP40 = (randomPathJasperFilled + "/p40.jasperFilled");

        pdfRankFiles.put("0.0.40", pdfPathP40);
        pptxRankFiles.put("0.0.40", pptxPathP40);
    } else {
        System.err.println("no entry 'p40' found in ini file");
        System.exit(1);
    }

    report.setParameter("processName", process.getName());
    report.setParameter("processVersion", process.getVersion());
    report.setParameter("processArchitectCompany", process.getArchitectCompany());
    report.setParameter("processArchitectName", process.getArchitectName());
    report.setParameter("processArchitectMail", process.getArchitectMail());
    report.setParameter("processCustomerCompany", process.getCustomerCompany());
    report.setParameter("processCustomerName", process.getCustomerName());
    report.setParameter("processCustomerMail", process.getCustomerMail());

    // P40) bild an report melden
    report.setParameter("processTopologyImagePath", processTopologyImagePath);

    // Tabelle erzeugen

    ArrayList<Step> steps = process.getStep();
    for (int x = 0; x < steps.size(); x++) {
        HashMap<String, Object> row = new HashMap<String, Object>();
        Step actualStep = steps.get(x);

        // erste Spalte ist 'rank'
        // um die korrekte sortierung zu erhalten soll der rank-string auf jeweils 2 Stellen erweitert werden
        String[] rankArray = actualStep.getRank().split("\\.");
        Integer[] rankArrayInt = new Integer[rankArray.length];
        for (int y = 0; y < rankArray.length; y++) {
            rankArrayInt[y] = Integer.parseInt(rankArray[y]);
        }
        String rankFormated = String.format("%02d.%02d", rankArrayInt);
        row.put("stepRank", rankFormated);

        // zweite Spalte ist 'stepname'
        row.put("stepName", actualStep.getName());
        //            System.out.println("stepName: "+actualStep.getName());

        // dritte Spalte ist 'Beschreibung'
        row.put("stepDescription", actualStep.getDescription());
        //            System.out.println("stepRank: "+actualStep.getDescription());

        // wenn nicht der root-step, dann row eintragen
        if (!(actualStep.getName().equals(process.getRootstepname()))) {
            report.addField(row);
        }
    }

    try {
        report.fillReportFileToFile(jasperPathP40, jasperFilledPathP40);
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (JRException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    // export to pdf
    try {
        report.convertFileToPdf(jasperFilledPathP40, pdfPathP40);
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (JRException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    // export to pptx
    try {
        report.convertFileToPptx(jasperFilledPathP40, pptxPathP40);
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (JRException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    report = null;

    //////////////////////////////////////////

    // fuer jeden Step einen eigenen Input Report erzeugen

    for (Step actualStep : process.getStep()) {
        // root-step ueberspringen
        if (actualStep.getName().equals(process.getRootstepname())) {
            System.out.println("skipping step root");
        }

        // alle anderen auswerten
        else {

            report = new Reporter();

            // P51x) erstellen des p51
            System.out.println(
                    "info: generating p51 for step " + actualStep.getRank() + " => " + actualStep.getName());

            String stepRank = actualStep.getRank();

            String pdfPathP51 = null;
            String pptxPathP51 = null;
            String jasperPathP51 = null;
            String jasperFilledPathP51 = null;

            // P51x) feststellen, welches jasperreports-template fuer den angeforderten typ verwendet werden soll
            if (ini.get("pkraft-createdoc", "p51") != null) {
                pdfPathP51 = randomPathPdf + "/p5." + stepRank + ".1.pdf";
                pptxPathP51 = randomPathPptx + "/p5." + stepRank + ".1.pptx";
                jasperPathP51 = installDir.getAbsolutePath() + "/" + ini.get("pkraft-createdoc", "p51");
                jasperFilledPathP51 = randomPathJasperFilled + "/p5." + stepRank + ".1.jasperFilled";

                String[] rankArray = stepRank.split("\\.");
                Integer[] rankArrayInt = new Integer[rankArray.length];
                for (int x = 0; x < rankArray.length; x++) {
                    rankArrayInt[x] = Integer.parseInt(rankArray[x]);
                }
                String rankFormated = String.format("%03d.%03d", rankArrayInt);

                pdfRankFiles.put(rankFormated + ".1", pdfPathP51);
                pptxRankFiles.put(rankFormated + ".1", pptxPathP51);
            } else {
                System.err.println("no entry 'p51' found in ini file");
                System.exit(1);
            }

            report.setParameter("processName", process.getName());
            report.setParameter("processVersion", process.getVersion());
            report.setParameter("processArchitectCompany", process.getArchitectCompany());
            report.setParameter("processArchitectName", process.getArchitectName());
            report.setParameter("processArchitectMail", process.getArchitectMail());
            report.setParameter("processCustomerCompany", process.getCustomerCompany());
            report.setParameter("processCustomerName", process.getCustomerName());
            report.setParameter("processCustomerMail", process.getCustomerMail());

            report.setParameter("stepName", actualStep.getName());
            report.setParameter("stepRank", stepRank);
            report.setParameter("stepDescription", actualStep.getDescription());

            String aufruf = "";
            if (actualStep.getWork() != null) {
                // zusammensetzen des scriptaufrufs
                String interpreter = "";

                if (actualStep.getWork().getInterpreter() != null) {
                    interpreter = actualStep.getWork().getInterpreter();
                }

                aufruf = interpreter + " " + actualStep.getWork().getCommand();
                for (Callitem actualCallitem : actualStep.getWork().getCallitem()) {
                    aufruf += " " + actualCallitem.getPar();
                    if (!(actualCallitem.getDel() == null)) {
                        aufruf += actualCallitem.getDel();
                    }
                    if (!(actualCallitem.getVal() == null)) {
                        aufruf += actualCallitem.getVal();
                    }
                }
            } else if (actualStep.getSubprocess() != null) {
                aufruf = ini.get("apps", "pkraft-startinstance");
                aufruf += " --pdomain " + actualStep.getSubprocess().getDomain();
                aufruf += " --pname " + actualStep.getSubprocess().getName();
                aufruf += " --pversion " + actualStep.getSubprocess().getVersion();

                for (Commit actCommit : actualStep.getSubprocess().getStep().getCommit()) {
                    for (de.prozesskraft.pkraft.File actFile : actCommit.getFile()) {
                        aufruf += " --commitfile " + actFile.getGlob();
                    }
                    for (Variable actVariable : actCommit.getVariable()) {
                        aufruf += " --commitvariable " + actVariable.getKey() + "=" + actVariable.getValue();
                    }
                }
            }
            report.setParameter("stepWorkCall", aufruf);

            // P51x) bild an report melden
            report.setParameter("stepTopologyImagePath", stepTopologyImagePath.get(actualStep.getName()));

            // ueber alle lists iterieren
            for (List actualList : actualStep.getList()) {
                HashMap<String, Object> row = new HashMap<String, Object>();

                // Spalte 'Woher?'
                row.put("origin", "-");

                // Spalte 'typ'
                row.put("objectType", "wert");

                // Spalte 'minOccur'
                row.put("minOccur", "-");

                // Spalte 'maxOccur'
                row.put("maxOccur", "-");

                // Spalte 'Label'
                row.put("objectKey", actualList.getName());

                // Spalte 'Label'
                String listString = actualList.getItem().toString();
                row.put("objectDescription", listString.substring(1, listString.length() - 1));

                report.addField(row);
            }

            // ueber alle inits iterieren
            for (Init actualInit : actualStep.getInit()) {
                HashMap<String, Object> row = new HashMap<String, Object>();

                // Spalte 'Woher?'
                if (actualInit.getFromstep().equals(process.getRootstepname())) {
                    row.put("origin", "user/cb2");
                } else {
                    row.put("origin", actualInit.getFromstep());
                }

                // Spalte 'typ'
                row.put("objectType", actualInit.getFromobjecttype());

                // Spalte 'minOccur'
                row.put("minOccur", "" + actualInit.getMinoccur());

                // Spalte 'maxOccur'
                row.put("maxOccur", "" + actualInit.getMaxoccur());

                // Spalte 'Label'
                row.put("objectKey", actualInit.getListname());

                // Spalte 'Label'
                row.put("objectDescription", "-");

                report.addField(row);
            }

            try {
                report.fillReportFileToFile(jasperPathP51, jasperFilledPathP51);
            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (JRException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

            // export to pdf
            try {
                report.convertFileToPdf(jasperFilledPathP51, pdfPathP51);
            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (JRException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

            // export to pptx
            try {
                report.convertFileToPptx(jasperFilledPathP51, pptxPathP51);
            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (JRException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

            report = null;
        }
    }

    //////////////////////////////////////////

    // fuer jeden Step einen eigenen Output Report erzeugen

    for (Step actualStep : process.getStep()) {
        // root-step ueberspringen
        if (actualStep.getName().equals(process.getRootstepname())) {
            System.out.println("skipping step root");
        }

        // alle anderen auswerten
        else {

            report = new Reporter();

            // P52x) erstellen des p52
            System.out.println(
                    "info: generating p52 for step " + actualStep.getRank() + " => " + actualStep.getName());

            String stepRank = actualStep.getRank();

            String pdfPathP52 = null;
            String pptxPathP52 = null;
            String jasperPathP52 = null;
            String jasperFilledPathP52 = null;

            // P52x) feststellen, welches jasperreports-template fuer den angeforderten typ verwendet werden soll
            if (ini.get("pkraft-createdoc", "p52") != null) {
                pdfPathP52 = randomPathPdf + "/p5." + stepRank + ".2.pdf";
                pptxPathP52 = randomPathPptx + "/p5." + stepRank + ".2.pptx";
                jasperPathP52 = installDir.getAbsolutePath() + "/" + ini.get("pkraft-createdoc", "p52");
                jasperFilledPathP52 = randomPathJasperFilled + "/p5." + stepRank + ".1.jasperFilled";

                String[] rankArray = stepRank.split("\\.");
                Integer[] rankArrayInt = new Integer[rankArray.length];
                for (int x = 0; x < rankArray.length; x++) {
                    rankArrayInt[x] = Integer.parseInt(rankArray[x]);
                }
                String rankFormated = String.format("%03d.%03d", rankArrayInt);

                pdfRankFiles.put(rankFormated + ".2", pdfPathP52);
                pptxRankFiles.put(rankFormated + ".2", pptxPathP52);
            } else {
                System.err.println("no entry 'p52' found in ini file");
                System.exit(1);
            }

            report.setParameter("processName", process.getName());
            report.setParameter("processVersion", process.getVersion());
            report.setParameter("processArchitectCompany", process.getArchitectCompany());
            report.setParameter("processArchitectName", process.getArchitectName());
            report.setParameter("processArchitectMail", process.getArchitectMail());
            report.setParameter("processCustomerCompany", process.getCustomerCompany());
            report.setParameter("processCustomerName", process.getCustomerName());
            report.setParameter("processCustomerMail", process.getCustomerMail());

            report.setParameter("stepName", actualStep.getName());
            report.setParameter("stepRank", stepRank);

            // logfile ermitteln
            String logfile = "-";
            if (actualStep.getWork() != null) {
                if (actualStep.getWork().getLogfile() == null || actualStep.getWork().getLogfile().equals("")) {
                    report.setParameter("stepWorkLogfile", actualStep.getWork().getLogfile());
                }
            } else if (actualStep.getSubprocess() != null) {
                logfile = ".log";
            }
            report.setParameter("stepWorkLogfile", logfile);

            // zusammensetzen der return/exitcode informationen
            String exitInfo = "exit 0 = kein fehler aufgetreten";
            exitInfo += "\nexit >0 = ein fehler ist aufgetreten.";
            if (actualStep.getWork() != null) {
                for (Exit actualExit : actualStep.getWork().getExit()) {
                    exitInfo += "\nexit " + actualExit.getValue() + " = " + actualExit.getMsg();
                }
            }
            report.setParameter("stepWorkExit", exitInfo);

            // P52x) bild an report melden
            report.setParameter("stepTopologyImagePath", stepTopologyImagePath.get(actualStep.getName()));

            // ueber alle inits iterieren
            for (Commit actualCommit : actualStep.getCommit()) {

                // ueber alle files iterieren
                for (de.prozesskraft.pkraft.File actualFile : actualCommit.getFile()) {

                    HashMap<String, Object> row = new HashMap<String, Object>();

                    // Spalte 'destination'
                    if (actualCommit.isTorootPresent()) {
                        row.put("destination", "user/cb2");
                    } else {
                        row.put("destination", "prozessintern");
                    }

                    // Spalte 'objectType'
                    row.put("objectType", "file");

                    // Spalte 'minOccur'
                    row.put("minOccur", "" + actualFile.getMinoccur());

                    // Spalte 'maxOccur'
                    row.put("maxOccur", "" + actualFile.getMaxoccur());

                    // Spalte 'objectKey'
                    row.put("objectKey", actualFile.getKey());

                    // Spalte 'objectDescription'
                    row.put("objectDescription", actualFile.getDescription());

                    // Datensatz dem report hinzufuegen
                    report.addField(row);
                }

                // ueber alle variablen iterieren
                for (de.prozesskraft.pkraft.Variable actualVariable : actualCommit.getVariable()) {
                    HashMap<String, Object> row = new HashMap<String, Object>();

                    // Spalte 'destination'
                    if (actualCommit.isTorootPresent()) {
                        row.put("destination", "user/cb2");
                    } else {
                        row.put("destination", "prozessintern");
                    }

                    // Spalte 'objectType'
                    row.put("objectType", "variable");

                    // Spalte 'minOccur'
                    row.put("minOccur", "" + actualVariable.getMinoccur());

                    // Spalte 'maxOccur'
                    row.put("maxOccur", "" + actualVariable.getMaxoccur());

                    // Spalte 'objectKey'
                    row.put("objectKey", actualVariable.getKey());

                    // Spalte 'objectDescription'
                    row.put("objectDescription", actualVariable.getDescription());

                    // Datensatz dem report hinzufuegen
                    report.addField(row);
                }

            }
            try {
                report.fillReportFileToFile(jasperPathP52, jasperFilledPathP52);
            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (JRException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

            // export to pdf
            try {
                report.convertFileToPdf(jasperFilledPathP52, pdfPathP52);
            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (JRException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

            // export to pptx
            try {
                report.convertFileToPptx(jasperFilledPathP52, pptxPathP52);
            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (JRException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

            report = null;
        }
    }

    // warten bis alles auf platte geschrieben ist
    try {
        Thread.sleep(1000);
    } catch (InterruptedException ex) {
        Thread.currentThread().interrupt();
    }

    // merge and output
    if (format.equals("pdf")) {
        mergePdf(pdfRankFiles, output);
    } else if (format.equals("pptx")) {
        mergePptx(pptxRankFiles, output);
    }

    System.out.println("info: generating process documentation ready.");
    System.exit(0);
}

From source file:Main.java

public final static void save(Object object, String path) {
    try {//  www  .ja  v a 2  s . c om
        File file = new File(path);
        JAXBContext jaxbContext = JAXBContext.newInstance(object.getClass());
        Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
        jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        jaxbMarshaller.marshal(object, file);
    } catch (JAXBException e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public final static Object load(Class clazz, String name) {
    try {//from   w  w  w .j  ava 2  s.co m
        File file = new File(name);
        JAXBContext jaxbContext = JAXBContext.newInstance(clazz);
        Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
        return jaxbUnmarshaller.unmarshal(file);
    } catch (JAXBException e) {
        e.printStackTrace();
        return null;
    }
}

From source file:Main.java

@SuppressWarnings("rawtypes")
public static Object unmarshal(String xmlBody, Class objectClass) {
    try {//ww  w. ja  v  a 2s  .  c o m
        JAXBContext context = JAXBContext.newInstance(objectClass);
        Unmarshaller u = context.createUnmarshaller();
        return u.unmarshal(new StreamSource(new StringReader(xmlBody)));
    } catch (JAXBException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:Main.java

public static <T> T asObject(String xml, Class<T> clazz) {
    try {//  ww w  . ja v  a 2s .  c o  m
        JAXBContext jaxbContext = null;
        jaxbContext = JAXBContext.newInstance(clazz);
        Unmarshaller unmarshaller = null;
        unmarshaller = jaxbContext.createUnmarshaller();
        return (T) unmarshaller.unmarshal(new StringReader(xml));
    } catch (JAXBException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:Main.java

@SuppressWarnings("unchecked")
public static <T> T xml2obj(String xml, Class<T> type) {
    T obj = null;/*w  w  w  .  ja  va 2  s  .  c o m*/
    try {
        JAXBContext context = JAXBContext.newInstance(type);
        Unmarshaller unmarshaller = context.createUnmarshaller();
        obj = (T) unmarshaller.unmarshal(new StringReader(xml));
    } catch (JAXBException e) {
        e.printStackTrace();
    }
    return obj;
}

From source file:Main.java

@SuppressWarnings("unchecked")
public static Object convertXmlStringToObject(String xml, Class clazz) {
    Object object = null;/*  www. ja  v a 2  s. c o m*/
    try {
        JAXBContext context = JAXBContext.newInstance(clazz);
        Unmarshaller unmarshaller = context.createUnmarshaller();
        StringReader xmlReader = new StringReader(xml);
        object = unmarshaller.unmarshal(xmlReader);
    } catch (JAXBException e) {
        e.printStackTrace();
    }
    return object;
}

From source file:Main.java

public static Object fromXml(@SuppressWarnings("rawtypes") Class clazz, String stringXml) {
    JAXBContext context = null;//  w ww  .  j  a v a  2  s  .c  o  m
    try {
        context = JAXBContext.newInstance(clazz);
        Unmarshaller unmarshaller = context.createUnmarshaller();
        return unmarshaller.unmarshal(new StreamSource(new StringReader(stringXml)));
    } catch (JAXBException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:Main.java

public static String beanToXml(ByteArrayOutputStream out, Object to) {
    try {//from  ww  w .  j  a va2 s  . c  om
        JAXBContext context = JAXBContext.newInstance(to.getClass());
        Marshaller marshaller = context.createMarshaller();
        marshaller.marshal(to, out);
        return new String(out.toByteArray(), "UTF-8");
    } catch (JAXBException e) {
        e.printStackTrace();
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    return null;
}