1 23 24 package org.objectweb.fractal.adl.implementations; 25 26 import java.io.PrintWriter ; 27 import java.util.Map ; 28 import java.util.WeakHashMap ; 29 30 35 36 public class StaticFractalImplementationBuilder implements ImplementationBuilder { 37 38 private Map counters = new WeakHashMap (); 39 40 44 public Object createComponent ( 45 final Object type, 46 final String name, 47 final String definition, 48 final Object controllerDesc, 49 final Object contentDesc, 50 final Object context) throws Exception 51 { 52 Integer i = (Integer )counters.get(context); 53 if (i == null) { 54 i = new Integer (0); 55 } 56 counters.put(context, new Integer (i.intValue() + 1)); 57 String id = "C" + i; 58 59 PrintWriter pw = (PrintWriter )((Map )context).get("printwriter"); 60 pw.print("Component "); 61 pw.print(id); 62 pw.print(" = genericFactory.newFcInstance("); 63 pw.print(type); 64 pw.print(", \""); 65 pw.print(controllerDesc); 66 pw.print("\", "); 67 if (contentDesc == null) { 68 pw.print("null"); 69 } else if (contentDesc instanceof Object []) { 70 Object [] descs = (Object [])contentDesc; 71 pw.print("new Object[] { \""); 72 pw.print(descs[0]); 73 pw.print("\", "); 74 if (descs[1] == null) { 75 pw.print("null"); 76 } else { 77 pw.print("\""); 78 pw.print(descs[1]); 79 pw.print("\""); 80 } 81 pw.print(" }"); 82 } else { 83 pw.print("\""); 84 pw.print(contentDesc); 85 pw.print("\""); 86 } 87 pw.println(");"); 88 89 pw.print("try { Fractal.getNameController("); 90 pw.print(id); 91 pw.print(").setFcName(\""); 92 pw.print(name); 93 pw.println("\"); } catch (NoSuchInterfaceException ignored) { }"); 94 95 return id; 96 } 97 } 98 | Popular Tags |