1 23 24 package org.objectweb.fractal.adl.nodes; 25 26 import java.util.HashMap ; 27 import java.util.List ; 28 import java.util.Map ; 29 30 import org.objectweb.deployment.scheduling.component.lib.AbstractInstanceProviderTask; 31 import org.objectweb.fractal.adl.components.ComponentContainer; 32 import org.objectweb.fractal.adl.implementations.ImplementationBuilder; 33 import org.objectweb.fractal.adl.implementations.ImplementationCompiler; 34 35 public class VirtualNodeImplementationCompiler extends ImplementationCompiler { 36 37 public AbstractInstanceProviderTask newCreateTask ( 38 final List path, 39 final ComponentContainer container, 40 final String name, 41 final String definition, 42 final Object controller, 43 final Object implementation, 44 final Map context) 45 { 46 VirtualNode n = null; 47 if (container instanceof VirtualNodeContainer) { 48 n = ((VirtualNodeContainer)container).getVirtualNode(); 49 } 50 if (n == null) { 51 for (int i = path.size() - 1; i >= 0; --i) { 52 if (path.get(i) instanceof VirtualNodeContainer) { 53 n = ((VirtualNodeContainer)path.get(i)).getVirtualNode(); 54 if (n != null) { 55 break; 56 } 57 } 58 } 59 } 60 if (n != null) { 61 return new RemoteCreateTask( 62 builder, name, definition, controller, implementation, context.get(n.getName())); 63 } 64 return super.newCreateTask( 65 path, container, name, definition, controller, implementation, context); 66 } 67 68 static class RemoteCreateTask extends AbstractInstanceProviderTask { 69 70 ImplementationBuilder builder; 71 72 String name; 73 74 String definition; 75 76 Object controllerDesc; 77 78 Object contentDesc; 79 80 Object node; 81 82 public RemoteCreateTask ( 83 final ImplementationBuilder builder, 84 final String name, 85 final String definition, 86 final Object controllerDesc, 87 final Object contentDesc, 88 final Object node) 89 { 90 this.builder = builder; 91 this.name = name; 92 this.definition = definition; 93 this.controllerDesc = controllerDesc; 94 this.contentDesc = contentDesc; 95 this.node = node; 96 } 97 98 public void execute (Object context) throws Exception { 99 if (getInstance() != null) { 100 return; 101 } 102 if (node != null && context instanceof Map ) { 103 context = new HashMap ((Map )context); 104 ((Map )context).put("bootstrap", node); 105 } 106 Object type = getFactoryProviderTask().getFactory(); 107 Object result = builder.createComponent( 108 type, name, definition, controllerDesc, contentDesc, context); 109 setInstance(result); 110 } 111 112 public String toString () { 113 return "T" + System.identityHashCode(this) + 114 "[CreateTask(" + name + "," + controllerDesc + "," + contentDesc + ")]"; 115 } 116 } 117 } 118 | Popular Tags |