1 2 package SOFA.SOFAnode.Made.CodeGen; 3 4 import java.util.ArrayList ; 5 6 10 public class ID { 11 ArrayList name; 12 String ver; 13 14 19 public ID(String nm) throws BadIDException { 20 name = new ArrayList (); 21 int iOfQ = nm.indexOf('?'); 22 if (iOfQ == -1) { parseAN(nm, name); 24 } else { String absnm = nm.substring(0, iOfQ); 26 ver = nm.substring(iOfQ+1); 27 if (ver.length()==0 || ver.indexOf('?')!=-1) 28 throw new BadIDException(); 29 parseAN(absnm, name); 30 } 31 } 32 33 39 private void parseAN(String nm, ArrayList name) throws BadIDException { 40 StringBuffer sn = new StringBuffer (); 41 boolean dv = false; 42 for (int i=0;i<nm.length();i++) { 43 if (dv && nm.charAt(i)!=':') 44 throw new BadIDException(); 45 if (dv) { if (name.size()!=0 || sn.length()!=0) { if (sn.length()==0) throw new BadIDException(); 49 name.add(sn.toString()); 50 sn.delete(0, sn.length()); 51 } 52 dv = false; 53 continue; 54 } 55 if (nm.charAt(i)==':') { 56 dv = true; 57 continue; 58 } 59 sn.append(nm.charAt(i)); 60 } 61 if (sn.length() != 0) name.add(sn.toString()); 63 else 64 throw new BadIDException(); 65 } 66 67 69 public String toString() { 70 StringBuffer ret = new StringBuffer ("::"); 71 for (int i=0; i<name.size();i++) { 72 ret.append((String ) name.get(i)); 73 if (i+1 != name.size()) 74 ret.append("::"); 75 } 76 if (ver != null && ver.length() != 0) { 77 ret.append("?"); 78 ret.append(ver); 79 } 80 return ret.toString(); 81 } 82 83 85 public String absoluteName() { 86 StringBuffer ret = new StringBuffer ("::"); 87 for (int i=0; i<name.size();i++) { 88 ret.append((String ) name.get(i)); 89 if (i+1 != name.size()) 90 ret.append("::"); 91 } 92 return ret.toString(); 93 } 94 95 97 public int size() { 98 return name.size(); 99 } 100 101 103 public String version() { 104 return ver; 105 } 106 107 112 public String get(int index) { 113 return (String ) name.get(index); 114 } 115 } 116 | Popular Tags |