KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > fractal > api > Fractal


1 /***
2  * Fractal API
3  * Copyright (C) 2001-2002 France Telecom, INRIA
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: fractal@objectweb.org
20  *
21  * Authors: Eric Bruneton, Thierry Coupaye, Pascal Dechamboux, Romain Lenglet,
22  * Philippe Merle, Jean-Bernard Stefani.
23  */

24
25 package org.objectweb.fractal.api;
26
27 import org.objectweb.fractal.api.factory.InstantiationException;
28 import org.objectweb.fractal.api.factory.Factory;
29
30 /**
31  * Provides a static method to get a bootstrap component. <i>This class is only
32  * required for Java implementations of the Fractal model (level 3.2 at least).
33  * In other languages the "well known name" used to get the bootstrap component
34  * may take a different form than a static method.</i>
35  */

36
37 public class Fractal {
38
39   /**
40    * Private constructor (uninstantiable class).
41    */

42
43   private Fractal () {
44   }
45
46   /**
47    * Returns a bootstrap component to create other components. This method
48    * creates an instance of the class whose name is specified in the
49    * <tt>fractal.provider</tt> system property, which much implement the {@link
50    * Factory} interface, and returns the component instantiated by this factory.
51    *
52    * @return a bootstrap component to create other components. This component
53    * provides at least two interfaces named <tt>type-factory</tt> and
54    * <tt>generic-factory</tt> to create component types and components.
55    * The type of the <tt>generic-factory</tt> interface is {@link
56    * org.objectweb.fractal.api.factory.GenericFactory}, or a
57    * sub type of this type, but the type of the <tt>type-factory</tt>
58    * interface is <i>not</i> necessarily {@link
59    * org.objectweb.fractal.api.type.TypeFactory} (or a sub type of this
60    * type).
61    * @throws InstantiationException if the bootstrap component cannot be
62    * created.
63    */

64
65   public static Component getBootstrapComponent ()
66     throws InstantiationException JavaDoc
67   {
68     String JavaDoc bootTmplClassName = System.getProperty("fractal.provider");
69     if (bootTmplClassName == null) {
70       throw new InstantiationException JavaDoc(
71         "The fractal.provider system property is not defined");
72     }
73     Factory bootTmpl;
74     try {
75       Class JavaDoc bootTmplClass = Class.forName(bootTmplClassName);
76       bootTmpl = (Factory)bootTmplClass.newInstance();
77     } catch (Exception JavaDoc e) {
78       throw new InstantiationException JavaDoc(
79         "Cannot find or instantiate the '" + bootTmplClassName +
80         "' class specified in the fractal.provider system property");
81     }
82     return bootTmpl.newFcInstance();
83   }
84 }
85
Popular Tags