Coverage Report - org.kuali.rice.kns.bo.BusinessObjectBase
 
Classes in this File Line Coverage Branch Coverage Complexity
BusinessObjectBase
0%
0/36
0%
0/14
2.6
 
 1  
 /*
 2  
  * Copyright 2005-2007 The Kuali Foundation
 3  
  * 
 4  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  * 
 8  
  * http://www.opensource.org/licenses/ecl2.php
 9  
  * 
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 package org.kuali.rice.kns.bo;
 17  
 
 18  
 import java.util.Iterator;
 19  
 import java.util.LinkedHashMap;
 20  
 import java.util.Map;
 21  
 
 22  
 import org.apache.commons.lang.StringUtils;
 23  
 import org.kuali.rice.kns.util.TypeUtils;
 24  
 
 25  
 /**
 26  
  * Transient Business Object Base Business Object
 27  
  */
 28  
 public abstract class BusinessObjectBase implements BusinessObject {
 29  
     //private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(BusinessObjectBase.class);
 30  
 
 31  
     /**
 32  
      * Default constructor. Required to do some of the voodoo involved in letting the DataDictionary validate attributeNames for a
 33  
      * given BusinessObject subclass.
 34  
      */
 35  0
     public BusinessObjectBase() {
 36  0
     }
 37  
 
 38  
     /**
 39  
      * @param fieldValues
 40  
      * @return consistently-formatted String containing the given fieldnames and their values
 41  
      */
 42  
     protected String toStringBuilder(LinkedHashMap fieldValues) {
 43  0
         String built = null;
 44  0
         String className = StringUtils.uncapitalize(StringUtils.substringAfterLast(this.getClass().getName(), "."));
 45  
 
 46  0
         if ((fieldValues == null) || fieldValues.isEmpty()) {
 47  0
             built = super.toString();
 48  
         }
 49  
         else {
 50  
 
 51  0
             StringBuffer prefix = new StringBuffer(className);
 52  0
             StringBuffer suffix = new StringBuffer("=");
 53  
 
 54  0
             prefix.append("(");
 55  0
             suffix.append("(");
 56  0
             for (Iterator i = fieldValues.entrySet().iterator(); i.hasNext();) {
 57  0
                 Map.Entry e = (Map.Entry) i.next();
 58  
 
 59  0
                 String fieldName = e.getKey().toString();
 60  0
                 Object fieldValue = e.getValue();
 61  
 
 62  0
                 String fieldValueString = String.valueOf(e.getValue()); // prevent NullPointerException;
 63  
 
 64  
 
 65  0
                 if ((fieldValue == null) || TypeUtils.isSimpleType(fieldValue.getClass())) {
 66  0
                     prefix.append(fieldName);
 67  0
                     suffix.append(fieldValueString);
 68  
                 }
 69  
                 else {
 70  0
                     prefix.append("{");
 71  0
                     prefix.append(fieldName);
 72  0
                     prefix.append("}");
 73  
 
 74  0
                     suffix.append("{");
 75  0
                     suffix.append(fieldValueString);
 76  0
                     suffix.append("}");
 77  
                 }
 78  
 
 79  0
                 if (i.hasNext()) {
 80  0
                     prefix.append(",");
 81  0
                     suffix.append(",");
 82  
                 }
 83  0
             }
 84  0
             prefix.append(")");
 85  0
             suffix.append(")");
 86  
 
 87  0
             built = prefix.toString() + suffix.toString();
 88  
         }
 89  
 
 90  0
         return built;
 91  
     }
 92  
 
 93  
     /**
 94  
      * @return Map containing the fieldValues of the key fields for this class, indexed by fieldName
 95  
      */
 96  
     abstract protected LinkedHashMap toStringMapper();
 97  
 
 98  
 
 99  
     /**
 100  
      * @see java.lang.Object#toString()
 101  
      */
 102  
     public String toString() {
 103  0
         if (!StringUtils.contains(this.getClass().getName(), "$$")) {
 104  0
             return toStringBuilder(toStringMapper());
 105  
         }
 106  
         else {
 107  0
             return "Proxy: " + this.getClass().getName();
 108  
         }
 109  
     }
 110  
     
 111  
     public void prepareForWorkflow() {
 112  
         // do nothing
 113  0
     }
 114  
 }