KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > modeler > demo > Server


1 /*
2  * Copyright 1999,2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17
18 package org.apache.commons.modeler.demo;
19
20
21 import java.util.HashMap JavaDoc;
22
23
24 /**
25  * <p>Sample managed object for the Modeler Demonstration Application,
26  * based on the Catalina architecture of Tomcat 4.</p>
27  *
28  * @author Craig R. McClanahan
29  * @version $Revision$ $Date: 2005-02-26 05:12:25 -0800 (Sat, 26 Feb 2005) $
30  */

31
32 public class Server {
33
34
35     // ----------------------------------------------------------- Constructors
36

37
38     /**
39      * Construct a default instance of this class.
40      */

41     public Server() {
42
43         super();
44
45     }
46
47
48     /**
49      * Construct a configured instance of this class.
50      *
51      * @param port Port number of this server
52      * @param shutdown Shutdown command of this server
53      */

54     public Server(int port, String JavaDoc shutdown) {
55
56         super();
57         setPort(port);
58         setShutdown(shutdown);
59
60     }
61
62
63     // ----------------------------------------------------- Instance Variables
64

65
66     /**
67      * The set of services associated with this Server, keyed by name.
68      */

69     private HashMap JavaDoc services = new HashMap JavaDoc();
70
71
72     // ------------------------------------------------------------- Properties
73

74
75     /**
76      * The port number for our shutdown commands.
77      */

78     private int port = 8005;
79
80     public int getPort() {
81         return (this.port);
82     }
83
84     public void setPort(int port) {
85         this.port = port;
86     }
87
88
89     /**
90      * The shutdown command password.
91      */

92     private String JavaDoc shutdown = "SHUTDOWN";
93
94     public String JavaDoc getShutdown() {
95         return (this.shutdown);
96     }
97
98     public void setShutdown(String JavaDoc shutdown) {
99         this.shutdown = shutdown;
100     }
101
102     // --------------------------------------------------------- Public Methods
103

104
105     /**
106      * Add a new Service to this Server.
107      *
108      * @param service The service to be added
109      */

110     public void addService(Service service) {
111
112         services.put(service.getName(), service);
113
114     }
115
116
117     /**
118      * Find and return the specified Service associated with this Server.
119      *
120      * @param name Name of the requested service
121      */

122     public Service findService(String JavaDoc name) {
123
124         return ((Service) services.get(name));
125
126     }
127
128
129     /**
130      * Find and return all Services associated with this Server.
131      */

132     public Service[] findServices() {
133
134         Service results[] = new Service[services.size()];
135         return ((Service[]) services.values().toArray(results));
136
137     }
138
139
140     /**
141      * Remove the specified Service from association with this Server.
142      *
143      * @param service The Service to be removed
144      */

145     public void removeService(Service service) {
146
147         services.remove(service.getName());
148
149     }
150
151
152     /**
153      * Return a String representation of this object.
154      */

155     public String JavaDoc toString() {
156
157         StringBuffer JavaDoc sb = new StringBuffer JavaDoc("Server[");
158         sb.append("port=");
159         sb.append(port);
160         sb.append(", shutdown=");
161         sb.append(shutdown);
162         sb.append("]");
163         return (sb.toString());
164
165     }
166
167
168 }
169
Popular Tags