KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > service > AbsServiceImpl


1 /**
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999-2004 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: AbsServiceImpl.java,v 1.7 2004/09/24 09:40:14 danesa Exp $
23  * --------------------------------------------------------------------------
24  */

25 package org.objectweb.jonas.service;
26
27 import javax.naming.Context JavaDoc;
28
29 import org.objectweb.jonas.common.JProp;
30 import org.objectweb.jonas.management.ReconfigDispatcher;
31
32 /**
33  * Abstract implementation of a Service
34  */

35 public abstract class AbsServiceImpl extends ReconfigDispatcher implements Service {
36
37     /**
38      * service name
39      */

40     private String JavaDoc name = null;
41     /**
42      * service status
43      */

44     private boolean started = false;
45
46     /**
47      * Name of the domain of server
48      */

49     private String JavaDoc domainName = null;
50
51     /**
52      * Name of the JOnAS server
53      */

54     private String JavaDoc jonasServerName = null;
55
56
57     /**
58      * Initialize the service
59      * @param ctx configuration of the service
60      * @throws ServiceException service initialization failed
61      */

62     public void init(Context JavaDoc ctx) throws ServiceException {
63         // General properties infos
64
try {
65             JProp oProp = JProp.getInstance();
66             domainName = oProp.getValue(JProp.DOMAIN_NAME, JProp.JONAS_DEF_NAME);
67             jonasServerName = oProp.getValue(JProp.JONAS_NAME, JProp.JONAS_DEF_NAME);
68         } catch (Exception JavaDoc e) {
69             domainName = JProp.JONAS_DEF_NAME;
70             jonasServerName = JProp.JONAS_DEF_NAME;
71         }
72         this.doInit(ctx);
73     }
74
75     /**
76      * Start the service
77      * @throws ServiceException service start-up failed
78      */

79     public void start() throws ServiceException {
80         this.doStart();
81         this.started = true;
82     }
83
84     /**
85      * Stop the service
86      * @throws ServiceException service stopping failed
87      */

88     public void stop() throws ServiceException {
89         if (this.isStarted()) {
90             this.started = false;
91             this.doStop();
92         }
93     }
94
95     /**
96      * Returns true if the service is started, false otherwise
97      * @return true if the service is started
98      */

99     public boolean isStarted() {
100         return this.started;
101     }
102
103     /**
104      * Returns the service's name
105      * @return the service name
106      */

107     public String JavaDoc getName() {
108         return this.name;
109     }
110
111     /**
112      * Set the service's name
113      * @param name the name to set
114      */

115     public void setName(String JavaDoc name) {
116         this.name = name;
117     }
118
119
120     /**
121      * Return the domain's name of this service.
122      * @return the domain name
123      */

124     public String JavaDoc getDomainName() {
125         return this.domainName;
126     }
127
128     /**
129      * Return the JOnAS server's name of this service.
130      * @return the server name
131      */

132     public String JavaDoc getJonasServerName() {
133         return this.jonasServerName;
134     }
135
136     /**
137      * Abstract initialization method to be implemented by sub-classes
138      * @param ctx configuration of the service
139      * @throws ServiceException service initialization failed
140      */

141     protected abstract void doInit(Context JavaDoc ctx) throws ServiceException;
142     /**
143      * Abstract start-up method to be implemented by sub-classes
144      * @throws ServiceException service start-up failed
145      */

146     protected abstract void doStart() throws ServiceException;
147     /**
148      * Abstract method for service stopping to be implemented by sub-classes
149      * @throws ServiceException service stopping failed
150      */

151     protected abstract void doStop() throws ServiceException;
152 }
153
Popular Tags