KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sape > carbon > core > component > startup > DefaultStartupServiceImpl


1 /*
2  * The contents of this file are subject to the Sapient Public License
3  * Version 1.0 (the "License"); you may not use this file except in compliance
4  * with the License. You may obtain a copy of the License at
5  * http://carbon.sf.net/License.html.
6  *
7  * Software distributed under the License is distributed on an "AS IS" basis,
8  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
9  * the specific language governing rights and limitations under the License.
10  *
11  * The Original Code is The Carbon Component Framework.
12  *
13  * The Initial Developer of the Original Code is Sapient Corporation
14  *
15  * Copyright (C) 2003 Sapient Corporation. All Rights Reserved.
16  */

17
18 package org.sape.carbon.core.component.startup;
19
20
21 import org.sape.carbon.core.component.ComponentConfiguration;
22 import org.sape.carbon.core.component.Lookup;
23 import org.sape.carbon.core.component.lifecycle.Configurable;
24 import org.sape.carbon.core.component.startup.StartupServiceConfiguration.StartupComponentConfiguration;
25 import org.sape.carbon.core.exception.ExceptionUtility;
26
27 import org.apache.commons.logging.Log;
28 import org.apache.commons.logging.LogFactory;
29
30 /**
31  * <p>Default implementation of the Startup Service. This implementation
32  * defines the list of components to start in configuration.</p>
33  *
34  * Copyright 2002 Sapient
35  * @since carbon 1.0
36  * @author Douglas Voet, January 2002
37  * @version $Revision: 1.19 $($Author: dvoet $ / $Date: 2003/05/05 21:21:14 $)
38  */

39 public class DefaultStartupServiceImpl implements StartupService, Configurable {
40
41     /**
42      * Provides a handle to Apache-commons logger
43      */

44     private Log log = LogFactory.getLog(this.getClass());
45
46     /** set of all component names that need to be started */
47     private StartupComponentConfiguration[] startupComponents;
48
49     /**
50      * <p>Starts all components that this service is configured to start.</p>
51      */

52     public void startComponents() {
53         for (int i = 0; i < this.startupComponents.length; i++) {
54
55             StartupComponentConfiguration componentConfig =
56                 this.startupComponents[i];
57
58
59             if (componentConfig.isEnabled()) {
60                 if (log.isInfoEnabled()) {
61                     log.info("Starting component ["
62                         + componentConfig.getComponentName() + "]");
63                 }
64
65                 try {
66                     Lookup.getInstance().fetchComponent(componentConfig.getComponentName());
67
68                 } catch (Exception JavaDoc e) {
69                     if (log.isWarnEnabled()) {
70                         log.warn("Could not start component ["
71                             + componentConfig.getComponentName()
72                             + "], caught exception "
73                             + ExceptionUtility.printStackTracesToString(e));
74                     }
75                 }
76             } else {
77                 if (log.isDebugEnabled()) {
78                     log.debug("Startup component disabled ["
79                         + componentConfig.getComponentName() + "]");
80                 }
81             }
82         }
83     }
84
85     /**
86      * <p>Configuration lifecycle method.</p>
87      *
88      * @param configuration <code>StartupServiceConfiguration</code>
89      * configuration of the component
90      */

91     public void configure(ComponentConfiguration configuration) {
92         StartupServiceConfiguration startupConfiguration =
93             (StartupServiceConfiguration) configuration;
94
95         this.startupComponents =
96             startupConfiguration.getStartupComponent();
97     }
98
99     /** @link dependency */
100     /*#StartupServiceConfiguration lnkStartupServiceConfiguration;*/
101 }
102
Popular Tags