1 2 package SOFA.SOFAnode.Made.TIR.Impl; 3 import java.io.DataInputStream ; 4 import java.io.DataOutputStream ; 5 import java.io.IOException ; 6 import java.rmi.RemoteException ; 7 import java.rmi.server.UnicastRemoteObject ; 8 9 import SOFA.SOFAnode.Made.TIR.AbsoluteName; 10 import SOFA.SOFAnode.Made.TIR.Identification; 11 12 public class IdentificationImpl extends UnicastRemoteObject implements Identification, SIdentification { 13 public String nm; public String ver; public String [] tg; public String brtg; public AbsoluteNameImpl abs; 18 public AbsoluteNameImpl langabs; 19 20 public String lang; 22 Lock nextLock; long lockId; long nextNBranch; boolean hasNext; 27 public IdentificationImpl(String lng, String name, String version) throws RemoteException { 29 super(); 30 lang = new String (lng); 31 abs = new AbsoluteNameImpl(name); 32 langabs = new AbsoluteNameImpl(lng, abs); 33 if (abs.size() != 0) { 34 nm = new String (abs.elementAt(abs.size()-1)); 35 } else { 36 nm = ""; 37 } 38 ver = new String (version); 39 brtg = ""; tg = new String [0]; 40 nextLock = new Lock(false); 41 lockId = -1L; 42 hasNext = false; 43 nextNBranch = 1; 44 } 45 46 public IdentificationImpl(String lng, String name, String version, String branchTag) throws RemoteException { 48 super(); 49 lang = new String (lng); 50 abs = new AbsoluteNameImpl(name); 51 langabs = new AbsoluteNameImpl(lng, abs); 52 if (abs.size() != 0) { 53 nm = new String (abs.elementAt(abs.size()-1)); 54 } else { 55 nm = ""; 56 } 57 ver = new String (version); 58 brtg = new String (branchTag); tg = new String [0]; 59 nextLock = new Lock(false); 60 lockId = -1L; 61 hasNext = false; 62 nextNBranch = 1; 63 } 64 65 public IdentificationImpl() throws RemoteException { 66 nm = ""; 67 ver = ""; 68 lang = ""; 69 tg = new String [0]; 70 brtg = ""; 71 abs = new AbsoluteNameImpl(""); 72 langabs = null; 73 nextLock = new Lock(false); 74 lockId = -1L; 75 hasNext = false; 76 nextNBranch = 1; 77 } 78 79 public IdentificationImpl(Identification i) throws RemoteException { 80 nm = new String (i.name()); 81 ver = new String (i.version()); 82 brtg = new String (i.branchTag()); 83 String [] t = i.tag(); 84 int j; 85 tg = new String [t.length]; 86 for(j=0;j<t.length;j++) 87 tg[j] = new String (t[j]); 88 abs = new AbsoluteNameImpl(i.absolute_name().name()); 89 nextLock = new Lock(false); 90 lockId = -1L; 91 hasNext = ((SIdentification)i).hasNextVersion(); 92 nextNBranch = ((SIdentification)i).nextNumBranch(); 93 94 lang = new String (((SIdentification)i).language()); 95 96 langabs = new AbsoluteNameImpl(lang, abs); 97 } 98 99 public String language() throws RemoteException { 100 return lang; 101 } 102 103 public boolean is_equal(Identification id) throws RemoteException { 104 if ((nm.compareTo(id.name())==0) && (ver.compareTo(id.version())==0) 105 && abs.isEqual(id.absolute_name()) && (lang.compareTo(((SIdentification)id).language())==0)) 106 return true; 107 else 108 return false; 109 } 110 111 public boolean is_name_equal(Identification id) throws RemoteException { 112 if ((nm.compareTo(id.name())==0)&& abs.isEqual(id.absolute_name())) 113 return true; 114 else 115 return false; 116 } 117 118 public boolean is_name_equal(String name) throws RemoteException { 119 if (name.compareTo(abs.name())==0) 120 return true; 121 else 122 return false; 123 } 124 125 public String name() { 126 return nm; 127 } 128 129 public AbsoluteName absolute_name() { 130 return abs; 131 } 132 133 public AbsoluteName lang_absolute_name() throws RemoteException { 134 return langabs; 135 } 136 137 public String version() { 138 return ver; 139 } 140 141 public void version(String v) { 142 if (v==null) 143 ver = ""; 144 ver = v; 145 } 146 147 public void tag(String t) { 148 if (t!=null) { 149 int i, len = tg.length; 150 for (i=0;i<len;i++) { 151 if (tg[i].compareTo(t)==0) 152 return; 153 } 154 String [] newt = new String [len+1]; 155 for (i=0;i<len;i++) { 156 newt[i] = tg[i]; 157 } 158 newt[i] = new String (t); 159 tg = newt; 160 } 161 } 162 163 public String [] tag() { 164 String t[] = new String [tg.length]; 165 for (int i=0;i<tg.length;i++) 166 t[i] = new String (tg[i]); 167 return t; 168 } 169 170 public String branchTag() { 171 return brtg; 172 } 173 174 public void save(DataOutputStream out) throws TIRExceptStorage { 175 try { 176 Storage.writeString(out, nm); 177 Storage.writeString(out, abs.toString()); 178 Storage.writeString(out, lang); 179 Storage.writeString(out, ver); 180 out.writeInt(tg.length); 181 for (int i=0; i<tg.length;i++) 182 Storage.writeString(out, tg[i]); 183 Storage.writeString(out, brtg); 184 out.writeLong(nextNBranch); 185 if (nextLock.isLocked()) 186 out.writeBoolean(false); 187 else 188 out.writeBoolean(hasNext); 189 } catch (IOException e) { 190 throw new TIRExceptStorage("Access error in saving identification "+nm); 191 } 192 } 193 194 public void load(DataInputStream in) throws TIRExceptStorage { 195 try { 196 nm = Storage.readString(in); 197 abs = new AbsoluteNameImpl(Storage.readString(in)); 198 lang = Storage.readString(in); 199 langabs = new AbsoluteNameImpl(lang, abs); 200 ver = Storage.readString(in); 201 int i, len = in.readInt(); 202 tg = new String [len]; 203 for(i=0;i<len;i++) 204 tg[i] = Storage.readString(in); 205 brtg = Storage.readString(in); 206 nextNBranch = in.readLong(); 207 hasNext = in.readBoolean(); 208 } catch (IOException e) { 209 throw new TIRExceptStorage("Access error"); 210 } 211 } 212 213 public boolean is_equal(String name, String version) throws RemoteException { 214 if (name.compareTo(abs.name())==0 && (ver.compareTo(version)==0)) 215 return true; 216 else 217 return false; 218 } 219 220 public String toString() { 221 return new String (nm+"?"+ver); 222 } 223 224 public boolean isLocked() throws RemoteException { 225 return nextLock.isLocked(); 226 } 227 228 public long lockFor() throws RemoteException { 229 return lockId; 230 } 231 232 public boolean lock(long lockFor) throws RemoteException { 233 boolean a = nextLock.lock(); 234 if (a) 235 this.lockId = lockFor; 236 return a; 237 } 238 239 public void unlock() throws RemoteException { 240 lockId = -1L; 241 nextLock.unlock(); 242 } 243 244 public long nextNumBranch() throws RemoteException { 245 return nextNBranch; 246 } 247 248 public void incNextNumBranch() throws RemoteException { nextNBranch++; } 249 public boolean hasNextVersion() throws RemoteException { return hasNext; } 250 public void setNextVersion() throws RemoteException { hasNext = true; } 251 252 public boolean is_short_equal(Identification id) throws RemoteException { 253 if ((nm.compareTo(id.name())==0) && (ver.compareTo(id.version())==0)) 254 return true; 255 else 256 return false; 257 } 258 259 public boolean is_short_equal(String name, String version) throws RemoteException { 260 if ((nm.compareTo(name)==0) && (ver.compareTo(version)==0)) 261 return true; 262 else 263 return false; 264 } 265 266 public boolean is_short_name_equal(Identification id) throws RemoteException { 267 if ((nm.compareTo(id.name())==0)) 268 return true; 269 else 270 return false; 271 } 272 273 public boolean is_short_name_equal(String name) throws RemoteException { 274 if (nm.compareTo(name)==0) 275 return true; 276 else 277 return false; 278 } 279 280 public boolean is_local() throws RemoteException { 281 String sofaNodeName = System.getProperty("sofanode.name",""); 282 283 StringBuffer ip = new StringBuffer (); 285 int i = 0; 286 while ((i<ver.length()) && (ver.charAt(i)!='!')) { 287 ip.append(ver.charAt(i)); 288 i++; 289 } 290 291 if (sofaNodeName.compareTo(ip.toString())==0) 292 return true; 293 else 294 return false; 295 } 296 } 297 | Popular Tags |