Advertisement
Guest User

RMI for Note taking app

a guest
Feb 5th, 2015
437
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.03 KB | None | 0 0
  1. import java.rmi.*;
  2. import java.util.Vector;
  3. public interface HelloInterface extends Remote {
  4.         boolean login(String name, String password)throws RemoteException;
  5.         boolean saveText(String text, String access, String user)throws RemoteException;
  6.         Vector<Text> viewTexts(String user)throws RemoteException;
  7. }
  8.  
  9. import java.net.*;
  10. import java.rmi.*;
  11. public class HelloServer {
  12.         public static void main(String args[]) {
  13.             try {
  14.                 HelloServerImplementation helloServer = new HelloServerImplementation();
  15.                 Naming.rebind("HelloServer", helloServer);
  16.             }
  17.             catch(Exception e) {
  18.                 System.out.println("Exception: " + e);
  19.             }
  20.         }
  21. }
  22.  
  23. import java.rmi.*;
  24. import java.rmi.server.*;
  25. import java.rmi.registry.*;
  26. import java.net.MalformedURLException;
  27. import java.util.Vector;
  28. class Text{
  29.         String text;
  30.         String access;
  31.         String user;
  32.         Text(String text, String access, String user){
  33.             this.text = text;
  34.             this.access = access;
  35.             this.user = user;
  36.         }
  37. }
  38. public class HelloServerImplementation extends UnicastRemoteObject implements HelloInterface {
  39.             static Vector<Text> v = new Vector<Text>();
  40.             public HelloServerImplementation()throws RemoteException
  41.             {
  42.                 for(int i = 0; i<10; i++){
  43.                     v.add(i, new Text("This is Text No. "+i, "public", "root"));
  44.                 }
  45.             }
  46.             public boolean login(String u, String pass)throws RemoteException
  47.             {
  48.                 if(u.equals("shail")&&pass.equals("password"))
  49.                     return true;
  50.                 else return false;
  51.             }
  52.             public boolean saveText(String text, String access, String user)throws RemoteException{
  53.                 v.add(new Text(text, access, user));
  54.                 return true;
  55.             }
  56.             public Vector<Text> viewTexts(String user)throws RemoteException{
  57.                 Vector<Text> send = new Vector<Text>();
  58.                 for(int i = 0; i<v.size(); i++)
  59.                     if(v.elementAt(i).access.equals("public")||v.elementAt(i).user.equals(user))
  60.                         send.add(v.elementAt(i));
  61.                 return send;
  62.             }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement