1 29 30 package nextapp.echo2.app.componentxml.propertypeer; 31 32 import java.util.Collections ; 33 import java.util.HashMap ; 34 import java.util.Map ; 35 36 import org.w3c.dom.Element ; 37 38 import nextapp.echo2.app.Alignment; 39 import nextapp.echo2.app.componentxml.InvalidPropertyException; 40 import nextapp.echo2.app.componentxml.PropertyXmlPeer; 41 import nextapp.echo2.app.util.DomUtil; 42 43 47 public class AlignmentPeer 48 implements PropertyXmlPeer { 49 50 private static final Map HORIZONTAL_CONSTANTS; 51 static { 52 Map constantMap = new HashMap (); 53 constantMap.put("leading", new Integer (Alignment.LEADING)); 54 constantMap.put("trailing", new Integer (Alignment.TRAILING)); 55 constantMap.put("left", new Integer (Alignment.LEFT)); 56 constantMap.put("center", new Integer (Alignment.CENTER)); 57 constantMap.put("right", new Integer (Alignment.RIGHT)); 58 HORIZONTAL_CONSTANTS = Collections.unmodifiableMap(constantMap); 59 } 60 61 private static final Map VERTICAL_CONSTANTS; 62 static { 63 Map constantMap = new HashMap (); 64 constantMap.put("top", new Integer (Alignment.TOP)); 65 constantMap.put("center", new Integer (Alignment.CENTER)); 66 constantMap.put("bottom", new Integer (Alignment.BOTTOM)); 67 VERTICAL_CONSTANTS = Collections.unmodifiableMap(constantMap); 68 } 69 70 74 public Object getValue(ClassLoader classLoader, Class objectClass, Element propertyElement) 75 throws InvalidPropertyException { 76 Element alignmentElement = DomUtil.getChildElementByTagName(propertyElement, "alignment"); 77 int horizontal = Alignment.DEFAULT; 78 int vertical = Alignment.DEFAULT; 79 if (alignmentElement.hasAttribute("horizontal")) { 80 Integer horizontalValue = (Integer ) HORIZONTAL_CONSTANTS.get(alignmentElement.getAttribute("horizontal")); 81 if (horizontalValue != null) { 82 horizontal = horizontalValue.intValue(); 83 } 84 } 85 if (alignmentElement.hasAttribute("vertical")) { 86 Integer verticalValue = (Integer ) VERTICAL_CONSTANTS.get(alignmentElement.getAttribute("vertical")); 87 if (verticalValue != null) { 88 vertical = verticalValue.intValue(); 89 } 90 } 91 return new Alignment(horizontal, vertical); 92 } 93 } 94 | Popular Tags |