1 23 24 package org.objectweb.fractal.julia; 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.NoSuchInterfaceException; 31 import org.objectweb.fractal.api.Type; 32 import org.objectweb.fractal.api.factory.Factory; 33 import org.objectweb.fractal.api.factory.GenericFactory; 34 import org.objectweb.fractal.api.factory.InstantiationException; 35 import org.objectweb.fractal.api.type.ComponentType; 36 import org.objectweb.fractal.api.type.InterfaceType; 37 38 import org.objectweb.fractal.julia.factory.BasicGenericFactoryMixin; 39 import org.objectweb.fractal.julia.factory.ChainedInstantiationException; 40 import org.objectweb.fractal.julia.loader.Loader; 41 import org.objectweb.fractal.julia.type.BasicTypeFactoryMixin; 42 43 46 47 public class Julia implements Factory, GenericFactory { 48 49 52 53 private static Component bootstrapComponent; 54 55 59 62 63 public Type getFcInstanceType () { 64 return null; 65 } 66 67 70 71 public Object getFcControllerDesc () { 72 return null; 73 } 74 75 78 79 public Object getFcContentDesc () { 80 return null; 81 } 82 83 102 103 public Component newFcInstance () throws InstantiationException { 104 return newFcInstance(new HashMap ()); 105 } 106 107 130 131 public Component newFcInstance ( 132 final Type type, 133 final Object controllerDesc, 134 final Object contentDesc) throws InstantiationException 135 { 136 Map context; 137 if (contentDesc instanceof Map ) { 138 context = (Map )contentDesc; 139 } else { 140 context = new HashMap (); 141 } 142 return newFcInstance(context); 143 } 144 145 private Component newFcInstance (final Map context) 146 throws InstantiationException 147 { 148 if (bootstrapComponent == null) { 149 String boot = (String )context.get("julia.loader"); 150 if (boot == null) { 151 boot = System.getProperty("julia.loader"); 152 } 153 if (boot == null) { 154 throw new InstantiationException ( 155 "The julia.loader [system] property is not defined"); 156 } 157 158 Loader loader; 160 try { 161 loader = (Loader)_forName(boot).newInstance(); 162 loader.init(context); 163 } catch (Exception e) { 164 throw new InstantiationException ( 165 "Cannot find or instantiate the '" + boot + 166 "' class specified in the julia.loader [system] property"); 167 } 168 BasicTypeFactoryMixin typeFactory = new BasicTypeFactoryMixin(); 169 BasicGenericFactoryMixin genericFactory = new BasicGenericFactoryMixin(); 170 genericFactory._this_weaveableL = loader; 171 genericFactory._this_weaveableTF = typeFactory; 172 173 ComponentType t = typeFactory.createFcType(new InterfaceType[0]); 175 try { 176 bootstrapComponent = genericFactory.newFcInstance(t, "bootstrap", null); 177 try { 178 ((Loader)bootstrapComponent.getFcInterface("loader")).init(context); 179 } catch (NoSuchInterfaceException ignored) { 180 } 181 } catch (Exception e) { 182 throw new ChainedInstantiationException( 183 e, null, "Cannot create the bootstrap component"); 184 } 185 } 186 return bootstrapComponent; 187 } 188 189 193 194 private Class _forName (final String name) throws ClassNotFoundException { 195 return getClass().getClassLoader().loadClass(name); 196 } 197 } 198 | Popular Tags |