1 23 24 package org.objectweb.fractal.adl.coordinates; 25 26 import java.util.List ; 27 import java.util.Map ; 28 29 import org.objectweb.deployment.scheduling.component.api.InstanceProviderTask; 30 import org.objectweb.deployment.scheduling.component.lib.AbstractConfigurationTask; 31 import org.objectweb.fractal.adl.ADLException; 32 import org.objectweb.fractal.adl.TaskMap; 33 import org.objectweb.fractal.adl.components.Component; 34 import org.objectweb.fractal.adl.components.ComponentContainer; 35 import org.objectweb.fractal.adl.components.ComponentPair; 36 import org.objectweb.fractal.adl.components.PrimitiveCompiler; 37 import org.objectweb.fractal.adl.coordinates.Coordinates; 38 import org.objectweb.fractal.adl.coordinates.CoordinatesContainer; 39 import org.objectweb.fractal.api.control.BindingController; 40 41 45 46 public class CoordinatesCompiler implements PrimitiveCompiler, BindingController { 47 48 52 53 public final static String BUILDER_BINDING = "builder"; 54 57 58 private CoordinatesBuilder builder; 59 60 64 public String [] listFc () { 65 return new String [] { BUILDER_BINDING }; 66 } 67 68 public Object lookupFc (final String clientItfName) { 69 if (BUILDER_BINDING.equals(clientItfName)) { 70 return builder; 71 } 72 return null; 73 } 74 75 public void bindFc ( 76 final String clientItfName, 77 final Object serverItf) 78 { 79 if (BUILDER_BINDING.equals(clientItfName)) { 80 builder = (CoordinatesBuilder)serverItf; 81 } 82 } 83 84 public void unbindFc (final String clientItfName) { 85 if (BUILDER_BINDING.equals(clientItfName)) { 86 builder = null; 87 } 88 } 89 90 94 public void compile ( 95 List path, 96 ComponentContainer container, 97 TaskMap tasks, 98 Map context) throws ADLException 99 { 100 if (path.size() > 0 || !(container instanceof CoordinatesContainer)) { 101 return; 102 } 103 compile((CoordinatesContainer)container, container, tasks); 104 } 105 106 private void compile (CoordinatesContainer c, ComponentContainer cc, TaskMap tasks) { 107 Coordinates[] coords = c.getCoordinatess(); 108 Component[] comps = cc.getComponents(); 109 for (int i = 0; i < coords.length; ++i) { 110 String name = coords[i].getName(); 111 for (int j = 0; j < comps.length; ++j) { 112 if (comps[j].getName().equals(name)) { 113 double x0 = Double.parseDouble(coords[i].getX0()); 114 double y0 = Double.parseDouble(coords[i].getY0()); 115 double x1 = Double.parseDouble(coords[i].getX1()); 116 double y1 = Double.parseDouble(coords[i].getY1()); 117 int color = Integer.parseInt(coords[i].getColor()); 118 InstanceProviderTask pt = (InstanceProviderTask)tasks.getTask("create", cc); 119 InstanceProviderTask ct = (InstanceProviderTask)tasks.getTask("create", comps[j]); 120 SetCoordinatesTask t = new SetCoordinatesTask(builder, x0, y0, x1, y1, color); 121 t.setParentInstanceProviderTask(pt); 122 t.setInstanceProviderTask(ct); 123 ComponentPair pair = new ComponentPair(cc, comps[j]); 124 t.addPreviousTask(tasks.getTask("add", pair)); 125 tasks.addTask("coordinates", pair, t); 126 compile(coords[i], comps[j], tasks); 127 } 128 } 129 } 130 } 131 132 136 static class SetCoordinatesTask extends AbstractConfigurationTask { 137 138 private InstanceProviderTask parentInstanceProviderTask; 139 140 private CoordinatesBuilder builder; 141 142 private double x0, y0, x1, y1; 143 144 private int color; 145 146 public SetCoordinatesTask ( 147 CoordinatesBuilder builder, 148 double x0, 149 double y0, 150 double x1, 151 double y1, 152 int color) 153 { 154 this.builder = builder; 155 this.x0 = x0; 156 this.y0 = y0; 157 this.x1 = x1; 158 this.y1 = y1; 159 this.color = color; 160 } 161 162 public InstanceProviderTask getParentInstanceProviderTask () { 163 return parentInstanceProviderTask; 164 } 165 166 public void setParentInstanceProviderTask (InstanceProviderTask task) { 167 if (parentInstanceProviderTask != null) { 168 removePreviousTask(parentInstanceProviderTask); 169 } 170 parentInstanceProviderTask = task; 171 if (parentInstanceProviderTask != null) { 172 addPreviousTask(parentInstanceProviderTask); 173 } 174 } 175 176 public void execute (final Object context) throws Exception { 177 Object parent = getParentInstanceProviderTask().getResult(); 178 Object component = getInstanceProviderTask().getResult(); 179 builder.setCoordinates(parent, component, x0, y0, x1, y1, color, context); 180 } 181 182 public Object getResult() { 183 return null; 184 } 185 186 public void setResult (Object result) { 187 } 188 } 189 } 190 | Popular Tags |