KickJava   Java API By Example, From Geeks To Geeks.

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


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 Service {
33
34
35     // ----------------------------------------------------------- Constructors
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 JavaDoc name, Server server) {
55
56         super();
57         setName(name);
58         setServer(server);
59
60     }
61
62
63     // ----------------------------------------------------- Instance Variables
64

65
66     /**
67      * The set of connectors associated with this Service, keyed by port.
68      */

69     private HashMap JavaDoc connectors = new HashMap JavaDoc();
70
71
72     // ------------------------------------------------------------- Properties
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 JavaDoc name = null;
93
94     public String JavaDoc getName() {
95         return (this.name);
96     }
97
98     public void setName(String JavaDoc 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     // --------------------------------------------------------- Public Methods
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 JavaDoc(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 JavaDoc(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 JavaDoc(connector.getPort()));
162
163     }
164
165
166
167     /**
168      * Return a String representation of this object.
169      */

170     public String JavaDoc toString() {
171
172         StringBuffer JavaDoc sb = new StringBuffer JavaDoc("Service[");
173         sb.append("name=");
174         sb.append(name);
175         sb.append("]");
176         return (sb.toString());
177
178     }
179
180
181 }
182
Popular Tags