2011/08/05 - Jakarta Cactus has been retired.

For more information, please explore the Attic.

View Javadoc

1   /* 
2    * ========================================================================
3    * 
4    * Licensed to the Apache Software Foundation (ASF) under one or more
5    * contributor license agreements.  See the NOTICE file distributed with
6    * this work for additional information regarding copyright ownership.
7    * The ASF licenses this file to You under the Apache License, Version 2.0
8    * (the "License"); you may not use this file except in compliance with
9    * the License.  You may obtain a copy of the License at
10   * 
11   *   http://www.apache.org/licenses/LICENSE-2.0
12   * 
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   * 
19   * ========================================================================
20   */
21  package org.apache.cactus.integration.ant.util;
22  
23  import java.io.File;
24  import java.io.FileInputStream;
25  import java.io.IOException;
26  import java.util.PropertyResourceBundle;
27  import java.util.ResourceBundle;
28  
29  import org.apache.tools.ant.BuildException;
30  
31  /**
32   * Ant element used to tell the Cactus task to load a properties file
33   * and passed its properties to the client side or server side JVMs. 
34   * 
35   * @version $Id: PropertySet.java 238812 2004-02-29 10:21:34Z vmassol $
36   */
37  public class PropertySet
38  {
39      /**
40       * Properties file to load.
41       */
42      private File propertiesFile;
43  
44      /**
45       * Are the properties for the Cactus server side JVM?
46       */
47      private boolean isServer;
48      
49      /**
50       * @param thePropertiesFile the properties file to load
51       */
52      public void setPropertiesFile(File thePropertiesFile)
53      {
54          this.propertiesFile = thePropertiesFile;
55      }
56  
57      /**
58       * @param isServer if true the properties will be passed to the
59       *        Cactus server side JVM
60       */
61      public void setServer(boolean isServer)
62      {
63          this.isServer = isServer;
64      }
65  
66      /**
67       * @return true if the properties are to be passed to the Cactus
68       *         server side JVM, false otherwise
69       */
70      public boolean isServer()
71      {
72          return this.isServer;
73      }
74  
75      /**
76       * @return the properties loaded from the proeprties file
77       */
78      public ResourceBundle readProperties()
79      {
80          if (this.propertiesFile == null)
81          {
82              throw new BuildException("Missing 'propertiesFiles' attribute");
83          }
84          
85          ResourceBundle bundle;
86          try
87          {
88              bundle = new PropertyResourceBundle(
89                  new FileInputStream(this.propertiesFile));
90          } 
91          catch (IOException e)
92          {
93              throw new BuildException("Failed to load properties "
94                  + "file [" + this.propertiesFile + "]");
95          }
96          return bundle;
97      }
98  }