View Javadoc

1   /*
2    * $Id: AbstractService.java 269 2005-08-10 17:49:22Z josem $
3    *
4    * Tarsis
5    * Copyright (C) 2002 Talika Open Source Group
6    *
7    * This program is free software; you can redistribute it and/or modify
8    * it under the terms of the GNU General Public License as published by
9    * the Free Software Foundation; either version 2 of the License, or
10   * (at your option) any later version.
11   *
12   * This program is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   * GNU General Public License for more details.
16   *
17   * You should have received a copy of the GNU General Public License
18   * along with this program; if not, write to the Free Software
19   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20   *
21   */
22  
23  package org.talika.tarsis.service;
24  
25  import org.talika.tarsis.context.Context;
26  import org.talika.tarsis.log.Logger;
27  
28  /**
29   * Base implementation of <code>Service</code> interface.
30   *
31   * @author  Jose M. Palomar
32   * @version $Revision: 269 $
33   */
34  public abstract class AbstractService implements Service {
35  
36      // Constants
37  
38      // Fields
39      /**
40       * Tarsis context.
41       */
42      private Context context;
43  
44      /**
45       * Tarsis logger.
46       */
47      private Logger logger;
48  
49      // Constructors
50      /**
51       * Creates a new <code>AbstractService</code> object.
52       */
53      public AbstractService() {
54      }
55  
56      // Methods
57      /**
58       * Called by the framework to indicate that is being placed into service.
59       *
60       * @param context Context context that initialized service.
61       * @throws ServiceException if an exception has occurred that interferes with the
62       * services's normal operation
63       * @see org.talika.tarsis.service.Service#init(Context)
64       */
65      public void init(Context context) throws ServiceException {
66          this.context = context;
67          this.logger = context.getLogger();
68  
69          if (this.logger.isInfoEnabled()) {
70              this.logger.logInfo(getName() + ": init");
71          }
72      }
73  
74      /**
75       * Called by the framework to indicate that is being placed out of service.
76       *
77       * @see org.talika.tarsis.service.Service#destroy()
78       */
79      public void destroy() {
80          if (this.logger.isInfoEnabled()) {
81              this.logger.logInfo(getName() + ": destroy");
82          }
83  
84          this.logger = null;
85          this.context = null;
86      }
87  
88      /**
89       * Returns name of service.
90       *
91       * @return String name of service.
92       * @see org.talika.tarsis.service.Service#getName()
93       */
94      public abstract String getName();
95  
96      /**
97       * Returns the Tarsis context.
98       *
99       * @return Context the Tarsis context.
100      */
101     protected final Context getContext() {
102         return context;
103     }
104 
105     /**
106      * Returns the Tarsis logger.
107      *
108      * @return Logger the Tarsis logger.
109      */
110     protected final Logger getLogger() {
111         return logger;
112     }
113 
114 }