001: /*
002: * Copyright (C) 2005 - 2008 JasperSoft Corporation. All rights reserved.
003: * http://www.jaspersoft.com.
004: *
005: * Unless you have purchased a commercial license agreement from JasperSoft,
006: * the following license terms apply:
007: *
008: * This program is free software; you can redistribute it and/or modify
009: * it under the terms of the GNU General Public License version 2 as published by
010: * the Free Software Foundation.
011: *
012: * This program is distributed WITHOUT ANY WARRANTY; and without the
013: * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
014: * See the GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, see http://www.gnu.org/licenses/gpl.txt
018: * or write to:
019: *
020: * Free Software Foundation, Inc.,
021: * 59 Temple Place - Suite 330,
022: * Boston, MA USA 02111-1307
023: *
024: *
025: *
026: *
027: * IReportServerImpl.java
028: *
029: */
030:
031: package it.businesslogic.ireport.rmi;
032:
033: //-----------------------------------------------------------
034: // File: SampleServerImpl.java
035: //-----------------------------------------------------------
036:
037: import it.businesslogic.ireport.Report;
038: import it.businesslogic.ireport.gui.JReportFrame;
039: import it.businesslogic.ireport.gui.MainFrame;
040: import it.businesslogic.ireport.gui.WizardDialog;
041: import it.businesslogic.ireport.util.PageSize;
042: import java.io.File;
043: import java.rmi.*;
044: import java.rmi.server.*;
045: import java.rmi.registry.*;
046: import javax.swing.JOptionPane;
047: import javax.swing.SwingUtilities;
048:
049: public class IReportServerImpl extends UnicastRemoteObject implements
050: IReportServer, Runnable {
051: static IReportServerImpl mainInstance = null;
052:
053: public static IReportServerImpl getMainInstance() {
054: if (mainInstance == null) {
055: try {
056: mainInstance = new IReportServerImpl();
057: } catch (Exception ex) {
058: ex.printStackTrace();
059: }
060: }
061:
062: return mainInstance;
063: }
064:
065: IReportServerImpl() throws RemoteException {
066: super ();
067: }
068:
069: public static void runServer() {
070: //if (MainFrame.getMainInstance().getProperties().getProperty( "enableRMIServer" ,"false").equals("true"))
071: //{
072: System.setSecurityManager(new RMISecurityManager());
073: Thread t = new Thread(IReportServerImpl.getMainInstance());
074: t.start();
075: //}
076: }
077:
078: public void run() {
079: //set the security manager
080: try {
081: int port = 2100;
082: try {
083: port = Integer.parseInt(MainFrame.getMainInstance()
084: .getProperties().getProperty("RMIServerPort",
085: "2100"));
086: } catch (Exception ex) {
087: ex.printStackTrace();
088: }
089: Registry reg = LocateRegistry.createRegistry(port);
090:
091: //put the local instance in the registry
092: //Naming.rebind("iReportServer" , Server);
093: reg.bind("iReportServer", this );
094: System.out.println("RMI iReportServer waiting on port "
095: + port + ".....");
096: } catch (java.rmi.AlreadyBoundException abe) {
097: System.out
098: .println("Service already bound! Is another iReport instance running?");
099: } catch (RemoteException re) {
100: System.out.println("Remote exception: " + re.toString());
101: }
102:
103: }
104:
105: // --------------------------------------------------------------------------------------
106:
107: /**
108: * Used to check if iReport is alive
109: */
110: public boolean ping() {
111: return true;
112: }
113:
114: /**
115: * Used to show the main window and bring the iReport window on top...
116: */
117: public boolean setVisible(boolean b) {
118: MainFrame.getMainInstance().setVisible(b);
119: if (MainFrame.getMainInstance().getState() == java.awt.Frame.ICONIFIED) {
120: MainFrame.getMainInstance().setState(java.awt.Frame.NORMAL);
121: }
122: return MainFrame.getMainInstance().requestFocusInWindow();
123: }
124:
125: /**
126: * Open the file passed as parameter...
127: */
128: public boolean openFile(String file) {
129: setVisible(true);
130: try {
131: JReportFrame jrf = MainFrame.getMainInstance().openFile(
132: file);
133: jrf.setSelected(true);
134: return true;
135: } catch (Exception ex) {
136: return false;
137: }
138: }
139:
140: public boolean runWizard(String destFile) {
141: MainFrame mainFrame = MainFrame.getMainInstance();
142:
143: if (mainFrame == null)
144: return false;
145:
146: mainFrame.logOnConsole("Invocato wizard");
147: mainFrame
148: .logOnConsole("Pronto ad invocare la nuova finestra..."
149: + Thread.currentThread().getName());
150:
151: try {
152: // TODO
153: // Set the project directory as current directory;
154:
155: WizardDialog wd = new WizardDialog(mainFrame, true);
156:
157: mainFrame.logOnConsole("Lancio wizard");
158: wd.setVisible(true);
159: wd.requestFocus();
160:
161: Report report = null;
162: if (wd.getDialogResult() == javax.swing.JOptionPane.OK_OPTION) {
163: report = wd.getReport();
164: if (report == null) {
165: report = createBlankReport();
166: }
167: } else {
168: report = createBlankReport();
169: }
170:
171: if (report != null) {
172: mainFrame.openNewReportWindow(report);
173: report.setFilename(destFile);
174: report.saveXMLFile();
175: setVisible(true);
176: }
177:
178: } catch (Exception ex) {
179: System.out.println(ex.getMessage());
180: ex.printStackTrace();
181: }
182:
183: return true;
184: }
185:
186: private Report createBlankReport() {
187: Report newReport = new Report();
188:
189: newReport.setName(it.businesslogic.ireport.util.I18n.getString(
190: "untitledReport", "untitled_report_")
191: + "1");
192: newReport.setUsingMultiLineExpressions(false); //this.isUsingMultiLineExpressions());
193: newReport.setWidth(PageSize.A4.x);
194: newReport.setHeight(PageSize.A4.y);
195: newReport.setTopMargin(20);
196: newReport.setLeftMargin(30);
197: newReport.setRightMargin(30);
198: newReport.setBottomMargin(20);
199: newReport.setColumnCount(1);
200: newReport.setColumnWidth(newReport.getWidth()
201: - newReport.getLeftMargin()
202: - newReport.getRightMargin());
203: newReport.setColumnSpacing(0);
204:
205: return newReport;
206: }
207:
208: }
|