1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.commons.modeler.demo;
19
20
21 import java.util.HashMap;
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: 155428 $ $Date: 2005-02-26 08:12:25 -0500 (Sat, 26 Feb 2005) $
30 */
31
32 public class Service {
33
34
35
36
37
38 /***
39 * Construct a default instance of this class.
40 */
41 public Service() {
42
43 super();
44
45 }
46
47
48 /***
49 * Construct a configured instance of this class.
50 *
51 * @param name Name of this service
52 * @param server Associated server
53 */
54 public Service(String name, Server server) {
55
56 super();
57 setName(name);
58 setServer(server);
59
60 }
61
62
63
64
65
66 /***
67 * The set of connectors associated with this Service, keyed by port.
68 */
69 private HashMap connectors = new HashMap();
70
71
72
73
74
75 /***
76 * The associated Container for this Service.
77 */
78 public Container container = null;
79
80 public Container getContainer() {
81 return (this.container);
82 }
83
84 public void setContainer(Container container) {
85 this.container = container;
86 }
87
88
89 /***
90 * The name of this Service.
91 */
92 private String name = null;
93
94 public String getName() {
95 return (this.name);
96 }
97
98 public void setName(String name) {
99 this.name = name;
100 }
101
102
103 /***
104 * The associated Server for this Service.
105 */
106 private Server server = null;
107
108 public Server getServer() {
109 return (this.server);
110 }
111
112 public void setServer(Server server) {
113 this.server = server;
114 }
115
116
117
118
119
120 /***
121 * Add a new Connector to this Service.
122 *
123 * @param connector The connector to be added
124 */
125 public void addConnector(Connector connector) {
126
127 connectors.put(new Integer(connector.getPort()), connector);
128
129 }
130
131
132 /***
133 * Find and return the specified Connector associated with this Service.
134 *
135 * @param port Port number of the requested connector
136 */
137 public Connector findConnector(int port) {
138
139 return ((Connector) connectors.get(new Integer(port)));
140
141 }
142
143
144 /***
145 * Find and return all Connectors associated with this Service.
146 */
147 public Connector[] findConnectors() {
148
149 return ((Connector[]) connectors.values().toArray(new Connector[0]));
150
151 }
152
153
154 /***
155 * Remove the specified Connector from association with this Service.
156 *
157 * @param connector The Connector to be removed
158 */
159 public void removeConnector(Connector connector) {
160
161 connectors.remove(new Integer(connector.getPort()));
162
163 }
164
165
166
167 /***
168 * Return a String representation of this object.
169 */
170 public String toString() {
171
172 StringBuffer sb = new StringBuffer("Service[");
173 sb.append("name=");
174 sb.append(name);
175 sb.append("]");
176 return (sb.toString());
177
178 }
179
180
181 }