KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > fractal > adl > FactoryFactory


1 /***
2  * Fractal ADL Parser
3  * Copyright (C) 2002-2004 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 org.objectweb.fractal.adl;
25
26 import java.util.HashMap JavaDoc;
27 import java.util.Map JavaDoc;
28
29 import org.objectweb.deployment.scheduling.core.lib.BasicScheduler;
30 import org.objectweb.fractal.adl.arguments.ArgumentComponentLoader;
31 import org.objectweb.fractal.adl.arguments.ArgumentLoader;
32 import org.objectweb.fractal.adl.attributes.AttributeCompiler;
33 import org.objectweb.fractal.adl.attributes.AttributeLoader;
34 import org.objectweb.fractal.adl.attributes.JavaAttributeBuilder;
35 import org.objectweb.fractal.adl.bindings.BindingCompiler;
36 import org.objectweb.fractal.adl.bindings.JavaBindingBuilder;
37 import org.objectweb.fractal.adl.bindings.TypeBindingLoader;
38 import org.objectweb.fractal.adl.components.ComponentCompiler;
39 import org.objectweb.fractal.adl.components.JavaComponentBuilder;
40 import org.objectweb.fractal.adl.components.PrimitiveComponentCompiler;
41 import org.objectweb.fractal.adl.implementations.ImplementationCompiler;
42 import org.objectweb.fractal.adl.implementations.ImplementationLoader;
43 import org.objectweb.fractal.adl.implementations.JavaImplementationBuilder;
44 import org.objectweb.fractal.adl.interfaces.InterfaceLoader;
45 import org.objectweb.fractal.adl.types.JavaTypeBuilder;
46 import org.objectweb.fractal.adl.types.TypeCompiler;
47 import org.objectweb.fractal.adl.types.TypeLoader;
48 import org.objectweb.fractal.adl.xml.XMLLoader;
49
50 /**
51  * Provides static methods to get a {@link Factory} component.
52  */

53
54 public class FactoryFactory {
55   
56   public final static String JavaDoc FRACTAL_BACKEND =
57     "org.objectweb.fractal.adl.FractalBackend";
58   
59   public final static String JavaDoc STATIC_FRACTAL_BACKEND =
60     "org.objectweb.fractal.adl.StaticFractalBackend";
61   
62   public final static String JavaDoc JAVA_BACKEND =
63     "org.objectweb.fractal.adl.JavaBackend";
64   
65   public final static String JavaDoc STATIC_JAVA_BACKEND =
66     "org.objectweb.fractal.adl.StaticJavaBackend";
67   
68   private static Factory FACTORY;
69   
70   /**
71    * Returns a bootstrap {@link Factory}, with a Java backend.
72    *
73    * @return a bootstrap factory.
74    */

75   
76   public static Factory getFactory () {
77     if (FACTORY != null) {
78       return FACTORY;
79     }
80     
81     BasicFactory r = new BasicFactory();
82         
83     XMLLoader xmll = new XMLLoader();
84     ArgumentLoader argl = new ArgumentLoader();
85     InterfaceLoader itfl = new InterfaceLoader();
86     TypeLoader typl = new TypeLoader();
87     ImplementationLoader impll = new ImplementationLoader();
88     AttributeLoader attrl1 = new AttributeLoader();
89     ArgumentComponentLoader compl = new ArgumentComponentLoader();
90     TypeBindingLoader bindl = new TypeBindingLoader();
91     // necessary to check inherited/overriden attributes
92
AttributeLoader attrl2 = new AttributeLoader();
93     
94     TypeCompiler typc = new TypeCompiler();
95     ImplementationCompiler implc = new ImplementationCompiler();
96     PrimitiveComponentCompiler compc = new PrimitiveComponentCompiler();
97     BindingCompiler bindc = new BindingCompiler();
98     AttributeCompiler attrc = new AttributeCompiler();
99     ComponentCompiler allc = new ComponentCompiler();
100         
101     JavaTypeBuilder typb = new JavaTypeBuilder();
102     JavaImplementationBuilder implb = new JavaImplementationBuilder();
103     JavaComponentBuilder compb = new JavaComponentBuilder();
104     JavaBindingBuilder bindb = new JavaBindingBuilder();
105     JavaAttributeBuilder attrb = new JavaAttributeBuilder();
106
107     BasicScheduler s = new BasicScheduler();
108     
109     typc.bindFc(TypeCompiler.BUILDER_BINDING, typb);
110     implc.bindFc(ImplementationCompiler.BUILDER_BINDING, implb);
111     compc.bindFc(PrimitiveComponentCompiler.BUILDER_BINDING, compb);
112     bindc.bindFc(BindingCompiler.BUILDER_BINDING, bindb);
113     attrc.bindFc(AttributeCompiler.BUILDER_BINDING, attrb);
114     
115     argl.clientLoader = xmll;
116     itfl.clientLoader = argl;
117     typl.clientLoader = itfl;
118     impll.clientLoader = typl;
119     attrl1.clientLoader = impll;
120     compl.clientLoader = attrl1;
121     bindl.clientLoader = compl;
122     attrl2.clientLoader = bindl;
123     
124     allc.bindFc(ComponentCompiler.PRIMITIVE_COMPILERS_BINDING+"0", typc);
125     allc.bindFc(ComponentCompiler.PRIMITIVE_COMPILERS_BINDING+"1", implc);
126     allc.bindFc(ComponentCompiler.PRIMITIVE_COMPILERS_BINDING+"2", compc);
127     allc.bindFc(ComponentCompiler.PRIMITIVE_COMPILERS_BINDING+"3", bindc);
128     allc.bindFc(ComponentCompiler.PRIMITIVE_COMPILERS_BINDING+"4", attrc);
129     
130     r.bindFc(BasicFactory.LOADER_BINDING, attrl2);
131     r.bindFc(BasicFactory.COMPILER_BINDING, allc);
132     r.bindFc(BasicFactory.SCHEDULER_BINDING, s);
133     
134     FACTORY = r;
135     return r;
136   }
137   
138   /**
139    * Returns a {@link Factory} with the given backend.
140    *
141    * @param backend the desired backend.
142    * @return a {@link Factory} with the given backend.
143    * @throws ADLException if the factory cannot be created.
144    */

145   
146   public static Factory getFactory (final String JavaDoc backend) throws ADLException {
147     return getFactory(backend, new HashMap JavaDoc());
148   }
149
150   /**
151    * Returns a {@link Factory} with the given backend.
152    *
153    * @param backend the desired backend.
154    * @param context additional optional information.
155    * @return a {@link Factory} with the given backend.
156    * @throws ADLException if the factory cannot be created.
157    */

158   
159   public static Factory getFactory (final String JavaDoc backend, final Map JavaDoc context)
160     throws ADLException
161   {
162     return getFactory("org.objectweb.fractal.adl.BasicFactory", backend, context);
163   }
164   
165   /**
166    * Returns a {@link Factory} with the given implementation and backend.
167    *
168    * @param factory the name of the desired factory.
169    * @param backend the desired backend.
170    * @param context additional optional information.
171    * @return a {@link Factory} with the given backend.
172    * @throws ADLException if the factory cannot be created.
173    */

174   
175   public static Factory getFactory (
176     final String JavaDoc factory,
177     final String JavaDoc backend,
178     final Map JavaDoc context) throws ADLException
179   {
180     context.put("backend", backend);
181     Factory f = getFactory();
182     Map JavaDoc c = (Map JavaDoc)f.newComponent(factory, context);
183     return (Factory)c.get("factory");
184   }
185 }
186
Popular Tags