All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.objectweb.fractal.bf.adl.binder.StaticBinderBuilder Maven / Gradle / Ivy

There is a newer version: 0.9
Show newest version
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);");

	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy