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