KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > bsf > remoteIterator > BasicRemoteIteratorFrame


1 package org.bsf.remoteIterator;
2
3 import org.bsf.remoteIterator.client.RemoteIteratorClient;
4 import org.bsf.remoteIterator.client.tableModel.DefaultRemoteIteratorTableModel;
5 import org.bsf.remoteIterator.server.RemoteIteratorService;
6 import org.bsf.remoteIterator.server.RemoteIteratorServiceHome;
7 import org.bsf.remoting.EJBDefinition;
8 import org.bsf.remoting.http.HttpServiceFactory;
9
10 import javax.naming.Context JavaDoc;
11 import javax.naming.InitialContext JavaDoc;
12 import javax.naming.NamingException JavaDoc;
13 import javax.swing.JFrame JavaDoc;
14 import javax.swing.JScrollPane JavaDoc;
15 import javax.swing.JTable JavaDoc;
16 import javax.swing.table.DefaultTableColumnModel JavaDoc;
17 import javax.swing.table.TableColumn JavaDoc;
18 import java.awt.BorderLayout JavaDoc;
19 import java.awt.HeadlessException JavaDoc;
20 import java.util.Properties JavaDoc;
21
22 /**
23  * BasicRemoteIteratorFrame
24  */

25 public class BasicRemoteIteratorFrame extends JFrame JavaDoc {
26     // Set to true to use the remoting, false for rmi
27
private boolean _mustUseRemoting = true;
28
29     private RemoteIteratorService _riService = null;
30     private HttpServiceFactory _factory = new HttpServiceFactory();
31
32     private static final String JavaDoc SQL_STATEMENT = "select * from " + RITestDatabaseManager.TABLE_NAME;
33
34     EJBDefinition REMOTE_ITERATOR_SERVICE_DEFINITION = new EJBDefinition( "ejb/RemoteIteratorService",
35                                                                           "org.bsf.remoteIterator.server.RemoteIteratorServiceHome",
36                                                                           "org.bsf.remoteIterator.server.RemoteIteratorService" );
37
38     public BasicRemoteIteratorFrame() throws HeadlessException JavaDoc {
39         super( "Basic Frame containing a Table using the DefaultremoteIteratorTableModel" );
40         setBounds( 100, 100, 650, 500 );
41
42         DefaultRemoteIteratorTableModel tableModel = new DefaultRemoteIteratorTableModel();
43
44         DefaultTableColumnModel JavaDoc columnModel = new DefaultTableColumnModel JavaDoc();
45         TableColumn JavaDoc aColumn = new TableColumn JavaDoc();
46         aColumn.setHeaderValue( "OID" );
47         columnModel.addColumn( aColumn );
48         aColumn = new TableColumn JavaDoc();
49         aColumn.setHeaderValue( "Label" );
50         columnModel.addColumn( aColumn );
51
52         JTable JavaDoc myTable = new JTable JavaDoc( tableModel, columnModel );
53
54         getContentPane().setLayout( new BorderLayout JavaDoc() );
55         getContentPane().add( new JScrollPane JavaDoc( myTable ), BorderLayout.CENTER );
56
57         tableModel.setRemoteIteratorClient( getRemoteIteratorClient( SQL_STATEMENT ) );
58         tableModel.setInitialBlockSize( 25 );
59         tableModel.setDefaultBlockSize( 500 );
60         tableModel.setDelayBetweenRetrieval( 250 );
61
62         // We start loading the data
63
tableModel.startLoadingData();
64     }
65
66     protected RemoteIteratorClient getRemoteIteratorClient( String JavaDoc p_statement ) {
67         RemoteIteratorClient riClient = null;
68
69         try {
70             if ( _riService == null ) {
71                 if ( _mustUseRemoting ) {
72                     // The port to use, on the server, to communicate (default is 8080)
73
_factory.setPort( 8080 );
74                     // The location of the server on which the server is deployed
75
_factory.setHost( "localhost" );
76                     // The context of the remoting (in the ear def)
77
_factory.setServerContext( "testRI" );
78
79                     _riService = (RemoteIteratorService) _factory.getService( REMOTE_ITERATOR_SERVICE_DEFINITION );
80                 } else {
81                     Context JavaDoc jndiContext = getInitialContext();
82                     _riService = ( (RemoteIteratorServiceHome) jndiContext.lookup( "ejb/RemoteIteratorService" ) ).create();
83                 }
84             }
85
86             riClient = new RemoteIteratorClient( _riService.getRemoteIterator( p_statement ) );
87         } catch( Exception JavaDoc e ) {
88             // We display the stack trace
89
e.printStackTrace();
90
91             // And exit
92
System.exit( 0 );
93         }
94
95         return riClient;
96     }
97
98     private Context JavaDoc getInitialContext() throws NamingException JavaDoc {
99         Properties JavaDoc properties = new Properties JavaDoc();
100         properties.put( "java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory" );
101         properties.put( "java.naming.provider.url", "jnp://localhost:1099" );
102         properties.put( "java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces" );
103
104         return new InitialContext JavaDoc( properties );
105     }
106
107     public static void main( String JavaDoc[] args ) {
108         BasicRemoteIteratorFrame myFrame = new BasicRemoteIteratorFrame();
109         myFrame.setDefaultCloseOperation( EXIT_ON_CLOSE );
110         myFrame.show();
111     }
112 }
113
Popular Tags