1 23 24 package org.objectweb.fractal.adl.types; 25 26 import java.util.HashMap ; 27 import java.util.Map ; 28 29 import org.objectweb.fractal.api.Component; 30 import org.objectweb.fractal.api.type.InterfaceType; 31 import org.objectweb.fractal.util.Fractal; 32 33 37 38 public class FractalTypeBuilder implements TypeBuilder { 39 40 44 public Object createInterfaceType ( 45 final String name, 46 final String signature, 47 final String role, 48 final String contingency, 49 final String cardinality, 50 final Object context) throws Exception 51 { 52 ClassLoader loader = null; 53 if (context instanceof Map ) { 54 loader = (ClassLoader )((Map )context).get("classloader"); 55 } 56 if (loader == null) { 57 loader = getClass().getClassLoader(); 58 } 59 60 Component bootstrap = null; 62 if (context != null) { 63 bootstrap = (Component)((Map )context).get("bootstrap"); 64 } 65 if (bootstrap == null) { 66 Map ctxt = new HashMap (); 67 ctxt.put("classloader", loader); 68 bootstrap = Fractal.getBootstrapComponent(ctxt); 69 } 70 boolean client = "client".equals(role); 71 boolean optional = "optional".equals(contingency); 72 boolean collection = "collection".equals(cardinality); 73 74 return Fractal.getTypeFactory(bootstrap).createFcItfType( 75 name, signature, client, optional, collection); 76 } 77 78 public Object createComponentType ( 79 final String name, 80 final Object [] interfaceTypes, 81 final Object context) throws Exception 82 { 83 ClassLoader loader = null; 84 if (context instanceof Map ) { 85 loader = (ClassLoader )((Map )context).get("classloader"); 86 } 87 if (loader == null) { 88 loader = getClass().getClassLoader(); 89 } 90 91 Component bootstrap = null; 92 if (context != null) { 93 bootstrap = (Component)((Map )context).get("bootstrap"); 94 } 95 if (bootstrap == null) { 96 Map ctxt = new HashMap (); 97 ctxt.put("classloader", loader); 98 bootstrap = Fractal.getBootstrapComponent(ctxt); 99 } 100 InterfaceType[] types = new InterfaceType[interfaceTypes.length]; 101 for (int i = 0; i < types.length; ++i) { 102 types[i] = (InterfaceType)interfaceTypes[i]; 103 } 104 return Fractal.getTypeFactory(bootstrap).createFcType(types); 105 } 106 } 107 | Popular Tags |