KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > tanukisoftware > wrapper > WrapperWin32Service


1 package org.tanukisoftware.wrapper;
2
3 /*
4  * Copyright (c) 1999, 2006 Tanuki Software Inc.
5  *
6  * Permission is hereby granted, free of charge, to any person
7  * obtaining a copy of the Java Service Wrapper and associated
8  * documentation files (the "Software"), to deal in the Software
9  * without restriction, including without limitation the rights
10  * to use, copy, modify, merge, publish, distribute, sub-license,
11  * and/or sell copies of the Software, and to permit persons to
12  * whom the Software is furnished to do so, subject to the
13  * following conditions:
14  *
15  * The above copyright notice and this permission notice shall be
16  * included in all copies or substantial portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
20  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21  * NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22  * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25  * OTHER DEALINGS IN THE SOFTWARE.
26  */

27
28 /**
29  * A WrapperWin32Service contains information about an individual service
30  * registered with the current system.
31  *
32  * @author Leif Mortenson <leif@tanukisoftware.com>
33  */

34 public class WrapperWin32Service
35 {
36     public static final int SERVICE_STATE_STOPPED = 0x00000001;
37     public static final int SERVICE_STATE_START_PENDING = 0x00000002;
38     public static final int SERVICE_STATE_STOP_PENDING = 0x00000003;
39     public static final int SERVICE_STATE_RUNNING = 0x00000004;
40     public static final int SERVICE_STATE_CONTINUE_PENDING = 0x00000005;
41     public static final int SERVICE_STATE_PAUSE_PENDING = 0x00000006;
42     public static final int SERVICE_STATE_PAUSED = 0x00000007;
43     
44     /** The name of the service. */
45     private String JavaDoc m_name;
46     
47     /** The display name of the service. */
48     private String JavaDoc m_displayName;
49     
50     /** The last known state of the service. */
51     private int m_serviceState;
52     
53     /** The exit of the service. */
54     private int m_exitCode;
55     
56     /*---------------------------------------------------------------
57      * Constructors
58      *-------------------------------------------------------------*/

59     WrapperWin32Service( byte[] name, byte[] displayName, int serviceState, int exitCode )
60     {
61         // Decode the parameters using the default system encoding.
62
m_name = new String JavaDoc( name );
63         m_displayName = new String JavaDoc( displayName );
64         
65         m_serviceState = serviceState;
66         m_exitCode = exitCode;
67     }
68     
69     /*---------------------------------------------------------------
70      * Methods
71      *-------------------------------------------------------------*/

72     /**
73      * Returns the name of the service.
74      *
75      * @return The name of the service.
76      */

77     public String JavaDoc getName()
78     {
79         return m_name;
80     }
81     
82     /**
83      * Returns the display name of the service.
84      *
85      * @return The display name of the service.
86      */

87     public String JavaDoc getDisplayName()
88     {
89         return m_displayName;
90     }
91     
92     /**
93      * Returns the last known state name of the service.
94      *
95      * @return The last known state name of the service.
96      */

97     public String JavaDoc getServiceStateName()
98     {
99         int serviceState = getServiceState();
100         switch( serviceState )
101         {
102         case SERVICE_STATE_STOPPED:
103             return "STOPPED";
104             
105         case SERVICE_STATE_START_PENDING:
106             return "START_PENDING";
107             
108         case SERVICE_STATE_STOP_PENDING:
109             return "STOP_PENDING";
110             
111         case SERVICE_STATE_RUNNING:
112             return "RUNNING";
113             
114         case SERVICE_STATE_CONTINUE_PENDING:
115             return "CONTINUE_PENDING";
116             
117         case SERVICE_STATE_PAUSE_PENDING:
118             return "PAUSE_PENDING";
119             
120         case SERVICE_STATE_PAUSED:
121             return "PAUSED";
122             
123         default:
124             return "UNKNOWN(" + serviceState + ")";
125         }
126     }
127     
128     /**
129      * Returns the last known state of the service.
130      *
131      * @return The last known state of the service.
132      */

133     public int getServiceState()
134     {
135         return m_serviceState;
136     }
137     
138     /**
139      * Returns the exit of the service, or 0 if it is still running.
140      *
141      * @return The exit of the service.
142      */

143     public int getExitCode()
144     {
145         return m_exitCode;
146     }
147     
148     /**
149      * Returns a string representation of the user.
150      *
151      * @return A string representation of the user.
152      */

153     public String JavaDoc toString()
154     {
155         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
156         sb.append( "WrapperWin32Service[name=\"" );
157         sb.append( getName() );
158         sb.append( "\", displayName=\"" );
159         sb.append( getDisplayName() );
160         
161         sb.append( "\", state=" );
162         sb.append( getServiceStateName() );
163         sb.append( ", exitCode=" );
164         sb.append( getExitCode() );
165         sb.append( "]" );
166         return sb.toString();
167     }
168 }
169
170
Popular Tags