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 ; 11 import javax.naming.InitialContext ; 12 import javax.naming.NamingException ; 13 import javax.swing.JFrame ; 14 import javax.swing.JScrollPane ; 15 import javax.swing.JTable ; 16 import javax.swing.table.DefaultTableColumnModel ; 17 import javax.swing.table.TableColumn ; 18 import java.awt.BorderLayout ; 19 import java.awt.HeadlessException ; 20 import java.util.Properties ; 21 22 25 public class BasicRemoteIteratorFrame extends JFrame { 26 private boolean _mustUseRemoting = true; 28 29 private RemoteIteratorService _riService = null; 30 private HttpServiceFactory _factory = new HttpServiceFactory(); 31 32 private static final String 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 { 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 columnModel = new DefaultTableColumnModel (); 45 TableColumn aColumn = new TableColumn (); 46 aColumn.setHeaderValue( "OID" ); 47 columnModel.addColumn( aColumn ); 48 aColumn = new TableColumn (); 49 aColumn.setHeaderValue( "Label" ); 50 columnModel.addColumn( aColumn ); 51 52 JTable myTable = new JTable ( tableModel, columnModel ); 53 54 getContentPane().setLayout( new BorderLayout () ); 55 getContentPane().add( new JScrollPane ( myTable ), BorderLayout.CENTER ); 56 57 tableModel.setRemoteIteratorClient( getRemoteIteratorClient( SQL_STATEMENT ) ); 58 tableModel.setInitialBlockSize( 25 ); 59 tableModel.setDefaultBlockSize( 500 ); 60 tableModel.setDelayBetweenRetrieval( 250 ); 61 62 tableModel.startLoadingData(); 64 } 65 66 protected RemoteIteratorClient getRemoteIteratorClient( String p_statement ) { 67 RemoteIteratorClient riClient = null; 68 69 try { 70 if ( _riService == null ) { 71 if ( _mustUseRemoting ) { 72 _factory.setPort( 8080 ); 74 _factory.setHost( "localhost" ); 76 _factory.setServerContext( "testRI" ); 78 79 _riService = (RemoteIteratorService) _factory.getService( REMOTE_ITERATOR_SERVICE_DEFINITION ); 80 } else { 81 Context jndiContext = getInitialContext(); 82 _riService = ( (RemoteIteratorServiceHome) jndiContext.lookup( "ejb/RemoteIteratorService" ) ).create(); 83 } 84 } 85 86 riClient = new RemoteIteratorClient( _riService.getRemoteIterator( p_statement ) ); 87 } catch( Exception e ) { 88 e.printStackTrace(); 90 91 System.exit( 0 ); 93 } 94 95 return riClient; 96 } 97 98 private Context getInitialContext() throws NamingException { 99 Properties properties = new Properties (); 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 ( properties ); 105 } 106 107 public static void main( String [] args ) { 108 BasicRemoteIteratorFrame myFrame = new BasicRemoteIteratorFrame(); 109 myFrame.setDefaultCloseOperation( EXIT_ON_CLOSE ); 110 myFrame.show(); 111 } 112 } 113 | Popular Tags |