1 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 25 public class ApplicationContextReader { 26 27 private static Logger log = Logging.getLoggerInstance(ApplicationContextReader.class); 28 29 32 public static Map getProperties(String path) throws NamingException { 33 if (path == null || "".equals(path)) { 34 throw new IllegalArgumentException ("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 contextName = element.getName(); 43 String lookupName = env.composeName(contextName, path); 44 Object value = env.lookup(lookupName); 45 properties.put(contextName, value); 46 } 47 } 48 return properties; 49 } 50 51 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 |