Report Application Server (RAS) Report Source


Crystal Enterprise Embedded Edition (covered in more detail in Chapter 22) is another web- based reporting method included with Crystal Reports 10 Developer and Advanced Developer Editions. CE Embedded makes use of the Report Application Server (RAS) portion of the full Crystal Enterprise product. The key advantage of using RAS is that you can create and modify reports and use assorted report viewers to display reports. In addition to using ASP pages (as illustrated in Chapter 22), you can access RAS directly from your JSP application.

Begin by creating a report application session by declaring an instance of the ReportAppSession class, which you use to create a report application server service. Both of these are shown here:

 ReportAppSession ra = new ReportAppSession(); 
ra.createService("com.crystaldecisions.sdk.occa.report.application.
ReportClientDocument");

You ll be using the local host for the service, so you ll need to set this by calling the setReportAppServer() method and then passing it to the string localhost. The localhost is not the only value that can be passed. The name of the RAS service can also be referenced by using the fully qualified domain name, IP address, or local name referenced in the HOSTS file (i.e., Localhost). Once this is set, you then call the initialize() method to initialize RAS, as shown here:

 ra.setReportAppServer("localhost"); 
ra.initialize();

A Crystal report is referenced as a report client document. You must declare an instance of the ReportClientDocument to store the Crystal report, then associate the report client document with a Report Application Server by calling the setReportAppServer() method. Both of these steps are illustrated in the following statements:

 ReportClientDocument clientDoc = new ReportClientDocument(); 
clientDoc.setReportAppServer(ra.getReportAppServer() );

The next step is to open the report by calling the open() method. The open () method requires two arguments. The first argument is a string containing the full path and name of the report. The second argument is the report option constant. This example opens the report c:\reports\myReport.rpt as read only:

 clientDoc.open("c:\reports\myReport.rpt", OpenReportOptions._openAsReadOnly); 

Now you retrieve the report from the report client document by calling the getReportSource() method. The getReportSource() method returns a reference to an IReportSource object, which is the report source. This is illustrated next. Once you have the report source, you can use techniques illustrated previously in the chapter to access the report.

 IReportSource reportSource = clientDoc.getReportSource(); 

In order to reduce the amount of overhead when the viewer triggers a post-back event, you should store the report source in the session. Here s how this is done:

 session.setAttribute("rptSource", reportSource); 

The following is the complete JSP application showing how to retrieve a report from RAS:

 <%@ page import= 
"com.crystaldecisions.sdk.occa.report.application.ReportAppSession,
com.crystaldecisions.sdk.occa.report.application.ReportClientDocument,
com.crystaldecisions.sdk.occa.report.application.OpenReportOptions,
com.crystaldecisions.sdk.occa.report.reportsource.IReportSource"%>
<%
ReportAppSession ra = new ReportAppSession();
ra.createService("com.crystaldecisions.sdk.occa.report.application.
ReportClientDocument");
ra.setReportAppServer("localhost");
ra.initialize();
ReportClientDocument clientDoc = new ReportClientDocument();
clientDoc.setReportAppServer(ra.getReportAppServer() );
clientDoc.open(reportName, OpenReportOptions._openAsReadOnly);
IReportSource reportSource = clientDoc.getReportSource();
session.setAttribute("rptSource", reportSource);
%>
Note  

The preceding section of code requires that a properly operating Crystal Enterprise Embedded Edition system be running on your network.




Crystal Reports 10
Crystal Reports 10: The Complete Reference
ISBN: B005DI80VA
EAN: N/A
Year: 2004
Pages: 223
Authors: George Peck

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net