KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mmbase > util > ApplicationContextReader


1 /*
2
3 This software is OSI Certified Open Source Software.
4 OSI Certified is a certification mark of the Open Source Initiative.
5
6 The license (Mozilla version 1.0) can be read at the MMBase site.
7 See http://www.MMBase.org/license
8
9 */

10 package org.mmbase.util;
11
12 import java.util.*;
13 import javax.naming.*;
14
15 import org.mmbase.util.logging.Logger;
16 import org.mmbase.util.logging.Logging;
17
18 /**
19  * @javadoc
20  *
21  * @author Nico Klasens
22  * @since MMBase 1.8.1
23  * @version $Id: ApplicationContextReader.java,v 1.2 2006/07/06 14:34:22 pierre Exp $
24  */

25 public class ApplicationContextReader {
26
27     private static Logger log = Logging.getLoggerInstance(ApplicationContextReader.class);
28
29     /**
30      * @javadoc
31      */

32     public static Map getProperties(String JavaDoc path) throws NamingException {
33         if (path == null || "".equals(path)) {
34             throw new IllegalArgumentException JavaDoc("Path is empty");
35         }
36         Map properties = new HashMap();
37         Context env = getContext();
38         if (env != null) {
39             NamingEnumeration ne = env.list(path);
40             while (ne.hasMoreElements()) {
41                 NameClassPair element = (NameClassPair) ne.nextElement();
42                 String JavaDoc contextName = element.getName();
43                 String JavaDoc lookupName = env.composeName(contextName, path);
44                 Object JavaDoc value = env.lookup(lookupName);
45                 properties.put(contextName, value);
46             }
47         }
48         return properties;
49     }
50
51     /**
52      * @javadoc
53      */

54     public static Context getContext() throws NamingException {
55         InitialContext context = new InitialContext();
56         return (Context) context.lookup("java:comp/env");
57     }
58
59 }
60
Popular Tags