KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > fulcrum > yaafi > service > servicemanager > ServiceManagerService


1 package org.apache.fulcrum.yaafi.service.servicemanager;
2
3 /*
4  * Copyright 2004 Apache Software Foundation
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
14  * implied.
15  *
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */

19
20 import org.apache.avalon.framework.activity.Disposable;
21 import org.apache.avalon.framework.logger.AbstractLogEnabled;
22 import org.apache.avalon.framework.service.ServiceException;
23 import org.apache.avalon.framework.service.ServiceManager;
24 import org.apache.avalon.framework.service.Serviceable;
25
26
27 /**
28  * Let's try to break the singleton addiction with this service. This
29  * service stores the instance of a service manager and allows access
30  * to this instance.
31  */

32
33 public class ServiceManagerService
34     extends AbstractLogEnabled
35     implements ServiceManager, Serviceable, Disposable
36 {
37     /** Store the ServiceContainer on a per instance base */
38     private static ServiceManager serviceManager;
39     
40     /**
41      * Constructor
42      */

43     public ServiceManagerService()
44     {
45     }
46
47     public static ServiceManager getServiceManager()
48     {
49         return ServiceManagerService.serviceManager;
50     }
51
52     /////////////////////////////////////////////////////////////////////////
53
// Avalon Lifecycle Implementation
54
/////////////////////////////////////////////////////////////////////////
55

56     /**
57      * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceContainer)
58      */

59     public void service(ServiceManager serviceManager) throws ServiceException
60     {
61         this.getLogger().debug( "Storing the ServiceContainer instance" );
62         ServiceManagerService.serviceManager = serviceManager;
63     }
64
65     /**
66      * @see org.apache.avalon.framework.activity.Disposable#dispose()
67      */

68     public void dispose()
69     {
70         this.getLogger().debug( "Removing the ServiceContainer instance" );
71         ServiceManagerService.serviceManager = null;
72     }
73
74     /////////////////////////////////////////////////////////////////////////
75
// ServiceContainer Implementation
76
/////////////////////////////////////////////////////////////////////////
77

78     /**
79      * @see org.apache.avalon.framework.service.ServiceContainer#hasService(java.lang.String)
80      */

81     public boolean hasService(String JavaDoc name)
82     {
83         return ServiceManagerService.serviceManager.hasService(name);
84     }
85     
86     /**
87      * @see org.apache.avalon.framework.service.ServiceContainer#lookup(java.lang.String)
88      */

89     public Object JavaDoc lookup(String JavaDoc name) throws ServiceException
90     {
91         return ServiceManagerService.serviceManager.lookup(name);
92     }
93     
94     /**
95      * @see org.apache.avalon.framework.service.ServiceContainer#release(java.lang.Object)
96      */

97     public void release(Object JavaDoc object)
98     {
99         ServiceManagerService.serviceManager.release(object);
100     }
101 }
102
Popular Tags