|  1 |     | 
     | 
  |  2 |     | 
     | 
  |  3 |     | 
     | 
  |  4 |     | 
     | 
  |  5 |     | 
     | 
  |  6 |     | 
     | 
  |  7 |     | 
     | 
  |  8 |     | 
     | 
  |  9 |     | 
     | 
  |  10 |     | 
     | 
  |  11 |     | 
     | 
  |  12 |     | 
     | 
  |  13 |     | 
     | 
  |  14 |     | 
     | 
  |  15 |     | 
     | 
  |  16 |     | 
     | 
  |  17 |     | 
   package org.kuali.rice.kew.engine.node;  | 
  |  18 |     | 
     | 
  |  19 |     | 
   import java.io.IOException;  | 
  |  20 |     | 
   import java.io.InputStream;  | 
  |  21 |     | 
   import java.io.InputStreamReader;  | 
  |  22 |     | 
   import java.util.Iterator;  | 
  |  23 |     | 
     | 
  |  24 |     | 
   import org.apache.log4j.Logger;  | 
  |  25 |     | 
   import org.kuali.rice.kew.engine.RouteContext;  | 
  |  26 |     | 
   import org.kuali.rice.kew.engine.node.var.Property;  | 
  |  27 |     | 
   import org.kuali.rice.kew.engine.node.var.PropertyScheme;  | 
  |  28 |     | 
     | 
  |  29 |     | 
     | 
  |  30 |     | 
     | 
  |  31 |     | 
     | 
  |  32 |     | 
     | 
  |  33 |     | 
     | 
  |  34 |     | 
     | 
  |  35 |     | 
   public final class PropertiesUtil { | 
  |  36 |    0 |        private static final Logger LOG = Logger.getLogger(PropertiesUtil.class);  | 
  |  37 |     | 
     | 
  |  38 |    0 |            private PropertiesUtil() { | 
  |  39 |    0 |                    throw new UnsupportedOperationException("do not call"); | 
  |  40 |     | 
           }  | 
  |  41 |     | 
     | 
  |  42 |     | 
       public static String readResource(InputStream stream) throws IOException { | 
  |  43 |    0 |            StringBuffer sb = new StringBuffer(2048);  | 
  |  44 |    0 |            InputStreamReader reader = new InputStreamReader(stream);  | 
  |  45 |    0 |            char[] buf = new char[1024];  | 
  |  46 |     | 
           int read;  | 
  |  47 |     | 
           try { | 
  |  48 |    0 |                while ((read = reader.read(buf)) != -1) { | 
  |  49 |    0 |                    sb.append(buf, 0, read);  | 
  |  50 |     | 
               }  | 
  |  51 |     | 
           } finally { | 
  |  52 |    0 |                reader.close();  | 
  |  53 |    0 |            }  | 
  |  54 |    0 |            return sb.toString();  | 
  |  55 |     | 
       }  | 
  |  56 |     | 
     | 
  |  57 |     | 
         | 
  |  58 |     | 
     | 
  |  59 |     | 
     | 
  |  60 |     | 
     | 
  |  61 |     | 
     | 
  |  62 |     | 
       public static Object retrieveProperty(String name, RouteContext context) { | 
  |  63 |    0 |            return retrieveProperty(new Property(name), context);  | 
  |  64 |     | 
       }  | 
  |  65 |     | 
     | 
  |  66 |     | 
         | 
  |  67 |     | 
     | 
  |  68 |     | 
     | 
  |  69 |     | 
     | 
  |  70 |     | 
     | 
  |  71 |     | 
     | 
  |  72 |     | 
       public static Object retrieveProperty(String name, PropertyScheme defaultScheme, RouteContext context) { | 
  |  73 |    0 |            return retrieveProperty(new Property(name), defaultScheme, context);  | 
  |  74 |     | 
       }  | 
  |  75 |     | 
     | 
  |  76 |     | 
         | 
  |  77 |     | 
     | 
  |  78 |     | 
     | 
  |  79 |     | 
     | 
  |  80 |     | 
     | 
  |  81 |     | 
     | 
  |  82 |     | 
       public static Object retrieveProperty(Property prop, PropertyScheme defaultScheme, RouteContext context) { | 
  |  83 |    0 |            if (prop.scheme == null && defaultScheme != null) { | 
  |  84 |    0 |                prop.scheme = defaultScheme.getName();  | 
  |  85 |     | 
           }  | 
  |  86 |    0 |            return retrieveProperty(prop, context);  | 
  |  87 |     | 
       }  | 
  |  88 |     | 
     | 
  |  89 |     | 
         | 
  |  90 |     | 
     | 
  |  91 |     | 
     | 
  |  92 |     | 
     | 
  |  93 |     | 
     | 
  |  94 |     | 
       public static Object retrieveProperty(Property prop, RouteContext context) { | 
  |  95 |    0 |            Iterator schemes = PropertyScheme.SCHEMES.iterator();  | 
  |  96 |    0 |            while (schemes.hasNext()) { | 
  |  97 |    0 |                PropertyScheme scheme = (PropertyScheme) schemes.next();  | 
  |  98 |    0 |                if (scheme.getName().equals(prop.scheme) ||  | 
  |  99 |     | 
                   scheme.getShortName().equals(prop.scheme)) { | 
  |  100 |    0 |                    LOG.debug("Loading prop " + prop + " with scheme " + scheme); | 
  |  101 |    0 |                    return scheme.load(prop, context);  | 
  |  102 |     | 
               }  | 
  |  103 |    0 |            }  | 
  |  104 |    0 |            String message = "Invalid property scheme: '" + prop.scheme + "'";   | 
  |  105 |    0 |            LOG.error(message);  | 
  |  106 |    0 |            throw new RuntimeException(message);  | 
  |  107 |     | 
       }  | 
  |  108 |     | 
   }  |