1 package org.objectweb.modfact.jmi.reflect; 2 3 import javax.jmi.reflect.*; 4 import java.io.*; 5 6 class M3ClientHelper { 7 8 static void loadLinks(M3Client c) { 9 try { 10 11 InputStream in = null; 12 String resourceURL = 13 System.getProperty("org.objectweb.modfact.resourceURL"); 14 if (resourceURL == null) { 15 in = 16 ClassLoader.getSystemResourceAsStream( 17 M3ClientGenerator.relpath + "/M3links.txt"); 18 if (in == null) { 19 in = 20 Thread.currentThread().getContextClassLoader().getResourceAsStream( 21 M3ClientGenerator.relpath + "/M3links.txt"); 22 } 23 if (in == null) { 24 throw new RuntimeException ("Please set system property 'org.objectweb.modfact.resourceURL'"); 25 } 26 } else { 27 in = 28 new java.net.URL (resourceURL + "/M3links.txt").openStream(); 29 } 30 31 BufferedReader r = new BufferedReader(new InputStreamReader(in)); 32 String line; 33 RefAssociationImpl asso = null; 34 int lineNo = 0; 35 while ((line = r.readLine()) != null) { 36 lineNo++; 37 38 if(line.startsWith("timestamp=")) { 39 long timestamp = Long.parseLong(r.readLine()); 40 c.checkTimeStamp(timestamp); 41 42 } else if (line.startsWith("Association=")) { 43 asso = 44 (RefAssociationImpl) c.p.refAssociation(r.readLine()); 45 } else if (line.startsWith("o")) { 46 String end1Key = line; 47 String end2Key = r.readLine(); 48 lineNo++; 49 try { 50 RefObject end1 = (RefObject) c.get(end1Key); 51 RefObject end2 = (RefObject) c.get(end2Key); 52 asso._refAddLink(end1, end2); 53 } catch (Exception e) { 54 System.out.println( 55 "Couldnot set link(" 56 + end1Key 57 + "," 58 + end2Key 59 + ")"); 60 throw e; 61 } 62 } else { 64 break; 65 } 66 } 67 in.close(); 68 } catch (Exception e) { 69 if (e instanceof RuntimeException ) 70 throw (RuntimeException ) e; 71 throw new RuntimeException (e); 72 } 73 } 74 75 } 76 | Popular Tags |