KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > wsif > util > WSIFProperties


1 /*
2  * The Apache Software License, Version 1.1
3  *
4  *
5  * Copyright (c) 2002 The Apache Software Foundation. All rights
6  * reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in
17  * the documentation and/or other materials provided with the
18  * distribution.
19  *
20  * 3. The end-user documentation included with the redistribution,
21  * if any, must include the following acknowledgment:
22  * "This product includes software developed by the
23  * Apache Software Foundation (http://www.apache.org/)."
24  * Alternately, this acknowledgment may appear in the software itself,
25  * if and wherever such third-party acknowledgments normally appear.
26  *
27  * 4. The names "WSIF" and "Apache Software Foundation" must
28  * not be used to endorse or promote products derived from this
29  * software without prior written permission. For written
30  * permission, please contact apache@apache.org.
31  *
32  * 5. Products derived from this software may not be called "Apache",
33  * nor may "Apache" appear in their name, without prior written
34  * permission of the Apache Software Foundation.
35  *
36  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
37  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
38  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39  * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
40  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
42  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
43  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
44  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
45  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
46  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47  * SUCH DAMAGE.
48  * ====================================================================
49  *
50  * This software consists of voluntary contributions made by many
51  * individuals on behalf of the Apache Software Foundation and was
52  * originally based on software copyright (c) 2001, 2002, International
53  * Business Machines, Inc., http://www.apache.org. For more
54  * information on the Apache Software Foundation, please see
55  * <http://www.apache.org/>.
56  */

57
58 package org.apache.wsif.util;
59
60 import java.io.InputStream JavaDoc;
61 import java.security.AccessController JavaDoc;
62 import java.security.PrivilegedAction JavaDoc;
63 import java.util.Properties JavaDoc;
64
65 import org.apache.wsif.WSIFConstants;
66 import org.apache.wsif.logging.Trc;
67
68 /**
69  * The WSIFProperties class contains various static methods to read
70  * values from the wsif.properties file. Its main purpose is to prevent the
71  * properties file from being read in from disk each time a property is checked.
72  *
73  * @author Ant Elder <antelder@apache.org>
74  */

75 public class WSIFProperties {
76
77     private static Properties JavaDoc properties;
78
79     /**
80      * Reads a property from the wsif.properties file.
81      *
82      * @param property the property to read
83      * @return the value of ther property or null if the property is not defined
84      */

85     public static String JavaDoc getProperty(String JavaDoc property) {
86         Trc.entry(null, property);
87         if (properties == null) {
88             properties =
89                 (Properties JavaDoc) AccessController.doPrivileged(new PrivilegedAction JavaDoc() {
90                 public Object JavaDoc run() {
91                     InputStream JavaDoc in = (Thread.currentThread().getContextClassLoader())
92                        .getResourceAsStream(WSIFConstants.WSIF_PROPERTIES);
93
94                     Properties JavaDoc p2 = new Properties JavaDoc();
95                     try {
96                         p2.load(in);
97                     } catch (Exception JavaDoc ignored) {
98                         Trc.exception(ignored);
99                         return null;
100                     }
101                     return p2;
102                 }
103             });
104         }
105
106         if (properties == null) {
107             Trc.exit(null);
108             return null;
109         }
110
111         String JavaDoc s = properties.getProperty(property);
112         Trc.exit(s);
113         return s;
114     }
115
116     /**
117      * Reads the async request timeout value from the wsif.properties file. This
118      * property defines how long WSIF will keep a WSIFOperation stored in the
119      * correlation service waiting for the reply to a WSIFOperation
120      * executeRequestResponseAsync method call.
121      *
122      * @return the async request timeout value in milliseconds. If the property
123      * is invalid or not defined in the properties file then a value of
124      * zero is returned.
125      */

126     public static long getAsyncTimeout() {
127         Trc.entry(null);
128         long t;
129         try {
130             t = Long.parseLong(getProperty(WSIFConstants.WSIF_PROP_ASYNC_TIMEOUT));
131             if (t < 0) {
132                 t = 0;
133             } else {
134                 t = t * 1000; // convert to milliseconds
135
}
136         } catch (NumberFormatException JavaDoc e) {
137             Trc.exception(e);
138             t = 0;
139         }
140         Trc.exit(new Long JavaDoc(t));
141         return t;
142     }
143
144     /**
145      * Reads the synchronous request timeout from the wsif.properties file. This defines
146      * how long (in milliseconds) WSIF will wait for a synchronous response.
147      * Default of 0 means forever.
148      */

149     public static long getSyncTimeout() {
150         Trc.entry(null);
151         long t;
152         try {
153             t = Long.parseLong(getProperty(WSIFConstants.WSIF_PROP_SYNC_TIMEOUT));
154             if (t < 0) {
155                 t = 0;
156             }
157         } catch (NumberFormatException JavaDoc e) {
158             Trc.exception(e);
159             t = 0;
160         }
161         Trc.exit(new Long JavaDoc(t));
162         return t;
163     }
164 }
Popular Tags