01: /*
02: * ========================================================================
03: *
04: * Copyright 2003 The Apache Software Foundation.
05: *
06: * Licensed under the Apache License, Version 2.0 (the "License");
07: * you may not use this file except in compliance with the License.
08: * You may obtain a copy of the License at
09: *
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;
23: import java.io.FileInputStream;
24: import java.io.IOException;
25: import java.util.PropertyResourceBundle;
26: import java.util.ResourceBundle;
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 238812 2004-02-29 10:21:34Z vmassol $
35: */
36: public class PropertySet {
37: /**
38: * Properties file to load.
39: */
40: private File propertiesFile;
41:
42: /**
43: * Are the properties for the Cactus server side JVM?
44: */
45: private boolean isServer;
46:
47: /**
48: * @param thePropertiesFile the properties file to load
49: */
50: public void setPropertiesFile(File thePropertiesFile) {
51: this .propertiesFile = thePropertiesFile;
52: }
53:
54: /**
55: * @param isServer if true the properties will be passed to the
56: * Cactus server side JVM
57: */
58: public void setServer(boolean isServer) {
59: this .isServer = isServer;
60: }
61:
62: /**
63: * @return true if the properties are to be passed to the Cactus
64: * server side JVM, false otherwise
65: */
66: public boolean isServer() {
67: return this .isServer;
68: }
69:
70: /**
71: * @return the properties loaded from the proeprties file
72: */
73: public ResourceBundle readProperties() {
74: if (this .propertiesFile == null) {
75: throw new BuildException(
76: "Missing 'propertiesFiles' attribute");
77: }
78:
79: ResourceBundle bundle;
80: try {
81: bundle = new PropertyResourceBundle(new FileInputStream(
82: this .propertiesFile));
83: } catch (IOException e) {
84: throw new BuildException("Failed to load properties "
85: + "file [" + this .propertiesFile + "]");
86: }
87: return bundle;
88: }
89: }
|