1 package org.objectweb.proactive.examples.components.helloworld; 2 3 8 import org.objectweb.fractal.api.Component; 9 import org.objectweb.fractal.api.factory.GenericFactory; 10 import org.objectweb.fractal.api.type.ComponentType; 11 import org.objectweb.fractal.api.type.InterfaceType; 12 import org.objectweb.fractal.api.type.TypeFactory; 13 import org.objectweb.fractal.util.Fractal; 14 15 16 import org.objectweb.proactive.core.component.Constants; 17 import org.objectweb.proactive.core.component.ContentDescription; 18 import org.objectweb.proactive.core.component.ControllerDescription; 19 20 21 import org.objectweb.proactive.core.component.xml.Loader; 22 23 36 public class HelloWorld { 37 private static String LOCAL_COMPONENTS_DESCRIPTOR = 38 HelloWorld 39 .class 40 .getResource("/org/objectweb/proactive/examples/components/helloworld/helloworld-local.xml") 41 .getPath(); 42 private static String DISTRIBUTED_COMPONENTS_DESCRIPTOR = 43 HelloWorld 44 .class 45 .getResource("/org/objectweb/proactive/examples/components/helloworld/helloworld-distributed.xml") 46 .getPath(); 47 private static String DEPLOYMENT_DESCRIPTOR = 48 HelloWorld 49 .class 50 .getResource("/org/objectweb/proactive/examples/components/helloworld/deployment.xml") 51 .getPath(); 52 53 public static void main(final String [] args) throws Exception { 54 boolean useParser = false; 55 boolean useTemplates = false; 56 boolean useWrapper = false; 57 boolean distributed = false; 58 59 for (int i = 0; i < args.length; ++i) { 60 useParser |= args[i].equals("parser"); 61 useTemplates |= args[i].equals("templates"); 62 useWrapper |= args[i].equals("wrapper"); 63 distributed |= args[i].equals("distributed"); 64 } 65 66 useParser = true; 67 useWrapper = true; 68 distributed=false; 69 70 Component rComp = null; 71 72 if (useParser) { 73 Loader loader = new Loader(); 77 78 if (distributed) { 80 loader.loadComponentsConfiguration(DISTRIBUTED_COMPONENTS_DESCRIPTOR, DEPLOYMENT_DESCRIPTOR); 81 } else { 82 loader.loadComponentsConfiguration(LOCAL_COMPONENTS_DESCRIPTOR, DEPLOYMENT_DESCRIPTOR); 83 } 84 if (useWrapper) { 86 rComp = loader.getComponent("ClientServerWrapper"); 87 } else { 88 rComp = loader.getComponent("ClientServer"); 89 } 90 System.out.println(); 91 } else { 92 Component boot = org.objectweb.fractal.api.Fractal.getBootstrapComponent(); 96 TypeFactory tf = Fractal.getTypeFactory(boot); 97 98 ComponentType rType = 100 tf.createFcType( 101 new InterfaceType[] { tf.createFcItfType("m", Main.class.getName(), false, false, false)}); 102 103 ComponentType cType = 105 tf.createFcType( 106 new InterfaceType[] { 107 tf.createFcItfType("m", Main.class.getName(), false, false, false), 108 tf.createFcItfType("s", Service.class.getName(), true, false, false)}); 109 110 ComponentType sType = 112 tf.createFcType( 113 new InterfaceType[] { 114 tf.createFcItfType("s", Service.class.getName(), false, false, false), 115 tf.createFcItfType( 116 "attribute-controller", 117 ServiceAttributes.class.getName(), 118 false, 119 false, 120 false)}); 121 122 GenericFactory cf = Fractal.getGenericFactory(boot); 124 125 if (!useTemplates) { 126 rComp = 131 cf.newFcInstance(rType, new ControllerDescription("root", Constants.COMPOSITE), null); 132 Component cComp = 134 cf.newFcInstance( 135 cType, 136 new ControllerDescription("client", Constants.PRIMITIVE), 137 new ContentDescription(ClientImpl.class.getName())); 139 Component sComp = 141 cf.newFcInstance( 142 sType, 143 new ControllerDescription("server", Constants.PRIMITIVE), 144 new ContentDescription(ServerImpl.class.getName())); 145 ((ServiceAttributes) Fractal.getAttributeController(sComp)).setHeader("--------> "); 146 ((ServiceAttributes) Fractal.getAttributeController(sComp)).setCount(1); 147 148 if (useWrapper) { 149 sType = 150 tf.createFcType( 151 new InterfaceType[] { 152 tf.createFcItfType("s", Service.class.getName(), false, false, false)}); 153 Component CComp = 155 cf.newFcInstance( 156 cType, 157 new ControllerDescription("client-wrapper", Constants.COMPOSITE), 158 null); 159 160 Component SComp = 162 cf.newFcInstance( 163 sType, 164 new ControllerDescription("server-wrapper", Constants.COMPOSITE), 165 null); 166 167 Fractal.getContentController(CComp).addFcSubComponent(cComp); 169 Fractal.getContentController(SComp).addFcSubComponent(sComp); 170 Fractal.getBindingController(CComp).bindFc("m", cComp.getFcInterface("m")); 171 Fractal.getBindingController(cComp).bindFc( 172 "s", 173 Fractal.getContentController(CComp).getFcInternalInterface("s")); 174 Fractal.getBindingController(SComp).bindFc("s", sComp.getFcInterface("s")); 176 cComp = CComp; 179 sComp = SComp; 180 } 181 182 Fractal.getContentController(rComp).addFcSubComponent(cComp); 184 Fractal.getContentController(rComp).addFcSubComponent(sComp); 185 Fractal.getBindingController(rComp).bindFc("m", cComp.getFcInterface("m")); 186 Fractal.getBindingController(cComp).bindFc("s", sComp.getFcInterface("s")); 187 } 188 } 189 190 Fractal.getLifeCycleController(rComp).startFc(); 195 196 ((Main) rComp.getFcInterface("m")).main(null); 198 } 199 200 } 201 | Popular Tags |