KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > j2me > HelloWorld


1 /***
2  * Julia: France Telecom's implementation of the Fractal API
3  * Copyright (C) 2001-2002 France Telecom R&D
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * Contact: Eric.Bruneton@rd.francetelecom.com
20  *
21  * Author: Eric Bruneton
22  */

23
24 package j2me;
25
26 import org.objectweb.fractal.api.Component;
27 import org.objectweb.fractal.api.factory.GenericFactory;
28 import org.objectweb.fractal.api.type.ComponentType;
29 import org.objectweb.fractal.api.type.InterfaceType;
30 import org.objectweb.fractal.api.type.TypeFactory;
31
32 import org.objectweb.fractal.util.Fractal;
33
34 public class HelloWorld {
35
36   public static void main (final String JavaDoc[] args) throws Exception JavaDoc {
37
38     Component boot = Fractal.getBootstrapComponent();
39     TypeFactory tf = Fractal.getTypeFactory(boot);
40     // type of root component
41
ComponentType rType = tf.createFcType(new InterfaceType[] {
42       tf.createFcItfType("m", "j2me.Main", false, false, false)
43     });
44     // type of client component
45
ComponentType cType = tf.createFcType(new InterfaceType[] {
46       tf.createFcItfType("m", "j2me.Main", false, false, false),
47       tf.createFcItfType("s", "j2me.Service", true, false, false)
48     });
49     // type of server component
50
ComponentType sType = tf.createFcType(new InterfaceType[] {
51       tf.createFcItfType("s", "j2me.Service", false, false, false),
52       tf.createFcItfType(
53         "attribute-controller",
54         "j2me.ServiceAttributes",
55         false,
56         false,
57         false)
58     });
59
60     GenericFactory cf = Fractal.getGenericFactory(boot);
61
62     // create root component
63
Component rComp = cf.newFcInstance(rType, "composite", null);
64     // create client component
65
Component cComp = cf.newFcInstance(cType, "primitive", "j2me.ClientImpl");
66     // create server component
67
Component sComp = cf.newFcInstance(sType, "primitive", "j2me.ServerImpl");
68     ((ServiceAttributes)Fractal.getAttributeController(sComp)).setHeader("-> ");
69     ((ServiceAttributes)Fractal.getAttributeController(sComp)).setCount(1);
70
71     // component assembly
72
Fractal.getContentController(rComp).addFcSubComponent(cComp);
73     Fractal.getContentController(rComp).addFcSubComponent(sComp);
74     Fractal.getBindingController(rComp).bindFc("m", cComp.getFcInterface("m"));
75     Fractal.getBindingController(cComp).bindFc("s", sComp.getFcInterface("s"));
76
77     // start root component
78
Fractal.getLifeCycleController(rComp).startFc();
79
80     // call main method
81
((Main)rComp.getFcInterface("m")).main(null);
82   }
83 }
84
Popular Tags