KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > modfact > jmi > reflect > M3ClientHelper


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 JavaDoc 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 JavaDoc("Please set system property 'org.objectweb.modfact.resourceURL'");
25                 }
26             } else {
27                 in =
28                     new java.net.URL JavaDoc(resourceURL + "/M3links.txt").openStream();
29             }
30
31             BufferedReader r = new BufferedReader(new InputStreamReader(in));
32             String JavaDoc 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 JavaDoc end1Key = line;
47                     String JavaDoc 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 JavaDoc e) {
54                         System.out.println(
55                             "Couldnot set link("
56                                 + end1Key
57                                 + ","
58                                 + end2Key
59                                 + ")");
60                         throw e;
61                     }
62                     //System.out.println("line " +lineNo);
63
} else {
64                     break;
65                 }
66             }
67             in.close();
68         } catch (Exception JavaDoc e) {
69             if (e instanceof RuntimeException JavaDoc)
70                 throw (RuntimeException JavaDoc) e;
71             throw new RuntimeException JavaDoc(e);
72         }
73     }
74
75 }
76
Popular Tags