1 23 24 package org.objectweb.fractal.adl; 25 26 import java.util.Map ; 27 28 import org.objectweb.deployment.scheduling.core.api.Scheduler; 29 import org.objectweb.deployment.scheduling.component.api.FactoryProviderTask; 30 import org.objectweb.deployment.scheduling.component.api.InstanceProviderTask; 31 import org.objectweb.fractal.api.control.BindingController; 32 33 38 39 public class BasicFactory implements BindingController, Factory { 40 41 45 46 public final static String LOADER_BINDING = "loader"; 47 48 52 53 public final static String COMPILER_BINDING = "compiler"; 54 55 59 60 public final static String SCHEDULER_BINDING = "scheduler"; 61 62 65 66 public Loader loader; 67 68 71 72 public Compiler compiler; 73 74 77 78 public Scheduler scheduler; 79 80 84 public String [] listFc() { 85 return new String [] { LOADER_BINDING, COMPILER_BINDING, SCHEDULER_BINDING }; 86 } 87 88 public Object lookupFc (final String itf) { 89 if (itf.equals(LOADER_BINDING)) { 90 return loader; 91 } else if (itf.equals(COMPILER_BINDING)) { 92 return compiler; 93 } else if (itf.equals(SCHEDULER_BINDING)) { 94 return scheduler; 95 } 96 return null; 97 } 98 99 public void bindFc (final String itf, final Object value) { 100 if (itf.equals(LOADER_BINDING)) { 101 loader = (Loader)value; 102 } else if (itf.equals(COMPILER_BINDING)) { 103 compiler = (Compiler )value; 104 } else if (itf.equals(SCHEDULER_BINDING)) { 105 scheduler = (Scheduler)value; 106 } 107 } 108 109 public void unbindFc (final String itf) { 110 if (itf.equals(LOADER_BINDING)) { 111 loader = null; 112 } else if (itf.equals(COMPILER_BINDING)) { 113 compiler = null; 114 } else if (itf.equals(SCHEDULER_BINDING)) { 115 scheduler = null; 116 } 117 } 118 119 123 public Object newComponentType (final String name, final Map context) 124 throws ADLException 125 { 126 Definition d = loader.load(name, context); 127 TaskMap m = new BasicTaskMap(); 128 compiler.compile(d, m, context); 129 try { 130 m.getTask("type", d).execute(context); 131 return ((FactoryProviderTask)m.getTask("type", d)).getFactory(); 132 } catch (Exception e) { 133 e.printStackTrace(); 134 } 135 return null; 136 } 137 138 public Object newComponent (final String name, final Map context) 139 throws ADLException 140 { 141 Definition d = loader.load(name, context); 142 152 TaskMap m = new BasicTaskMap(); 153 compiler.compile(d, m, context); 154 161 scheduler.schedule(m.getTasks(), context); 162 return ((InstanceProviderTask)m.getTask("create", d)).getInstance(); 163 } 164 } 165 | Popular Tags |