3 import java.awt.BorderLayout;
4 import java.awt.FlowLayout;
5 import java.io.BufferedReader;
6 import java.io.InputStreamReader;
7 import java.rmi.Naming;
8 import java.rmi.RMISecurityManager;
9 import java.rmi.RemoteException;
11 import javax.swing.JButton;
12 import javax.swing.JDialog;
13 import javax.swing.JPanel;
14 import javax.swing.border.EmptyBorder;
16 import configuration.ConfigXML;
18 import javax.swing.JTextArea;
20 import dataAccess.DB4oManager;
22 import java.awt.event.ActionListener;
23 import java.awt.event.ActionEvent;
25 public class BusinessLogicServer extends JDialog {
27 private final JPanel contentPanel = new JPanel();
29 ApplicationFacadeInterface server;
32 * Launch the application.
34 public static void main(String[] args) {
36 BusinessLogicServer dialog = new BusinessLogicServer();
37 dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
38 dialog.setVisible(true);
39 } catch (Exception e) {
47 public BusinessLogicServer() {
48 setTitle("BusinessLogicServer: running the business logic");
49 setBounds(100, 100, 486, 209);
50 getContentPane().setLayout(new BorderLayout());
51 contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
52 getContentPane().add(contentPanel, BorderLayout.CENTER);
53 contentPanel.setLayout(new BorderLayout(0, 0));
55 textArea = new JTextArea();
56 contentPanel.add(textArea);
59 JPanel buttonPane = new JPanel();
60 buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
61 getContentPane().add(buttonPane, BorderLayout.SOUTH);
63 JButton okButton = new JButton("OK");
64 okButton.addActionListener(new ActionListener() {
65 public void actionPerformed(ActionEvent e) {
66 textArea.append("\n\n\nClosing the server... ");
69 } catch (RemoteException e1) {
74 okButton.setActionCommand("OK");
75 buttonPane.add(okButton);
76 getRootPane().setDefaultButton(okButton);
79 JButton cancelButton = new JButton("Cancel");
80 cancelButton.setActionCommand("Cancel");
81 buttonPane.add(cancelButton);
85 ConfigXML c=ConfigXML.getInstance();
88 System.setProperty("java.security.policy", c.getJavaPolicyPath());
91 System.setSecurityManager(new RMISecurityManager());
94 java.rmi.registry.LocateRegistry.createRegistry(Integer.parseInt(c.getPortRMI()));
96 } catch (Exception e) {
97 textArea.append(e.toString() + "Rmiregistry already running.");
103 server = new FacadeImplementation();
105 catch (com.db4o.ext.DatabaseFileLockedException e) {
106 System.out.println("Error in BusinessLogicServer: "+e.toString());
107 textArea.append("\nYou should have not launched DB4oManagerServer...\n");
108 textArea.append("\n\nOr maybe there is a BusinessLogicServer already launched...\n");
113 String service= "//"+c.getBusinessLogicNode() +":"+ c.getPortRMI()+"/"+c.getServiceRMI();
115 // Register the remote server
116 Naming.rebind(service, server);
117 textArea.append("Running service at:\n\t" + service);
118 //This operation removes the actual database and initialize with predefined values
120 textArea.append("\n\n\nPress button to exit this server... ");
122 } catch (Exception e) {
123 textArea.append(e.toString());