org.objectweb.fractal.bf.adl.binder.StaticBinderBuilder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of fractal-bf-adl Show documentation
Show all versions of fractal-bf-adl Show documentation
Extend Fractal-ADL to specify binding protocols.
package org.objectweb.fractal.bf.adl.binder;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;
import org.objectweb.fractal.bf.BindingFactoryException;
import org.objectweb.fractal.bf.adl.common.Parameter;
/**
* A binder builder meant to be used with a static backend of Fractal-BF ADL.
*/
public class StaticBinderBuilder implements BinderBuilder {
Logger log = Logger.getLogger(StaticBinderBuilder.class.getCanonicalName());
/**
* @see org.objectweb.fractal.bf.adl.binder.BinderBuilder#bind(java.lang.String,
* java.lang.Object, java.util.List, java.lang.String,
* java.lang.Object)
*/
public void bind(String itfName, Object component,
List parameters, String type, Object context)
throws BindingFactoryException {
PrintWriter pw = (PrintWriter) ((Map, ?>) context).get("printwriter");
log.finest("PrintWriter for static binder builder: " + pw);
pw.write(Map.class.getCanonicalName()
+ " binderHints = new "
+ HashMap.class.getCanonicalName() + "();");
for (Parameter p : parameters) {
// xportHints.put(p.getName(), p.getValue());
pw.write("binderHints.put(\"" + p.getName() + "\",\""
+ p.getValue() + "\");");
}
pw
.write("BindingFactory bf = BindingFactoryHelper.getBindingFactory();");
pw.write("Component component = (Component)" + component + ";\n");
pw.write("bf.bind(component, \"" + itfName + "\", binderHints);");
}
}