KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > proactive > core > component > xml > Loader


1 /*
2  * ################################################################
3  *
4  * ProActive: The Java(TM) library for Parallel, Distributed,
5  * Concurrent computing with Security and Mobility
6  *
7  * Copyright (C) 1997-2004 INRIA/University of Nice-Sophia Antipolis
8  * Contact: proactive-support@inria.fr
9  *
10  * This library is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Lesser General Public
12  * License as published by the Free Software Foundation; either
13  * version 2.1 of the License, or any later version.
14  *
15  * This library is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  * Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public
21  * License along with this library; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23  * USA
24  *
25  * Initial developer(s): The ProActive Team
26  * http://www.inria.fr/oasis/ProActive/contacts.html
27  * Contributor(s):
28  *
29  * ################################################################
30  */

31 package org.objectweb.proactive.core.component.xml;
32
33 import org.apache.log4j.Logger;
34
35 import org.objectweb.fractal.api.Component;
36
37 import org.objectweb.proactive.ProActive;
38 import org.objectweb.proactive.core.ProActiveException;
39 import org.objectweb.proactive.core.descriptor.data.ProActiveDescriptor;
40 import org.objectweb.proactive.core.runtime.RuntimeFactory;
41
42
43 /**
44  * This class is used for automatic deployment of components with the ADL.
45  * Virtual nodes specified in the ADL have to match with virtual nodes defined in the
46  * deployment descriptor.
47  * The deployment process is the following :
48  * 1. instatiation of the components on virtual nodes defined in the deployment descriptor
49  * 2. storing of component references in a cache
50  * 3. assembly of the components
51  * 4. binding of the components
52  * Components are then accessible through the components cache.
53  *
54  * @author Matthieu Morel
55  */

56 public class Loader {
57     protected static Logger logger = Logger.getLogger(Loader.class.getName());
58     private ComponentsCache cache;
59
60     public Loader() {
61     }
62
63     /**
64      * Configures and instantiates a component system : creation of the components,
65      * deployment on virtual nodes, assembly and binding.
66      * Components are indexed by their name in a local cache, and can be retreived from there.
67      * @param componentsDescriptorURL the location of the components descriptor
68      * @param deploymentDescriptor an instance of ProActiveDescriptor, representing the deployment descriptor
69      * @throws ProActiveException in case of a failure
70      */

71     public void loadComponentsConfiguration(String JavaDoc componentsDescriptorURL,
72         ProActiveDescriptor deploymentDescriptor) throws ProActiveException {
73         RuntimeFactory.getDefaultRuntime();
74         try {
75             cache = (ComponentsCache) ComponentsDescriptorHandler.createComponentsDescriptorHandler(componentsDescriptorURL,
76                     deploymentDescriptor).getResultObject();
77         } catch (org.xml.sax.SAXException JavaDoc e) {
78             e.printStackTrace();
79             logger.fatal(
80                 "a problem occured when getting the ProActive descriptor or the ComponentsDescriptor");
81             throw new ProActiveException(e);
82         } catch (java.io.IOException JavaDoc e) {
83             e.printStackTrace();
84             logger.fatal(
85                 "a problem occured during the ProActiveDescriptor object creation");
86             throw new ProActiveException(e);
87         }
88     }
89
90     /**
91      * Configures and instantiates a component system.
92      * @param componentsDescriptorLocation the location of the components descriptor
93      * @param deploymentDescriptorLocation the location of the deployment descriptor
94      * @throws ProActiveException in case of a failure
95      */

96     public void loadComponentsConfiguration(
97         String JavaDoc componentsDescriptorLocation, String JavaDoc deploymentDescriptorLocation)
98         throws ProActiveException {
99         ProActiveDescriptor deploymentDescriptor = ProActive.getProactiveDescriptor(deploymentDescriptorLocation);
100         loadComponentsConfiguration(componentsDescriptorLocation,
101             deploymentDescriptor);
102     }
103
104     /**
105      * Returns an instantiated+deployed+assembled+bound component from the cache.
106      * @param name the name of a component
107      * @return the named component
108      */

109     public Component getComponent(String JavaDoc name) {
110         return cache.getComponent(name);
111     }
112 }
113
Popular Tags