1 23 24 package org.objectweb.fractal.adl.types; 25 26 import java.io.PrintWriter ; 27 import java.util.Map ; 28 import java.util.WeakHashMap ; 29 30 35 36 public class StaticFractalTypeBuilder implements TypeBuilder { 37 38 private Map itfCounters = new WeakHashMap (); 39 40 private Map compCounters = new WeakHashMap (); 41 42 46 public Object createInterfaceType ( 47 final String name, 48 final String signature, 49 final String role, 50 final String contingency, 51 final String cardinality, 52 final Object context) throws Exception 53 { 54 Integer i = (Integer )itfCounters.get(context); 55 if (i == null) { 56 i = new Integer (0); 57 } 58 itfCounters.put(context, new Integer (i.intValue() + 1)); 59 String id = "IT" + i; 60 61 PrintWriter pw = (PrintWriter )((Map )context).get("printwriter"); 62 pw.print("InterfaceType "); 63 pw.print(id); 64 pw.print(" = typeFactory.createFcItfType(\""); 65 pw.print(name); 66 pw.print("\", \""); 67 pw.print(signature); 68 pw.print("\", "); 69 pw.print("client".equals(role)); 70 pw.print(", "); 71 pw.print("optional".equals(contingency)); 72 pw.print(", "); 73 pw.print("collection".equals(cardinality)); 74 pw.println(");"); 75 76 return id; 77 } 78 79 public Object createComponentType ( 80 final String name, 81 final Object [] interfaceTypes, 82 final Object context) throws Exception 83 { 84 Integer i = (Integer )compCounters.get(context); 85 if (i == null) { 86 i = new Integer (0); 87 } 88 compCounters.put(context, new Integer (i.intValue() + 1)); 89 String id = "CT" + i; 90 91 PrintWriter pw = (PrintWriter )((Map )context).get("printwriter"); 92 pw.print("ComponentType "); 93 pw.print(id); 94 pw.print(" = typeFactory.createFcType(new InterfaceType [] { "); 95 for (int j = 0; j < interfaceTypes.length; ++j) { 96 if (j > 0) { 97 pw.print(", "); 98 } 99 pw.print(interfaceTypes[j]); 100 } 101 pw.println(" });"); 102 return id; 103 } 104 } 105 | Popular Tags |