|
|||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
ContainerSet.java | 62.5% | 68.4% | 88.9% | 72.2% |
|
1 |
/*
|
|
2 |
* ====================================================================
|
|
3 |
*
|
|
4 |
* The Apache Software License, Version 1.1
|
|
5 |
*
|
|
6 |
* Copyright (c) 2003 The Apache Software Foundation. All rights
|
|
7 |
* reserved.
|
|
8 |
*
|
|
9 |
* Redistribution and use in source and binary forms, with or without
|
|
10 |
* modification, are permitted provided that the following conditions
|
|
11 |
* are met:
|
|
12 |
*
|
|
13 |
* 1. Redistributions of source code must retain the above copyright
|
|
14 |
* notice, this list of conditions and the following disclaimer.
|
|
15 |
*
|
|
16 |
* 2. Redistributions in binary form must reproduce the above copyright
|
|
17 |
* notice, this list of conditions and the following disclaimer in
|
|
18 |
* the documentation and/or other materials provided with the
|
|
19 |
* distribution.
|
|
20 |
*
|
|
21 |
* 3. The end-user documentation included with the redistribution, if
|
|
22 |
* any, must include the following acknowlegement:
|
|
23 |
* "This product includes software developed by the
|
|
24 |
* Apache Software Foundation (http://www.apache.org/)."
|
|
25 |
* Alternately, this acknowlegement may appear in the software itself,
|
|
26 |
* if and wherever such third-party acknowlegements normally appear.
|
|
27 |
*
|
|
28 |
* 4. The names "The Jakarta Project", "Cactus" and "Apache Software
|
|
29 |
* Foundation" must not be used to endorse or promote products
|
|
30 |
* derived from this software without prior written permission. For
|
|
31 |
* written permission, please contact apache@apache.org.
|
|
32 |
*
|
|
33 |
* 5. Products derived from this software may not be called "Apache"
|
|
34 |
* nor may "Apache" appear in their names without prior written
|
|
35 |
* permission of the Apache Group.
|
|
36 |
*
|
|
37 |
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
|
|
38 |
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
39 |
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
40 |
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
|
|
41 |
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
42 |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
43 |
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
|
44 |
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
45 |
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
46 |
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
|
47 |
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
48 |
* SUCH DAMAGE.
|
|
49 |
* ====================================================================
|
|
50 |
*
|
|
51 |
* This software consists of voluntary contributions made by many
|
|
52 |
* individuals on behalf of the Apache Software Foundation. For more
|
|
53 |
* information on the Apache Software Foundation, please see
|
|
54 |
* <http://www.apache.org/>.
|
|
55 |
*
|
|
56 |
*/
|
|
57 |
package org.apache.cactus.integration.ant;
|
|
58 |
|
|
59 |
import java.util.ArrayList;
|
|
60 |
import java.util.List;
|
|
61 |
|
|
62 |
import org.apache.cactus.integration.ant.container.Container;
|
|
63 |
import org.apache.cactus.integration.ant.container.ContainerFactory;
|
|
64 |
import org.apache.cactus.integration.ant.container.ContainerWrapper;
|
|
65 |
import org.apache.cactus.integration.ant.container.GenericContainer;
|
|
66 |
import org.apache.tools.ant.BuildException;
|
|
67 |
import org.apache.tools.ant.DynamicConfigurator;
|
|
68 |
import org.apache.tools.ant.types.DataType;
|
|
69 |
|
|
70 |
/**
|
|
71 |
* Ant data type that represents a set of J2EE containers.
|
|
72 |
*
|
|
73 |
* @author <a href="mailto:cmlenz@apache.org">Christopher Lenz</a>
|
|
74 |
*
|
|
75 |
* @version $Id: ContainerSet.java,v 1.2 2003/06/11 16:19:26 cmlenz Exp $
|
|
76 |
*/
|
|
77 |
public class ContainerSet extends DataType implements DynamicConfigurator |
|
78 |
{ |
|
79 |
|
|
80 |
// Instance Variables ------------------------------------------------------
|
|
81 |
|
|
82 |
/**
|
|
83 |
* The list of nested container elements.
|
|
84 |
*/
|
|
85 |
private ContainerFactory factory = new ContainerFactory(); |
|
86 |
|
|
87 |
/**
|
|
88 |
* The list of nested container and containerset elements.
|
|
89 |
*/
|
|
90 |
private List containers = new ArrayList(); |
|
91 |
|
|
92 |
/**
|
|
93 |
* The timeout in milliseconds.
|
|
94 |
*/
|
|
95 |
private long timeout = -1; |
|
96 |
|
|
97 |
/**
|
|
98 |
* The proxy port.
|
|
99 |
*/
|
|
100 |
private int proxyPort = -1; |
|
101 |
|
|
102 |
// DynamicConfigurator Implementation --------------------------------------
|
|
103 |
|
|
104 |
/**
|
|
105 |
* @see org.apache.tools.ant.DynamicConfigurator#createDynamicElement
|
|
106 |
*/
|
|
107 | 0 |
public final Object createDynamicElement(String theName)
|
108 |
throws BuildException
|
|
109 |
{ |
|
110 | 0 |
if (isReference())
|
111 |
{ |
|
112 | 0 |
throw noChildrenAllowed();
|
113 |
} |
|
114 | 0 |
Container container = this.factory.createContainer(theName);
|
115 | 0 |
this.containers.add(container);
|
116 | 0 |
return container;
|
117 |
} |
|
118 |
|
|
119 |
/**
|
|
120 |
* @see org.apache.tools.ant.DynamicConfigurator#setDynamicAttribute
|
|
121 |
*/
|
|
122 | 6 |
public final void setDynamicAttribute(String theName, String theValue) |
123 |
throws BuildException
|
|
124 |
{ |
|
125 | 6 |
if (isReference())
|
126 |
{ |
|
127 | 0 |
throw tooManyAttributes();
|
128 |
} |
|
129 | 6 |
throw new BuildException("Attribute [" + theName |
130 |
+ "] not supported");
|
|
131 |
} |
|
132 |
|
|
133 |
// Public Methods ----------------------------------------------------------
|
|
134 |
|
|
135 |
/**
|
|
136 |
* Adds a nested generic container to the set of containers.
|
|
137 |
*
|
|
138 |
* @param theContainer The generic container element to add
|
|
139 |
*/
|
|
140 | 3 |
public final void addGeneric(GenericContainer theContainer) |
141 |
{ |
|
142 | 3 |
this.containers.add(theContainer);
|
143 |
} |
|
144 |
|
|
145 |
/**
|
|
146 |
* Returns an iterator over the nested container elements, in the order
|
|
147 |
* they appear in the build file.
|
|
148 |
*
|
|
149 |
* @return An iterator over the nested container elements
|
|
150 |
*/
|
|
151 | 6 |
public final Container[] getContainers()
|
152 |
{ |
|
153 | 6 |
Container[] containers = (Container[]) |
154 |
this.containers.toArray(new Container[this.containers.size()]); |
|
155 | 6 |
if (this.proxyPort > 0) |
156 |
{ |
|
157 | 3 |
for (int i = 0; i < containers.length; i++) |
158 |
{ |
|
159 | 2 |
containers[i] = new ContainerWrapper(containers[i])
|
160 |
{ |
|
161 | 1 |
public int getPort() |
162 |
{ |
|
163 | 1 |
return proxyPort;
|
164 |
} |
|
165 |
}; |
|
166 |
} |
|
167 |
} |
|
168 | 6 |
return containers;
|
169 |
} |
|
170 |
|
|
171 |
/**
|
|
172 |
* Returns the timeout after which connecting to a container will be
|
|
173 |
* given up, or <code>-1</code> if no timeout has been set.
|
|
174 |
*
|
|
175 |
* @return The timeout in milliseconds
|
|
176 |
*/
|
|
177 | 3 |
public final long getTimeout() |
178 |
{ |
|
179 | 3 |
return this.timeout; |
180 |
} |
|
181 |
|
|
182 |
/**
|
|
183 |
* Sets the timeout after which connecting to a container will be given
|
|
184 |
* up.
|
|
185 |
*
|
|
186 |
* @param theTimeout The timeout in milliseconds
|
|
187 |
*/
|
|
188 | 1 |
public final void setTimeout(long theTimeout) |
189 |
{ |
|
190 | 1 |
this.timeout = theTimeout;
|
191 |
} |
|
192 |
|
|
193 |
/**
|
|
194 |
* Returns the proxy port, or <code>-1</code> if no proxy port has been set.
|
|
195 |
*
|
|
196 |
* @return The proxy port
|
|
197 |
*/
|
|
198 | 3 |
public final int getProxyPort() |
199 |
{ |
|
200 | 3 |
return this.proxyPort; |
201 |
} |
|
202 |
|
|
203 |
/**
|
|
204 |
* Sets the proxy port which will be used by the test caller instead
|
|
205 |
* of the real container port. This can be used to insert protocol
|
|
206 |
* tracers between the test caller and the container.
|
|
207 |
*
|
|
208 |
* @param theProxyPort The proxy port to set
|
|
209 |
*/
|
|
210 | 3 |
public final void setProxyPort(int theProxyPort) |
211 |
{ |
|
212 | 3 |
this.proxyPort = theProxyPort;
|
213 |
} |
|
214 |
|
|
215 |
} |
|
216 |
|
|