KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > Collection


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 import java.util.Arrays JavaDoc;
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 Collection {
35
36   public static void main (String JavaDoc[] args) throws Exception JavaDoc {
37     Component boot = Fractal.getBootstrapComponent();
38
39     TypeFactory tf = Fractal.getTypeFactory(boot);
40     ComponentType aType = tf.createFcType(new InterfaceType[0]);
41     ComponentType bType = tf.createFcType(new InterfaceType[] {
42       tf.createFcItfType("client", "I", true, true, true)
43     });
44     ComponentType sType = tf.createFcType(new InterfaceType[] {
45       tf.createFcItfType("server", "I", false, false, false)
46     });
47     
48     GenericFactory cf = Fractal.getGenericFactory(boot);
49
50     Component aComp = cf.newFcInstance(aType, "composite", null);
51     Component bComp = cf.newFcInstance(bType, "autoBindingComposite", null);
52     Component cComp = cf.newFcInstance(bType, "autoBindingPrimitive", "CImpl");
53     Component s1Comp = cf.newFcInstance(sType, "primitive", "SImpl");
54     Component s2Comp = cf.newFcInstance(sType, "primitive", "SImpl");
55     Component s3Comp = cf.newFcInstance(sType, "primitive", "SImpl");
56     
57     Fractal.getContentController(aComp).addFcSubComponent(bComp);
58     Fractal.getContentController(aComp).addFcSubComponent(s1Comp);
59     Fractal.getContentController(aComp).addFcSubComponent(s2Comp);
60     Fractal.getContentController(aComp).addFcSubComponent(s3Comp);
61     Fractal.getContentController(bComp).addFcSubComponent(cComp);
62     
63     // creates a binding between b and s1
64
Fractal.getBindingController(bComp).bindFc(
65       "client-I", s1Comp.getFcInterface("server"));
66
67     // creates a "model" binding between c and b
68
// this automatically creates similar bindings bewteen c and b,
69
// for each interface in the collection in b
70
Fractal.getBindingController(cComp).bindFc(
71       "client",
72       Fractal.getContentController(bComp).getFcInternalInterface("client"));
73     
74     // we can check this with the following code:
75
String JavaDoc[] itfs = Fractal.getBindingController(cComp).listFc();
76     System.out.println(Arrays.asList(itfs));
77
78     // during the following bindings between b and si,
79
// similar bindings are created between c and b (following the model binding)
80
Fractal.getBindingController(bComp).bindFc(
81       "client-II", s2Comp.getFcInterface("server"));
82     Fractal.getBindingController(bComp).bindFc(
83       "client-III", s3Comp.getFcInterface("server"));
84      
85     // we can check this with the following code:
86
itfs = Fractal.getBindingController(cComp).listFc();
87     System.out.println(Arrays.asList(itfs));
88     
89     // removing bindings between b and si also removes bindings between c and b
90
Fractal.getBindingController(bComp).unbindFc("client-I");
91     Fractal.getBindingController(bComp).unbindFc("client-II");
92     Fractal.getBindingController(bComp).unbindFc("client-III");
93     
94     itfs = Fractal.getBindingController(cComp).listFc();
95     System.out.println(Arrays.asList(itfs));
96   }
97 }
98
Popular Tags