1 16 package org.springframework.binding.mapping; 17 18 import java.io.Serializable ; 19 import java.util.Arrays ; 20 import java.util.Iterator ; 21 import java.util.LinkedList ; 22 import java.util.List ; 23 24 import org.springframework.core.style.ToStringCreator; 25 26 34 public class DefaultAttributeMapper implements AttributeMapper, Serializable { 35 36 39 private List mappings = new LinkedList (); 40 41 46 public DefaultAttributeMapper addMapping(AttributeMapper mapping) { 47 mappings.add(mapping); 48 return this; 49 } 50 51 55 public void addMappings(AttributeMapper[] mappings) { 56 if (mappings == null) { 57 return; 58 } 59 this.mappings.addAll(Arrays.asList(mappings)); 60 } 61 62 66 public AttributeMapper[] getMappings() { 67 return (AttributeMapper[])mappings.toArray(new AttributeMapper[mappings.size()]); 68 } 69 70 public void map(Object source, Object target, MappingContext context) { 71 if (mappings != null) { 72 Iterator it = mappings.iterator(); 73 while (it.hasNext()) { 74 AttributeMapper mapping = (AttributeMapper)it.next(); 75 mapping.map(source, target, context); 76 } 77 } 78 } 79 80 public String toString() { 81 return new ToStringCreator(this).append("mappings", mappings).toString(); 82 } 83 } | Popular Tags |