IteraciĆ³n 3(VersiĆ³n sin idiomas)
[ISBets21MAUBRY] / eclipse-workspace / ISBets21MAUBRY / src / main / java / businessLogic / BusinessLogicServer.java
1 /**
2  * Package with the business logic of the application.
3  */
4 package businessLogic;
5
6 import java.awt.BorderLayout;
7 import java.awt.FlowLayout;
8
9
10 import javax.swing.JButton;
11 import javax.swing.JDialog;
12 import javax.swing.JPanel;
13 import javax.swing.border.EmptyBorder;
14
15 import configuration.ConfigXML;
16
17 import javax.swing.JTextArea;
18 import javax.xml.ws.Endpoint;
19
20
21 import java.awt.event.ActionListener;
22 import java.awt.event.ActionEvent;
23 import java.awt.event.WindowAdapter;
24 import java.awt.event.WindowEvent;
25
26 /**
27  * It runs the business logic server as a separate process.
28  */
29 public class BusinessLogicServer extends JDialog {
30
31         /**
32          * 
33          */
34         private static final long serialVersionUID = 1L;
35         private final JPanel contentPanel = new JPanel();
36         JTextArea textArea;
37         BLFacade server;
38         String service;
39
40         public static void main(String[] args) {
41                 try {
42                         BusinessLogicServer dialog = new BusinessLogicServer();
43                         dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
44                         dialog.setVisible(true);
45                 } catch (Exception e) {
46                         e.printStackTrace();
47                 }
48         }
49
50
51         public BusinessLogicServer() {
52                 addWindowListener(new WindowAdapter() {
53                         @Override
54                         public void windowClosed(WindowEvent arg0) {
55                                 System.exit(1);
56                         }
57                 });
58                 setTitle("BusinessLogicServer: running the business logic");
59                 setBounds(100, 100, 486, 209);
60                 getContentPane().setLayout(new BorderLayout());
61                 contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
62                 getContentPane().add(contentPanel, BorderLayout.CENTER);
63                 contentPanel.setLayout(new BorderLayout(0, 0));
64                 {
65                         textArea = new JTextArea();
66                         contentPanel.add(textArea);
67                 }
68                 {
69                         JPanel buttonPane = new JPanel();
70                         buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
71                         getContentPane().add(buttonPane, BorderLayout.SOUTH);
72                         {
73                                 JButton okButton = new JButton("OK");
74                                 okButton.addActionListener(new ActionListener() {
75                                         public void actionPerformed(ActionEvent e) {
76                                                 textArea.append("\n\n\nClosing the server... ");
77                                             
78                                                         //server.close();
79                                                 
80                                                 System.exit(1);
81                                         }
82                                 });
83                                 okButton.setActionCommand("OK");
84                                 buttonPane.add(okButton);
85                                 getRootPane().setDefaultButton(okButton);
86                         }
87                         {
88                                 JButton cancelButton = new JButton("Cancel");
89                                 cancelButton.setActionCommand("Cancel");
90                                 buttonPane.add(cancelButton);
91                         }
92                 }
93                 
94                 ConfigXML c=ConfigXML.getInstance();
95
96                 if (c.isBusinessLogicLocal()) {
97                         textArea.append("\nERROR, the business logic is configured as local");
98                 }
99                 else {
100                 try {
101
102                         try{
103                                 
104                                 if (!c.isDatabaseLocal()) {
105                                         System.out.println("\nWARNING: Please be sure ObjectdbManagerServer is launched\n           in machine: "+c.getDatabaseNode()+" port: "+c.getDatabasePort()+"\n");      
106                                 }
107                                 
108                                 service= "http://"+c.getBusinessLogicNode() +":"+ c.getBusinessLogicPort()+"/ws/"+c.getBusinessLogicName();
109                                 
110                                 Endpoint.publish(service, new BLFacadeImplementation());
111                                 
112                                 
113                         }
114                         catch (Exception e) {
115                                 System.out.println("Error in BusinessLogicServer: "+e.toString());
116                                 textArea.append("\nYou should have not launched DBManagerServer...\n");
117                                 textArea.append("\n\nOr maybe there is a BusinessLogicServer already launched...\n");
118                                 throw e;
119                         }
120                         
121                         textArea.append("Running service at:\n\t" + service);
122                         textArea.append("\n\n\nPress button to exit this server... ");
123                         
124                   } catch (Exception e) {
125                         textArea.append(e.toString());
126                   }
127
128           }
129         }
130 }
131
132
133