1 23 24 package org.objectweb.fractal.adl.components; 25 26 import java.util.ArrayList ; 27 import java.util.Iterator ; 28 import java.util.List ; 29 import java.util.Map ; 30 import java.util.TreeMap ; 31 32 import org.objectweb.fractal.adl.ADLException; 33 import org.objectweb.fractal.adl.Compiler; 34 import org.objectweb.fractal.adl.Definition; 35 import org.objectweb.fractal.adl.TaskMap; 36 import org.objectweb.fractal.api.control.BindingController; 37 38 43 44 public class ComponentCompiler implements BindingController, Compiler { 45 46 50 51 public final static String PRIMITIVE_COMPILERS_BINDING = "primitive-compilers"; 52 53 56 57 public Map primitiveCompilers = new TreeMap (); 58 59 63 public String [] listFc() { 64 return (String [])primitiveCompilers.keySet().toArray(new String [primitiveCompilers.size()]); 65 } 66 67 public Object lookupFc (final String itf) { 68 if (itf.startsWith(PRIMITIVE_COMPILERS_BINDING)) { 69 return primitiveCompilers.get(itf); 70 } 71 return null; 72 } 73 74 public void bindFc (final String itf, final Object value) { 75 if (itf.startsWith(PRIMITIVE_COMPILERS_BINDING)) { 76 primitiveCompilers.put(itf, value); 77 } 78 } 79 80 public void unbindFc (final String itf) { 81 if (itf.startsWith(PRIMITIVE_COMPILERS_BINDING)) { 82 primitiveCompilers.remove(itf); 83 } 84 } 85 86 90 public void compile ( 91 final Definition definition, 92 final TaskMap tasks, 93 final Map context) throws ADLException 94 { 95 if (definition instanceof ComponentContainer) { 96 compile(new ArrayList (), (ComponentContainer)definition, tasks, context); 97 } 98 } 99 100 104 void compile ( 105 final List path, 106 final ComponentContainer container, 107 final TaskMap tasks, 108 final Map context) throws ADLException 109 { 110 path.add(container); 111 Component[] comps = container.getComponents(); 112 for (int i = 0; i < comps.length; i++) { 113 compile(path, comps[i], tasks, context); 114 } 115 path.remove(path.size() - 1); 116 117 Iterator it = primitiveCompilers.values().iterator(); 118 while (it.hasNext()) { 119 ((PrimitiveCompiler)it.next()).compile(path, container, tasks, context); 120 } 121 } 122 } 123 | Popular Tags |