1 23 24 package org.objectweb.fractal.adl.bindings; 25 26 import java.io.PrintWriter ; 27 import java.util.ArrayList ; 28 import java.util.HashSet ; 29 import java.util.List ; 30 import java.util.Map ; 31 import java.util.Set ; 32 import java.util.WeakHashMap ; 33 34 38 39 public class StaticJavaBindingBuilder implements BindingBuilder { 40 41 47 48 private Map bindingLists = new WeakHashMap (); 49 50 55 56 private Map itfSets = new WeakHashMap (); 57 58 62 public void bindComponent ( 63 final int type, 64 final Object clientComp, 65 final String clientItf, 66 final Object serverComp, 67 final String serverItf, 68 final Object context) 69 { 70 Binding b = new Binding(); 71 b.client = (String )clientComp; 72 b.clientInterface = clientItf; 73 b.server = (String )serverComp; 74 b.serverInterface = serverItf; 75 76 List bindings = (List )bindingLists.get(context); 77 if (bindings == null) { 78 bindings = new ArrayList (); 79 bindingLists.put(context, bindings); 80 } 81 bindings.add(b); 82 Set itfs = (Set )itfSets.get(context); 83 if (itfs == null) { 84 itfs = new HashSet (); 85 itfSets.put(context, itfs); 86 } 87 88 PrintWriter pw = (PrintWriter )((Map )context).get("printwriter"); 89 90 for (int i = 0; i < bindings.size(); ++i) { 92 b = (Binding)bindings.get(i); 93 String client = (String )b.client; 94 String clientInterface = b.clientInterface; 95 String server = (String )b.server; 96 String serverInterface = b.serverInterface; 97 top: while (server != null && !server.startsWith("P")) { 98 for (int j = 0; j < bindings.size(); ++j) { 99 b = (Binding)bindings.get(j); 100 if (b.client.equals(server) && b.clientInterface.equals(serverInterface)) { 101 server = b.server; 102 serverInterface = b.serverInterface; 103 continue top; 104 } 105 } 106 server = null; 107 } 108 if (server != null) { 109 if (client.startsWith("P") ){ 110 pw.print(client); 111 pw.print(".bindFc(\""); 112 pw.print(clientInterface); 113 pw.print("\","); 114 pw.print(server); 115 pw.println(");"); 116 bindings.remove(i--); 117 } else { 118 StringBuffer buf = new StringBuffer (); 119 buf.append(client); 120 buf.append(".put(\""); 121 buf.append(clientInterface); 122 buf.append("\","); 123 buf.append(server); 124 buf.append(");\n"); 125 String s = buf.toString(); 126 if (!itfs.contains(s)) { 127 itfs.add(s); 128 pw.write(s); 129 } 130 } 131 } 132 } 133 } 134 135 139 static class Binding { 140 String client; 141 String clientInterface; 142 String server; 143 String serverInterface; 144 } 145 } 146 | Popular Tags |