KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > SOFA > SOFAnode > Made > TIR > Impl > AbsoluteNameImpl


1 /* $Id: AbsoluteNameImpl.java,v 1.2 2004/05/20 14:23:52 bures Exp $ */
2 package SOFA.SOFAnode.Made.TIR.Impl;
3 import java.rmi.RemoteException JavaDoc;
4 import java.rmi.server.UnicastRemoteObject JavaDoc;
5
6 import SOFA.SOFAnode.Made.TIR.AbsoluteName;
7
8 public class AbsoluteNameImpl extends UnicastRemoteObject JavaDoc implements AbsoluteName {
9   int count;
10   String JavaDoc[] n;
11   
12   public AbsoluteNameImpl(String JavaDoc name) throws RemoteException JavaDoc {
13     int i;
14     count = 0;
15     if (name.compareTo("")==0 || name.compareTo("::")==0) {
16       n = new String JavaDoc [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 JavaDoc [count];
25     int j = 0;
26     for(i=0;i<count;i++) {
27       StringBuffer JavaDoc str = new StringBuffer JavaDoc();
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 JavaDoc[] str) throws RemoteException JavaDoc {
43     count = str.length-1;
44     n = new String JavaDoc [count];
45     for(int i=0;i<str.length-1;i++) {
46       n[i] = new String JavaDoc(str[i]);
47     }
48   }
49
50   /** This constructor is called from constructor of IdentificationImpl for creating lang_absolute_name. */
51   AbsoluteNameImpl(String JavaDoc lang, AbsoluteNameImpl abs) throws RemoteException JavaDoc {
52     count = abs.count + 1;
53     n = new String JavaDoc[count];
54     n[0] = new String JavaDoc(lang);
55     for (int i=1;i<count;i++) {
56       n[i] = new String JavaDoc(abs.n[i-1]);
57     }
58   }
59  
60   public AbsoluteName parent() throws RemoteException JavaDoc {
61     if (count<=1)
62       return null;
63     return (AbsoluteName) new AbsoluteNameImpl(n);
64   }
65
66   public String JavaDoc name() throws RemoteException JavaDoc {
67     StringBuffer JavaDoc sb = new StringBuffer JavaDoc("");
68     for (int i=0;i<count;i++) {
69       sb = sb.append("::" + n[i]);
70     }
71     return sb.toString();
72   }
73
74   public String JavaDoc toString() {
75     StringBuffer JavaDoc sb = new StringBuffer JavaDoc("");
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 JavaDoc {
83     return count;
84   }
85   
86   public String JavaDoc elementAt(int i) throws RemoteException JavaDoc {
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 JavaDoc {
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