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.Border; 39 import nextapp.echo2.app.Color; 40 import nextapp.echo2.app.Extent; 41 import nextapp.echo2.app.componentxml.InvalidPropertyException; 42 import nextapp.echo2.app.componentxml.PropertyXmlPeer; 43 import nextapp.echo2.app.util.DomUtil; 44 45 49 public class BorderPeer 50 implements PropertyXmlPeer { 51 52 private static final Map STYLE_TEXT_TO_CONSTANT; 53 static { 54 Map constantMap = new HashMap (); 55 constantMap.put("dashed", new Integer (Border.STYLE_DASHED)); 56 constantMap.put("dotted", new Integer (Border.STYLE_DOTTED)); 57 constantMap.put("double", new Integer (Border.STYLE_DOUBLE)); 58 constantMap.put("groove", new Integer (Border.STYLE_GROOVE)); 59 constantMap.put("inset", new Integer (Border.STYLE_INSET)); 60 constantMap.put("none", new Integer (Border.STYLE_NONE)); 61 constantMap.put("outset", new Integer (Border.STYLE_OUTSET)); 62 constantMap.put("ridge", new Integer (Border.STYLE_RIDGE)); 63 constantMap.put("solid", new Integer (Border.STYLE_SOLID)); 64 STYLE_TEXT_TO_CONSTANT = Collections.unmodifiableMap(constantMap); 65 } 66 67 71 public Object getValue(ClassLoader classLoader, Class objectClass, Element propertyElement) 72 throws InvalidPropertyException { 73 Element borderElement = DomUtil.getChildElementByTagName(propertyElement, "border"); 74 75 Color color = borderElement.hasAttribute("color") ? ColorPeer.toColor(borderElement.getAttribute("color")) : null; 76 Extent size = borderElement.hasAttribute("size") ? ExtentPeer.toExtent(borderElement.getAttribute("size")) : null; 77 78 String styleString = borderElement.getAttribute("style"); 79 int style; 80 if (styleString == null) { 81 style = Border.STYLE_NONE; 82 } else if (!STYLE_TEXT_TO_CONSTANT.containsKey(styleString)) { 83 throw new IllegalArgumentException ("Invalid border style: " + styleString); 84 } else { 85 style = ((Integer ) STYLE_TEXT_TO_CONSTANT.get(styleString)).intValue(); 86 } 87 88 return new Border(size, color, style); 89 } 90 } 91 | Popular Tags |