Coverage Report - org.apache.commons.clazz.bean.BasicBean
 
Classes in this File Line Coverage Branch Coverage Complexity
BasicBean
0%
0/15
0%
0/2
1.2
 
 1  
 /*
 2  
  * Copyright 2002-2004 The Apache Software Foundation
 3  
  *
 4  
  * Licensed under the Apache 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.apache.org/licenses/LICENSE-2.0
 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.apache.commons.clazz.bean;
 17  
 
 18  
 import java.util.HashMap;
 19  
 import java.util.Iterator;
 20  
 import java.util.Map;
 21  
 
 22  
 import org.apache.commons.clazz.Clazz;
 23  
 
 24  
 /**
 25  
  * A trivial implementation of the Bean interface based on a HashMap.
 26  
  *
 27  
  * @author Dmitri Plotnikov
 28  
  * @version $Revision: 155436 $ $Date: 2005-02-26 13:17:48 +0000 (Sat, 26 Feb 2005) $
 29  
  */
 30  
 public class BasicBean implements Bean {
 31  
 
 32  
     private Clazz clazz;
 33  0
     private Map properties = new HashMap();
 34  
     
 35  
     /**
 36  
      * Constructor for BasicBean.
 37  
      */
 38  0
     public BasicBean(Clazz clazz) {
 39  0
         this.clazz = clazz;
 40  0
     }
 41  
 
 42  
     /**
 43  
      * Constructor that initializes properties of the bean.
 44  
      */
 45  
     public BasicBean(Clazz clazz, Map initialPropertyValues) {
 46  0
         this(clazz);
 47  0
         for (Iterator iter = initialPropertyValues.entrySet().iterator();
 48  0
             iter.hasNext();
 49  
             ) {
 50  0
             Map.Entry element = (Map.Entry) iter.next();
 51  0
             set((String) element.getKey(), element.getValue());
 52  0
         }
 53  0
     }
 54  
 
 55  
 
 56  
     /**
 57  
      * @see org.apache.commons.clazz.bean.Bean#getClazz()
 58  
      */
 59  
     public Clazz getClazz() {
 60  0
         return clazz;
 61  
     }
 62  
 
 63  
     /**
 64  
      * @see org.apache.commons.clazz.bean.Bean#get(java.lang.String)
 65  
      */
 66  
     public Object get(String propertyName) {
 67  
         // @todo validate property name using the clazz
 68  
         // @todo possible provide a default value based on the clazz
 69  0
         return properties.get(propertyName);
 70  
     }
 71  
 
 72  
     /**
 73  
      * @see Bean#set(String, Object)
 74  
      */
 75  
     public void set(String propertyName, Object value) {
 76  
         // @todo validate property name and value type using the clazz
 77  0
         properties.put(propertyName, value);       
 78  0
     }
 79  
 }