KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > services > JahiaService


1 // $Id: JahiaService.java 4506 2003-09-06 12:16:18Z shuber $
2
//
3
// ____.
4
// __/\ ______| |__/\. _______
5
// __ .____| | \ | +----+ \
6
// _______| /--| | | - \ _ | : - \_________
7
// \\______: :---| : : | : | \________>
8
// |__\---\_____________:______: :____|____:_____\
9
// /_____|
10
//
11
// . . . i n j a h i a w e t r u s t . . .
12
//
13

14 package org.jahia.services;
15
16 import org.jahia.exceptions.JahiaException;
17 import org.jahia.exceptions.JahiaInitializationException;
18 import org.jahia.settings.SettingsBean;
19
20
21 /**
22  * This class is the root class of all the Jahia services. The
23  * {@link #init init()} method is called when the service is created when the
24  * Jahia server starts, and the {@link #shutdown shutdown()} is called when
25  * the service has to be shutdown. Service developpers should override these two
26  * methods to perform specific initialization or shutdown operations. When the
27  * service needs to be restarted, a call to the
28  * {@link #restart restart()} method should be done.
29  *
30  * @author Khue Nguyen
31  * @author Fulco Houkes
32  *
33  * @version 1.2
34  */

35 public abstract class JahiaService
36 {
37     private String JavaDoc mServiceName = null;
38
39     /**
40      * This variable is true when the service has been initialized and is ready
41      * to be used, method calls should fail (raise an exception) when this
42      * variable is false.
43      */

44     protected boolean mIsServiceInitialized = false;
45
46
47     //-------------------------------------------------------------------------
48
/** Return true if the service is initialized and ready to be used.
49      *
50      * @return Return true if the service is initialized.
51      */

52     public boolean isInitialized ()
53     {
54         return mIsServiceInitialized;
55     }
56
57
58     //-------------------------------------------------------------------------
59
/** Check if the service is running (initialized). If it's not initialized
60      * yet, a JahiaException is thrown.
61      *
62      * @exception JahiaException
63      * Throws this exception when the service is not initialized.
64      */

65     protected void checkService ()
66         throws JahiaException
67     {
68         if (!mIsServiceInitialized) {
69             throw new JahiaException ("Service error.",
70                     "Service ["+mServiceName+"] is not initialized!",
71                     JahiaException.SERVICE_ERROR, JahiaException.CRITICAL_SEVERITY);
72         }
73     }
74
75
76     //-------------------------------------------------------------------------
77
/** Set the service name.
78      *
79      * @param name
80      * String representation of the service name.
81      */

82     public synchronized void setServiceName (String JavaDoc name)
83     {
84         if (name != null) {
85             if (name.length() > 0) {
86                 mServiceName = name;
87             }
88         }
89     }
90
91
92     //-------------------------------------------------------------------------
93
/** Get the service name.
94      *
95      * @return
96      * Return a reference on the service name. Might return
97      * <code>null</code> when the service has not be named yet.
98      */

99     public String JavaDoc getServiceName ()
100     {
101         return mServiceName;
102     }
103
104
105     //-------------------------------------------------------------------------
106
/**
107      * Code to clean up the services ressource here. Override this method
108      * with specific services shutdown codes.
109      *
110      * @exception JahiaException
111      * Raise an JahiaException exception on any failure.
112      */

113     public synchronized void shutdown ()
114         throws JahiaException
115     {
116         mIsServiceInitialized = false;
117     }
118
119
120     //-------------------------------------------------------------------------
121
/** Initialize the service. Override this method if specific initialization
122      * is needed to start the service.
123      *
124      * @exception JahiaInitializationException
125      * Thows this exception on any failure.
126      */

127     public synchronized void init (SettingsBean jSettings)
128         throws JahiaInitializationException
129     {
130         mIsServiceInitialized = true;
131     }
132
133
134     //-------------------------------------------------------------------------
135
/** Restart the service by cleaning the remaining resources. This method
136      * calls the {@link #shutdown() shutdown()} and
137      * {@link #init init()} method of the service.
138      *
139      * @exception JahiaInitializationException
140      * Thows this exception on any failure.
141      *
142      * @exception JahiaException
143      * Raise an JahiaException exception on any shutdown failure.
144      */

145     public synchronized void restart (SettingsBean jSettings)
146         throws JahiaInitializationException,
147                 JahiaException
148     {
149         shutdown ();
150         init (jSettings);
151     }
152
153 }
154
155
Popular Tags