1 2 package SOFA.SOFAnode.Made.TIR.Access; 3 4 5 import java.rmi.RemoteException ; 6 import java.util.ArrayList ; 7 import java.util.StringTokenizer ; 8 9 import SOFA.SOFAnode.Made.TIR.ArrayDef; 10 import SOFA.SOFAnode.Made.TIR.CDLType; 11 import SOFA.SOFAnode.Made.TIR.Contained; 12 import SOFA.SOFAnode.Made.TIR.Container; 13 import SOFA.SOFAnode.Made.TIR.DefinitionKind; 14 import SOFA.SOFAnode.Made.TIR.Identification; 15 import SOFA.SOFAnode.Made.TIR.InterfaceDef; 16 import SOFA.SOFAnode.Made.TIR.ProvideDef; 17 import SOFA.SOFAnode.Made.TIR.Repository; 18 import SOFA.SOFAnode.Made.TIR.RequireDef; 19 import SOFA.SOFAnode.Made.TIR.SequenceDef; 20 import SOFA.SOFAnode.Made.TIR.TIRExceptLock; 21 import SOFA.SOFAnode.Made.TIR.TypedefDef; 22 23 27 public class TIRAccessMethods { 28 29 36 public static Repository getRepository() throws java.net.MalformedURLException , java.rmi.NotBoundException , java.rmi.RemoteException { 37 String rmiport = System.getProperty("sofa.rmiport","1099"); 38 String rmihost = System.getProperty("sofa.rmihost","localhost"); 39 return (Repository) java.rmi.Naming.lookup("//"+rmihost+":"+rmiport+"/Repository"); 40 } 41 42 50 public static Contained lookupContained(Repository rep, String lang, String name, String version) throws RemoteException , TIRExceptLock { 51 ArrayList nm = new ArrayList (); 52 StringTokenizer st = new StringTokenizer (name,"::"); 53 while (st.hasMoreTokens()) { 54 nm.add(st.nextToken()); 55 } 56 57 Contained[] cnt; 58 Container cont; 59 Contained next = null; 60 next = rep.lookup(lang,""); 61 if (next == null) { 62 return null; 63 } 64 cont = (Container) next; 65 int i; 66 for (i=0; i<nm.size()-1; i++) { 67 cnt = cont.lookup_name((String ) nm.get(i)); 68 if (cnt == null || cnt.length == 0) { 69 return null; 70 } 71 if (cnt.length == 1) { 72 next = cnt[0]; 73 } else { 74 next = cont.lookup((String ) nm.get(i), version); 75 if (next == null) { 76 return null; 77 } 78 } 79 if (!(next instanceof Container)) { 80 return null; 81 } 82 cont = (Container) next; 83 } 84 return cont.lookup((String ) nm.get(i), version); 85 } 86 87 94 public static Contained lookupCDLContained(Repository rep, String name, String version) throws RemoteException , TIRExceptLock { 95 return lookupContained(rep, "cdl", name, version); 96 } 97 98 104 public static Contained lookupCDLContained(Repository rep, String fullName) throws RemoteException , TIRExceptLock { 105 int n = fullName.indexOf('?'); 106 if (n != 0) { 107 return lookupContained(rep, "cdl", fullName.substring(0,n), fullName.substring(n+1,fullName.length())); 108 } else 109 return null; 110 } 111 112 118 public static Contained[] getOperAttrOfInterface(Repository rep, String fullName) throws RemoteException , TIRExceptLock { 119 Contained cnt = lookupCDLContained(rep, fullName); 120 if (cnt!=null && cnt.get_def_kind().value() == DefinitionKind.dk_Interface) 121 return getOperAttrOfInterface((InterfaceDef) cnt); 122 else 123 return null; 124 } 125 126 131 public static Contained[] getOperAttrOfInterface(InterfaceDef iface) throws RemoteException , TIRExceptLock { 132 ArrayList all = new ArrayList (); 133 ArrayList scanned = new ArrayList (); 134 Contained[] cnt = iface.contents(null); 135 for (int i=0; i<cnt.length; i++) { 136 int dk = cnt[i].get_def_kind().value(); 137 if ( dk == DefinitionKind.dk_Attribute || dk == DefinitionKind.dk_Operation) { 138 all.add(cnt[i]); 139 } 140 } 141 scanned.add(iface); 142 143 scanBase(all, scanned, iface); 144 145 Contained[] ret = new Contained [all.size()]; 146 for (int i=0; i<ret.length; i++) { 147 ret[i] = (Contained) all.get(i); 148 } 149 return ret; 150 } 151 152 private static void scanBase(ArrayList all, ArrayList scanned, InterfaceDef iface) throws RemoteException , TIRExceptLock { 153 InterfaceDef[] base = iface.base_interfaces(); 154 for (int i=0; i< base.length; i++) { 155 if (! isInScanned(scanned, base[i])) { 156 Contained[] cnt = base[i].contents(null); 157 for (int j=0; j<cnt.length; j++) { 158 int dk = cnt[j].get_def_kind().value(); 159 if ( dk == DefinitionKind.dk_Attribute || dk == DefinitionKind.dk_Operation) { 160 all.add(cnt[j]); 161 } 162 } 163 scanned.add(base[i]); 164 scanBase(all, scanned, base[i]); 165 } 166 } 167 } 168 169 private static boolean isInScanned(ArrayList scanned, InterfaceDef iface) throws RemoteException { 170 Identification id = iface.get_identification(); 171 for (int i=0; i<scanned.size(); i++) { 172 if (((InterfaceDef) scanned.get(i)).get_identification().is_equal(id)) 173 return true; 174 } 175 return false; 176 } 177 178 185 public static InterfaceDef getIfaceOfProvides(ProvideDef prov) throws RemoteException , TIRExceptLock { 186 CDLType type = prov.provide(); 187 while (!(type instanceof InterfaceDef)) { 188 int kind = type.get_def_kind().value(); 189 switch (kind) { 190 case DefinitionKind.dk_Typedef: 191 type = ((TypedefDef) type).original_type(); 192 break; 193 case DefinitionKind.dk_Array: 194 type = ((ArrayDef) type).element_type(); 195 break; 196 case DefinitionKind.dk_Sequence: 197 type = ((SequenceDef) type).element_type(); 198 break; 199 } 200 } 201 return (InterfaceDef) type; 202 } 203 204 211 public static boolean containProvArrays(ProvideDef prov) throws RemoteException , TIRExceptLock { 212 CDLType type = prov.provide(); 213 while (!(type instanceof InterfaceDef)) { 214 int kind = type.get_def_kind().value(); 215 switch (kind) { 216 case DefinitionKind.dk_Typedef: 217 type = ((TypedefDef) type).original_type(); 218 break; 219 case DefinitionKind.dk_Array: 220 return true; 221 case DefinitionKind.dk_Sequence: 222 return true; 223 } 224 } 225 return false; 226 } 227 228 229 236 public static InterfaceDef getIfaceOfRequires(RequireDef prov) throws RemoteException , TIRExceptLock { 237 CDLType type = prov.require(); 238 while (!(type instanceof InterfaceDef)) { 239 int kind = type.get_def_kind().value(); 240 switch (kind) { 241 case DefinitionKind.dk_Typedef: 242 type = ((TypedefDef) type).original_type(); 243 break; 244 case DefinitionKind.dk_Array: 245 type = ((ArrayDef) type).element_type(); 246 break; 247 case DefinitionKind.dk_Sequence: 248 type = ((SequenceDef) type).element_type(); 249 break; 250 } 251 } 252 return (InterfaceDef) type; 253 } 254 255 262 public static boolean containReqArrays(RequireDef prov) throws RemoteException , TIRExceptLock { 263 CDLType type = prov.require(); 264 while (!(type instanceof InterfaceDef)) { 265 int kind = type.get_def_kind().value(); 266 switch (kind) { 267 case DefinitionKind.dk_Typedef: 268 type = ((TypedefDef) type).original_type(); 269 break; 270 case DefinitionKind.dk_Array: 271 return true; 272 case DefinitionKind.dk_Sequence: 273 return true; 274 } 275 } 276 return false; 277 } 278 279 296 } 297 | Popular Tags |