1 23 24 package org.objectweb.fractal.util; 25 26 import java.util.Map ; 27 28 import org.objectweb.fractal.api.Component; 29 import org.objectweb.fractal.api.NoSuchInterfaceException; 30 import org.objectweb.fractal.api.control.AttributeController; 31 import org.objectweb.fractal.api.control.BindingController; 32 import org.objectweb.fractal.api.control.ContentController; 33 import org.objectweb.fractal.api.control.LifeCycleController; 34 import org.objectweb.fractal.api.control.NameController; 35 import org.objectweb.fractal.api.control.SuperController; 36 import org.objectweb.fractal.api.factory.Factory; 37 import org.objectweb.fractal.api.factory.GenericFactory; 38 import org.objectweb.fractal.api.factory.InstantiationException; 39 import org.objectweb.fractal.api.type.TypeFactory; 40 41 44 45 public class Fractal { 46 47 50 51 private Fractal () { 52 } 53 54 63 64 public static Component getBootstrapComponent () 65 throws InstantiationException 66 { 67 return org.objectweb.fractal.api.Fractal.getBootstrapComponent(); 68 } 69 70 84 85 public static Component getBootstrapComponent (final Map hints) 86 throws InstantiationException 87 { 88 String bootTmplClassName = (String )hints.get("fractal.provider"); 89 if (bootTmplClassName == null) { 90 bootTmplClassName = System.getProperty("fractal.provider"); 91 } 92 if (bootTmplClassName == null) { 93 throw new InstantiationException ( 94 "The fractal.provider value is not defined"); 95 } 96 Object bootTmpl; 97 try { 98 ClassLoader cl = (ClassLoader )hints.get("classloader"); 99 if (cl == null) { 100 cl = new Fractal().getClass().getClassLoader(); 101 } 102 Class bootTmplClass = cl.loadClass(bootTmplClassName); 103 bootTmpl = bootTmplClass.newInstance(); 104 } catch (Exception e) { 105 throw new InstantiationException ( 106 "Cannot find or instantiate the '" + bootTmplClassName + 107 "' class associated to the fractal.provider key"); 108 } 109 if (bootTmpl instanceof GenericFactory) { 110 return ((GenericFactory)bootTmpl).newFcInstance(null, null, hints); 111 } else { 112 return ((Factory)bootTmpl).newFcInstance(); 113 } 114 } 115 116 123 124 public static AttributeController getAttributeController ( 125 final Component component) throws NoSuchInterfaceException 126 { 127 return (AttributeController)component.getFcInterface("attribute-controller"); 128 } 129 130 137 138 public static BindingController getBindingController ( 139 final Component component) throws NoSuchInterfaceException 140 { 141 return (BindingController)component.getFcInterface("binding-controller"); 142 } 143 144 151 152 public static ContentController getContentController ( 153 final Component component) throws NoSuchInterfaceException 154 { 155 return (ContentController)component.getFcInterface("content-controller"); 156 } 157 158 165 166 public static SuperController getSuperController (final Component component) 167 throws NoSuchInterfaceException 168 { 169 return (SuperController)component.getFcInterface("super-controller"); 170 } 171 172 179 180 public static NameController getNameController (final Component component) 181 throws NoSuchInterfaceException 182 { 183 return (NameController)component.getFcInterface("name-controller"); 184 } 185 186 193 194 public static LifeCycleController getLifeCycleController ( 195 final Component component) throws NoSuchInterfaceException 196 { 197 return (LifeCycleController)component.getFcInterface("lifecycle-controller"); 198 } 199 200 207 208 public static Factory getFactory (final Component component) 209 throws NoSuchInterfaceException 210 { 211 return (Factory)component.getFcInterface("factory"); 212 } 213 214 221 222 public static GenericFactory getGenericFactory (final Component component) 223 throws NoSuchInterfaceException 224 { 225 return (GenericFactory)component.getFcInterface("generic-factory"); 226 } 227 228 235 236 public static TypeFactory getTypeFactory (final Component component) 237 throws NoSuchInterfaceException 238 { 239 return (TypeFactory)component.getFcInterface("type-factory"); 240 } 241 } 242 | Popular Tags |