KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > nextapp > echo2 > app > componentxml > propertypeer > BorderPeer


1 /*
2  * This file is part of the Echo Web Application Framework (hereinafter "Echo").
3  * Copyright (C) 2002-2005 NextApp, Inc.
4  *
5  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6  *
7  * The contents of this file are subject to the Mozilla Public License Version
8  * 1.1 (the "License"); you may not use this file except in compliance with
9  * 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 JavaDoc;
33 import java.util.HashMap JavaDoc;
34 import java.util.Map JavaDoc;
35
36 import org.w3c.dom.Element JavaDoc;
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
50 implements PropertyXmlPeer {
51     
52     private static final Map JavaDoc STYLE_TEXT_TO_CONSTANT;
53     static {
54         Map JavaDoc constantMap = new HashMap JavaDoc();
55         constantMap.put("dashed", new Integer JavaDoc(Border.STYLE_DASHED));
56         constantMap.put("dotted", new Integer JavaDoc(Border.STYLE_DOTTED));
57         constantMap.put("double", new Integer JavaDoc(Border.STYLE_DOUBLE));
58         constantMap.put("groove", new Integer JavaDoc(Border.STYLE_GROOVE));
59         constantMap.put("inset", new Integer JavaDoc(Border.STYLE_INSET));
60         constantMap.put("none", new Integer JavaDoc(Border.STYLE_NONE));
61         constantMap.put("outset", new Integer JavaDoc(Border.STYLE_OUTSET));
62         constantMap.put("ridge", new Integer JavaDoc(Border.STYLE_RIDGE));
63         constantMap.put("solid", new Integer JavaDoc(Border.STYLE_SOLID));
64         STYLE_TEXT_TO_CONSTANT = Collections.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 JavaDoc getValue(ClassLoader JavaDoc classLoader, Class JavaDoc objectClass, Element JavaDoc propertyElement)
72     throws InvalidPropertyException {
73         Element JavaDoc 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 JavaDoc 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 JavaDoc("Invalid border style: " + styleString);
84         } else {
85             style = ((Integer JavaDoc) STYLE_TEXT_TO_CONSTANT.get(styleString)).intValue();
86         }
87         
88         return new Border(size, color, style);
89     }
90 }
91
Popular Tags