1 23 24 package org.objectweb.fractal.adl.types; 25 26 import java.util.List ; 27 import java.util.ArrayList ; 28 import java.util.Map ; 29 import java.util.NoSuchElementException ; 30 31 import org.objectweb.deployment.scheduling.component.lib.AbstractFactoryProviderTask; 32 import org.objectweb.fractal.adl.ADLException; 33 import org.objectweb.fractal.adl.Definition; 34 import org.objectweb.fractal.adl.TaskMap; 35 import org.objectweb.fractal.adl.attributes.Attributes; 36 import org.objectweb.fractal.adl.attributes.AttributesContainer; 37 import org.objectweb.fractal.adl.components.Component; 38 import org.objectweb.fractal.adl.components.ComponentContainer; 39 import org.objectweb.fractal.adl.components.PrimitiveCompiler; 40 import org.objectweb.fractal.adl.interfaces.Interface; 41 import org.objectweb.fractal.adl.interfaces.InterfaceContainer; 42 import org.objectweb.fractal.api.control.BindingController; 43 44 47 48 public class TypeCompiler implements BindingController, PrimitiveCompiler { 49 50 54 55 public final static String BUILDER_BINDING = "builder"; 56 57 60 61 public TypeBuilder builder; 62 63 67 public String [] listFc() { 68 return new String [] { BUILDER_BINDING }; 69 } 70 71 public Object lookupFc (final String itf) { 72 if (itf.equals(BUILDER_BINDING)) { 73 return builder; 74 } 75 return null; 76 } 77 78 public void bindFc (final String itf, final Object value) { 79 if (itf.equals(BUILDER_BINDING)) { 80 builder = (TypeBuilder)value; 81 } 82 } 83 84 public void unbindFc (final String itf) { 85 if (itf.equals(BUILDER_BINDING)) { 86 builder = null; 87 } 88 } 89 90 94 public void compile ( 95 final List path, 96 final ComponentContainer container, 97 final TaskMap tasks, 98 final Map context) throws ADLException 99 { 100 if (container instanceof InterfaceContainer) { 101 try { 102 tasks.getTask("type", container); 104 } catch (NoSuchElementException e) { 105 CreateTypeTask createTypeTask = 106 new CreateTypeTask(builder, (InterfaceContainer)container); 107 tasks.addTask("type", container, createTypeTask); 108 } 109 } 110 } 111 112 116 static class CreateTypeTask extends AbstractFactoryProviderTask { 117 118 private TypeBuilder builder; 119 120 private InterfaceContainer container; 121 122 public CreateTypeTask ( 123 final TypeBuilder builder, 124 final InterfaceContainer container) 125 { 126 this.builder = builder; 127 this.container = container; 128 } 129 130 public void execute (final Object context) throws Exception { 131 if (getFactory() != null) { 132 return; 133 } 134 List itfTypes = new ArrayList (); 135 Interface[] itfs = container.getInterfaces(); 136 for (int i = 0; i < itfs.length; i++) { 137 if (itfs[i] instanceof TypeInterface) { 138 TypeInterface itf = (TypeInterface)itfs[i]; 139 Object itfType = builder.createInterfaceType( 140 itf.getName(), 141 itf.getSignature(), 142 itf.getRole(), 143 itf.getContingency(), 144 itf.getCardinality(), 145 context); 146 itfTypes.add(itfType); 147 } 148 } 149 if (container instanceof AttributesContainer) { Attributes attr = ((AttributesContainer)container).getAttributes(); 151 if (attr != null) { 152 Object itfType = builder.createInterfaceType( 153 "attribute-controller", 154 attr.getSignature(), 155 "server", 156 "mandatory", 157 "singleton", 158 context); 159 itfTypes.add(itfType); 160 } 161 } 162 String name = null; 163 if (container instanceof Definition) { 164 name = ((Definition)container).getName(); 165 } else if (container instanceof Component) { 166 name = ((Component)container).getName(); 167 } 168 setFactory(builder.createComponentType(name, itfTypes.toArray(), context)); 169 } 170 171 public String toString () { 172 return "T" + System.identityHashCode(this) + "[CreateTypeTask()]"; 173 } 174 } 175 } 176
| Popular Tags
|