1 2 package SOFA.SOFAnode.Made.TIR.Impl; 3 import java.rmi.RemoteException ; 4 import java.rmi.server.UnicastRemoteObject ; 5 6 import SOFA.SOFAnode.Made.TIR.AbsoluteName; 7 8 public class AbsoluteNameImpl extends UnicastRemoteObject implements AbsoluteName { 9 int count; 10 String [] n; 11 12 public AbsoluteNameImpl(String name) throws RemoteException { 13 int i; 14 count = 0; 15 if (name.compareTo("")==0 || name.compareTo("::")==0) { 16 n = new String [1]; 17 n[0] = ""; 18 return; 19 } 20 for (i=0;i<name.length();i++) { 21 if (name.charAt(i)==':' && name.charAt(i+1)==':') 22 count++; 23 } 24 n = new String [count]; 25 int j = 0; 26 for(i=0;i<count;i++) { 27 StringBuffer str = new StringBuffer (); 28 while (name.charAt(j)==':') 29 j++; 30 while (j<name.length() && name.charAt(j)!=':') { 31 str = str.append(name.charAt(j)); 32 j++; 33 } 34 n[i] = str.toString(); 35 } 36 if (count == 0) 37 n[0] = ""; 38 if ((count==1) && (n[0].compareTo("")==0)) 39 count = 0; 40 } 41 42 private AbsoluteNameImpl(String [] str) throws RemoteException { 43 count = str.length-1; 44 n = new String [count]; 45 for(int i=0;i<str.length-1;i++) { 46 n[i] = new String (str[i]); 47 } 48 } 49 50 51 AbsoluteNameImpl(String lang, AbsoluteNameImpl abs) throws RemoteException { 52 count = abs.count + 1; 53 n = new String [count]; 54 n[0] = new String (lang); 55 for (int i=1;i<count;i++) { 56 n[i] = new String (abs.n[i-1]); 57 } 58 } 59 60 public AbsoluteName parent() throws RemoteException { 61 if (count<=1) 62 return null; 63 return (AbsoluteName) new AbsoluteNameImpl(n); 64 } 65 66 public String name() throws RemoteException { 67 StringBuffer sb = new StringBuffer (""); 68 for (int i=0;i<count;i++) { 69 sb = sb.append("::" + n[i]); 70 } 71 return sb.toString(); 72 } 73 74 public String toString() { 75 StringBuffer sb = new StringBuffer (""); 76 for (int i=0;i<count;i++) { 77 sb = sb.append("::" + n[i]); 78 } 79 return sb.toString(); 80 } 81 82 public int size() throws RemoteException { 83 return count; 84 } 85 86 public String elementAt(int i) throws RemoteException { 87 if (i>=0 && i<count) 88 return n[i]; 89 else 90 return null; 91 } 92 93 public boolean isEqual(AbsoluteName an) throws RemoteException { 94 if (count != an.size()) 95 return false; 96 for (int i=0;i<count;i++) { 97 if (n[i].compareTo(an.elementAt(i)) != 0) 98 return false; 99 } 100 return true; 101 } 102 103 boolean isEqualL(AbsoluteNameImpl an) { 104 if (count != an.count) 105 return false; 106 for (int i=0;i<count;i++) { 107 if (n[i].compareTo(an.n[i]) != 0) 108 return false; 109 } 110 return true; 111 } 112 } 113 | Popular Tags |