KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > boot > XMLPropertyDefinition


1 /*
2  * SSL-Explorer
3  *
4  * Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */

19             
20 package com.sslexplorer.boot;
21
22 import org.jdom.Element;
23 import org.jdom.JDOMException;
24
25
26 /**
27  * Extensions of {@link com.sslexplorer.boot.DefaultPropertyDefinition}
28  * that allows property defnitions to be created from XML
29  * {@link Element} objects.
30  *
31  * @author Brett Smith <a HREF="mailto: brett@3sp.com">&lt;brett@3sp.com&gt;</a>
32  */

33 public class XMLPropertyDefinition extends DefaultPropertyDefinition {
34
35     /**
36      * Constructor.
37      *
38      */

39     public XMLPropertyDefinition() {
40         super();
41     }
42
43     /**
44      * Constructor.
45      *
46      * @param type
47      * @param name
48      * @param typeMeta
49      * @param category
50      * @param defaultValue
51      * @param sortOrder
52      * @param hidden
53      * @param validationString
54      */

55     public XMLPropertyDefinition(int type, String JavaDoc name, String JavaDoc typeMeta, int category, String JavaDoc defaultValue, int sortOrder, boolean hidden, String JavaDoc validationString) {
56         super(type, name, typeMeta, category, defaultValue, sortOrder, hidden, validationString);
57     }
58
59     /**
60      * Constructor.
61      *
62      * @param type
63      * @param name
64      * @param typeMeta
65      * @param category
66      * @param defaultValue
67      * @param sortOrder
68      * @param hidden
69      */

70     public XMLPropertyDefinition(int type, String JavaDoc name, String JavaDoc typeMeta, int category, String JavaDoc defaultValue, int sortOrder, boolean hidden) {
71         super(type, name, typeMeta, category, defaultValue, sortOrder, hidden);
72     }
73
74     /**
75      * Constructor.
76      *
77      * @param type
78      * @param name
79      * @param typeMeta
80      * @param category
81      * @param defaultValue
82      * @param sortOrder
83      * @param messageResourcesKey
84      * @param hidden
85      * @param validationString
86      */

87     public XMLPropertyDefinition(int type, String JavaDoc name, String JavaDoc typeMeta, int category, String JavaDoc defaultValue, int sortOrder, String JavaDoc messageResourcesKey, boolean hidden, String JavaDoc validationString) {
88         super(type, name, typeMeta, category, defaultValue, sortOrder, messageResourcesKey, hidden, validationString);
89     }
90
91     /**
92      * Constructor.
93      *
94      * @param type
95      * @param name
96      * @param typeMeta
97      * @param category
98      * @param defaultValue
99      * @param sortOrder
100      * @param messageResourcesKey
101      * @param hidden
102      */

103     public XMLPropertyDefinition(int type, String JavaDoc name, String JavaDoc typeMeta, int category, String JavaDoc defaultValue, int sortOrder, String JavaDoc messageResourcesKey, boolean hidden) {
104         super(type, name, typeMeta, category, defaultValue, sortOrder, messageResourcesKey, hidden);
105     }
106
107     /**
108      * Constructor
109      *
110      * @param element XML element to construct parameter from
111      * @throws JDOMException on invalid XML
112      */

113     public XMLPropertyDefinition(Element element) throws JDOMException {
114         super();
115         
116         // 'name' - Property name. Required
117
name = element.getAttributeValue("name");
118         if (name == null || name.equals("")) {
119             throw new JDOMException("Missing or empty name attribute in <parameter>");
120         }
121         
122         // 'type' - Property type. Required
123
try {
124             type = Integer.parseInt(element.getAttributeValue("type"));
125         } catch (Exception JavaDoc e) {
126             throw new JDOMException("Missing or invalid type attribute in <parameter>");
127         }
128
129         // 'sortOrder' - Property sort order. Optional
130
try {
131             sortOrder = Integer.parseInt(element.getAttributeValue("sortOrder"));
132         } catch (Exception JavaDoc e) {
133             sortOrder = 0;
134         }
135
136         // 'typeMeta' - Property type meta info. Optional.
137
typeMeta = Util.trimmedOrBlank(element.getAttributeValue("typeMeta"));
138         
139         // 'validation' - Property validation string
140
validationString = element.getAttributeValue("validation");
141         
142         // 'hidden' - Hidden property
143
hidden = "true".equalsIgnoreCase(element.getAttributeValue("hidden"));
144         
145         // 'category' - Property category
146
try {
147             String JavaDoc c = element.getAttributeValue("category");
148             if (c != null) {
149                 category = Integer.parseInt(c);
150             }
151         } catch (Exception JavaDoc e) {
152             throw new JDOMException("Invalid category attribute in <parameter>");
153         }
154
155         // restart required
156
restartRequired = "true".equalsIgnoreCase(element.getAttributeValue("restartRequired"));
157         
158         // 'bundle' - Property bundle
159
messageResourcesKey = element.getAttributeValue("messageResourcesKey");
160         messageResourcesKey = messageResourcesKey == null ? "properties" : messageResourcesKey;
161         
162         // 'defaultValue' - Default value
163
defaultValue = element.getAttributeValue("defaultValue");
164         defaultValue = defaultValue == null ? UNDEFINED_PARAMETER : defaultValue;
165         defaultValue = defaultValue.replaceAll("\\\\n", "\n");
166         
167         // Additional type
168
}
169
170 }
Popular Tags