Clover Coverage Report - Kuali Student 1.2-M4-SNAPSHOT (Aggregated)
Coverage timestamp: Wed Jul 20 2011 11:14:35 EDT
../../../../../img/srcFileCovDistChart7.png 32% of files have more coverage
16   91   11   2.67
4   53   0.69   6
6     1.83  
1    
 
  BeanConstraintDataProvider       Line # 27 16 0% 11 8 69.2% 0.6923077
 
  (74)
 
1    /**
2    * Copyright 2010 The Kuali Foundation Licensed under the
3    * Educational Community License, Version 2.0 (the "License"); you may
4    * not use this file except in compliance with the License. You may
5    * obtain a copy of the License at
6    *
7    * http://www.osedu.org/licenses/ECL-2.0
8    *
9    * Unless required by applicable law or agreed to in writing,
10    * software distributed under the License is distributed on an "AS IS"
11    * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12    * or implied. See the License for the specific language governing
13    * permissions and limitations under the License.
14    */
15   
16    package org.kuali.student.common.validator;
17   
18    import java.beans.BeanInfo;
19    import java.beans.IntrospectionException;
20    import java.beans.Introspector;
21    import java.beans.PropertyDescriptor;
22    import java.util.HashMap;
23    import java.util.Map;
24   
25    import org.apache.log4j.Logger;
26   
 
27    public class BeanConstraintDataProvider implements ConstraintDataProvider {
28    final static Logger LOG = Logger.getLogger(BeanConstraintDataProvider.class);
29   
30    private static final String DYNAMIC_ATTRIBUTE = "attributes";
31   
32    Map<String, Object> dataMap = null;
33   
34    /*
35    * The only place where the dataprovider should get initialized is
36    * BeanConstraintSetupFactory
37    */
 
38  1590 toggle public BeanConstraintDataProvider() {
39   
40    }
41   
42    //TODO fix it later.
 
43  1576 toggle public String getPath(){
44  1576 return "";
45    }
46   
 
47  1590 toggle @SuppressWarnings("unchecked")
48    @Override
49    public void initialize(Object o) {
50   
51  1590 dataMap = new HashMap<String, Object>();
52   
53  1590 try {
54  1590 BeanInfo beanInfo = Introspector.getBeanInfo(o.getClass());
55   
56  1590 for (PropertyDescriptor pd : beanInfo.getPropertyDescriptors()) {
57  12084 Object value = null;
58  12084 try {
59  12084 value = pd.getReadMethod().invoke(o);
60    } catch (Exception e) {
61  0 LOG.warn("Method invokation failed",e);
62    }
63   
64    // Extract dynamic attributes
65  12084 if(DYNAMIC_ATTRIBUTE.equals(pd.getName())) {
66  721 dataMap.putAll((Map<String, String>)value);
67    } else {
68  11363 dataMap.put(pd.getName(), value);
69    }
70    }
71    } catch (IntrospectionException e) {
72  0 throw new RuntimeException(e);
73    }
74    }
75   
 
76  0 toggle @Override
77    public String getObjectId() {
78  0 return (dataMap.containsKey("id") && null != dataMap.get("id")) ? dataMap.get("id").toString() : null;
79    }
80   
 
81  9089 toggle @Override
82    public Object getValue(String fieldKey) {
83  9089 return dataMap.get(fieldKey);
84    }
85   
 
86  0 toggle @Override
87    public Boolean hasField(String fieldKey) {
88  0 return dataMap.containsKey(fieldKey);
89    }
90   
91    }