Coverage Report - org.kuali.rice.kew.engine.node.PropertiesUtil
 
Classes in this File Line Coverage Branch Coverage Complexity
PropertiesUtil
0%
0/26
0%
0/12
2.333
 
 1  
 /*
 2  
  * Copyright 2005-2008 The Kuali Foundation
 3  
  * 
 4  
  * 
 5  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 6  
  * you may not use this file except in compliance with the License.
 7  
  * You may obtain a copy of the License at
 8  
  * 
 9  
  * http://www.opensource.org/licenses/ecl2.php
 10  
  * 
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 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  
  * A utility class for reading properties from a document.
 32  
  *
 33  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 34  
  */
 35  
 public class PropertiesUtil {
 36  0
     private static final Logger LOG = Logger.getLogger(PropertiesUtil.class);
 37  
 
 38  0
     private PropertiesUtil() {}
 39  
 
 40  
     public static String readResource(InputStream stream) throws IOException {
 41  0
         StringBuffer sb = new StringBuffer(2048);
 42  0
         InputStreamReader reader = new InputStreamReader(stream);
 43  0
         char[] buf = new char[1024];
 44  
         int read;
 45  
         try {
 46  0
             while ((read = reader.read(buf)) != -1) {
 47  0
                 sb.append(buf, 0, read);
 48  
             }
 49  0
         } finally {
 50  0
             reader.close();
 51  0
         }
 52  0
         return sb.toString();
 53  
     }
 54  
 
 55  
     /**
 56  
      * Resolves the specified name as a qualified property
 57  
      * @param name the qualified property name
 58  
      * @return value if found, null otherwise
 59  
      */
 60  
     public static Object retrieveProperty(String name, RouteContext context) {
 61  0
         return retrieveProperty(new Property(name), context);
 62  
     }
 63  
 
 64  
     /**
 65  
      * Resolves the specified name as an unqualified property
 66  
      * @param name the potentially unqualified property name
 67  
      * @param defaultScheme the default scheme to use if the property is unqualified
 68  
      * @return value if found, null otherwise
 69  
      */
 70  
     public static Object retrieveProperty(String name, PropertyScheme defaultScheme, RouteContext context) {
 71  0
         return retrieveProperty(new Property(name), defaultScheme, context);
 72  
     }
 73  
 
 74  
     /**
 75  
      * Resolves the specified name as an unqualified property
 76  
      * @param prop the potentially unqualified property
 77  
      * @param defaultScheme the default scheme to use if the property is unqualified
 78  
      * @return value if found, null otherwise
 79  
      */
 80  
     public static Object retrieveProperty(Property prop, PropertyScheme defaultScheme, RouteContext context) {
 81  0
         if (prop.scheme == null && defaultScheme != null) {
 82  0
             prop.scheme = defaultScheme.getName();
 83  
         }
 84  0
         return retrieveProperty(prop, context);
 85  
     }
 86  
 
 87  
     /**
 88  
      * Resolves the specified name as a qualified property
 89  
      * @param prop the qualified property
 90  
      * @return value if found, null otherwise
 91  
      */
 92  
     public static Object retrieveProperty(Property prop, RouteContext context) {
 93  0
         Iterator schemes = PropertyScheme.SCHEMES.iterator();
 94  0
         while (schemes.hasNext()) {
 95  0
             PropertyScheme scheme = (PropertyScheme) schemes.next();
 96  0
             if (scheme.getName().equals(prop.scheme) ||
 97  
                 scheme.getShortName().equals(prop.scheme)) {
 98  0
                 LOG.debug("Loading prop " + prop + " with scheme " + scheme);
 99  0
                 return scheme.load(prop, context);
 100  
             }
 101  0
         }
 102  0
         String message = "Invalid property scheme: '" + prop.scheme + "'"; 
 103  0
         LOG.error(message);
 104  0
         throw new RuntimeException(message);
 105  
     }
 106  
 }