KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > kernel > deployment > jboss > beans > servicepojo > AbstractService


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software 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 GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.test.kernel.deployment.jboss.beans.servicepojo;
23
24 /**
25  * Supposedly a base class for services
26  *
27  * @author <a HREF="mailto:dimitris@jboss.org">Dimitris Andreadis</a>
28  * @version $Revision: 37406 $
29  */

30 public abstract class AbstractService
31 {
32    public static final String JavaDoc CONSTRUCTED = "CONSTRUCTED";
33    public static final String JavaDoc CREATED = "CREATED";
34    public static final String JavaDoc STARTED = "STARTED";
35    public static final String JavaDoc STOPPED = "STOPPED";
36    public static final String JavaDoc DESTROYED = "DESTROYED";
37    public static final String JavaDoc FAILED = "FAILED";
38    
39    // Protected -----------------------------------------------------
40

41    protected String JavaDoc name;
42    protected String JavaDoc state = CONSTRUCTED;
43    
44    // Constructor ---------------------------------------------------
45

46    public AbstractService(String JavaDoc name)
47    {
48       this.name = name;
49       log("CTOR");
50    }
51    
52    // Accessors -----------------------------------------------------
53

54    public String JavaDoc getName()
55    {
56       return name;
57    }
58    
59    public String JavaDoc getState()
60    {
61       return state;
62    }
63    
64    // Lifecycle -----------------------------------------------------
65

66    public void create() throws Exception JavaDoc
67    {
68       state = CREATED;
69       log("create()");
70    }
71    
72    public void start() throws Exception JavaDoc
73    {
74       state = STARTED;
75       log("start()");
76    }
77    
78    public void stop() throws Exception JavaDoc
79    {
80       state = STOPPED;
81       log("stop()");
82    }
83    
84    public void destroy() throws Exception JavaDoc
85    {
86       state = DESTROYED;
87       log("destroy()");
88    }
89    
90    // Just to avoid org.jboss.logging -------------------------------
91

92    public void log(Object JavaDoc message)
93    {
94       System.out.println(getName() + " - " + message);
95    }
96    
97    // Overrides -----------------------------------------------------
98

99    public String JavaDoc toString()
100    {
101       StringBuffer JavaDoc sbuf = new StringBuffer JavaDoc();
102       sbuf
103       .append(getClass().getName())
104       .append("[ name=").append(name)
105       .append(", state=").append(state)
106       .append(" ]");
107       
108       return sbuf.toString();
109    }
110 }
111
Popular Tags