00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 package org.objectweb.proactive.core.component;
00032
00033 import java.io.Serializable;
00034 import java.util.ArrayList;
00035 import java.util.HashMap;
00036 import java.util.List;
00037 import java.util.Map;
00038
00039 import org.objectweb.fractal.api.NoSuchInterfaceException;
00040 import org.objectweb.fractal.api.type.InterfaceType;
00041 import org.objectweb.proactive.core.ProActiveRuntimeException;
00042
00043
00058 public class Bindings implements Serializable {
00059
00060
00061
00062 private Map normalBindings;
00063 private Map exportBindings;
00064
00065
00066
00067 public Bindings() {
00068 normalBindings = new HashMap();
00069 exportBindings = new HashMap();
00070 }
00071
00075 public void add(Binding binding) {
00076 try {
00077 InterfaceType client_itf_type = (InterfaceType) binding.getClientInterface()
00078 .getFcItfType();
00079
00080
00081 if (!client_itf_type.isFcClientItf()) {
00082 if (Fractive.getComponentParametersController(
00083 binding.getClientInterface().getFcItfOwner())
00084 .getComponentParameters().getHierarchicalType()
00085 .equals(Constants.PARALLEL)) {
00086 addCollectiveBindingOnInternalClientItf(binding);
00087 } else {
00088 exportBindings.put(binding.getClientInterfaceName(), binding);
00089 }
00090 } else {
00091
00092 if (client_itf_type.isFcCollectionItf()) {
00093 addCollectiveBindingOnExternalClientItf(binding);
00094 } else {
00095 normalBindings.put(binding.getClientInterfaceName(), binding);
00096 }
00097 }
00098 } catch (NoSuchInterfaceException nsie) {
00099 throw new ProActiveRuntimeException("interface not found : " +
00100 nsie.getMessage());
00101 }
00102 }
00103
00104
00105
00111 public Object remove(String clientItfName) {
00112 if (normalBindings.containsKey(clientItfName)) {
00113 return normalBindings.remove(clientItfName);
00114 }
00115 if (exportBindings.containsKey(clientItfName)) {
00116 return exportBindings.remove(clientItfName);
00117 }
00118 return null;
00119 }
00120
00126 public Object get(String clientItfName) {
00127 if (normalBindings.containsKey(clientItfName)) {
00128 return normalBindings.get(clientItfName);
00129 }
00130 if (exportBindings.containsKey(clientItfName)) {
00131 return exportBindings.get(clientItfName);
00132 }
00133 return null;
00134 }
00135
00141 public boolean containsBindingOn(String clientItfName) {
00142 return (normalBindings.containsKey(clientItfName) ||
00143 exportBindings.containsKey(clientItfName));
00144 }
00145
00151 public String[] getExternalClientBindings() {
00152 return (String[]) normalBindings.keySet().toArray(new String[normalBindings.keySet()
00153 .size()]);
00154 }
00155
00160 private static void addCollectiveBinding(Map bindingsTable, Binding binding) {
00161 String client_itf_name = binding.getClientInterfaceName();
00162 if (binding.getClientInterface().getFcItfName().equals(client_itf_name)) {
00163 if (bindingsTable.containsKey(client_itf_name)) {
00164
00165 ((List) bindingsTable.get(client_itf_name)).add(binding);
00166 } else {
00167 ArrayList bindings_collection = new ArrayList();
00168 bindings_collection.add(binding);
00169 bindingsTable.put(client_itf_name, bindings_collection);
00170 }
00171 } else {
00172 bindingsTable.put(client_itf_name, binding);
00173 }
00174 }
00175
00180 private void addCollectiveBindingOnExternalClientItf(Binding binding) {
00181 addCollectiveBinding(normalBindings, binding);
00182 }
00183
00187 private void addCollectiveBindingOnInternalClientItf(Binding binding) {
00188 if (exportBindings == null) {
00189 exportBindings = new HashMap();
00190 }
00191 addCollectiveBinding(exportBindings, binding);
00192 }
00193 }