KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cactus > integration > ant > util > PropertySet


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.util;
21
22 import java.io.File JavaDoc;
23 import java.io.FileInputStream JavaDoc;
24 import java.io.IOException JavaDoc;
25 import java.util.PropertyResourceBundle JavaDoc;
26 import java.util.ResourceBundle JavaDoc;
27
28 import org.apache.tools.ant.BuildException;
29
30 /**
31  * Ant element used to tell the Cactus task to load a properties file
32  * and passed its properties to the client side or server side JVMs.
33  *
34  * @version $Id: PropertySet.java,v 1.4 2004/02/29 10:19:57 vmassol Exp $
35  */

36 public class PropertySet
37 {
38     /**
39      * Properties file to load.
40      */

41     private File JavaDoc propertiesFile;
42
43     /**
44      * Are the properties for the Cactus server side JVM?
45      */

46     private boolean isServer;
47     
48     /**
49      * @param thePropertiesFile the properties file to load
50      */

51     public void setPropertiesFile(File JavaDoc thePropertiesFile)
52     {
53         this.propertiesFile = thePropertiesFile;
54     }
55
56     /**
57      * @param isServer if true the properties will be passed to the
58      * Cactus server side JVM
59      */

60     public void setServer(boolean isServer)
61     {
62         this.isServer = isServer;
63     }
64
65     /**
66      * @return true if the properties are to be passed to the Cactus
67      * server side JVM, false otherwise
68      */

69     public boolean isServer()
70     {
71         return this.isServer;
72     }
73
74     /**
75      * @return the properties loaded from the proeprties file
76      */

77     public ResourceBundle JavaDoc readProperties()
78     {
79         if (this.propertiesFile == null)
80         {
81             throw new BuildException("Missing 'propertiesFiles' attribute");
82         }
83         
84         ResourceBundle JavaDoc bundle;
85         try
86         {
87             bundle = new PropertyResourceBundle JavaDoc(
88                 new FileInputStream JavaDoc(this.propertiesFile));
89         }
90         catch (IOException JavaDoc e)
91         {
92             throw new BuildException("Failed to load properties "
93                 + "file [" + this.propertiesFile + "]");
94         }
95         return bundle;
96     }
97 }
98
Popular Tags