1 23 24 package org.objectweb.fractal.adl.bindings; 25 26 import java.lang.reflect.Method ; 27 import java.util.ArrayList ; 28 import java.util.List ; 29 import java.util.Map ; 30 import java.util.WeakHashMap ; 31 32 35 36 public class JavaBindingBuilder implements BindingBuilder { 37 38 44 45 private Map bindingLists = new WeakHashMap (); 46 47 51 public void bindComponent ( 52 final int type, 53 final Object clientComp, 54 final String clientItf, 55 final Object serverComp, 56 final String serverItf, 57 final Object context) throws Exception 58 { 59 Binding b = new Binding(); 60 b.client = clientComp; 61 b.clientInterface = clientItf; 62 b.server = serverComp; 63 b.serverInterface = serverItf; 64 65 List bindings = (List )bindingLists.get(context); 66 if (bindings == null) { 67 bindings = new ArrayList (); 68 bindingLists.put(context, bindings); 69 } 70 bindings.add(b); 71 72 for (int i = 0; i < bindings.size(); ++i) { 73 b = (Binding)bindings.get(i); 74 Object client = b.client; 75 String clientInterface = b.clientInterface; 76 Object server = b.server; 77 String serverInterface = b.serverInterface; 78 top: while (server != null && server instanceof Map ) { 79 for (int j = 0; j < bindings.size(); ++j) { 80 b = (Binding)bindings.get(j); 81 if (b.client == server && b.clientInterface.equals(serverInterface)) { 82 server = b.server; 83 serverInterface = b.serverInterface; 84 continue top; 85 } 86 } 87 server = null; 88 } 89 if (server != null) { 90 if (client instanceof Map ) { 91 ((Map )client).put(clientInterface, server); 92 } else { 93 Method m = client.getClass().getMethod("bindFc", new Class [] { 94 String .class, Object .class 95 }); 96 m.invoke(client, new Object [] { clientInterface, server }); 97 bindings.remove(i--); 98 } 99 } 100 } 101 } 102 103 107 static class Binding { 108 Object client; 109 String clientInterface; 110 Object server; 111 String serverInterface; 112 } 113 } 114 | Popular Tags |