Meaningless Drivel is fun!*
The moose likes Beginning Java and the fly likes Try, Catch Throw Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Try, Catch Throw" Watch "Try, Catch Throw" New topic
Author

Try, Catch Throw

Rohith Anabheri
Greenhorn

Joined: Oct 22, 2007
Posts: 1
Hi der!,
Good day!, I am pretty new to java and would like to know little more about this IO exception here,
This si the following code I am working on and the excetion just trigger an email with report failed but I would like to know why the report has failed, If any of you java ppl could help, your help is much appreciated.
This is the piece of code:

***************************************************
String status = bean.getStatus();
if( ! status.startsWith("OK") ) {
throw new Exception( "Report failed: " + status );
}
******************************************************
Detailed code is the following:

**********************************************************************************************
package pfe.server;

import java.util.*;
import jet.bean.*;
import java.io.*;
//import ibt.util.*;

/**
*

*
* Title:

*
* Description:

*
* Copyright: Copyright (c) 2001

*
* Company:
*
*@author unascribed
*@created July 4, 2002
*@version 1.0
*/

public class JReportBeanController {
//Constants as defined by the JReports application for the various file types
static int HTML = 1;
static int PDF = 2;
static int TEXT = 3;
static int EXCEL = 4;
static int RTF = 6;
static int XML = 7;

private JREngine bean = null;

private static String TMP_PREFIX = "rpt";
private static String PARAMETER_DELIMITER = ",";

private String uid;
private String key;
private String reportHome;
private String logFile;
private int logLevel = 0;
private String reportLocation;
private String tmpLocation;
private String reportName;
private String reportFormat;
private String reportSuffix;
private String catalogName;
private String dbUsername;
private String dbPassword;
private Map reportParameters;

/**
* Constructor for the JReportBeanController object
*
*@exception Exception Description of the Exception
*/
public JReportBeanController() throws Exception { }

/**
* Description of the Method
*
*@exception Exception Description of the Exception
*/
public void initialise() throws Exception {
// try{
//
// } catch(Exception e){
// e.printStackTrace();
// throw e;
// }
}

/**
* Sets the uID attribute of the JReportBeanController object
*
*@param newUid The new uID value
*/
public void setUID(String newUid) {
uid = newUid;
}

/**
* Sets the key attribute of the JReportBeanController object
*
*@param newKey The new key value
*/
public void setKey(String newKey) {
key = newKey;
}

/**
* Sets the reportHome attribute of the JReportBeanController object
*
*@param home The new reportHome value
*/
public void setReportHome(String home) {
reportHome = home;
}

/**
* Sets the reportLocation attribute of the JReportBeanController object
*
*@param location The new reportLocation value
*/
public void setReportLocation(String location) {
reportLocation = location;
}

/**
* Sets the temporaryLocation attribute of the JReportBeanController object
*
*@param temp The new temporaryLocation value
*/
public void setTemporaryLocation(String temp) {
tmpLocation = temp;
}

/**
* Sets the reportName attribute of the JReportBeanController object
*
*@param name The new reportName value
*/
public void setReportName(String name) {
reportName = name;
}

/**
* Sets the reportFormat attribute of the JReportBeanController object
*
*@param format The new reportFormat value
*/
public void setReportFormat(String format) {
reportFormat = format;
}

public void setLogFile(String log){
logFile = log;
}

public void setLogLevel(String level){
if (level == null) logLevel = 0;
else logLevel = Integer.parseInt(level);
}
/**
* Sets the catalogName attribute of the JReportBeanController object
*
*@param name The new catalogName value
*/
public void setCatalogName(String name) {
catalogName = name;
}

/**
* Sets the dBUsername attribute of the JReportBeanController object
*
*@param user The new dBUsername value
*/
public void setDBUsername(String user) {
dbUsername = user;
}

/**
* Sets the dBPassword attribute of the JReportBeanController object
*
*@param password The new dBPassword value
*/
public void setDBPassword(String password) {
dbPassword = password;
}

/**
* Sets the parameters attribute of the JReportBeanController object
*
*@param parameters The new parameters value
*/
public void setParameters(Map parameters) {
reportParameters = parameters;
}

/**
* Sets the reportSuffix attribute of the JReportBeanController object
*
*@param suffix The new reportSuffix value
*/
public void setReportSuffix(String suffix) {
reportSuffix = suffix;
}

private static Object REPORT_LOCK = new Object();
/**
* Description of the Method
*
*@return Description of the Return Value
*@exception Exception Description of the Exception
*/
public File execute() throws Exception {
File tmpFile = null;
synchronized( REPORT_LOCK ) {
try{

if (reportLocation == null) {
reportLocation = reportHome;
}
bean = new JREngine();
bean.setUID(uid);
bean.setKey(key);
bean.setReportHome(reportHome);
// bean.setShowInfoLevel( bean.vDebug | bean.vError );
// bean.setLogFile("");
//CC - It would help if these were used.
bean.setShowInfoLevel( logLevel );
bean.setLogFile(logFile);

bean.setReportName(reportLocation + File.separator + reportName);
bean.setCatName(reportLocation + File.separator + catalogName);

if (reportParameters != null) {
bean.setParamValues(mapToString(reportParameters, PARAMETER_DELIMITER));
}

bean.runReport(false);

tmpFile = File.createTempFile(TMP_PREFIX, reportSuffix, new File(tmpLocation));
int format = decodeReportType(reportFormat);
if (format == HTML) {
bean.exportToHtml(tmpFile.getAbsolutePath());
} else if (format == PDF) {
bean.exportToPdf(tmpFile.getAbsolutePath());
} else if (format == RTF) {
bean.exportToRtf(tmpFile.getAbsolutePath());
} else if (format == EXCEL) {
bean.exportToXls(tmpFile.getAbsolutePath());
} else if (format == XML) {
//exportToXML(filePath, isMultiFile, isOnlyData)
bean.exportToXML(tmpFile.getAbsolutePath(), false, false);
} else if (format == TEXT) {
//exportToText(filePath, isPlainText)
bean.exportToText(tmpFile.getAbsolutePath(), false, false, ',');
} else {
throw new Exception("JReports does not generate to the selected format: " + reportFormat);
}

String status = bean.getStatus();
if( ! status.startsWith("OK") ) {
******************************************************************************
throw new Exception( "Report failed: " + status );
This is what it shows please help!
*********************************************************************************
}

} catch(Exception e){
System.err.println("Error in execute method....");
e.printStackTrace();
throw e;
} finally {
bean.exit();
}
}
return tmpFile;
}

/**
* Description of the Method
*
*@param desType Description of the Parameter
*@return Description of the Return Value
*/
static int decodeReportType(String desType) {
if (desType.equalsIgnoreCase("HTML")) {
return HTML;
} else if (desType.equalsIgnoreCase("PDF")) {
return PDF;
} else if (desType.equalsIgnoreCase("TXT")) {
return TEXT;
} else if (desType.equalsIgnoreCase("CSV")) {
return TEXT;
} else if (desType.equalsIgnoreCase("EXCEL")) {
return EXCEL;
} else if (desType.equalsIgnoreCase("RTF")) {
return RTF;
} else if (desType.equalsIgnoreCase("XML")) {
return XML;
} else {
return PDF;
}
//default type of PDF
}

/**
* Description of the Method
*
*@param desType Description of the Parameter
*@return Description of the Return Value
*/
static String decodeReportSuffix(String desType) {
if (desType.equalsIgnoreCase("HTML")) {
return ".htm";
} else if (desType.equalsIgnoreCase("PDF")) {
return ".pdf";
} else if (desType.equalsIgnoreCase("TXT")) {
return ".csv";
} else if (desType.equalsIgnoreCase("CSV")) {
return ".csv";
} else if (desType.equalsIgnoreCase("EXCEL")) {
return ".xls";
} else if (desType.equalsIgnoreCase("RTF")) {
return ".rtf";
} else if (desType.equalsIgnoreCase("XML")) {
return ".xml";
} else {
return ".pdf";
}
//default type of PDF
}

/**
* Description of the Method
*
*@param map Description of the Parameter
*@param delimiter Description of the Parameter
*@return Description of the Return Value
*/
public static String mapToString(Map map, String delimiter) {
boolean first = true;
StringBuffer mapList = new StringBuffer(101);

for (Iterator i = map.keySet().iterator(); i.hasNext(); ) {
if (!first) {
mapList.append(delimiter);
}
String sName = (String) i.next();
String sValue = replaceChar((String) map.get(sName), ',', "
,");
mapList.append(sName).append("=").append(sValue);
first = false;
}
return mapList.toString();
}

/**
* Description of the Method
*
*@param s1 Description of the Parameter
*@param cFind Description of the Parameter
*@param sRepl Description of the Parameter
*@return Description of the Return Value
*/
public static String replaceChar(String s1, char cFind, String sRepl) {
StringBuffer sNew = new StringBuffer(501);
for (int i = 0; i < s1.length(); i++) {
if (s1.charAt(i) == cFind) {
sNew.append(sRepl);
} else {
sNew.append(s1.charAt(i));
}
}
return sNew.toString();
}

/**
* The main program for the JReportBeanController class
*
*@param args The command line arguments
*@exception Exception Description of the Exception
*/
public static void main(String[] args) throws Exception {

// JReportBeanController jbc = new JReportBeanController();
// jbc.test2();

}
}
*************************************************************************************
 
wood burning stoves
 
subject: Try, Catch Throw