KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cactus > integration > ant > ContainerSet


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

20 package org.apache.cactus.integration.ant;
21
22 import java.util.ArrayList JavaDoc;
23 import java.util.List JavaDoc;
24
25 import org.apache.cactus.integration.ant.container.Container;
26 import org.apache.cactus.integration.ant.container.ContainerFactory;
27 import org.apache.cactus.integration.ant.container.ContainerWrapper;
28 import org.apache.cactus.integration.ant.container.GenericContainer;
29 import org.apache.tools.ant.BuildException;
30 import org.apache.tools.ant.DynamicConfigurator;
31 import org.apache.tools.ant.types.DataType;
32
33 /**
34  * Ant data type that represents a set of J2EE containers.
35  *
36  * @version $Id: ContainerSet.java,v 1.4 2004/02/29 10:05:26 vmassol Exp $
37  */

38 public class ContainerSet extends DataType implements DynamicConfigurator
39 {
40
41     // Instance Variables ------------------------------------------------------
42

43     /**
44      * The list of nested container elements.
45      */

46     private ContainerFactory factory = new ContainerFactory();
47
48     /**
49      * The list of nested container and containerset elements.
50      */

51     private List JavaDoc containers = new ArrayList JavaDoc();
52
53     /**
54      * The timeout in milliseconds.
55      */

56     private long timeout = -1;
57
58     /**
59      * The proxy port.
60      */

61     private int proxyPort = -1;
62
63     // DynamicConfigurator Implementation --------------------------------------
64

65     /**
66      * @see org.apache.tools.ant.DynamicConfigurator#createDynamicElement
67      */

68     public final Object JavaDoc createDynamicElement(String JavaDoc theName)
69         throws BuildException
70     {
71         if (isReference())
72         {
73             throw noChildrenAllowed();
74         }
75         Container container = this.factory.createContainer(theName);
76         this.containers.add(container);
77         return container;
78     }
79
80     /**
81      * @see org.apache.tools.ant.DynamicConfigurator#setDynamicAttribute
82      */

83     public final void setDynamicAttribute(String JavaDoc theName, String JavaDoc theValue)
84         throws BuildException
85     {
86         if (isReference())
87         {
88             throw tooManyAttributes();
89         }
90         throw new BuildException("Attribute [" + theName
91             + "] not supported");
92     }
93
94     // Public Methods ----------------------------------------------------------
95

96     /**
97      * Adds a nested generic container to the set of containers.
98      *
99      * @param theContainer The generic container element to add
100      */

101     public final void addGeneric(GenericContainer theContainer)
102     {
103         this.containers.add(theContainer);
104     }
105
106     /**
107      * Returns an iterator over the nested container elements, in the order
108      * they appear in the build file.
109      *
110      * @return An iterator over the nested container elements
111      */

112     public final Container[] getContainers()
113     {
114         Container[] containers = (Container[])
115             this.containers.toArray(new Container[this.containers.size()]);
116         if (this.proxyPort > 0)
117         {
118             for (int i = 0; i < containers.length; i++)
119             {
120                 containers[i] = new ContainerWrapper(containers[i])
121                 {
122                     public int getPort()
123                     {
124                         return proxyPort;
125                     }
126                 };
127             }
128         }
129         return containers;
130     }
131
132     /**
133      * Returns the timeout after which connecting to a container will be
134      * given up, or <code>-1</code> if no timeout has been set.
135      *
136      * @return The timeout in milliseconds
137      */

138     public final long getTimeout()
139     {
140         return this.timeout;
141     }
142
143     /**
144      * Sets the timeout after which connecting to a container will be given
145      * up.
146      *
147      * @param theTimeout The timeout in milliseconds
148      */

149     public final void setTimeout(long theTimeout)
150     {
151         this.timeout = theTimeout;
152     }
153
154     /**
155      * Returns the proxy port, or <code>-1</code> if no proxy port has been set.
156      *
157      * @return The proxy port
158      */

159     public final int getProxyPort()
160     {
161         return this.proxyPort;
162     }
163
164     /**
165      * Sets the proxy port which will be used by the test caller instead
166      * of the real container port. This can be used to insert protocol
167      * tracers between the test caller and the container.
168      *
169      * @param theProxyPort The proxy port to set
170      */

171     public final void setProxyPort(int theProxyPort)
172     {
173         this.proxyPort = theProxyPort;
174     }
175
176 }
177
Popular Tags