1 30 31 34 package com.nightlabs.inheritance; 35 36 import java.lang.reflect.Field ; 37 import java.util.Collection ; 38 import java.util.Iterator ; 39 40 43 public class SimpleFieldInheriter implements FieldInheriter 44 { 45 46 49 public void copyFieldValue( 50 Inheritable mother, Inheritable child, 51 Class motherClass, Class childClass, 52 Field field, 53 FieldMetaData motherFieldMetaData, 54 FieldMetaData childFieldMetaData) 55 { 56 try { 57 field.setAccessible(true); 58 if (Collection .class.isAssignableFrom(field.getType())) { 59 Collection motherCol = (Collection )field.get(mother); 60 Collection childCol = (Collection )field.get(child); 61 childCol.clear(); 62 for (Iterator iter = motherCol.iterator(); iter.hasNext();) { 63 childCol.add(iter.next()); 64 } 65 } 66 else 67 field.set(child, field.get(mother)); 68 } catch (IllegalArgumentException e) { 69 throw e; 70 } catch (IllegalAccessException e) { 71 throw new RuntimeException (e); 72 } 73 } 74 75 } 76 | Popular Tags |