KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > inversoft > verge > mvc > controller > form > config > MappingConfigBuilder


1 /*
2  * Copyright (c) 2003, Inversoft
3  *
4  * This software is distribuable under the GNU Lesser General Public License.
5  * For more information visit gnu.org.
6  */

7 package com.inversoft.verge.mvc.controller.form.config;
8
9
10 import org.jdom.Element;
11
12 import com.inversoft.config.ConfigurationException;
13 import com.inversoft.error.ErrorList;
14 import com.inversoft.util.StringTools;
15 import com.inversoft.verge.mvc.config.BaseConfig;
16 import com.inversoft.verge.mvc.config.BaseConfigBuilder;
17
18
19 /**
20  * This class is responsible for building the mapping config
21  * objects from the xml config files.
22  *
23  * @author Brian Pontarelli
24  */

25 public class MappingConfigBuilder extends BaseConfigBuilder {
26
27
28     /**
29      * Constructs a new <code>MappingConfigBuilder</code>
30      */

31     public MappingConfigBuilder() {
32     }
33
34
35     /**
36      * Builds the Mapping config object from the XML element and returns it.
37      *
38      * @param element The element to build the Mapping configs from
39      * @return The MappingConfig obejct and never null
40      */

41     public BaseConfig build(Element element) throws ConfigurationException {
42
43         ErrorList errors = new ErrorList();
44         String JavaDoc name = element.getAttributeValue(Constants.NAME_ATTRIBUTE);
45         String JavaDoc url = element.getAttributeValue(Constants.URL_ATTRIBUTE);
46         String JavaDoc forward = element.getAttributeValue(Constants.FORWARD_ATTRIBUTE);
47         String JavaDoc category = element.getAttributeValue(Constants.CATEGORY_ATTRIBUTE);
48
49         if (name == null) {
50             errors.addError("Mappings must have a name");
51         }
52
53         if (url == null) {
54             errors.addError("Mapping named: " + name + " must have a url");
55         }
56
57         // Defaults to true, if it is null, it will be the default value. If it
58
// is not null and invalid, an error is generated, otherwise it is parsed
59
boolean forwardBool = true;
60         if (forward != null && !StringTools.isValidBoolean(forward)) {
61             errors.addError("Mapping named: " + name +
62                 " has an invalid value for the forward attribute");
63         } else if (forward != null) {
64             forwardBool = Boolean.valueOf(forward).booleanValue();
65         }
66
67         if (!errors.isEmpty()) {
68             throw new ConfigurationException(errors);
69         }
70         
71         // Ignore the category if the URL is local
72
if (forwardBool) {
73             category = null;
74         }
75
76         return new MappingConfig(name, url, forwardBool, category);
77     }
78 }
79
80
Popular Tags