KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > it > businesslogic > ireport > rmi > IReportServerImpl


1 /*
2  * Copyright (C) 2005 - 2006 JasperSoft Corporation. All rights reserved.
3  * http://www.jaspersoft.com.
4  *
5  * Unless you have purchased a commercial license agreement from JasperSoft,
6  * the following license terms apply:
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 as published by
10  * the Free Software Foundation.
11  *
12  * This program is distributed WITHOUT ANY WARRANTY; and without the
13  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14  * See the GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, see http://www.gnu.org/licenses/gpl.txt
18  * or write to:
19  *
20  * Free Software Foundation, Inc.,
21  * 59 Temple Place - Suite 330,
22  * Boston, MA USA 02111-1307
23  *
24  *
25  *
26  *
27  * IReportServerImpl.java
28  *
29  */

30
31 package it.businesslogic.ireport.rmi;
32 //-----------------------------------------------------------
33
// File: SampleServerImpl.java
34
//-----------------------------------------------------------
35

36 import it.businesslogic.ireport.Report;
37 import it.businesslogic.ireport.gui.JReportFrame;
38 import it.businesslogic.ireport.gui.MainFrame;
39 import it.businesslogic.ireport.gui.WizardDialog;
40 import it.businesslogic.ireport.util.PageSize;
41 import java.io.File JavaDoc;
42 import java.rmi.*;
43 import java.rmi.server.*;
44 import java.rmi.registry.*;
45 import javax.swing.JOptionPane JavaDoc;
46 import javax.swing.SwingUtilities JavaDoc;
47
48 public class IReportServerImpl extends UnicastRemoteObject
49                              implements IReportServer, Runnable JavaDoc
50 {
51   static IReportServerImpl mainInstance = null;
52   
53   public static IReportServerImpl getMainInstance()
54   {
55       if (mainInstance == null)
56       {
57           try {
58                 mainInstance = new IReportServerImpl();
59           } catch (Exception JavaDoc ex)
60           {
61               ex.printStackTrace();
62           }
63       }
64       
65       return mainInstance;
66   }
67   
68   IReportServerImpl() throws RemoteException
69   {
70      super();
71   }
72
73  
74
75   public static void runServer()
76   {
77       //if (MainFrame.getMainInstance().getProperties().getProperty( "enableRMIServer" ,"false").equals("true"))
78
//{
79
System.setSecurityManager(new RMISecurityManager());
80         Thread JavaDoc t = new Thread JavaDoc( IReportServerImpl.getMainInstance() );
81         t.start();
82       //}
83
}
84   
85   public void run()
86   {
87     //set the security manager
88
try
89       {
90         int port = 2100;
91         try {
92             port = Integer.parseInt( MainFrame.getMainInstance().getProperties().getProperty( "RMIServerPort" ,"2100"));
93         }
94         catch (Exception JavaDoc ex)
95         {
96             ex.printStackTrace();
97         }
98         Registry reg =LocateRegistry.createRegistry( port );
99         
100     //put the local instance in the registry
101
//Naming.rebind("iReportServer" , Server);
102
reg.bind("iReportServer" , this);
103         System.out.println("RMI iReportServer waiting on port " + port + ".....");
104       }
105     catch (java.rmi.AlreadyBoundException JavaDoc abe)
106     {
107         System.out.println("Service already bound! Is another iReport instance running?");
108     }
109     catch (RemoteException re)
110       {
111          System.out.println("Remote exception: " + re.toString());
112       }
113
114   }
115   
116   // --------------------------------------------------------------------------------------
117

118   /**
119    * Used to check if iReport is alive
120    */

121   public boolean ping()
122   {
123       return true;
124   }
125   
126   /**
127    * Used to show the main window and bring the iReport window on top...
128    */

129   public boolean setVisible(boolean b)
130   {
131       MainFrame.getMainInstance().setVisible(b);
132       if (MainFrame.getMainInstance().getState() == java.awt.Frame.ICONIFIED)
133       {
134             MainFrame.getMainInstance().setState( java.awt.Frame.NORMAL );
135       }
136       return MainFrame.getMainInstance().requestFocusInWindow();
137   }
138   
139   /**
140    * Open the file passed as parameter...
141    */

142   public boolean openFile(String JavaDoc file)
143   {
144       setVisible(true);
145       try {
146           JReportFrame jrf = MainFrame.getMainInstance().openFile( file );
147           jrf.setSelected(true);
148           return true;
149       } catch (Exception JavaDoc ex){
150            return false;
151       }
152   }
153   
154
155   public boolean runWizard(String JavaDoc destFile)
156   {
157     MainFrame mainFrame = MainFrame.getMainInstance();
158     
159     if (mainFrame == null) return false;
160     
161         
162         
163     mainFrame.logOnConsole("Invocato wizard");
164     mainFrame.logOnConsole("Pronto ad invocare la nuova finestra..." + Thread.currentThread().getName());
165     
166         
167         try {
168                 // TODO
169
// Set the project directory as current directory;
170

171                 WizardDialog wd = new WizardDialog(mainFrame,true);
172
173                 mainFrame.logOnConsole("Lancio wizard");
174                 wd.setVisible(true);
175                 wd.requestFocus();
176
177
178                 Report report = null;
179                 if (wd.getDialogResult() == javax.swing.JOptionPane.OK_OPTION) {
180                     report = wd.getReport();
181                     if (report == null)
182                     {
183                         report = createBlankReport();
184                     }
185                 }
186                 else
187                 {
188                     report = createBlankReport();
189                 }
190
191                 if (report != null)
192                 {
193                         mainFrame.openNewReportWindow(report);
194                         report.setFilename(destFile);
195                         report.saveXMLFile();
196                         setVisible(true);
197                 }
198
199         } catch (Exception JavaDoc ex)
200         {
201               System.out.println(ex.getMessage());
202                 ex.printStackTrace();
203         }
204         
205
206       return true;
207   }
208   
209   private Report createBlankReport()
210   {
211       Report newReport = new Report();
212       
213         newReport.setName(it.businesslogic.ireport.util.I18n.getString("untitledReport", "untitled_report_")+"1");
214         newReport.setUsingMultiLineExpressions(false); //this.isUsingMultiLineExpressions());
215
newReport.setWidth( PageSize.A4.x);
216         newReport.setHeight( PageSize.A4.y);
217         newReport.setTopMargin(20);
218         newReport.setLeftMargin(30);
219         newReport.setRightMargin(30);
220         newReport.setBottomMargin(20);
221         newReport.setColumnCount(1);
222         newReport.setColumnWidth( newReport.getWidth() - newReport.getLeftMargin() - newReport.getRightMargin() );
223         newReport.setColumnSpacing(0);
224         
225         return newReport;
226   }
227   
228   
229 }
230
231
232
233
Popular Tags