01: /*
02: * This file is part of the Echo Web Application Framework (hereinafter "Echo").
03: * Copyright (C) 2002-2005 NextApp, Inc.
04: *
05: * Version: MPL 1.1/GPL 2.0/LGPL 2.1
06: *
07: * The contents of this file are subject to the Mozilla Public License Version
08: * 1.1 (the "License"); you may not use this file except in compliance with
09: * the License. You may obtain a copy of the License at
10: * http://www.mozilla.org/MPL/
11: *
12: * Software distributed under the License is distributed on an "AS IS" basis,
13: * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
14: * for the specific language governing rights and limitations under the
15: * License.
16: *
17: * Alternatively, the contents of this file may be used under the terms of
18: * either the GNU General Public License Version 2 or later (the "GPL"), or
19: * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
20: * in which case the provisions of the GPL or the LGPL are applicable instead
21: * of those above. If you wish to allow use of your version of this file only
22: * under the terms of either the GPL or the LGPL, and not to allow others to
23: * use your version of this file under the terms of the MPL, indicate your
24: * decision by deleting the provisions above and replace them with the notice
25: * and other provisions required by the GPL or the LGPL. If you do not delete
26: * the provisions above, a recipient may use your version of this file under
27: * the terms of any one of the MPL, the GPL or the LGPL.
28: */
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: /**
46: * <code>PropertyXmlPeer</code> implementation for
47: * <code>nextapp.echo2.app.Border</code> properties.
48: */
49: public class BorderPeer implements PropertyXmlPeer {
50:
51: private static final Map STYLE_TEXT_TO_CONSTANT;
52: static {
53: Map constantMap = new HashMap();
54: constantMap.put("dashed", new Integer(Border.STYLE_DASHED));
55: constantMap.put("dotted", new Integer(Border.STYLE_DOTTED));
56: constantMap.put("double", new Integer(Border.STYLE_DOUBLE));
57: constantMap.put("groove", new Integer(Border.STYLE_GROOVE));
58: constantMap.put("inset", new Integer(Border.STYLE_INSET));
59: constantMap.put("none", new Integer(Border.STYLE_NONE));
60: constantMap.put("outset", new Integer(Border.STYLE_OUTSET));
61: constantMap.put("ridge", new Integer(Border.STYLE_RIDGE));
62: constantMap.put("solid", new Integer(Border.STYLE_SOLID));
63: STYLE_TEXT_TO_CONSTANT = Collections
64: .unmodifiableMap(constantMap);
65: }
66:
67: /**
68: * @see nextapp.echo2.app.componentxml.PropertyXmlPeer#getValue(java.lang.ClassLoader,
69: * java.lang.Class, org.w3c.dom.Element)
70: */
71: public Object getValue(ClassLoader classLoader, Class objectClass,
72: Element propertyElement) throws InvalidPropertyException {
73: Element borderElement = DomUtil.getChildElementByTagName(
74: propertyElement, "border");
75:
76: Color color = borderElement.hasAttribute("color") ? ColorPeer
77: .toColor(borderElement.getAttribute("color")) : null;
78: Extent size = borderElement.hasAttribute("size") ? ExtentPeer
79: .toExtent(borderElement.getAttribute("size")) : null;
80:
81: String styleString = borderElement.getAttribute("style");
82: int style;
83: if (styleString == null) {
84: style = Border.STYLE_NONE;
85: } else if (!STYLE_TEXT_TO_CONSTANT.containsKey(styleString)) {
86: throw new IllegalArgumentException("Invalid border style: "
87: + styleString);
88: } else {
89: style = ((Integer) STYLE_TEXT_TO_CONSTANT.get(styleString))
90: .intValue();
91: }
92:
93: return new Border(size, color, style);
94: }
95: }
|