001    package com.khubla.pragmatach.framework.configuration;
002    
003    import javax.naming.InitialContext;
004    
005    import com.khubla.pragmatach.framework.api.Configuration;
006    import com.khubla.pragmatach.framework.api.PragmatachException;
007    
008    /**
009     * @author tome
010     */
011    public abstract class BaseConfiguration implements Configuration {
012       /**
013        * jndi strings start with this
014        */
015       private final static String JAVA = "java:";
016    
017       /**
018        * resolve an object
019        */
020       public static Object resolveObject(String value) throws PragmatachException {
021          try {
022             if (null != value) {
023                if (value.startsWith(JAVA)) {
024                   final InitialContext initialContext = new InitialContext();
025                   return initialContext.lookup(value);
026                } else {
027                   return value;
028                }
029             } else {
030                return null;
031             }
032          } catch (final Exception e) {
033             throw new PragmatachException("Exception in resolveObject: '" + value + "'", e);
034          }
035       }
036    
037       /**
038        * resolve a string
039        */
040       public static String resolveString(String value) throws PragmatachException {
041          try {
042             if (null != value) {
043                if (value.startsWith(JAVA)) {
044                   final InitialContext initialContext = new InitialContext();
045                   return (String) initialContext.lookup(value);
046                } else {
047                   return value;
048                }
049             } else {
050                return null;
051             }
052          } catch (final Exception e) {
053             throw new PragmatachException("Exception in resolveString: '" + value + "'", e);
054          }
055       }
056    }