1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    * 
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   * 
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  
19  package org.apache.commons.modeler.demo;
20  
21  
22  import java.util.HashMap;
23  
24  
25  /***
26   * <p>Sample managed object for the Modeler Demonstration Application,
27   * based on the Catalina architecture of Tomcat 4.</p>
28   *
29   * @author Craig R. McClanahan
30   * @version $Revision: 480402 $ $Date: 2006-11-29 04:43:23 +0000 (Wed, 29 Nov 2006) $
31   */
32  
33  public class Server {
34  
35  
36      // ----------------------------------------------------------- Constructors
37  
38  
39      /***
40       * Construct a default instance of this class.
41       */
42      public Server() {
43  
44          super();
45  
46      }
47  
48  
49      /***
50       * Construct a configured instance of this class.
51       *
52       * @param port Port number of this server
53       * @param shutdown Shutdown command of this server
54       */
55      public Server(int port, String shutdown) {
56  
57          super();
58          setPort(port);
59          setShutdown(shutdown);
60  
61      }
62  
63  
64      // ----------------------------------------------------- Instance Variables
65  
66  
67      /***
68       * The set of services associated with this Server, keyed by name.
69       */
70      private HashMap services = new HashMap();
71  
72  
73      // ------------------------------------------------------------- Properties
74  
75  
76      /***
77       * The port number for our shutdown commands.
78       */
79      private int port = 8005;
80  
81      public int getPort() {
82          return (this.port);
83      }
84  
85      public void setPort(int port) {
86          this.port = port;
87      }
88  
89  
90      /***
91       * The shutdown command password.
92       */
93      private String shutdown = "SHUTDOWN";
94  
95      public String getShutdown() {
96          return (this.shutdown);
97      }
98  
99      public void setShutdown(String shutdown) {
100         this.shutdown = shutdown;
101     }
102 
103     // --------------------------------------------------------- Public Methods
104 
105 
106     /***
107      * Add a new Service to this Server.
108      *
109      * @param service The service to be added
110      */
111     public void addService(Service service) {
112 
113         services.put(service.getName(), service);
114 
115     }
116 
117 
118     /***
119      * Find and return the specified Service associated with this Server.
120      *
121      * @param name Name of the requested service
122      */
123     public Service findService(String name) {
124 
125         return ((Service) services.get(name));
126 
127     }
128 
129 
130     /***
131      * Find and return all Services associated with this Server.
132      */
133     public Service[] findServices() {
134 
135         Service results[] = new Service[services.size()];
136         return ((Service[]) services.values().toArray(results));
137 
138     }
139 
140 
141     /***
142      * Remove the specified Service from association with this Server.
143      *
144      * @param service The Service to be removed
145      */
146     public void removeService(Service service) {
147 
148         services.remove(service.getName());
149 
150     }
151 
152 
153     /***
154      * Return a String representation of this object.
155      */
156     public String toString() {
157 
158         StringBuffer sb = new StringBuffer("Server[");
159         sb.append("port=");
160         sb.append(port);
161         sb.append(", shutdown=");
162         sb.append(shutdown);
163         sb.append("]");
164         return (sb.toString());
165 
166     }
167 
168 
169 }