KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > inversoft > verge > mvc > controller > actionflow > config > ActionHandlerNodeBuilder


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.actionflow.config;
8
9
10 import org.apache.log4j.Logger;
11 import org.jdom.Element;
12
13 import com.inversoft.config.ConfigurationException;
14 import com.inversoft.error.ErrorList;
15 import com.inversoft.util.StringTools;
16
17
18 /**
19  * This class is the config factory that builds
20  * ActionHandlerConfig objects
21  *
22  * @author Brian Pontarelli
23  * @since 1.0
24  * @version 2.0
25  */

26 public class ActionHandlerNodeBuilder extends BaseNodeBuilder {
27
28     /**
29      * This classes logger
30      */

31     private static final Logger logger = Logger.getLogger(ActionHandlerNodeBuilder.class);
32
33
34     /**
35      * Constructs a new <code>ActionHandlerNodeBuilder</code>.
36      */

37     public ActionHandlerNodeBuilder() {
38     }
39
40
41     /**
42      * <p>
43      * Constructs a BaseNode object from the given Element. This method uses
44      * the name, className, repositoryId, isEntryPoint, isDefaultEntry,
45      * and isExitPoint attributes from the XML Element to populate the BaseNode
46      * object. It also uses the inner actionLink Elements to add {@link
47      * ActionLink ActionLink} objects to the BaseNode.
48      * </p>
49      *
50      * <p>
51      * Sub-classes can call this method to build the BaseNode object and then
52      * instantiate their Node and either populate their Node from the BaseNode
53      * or call a copy constructor of some sort.
54      * </p>
55      *
56      * @param namespace The namespace the new Node belongs to
57      * @param element The Element to build from
58      * @return The BaseNode built
59      * @throws ConfigurationException If the XML was invalid
60      */

61     public Node build(Namespace namespace, Element element)
62     throws ConfigurationException {
63
64         ErrorList errors = new ErrorList();
65         BaseNode.BaseValues values = super.buildValues(element, errors);
66
67         // Validate the name value exists and is not empty
68
if (StringTools.isEmpty(values.name)) {
69             errors.addError(Constants.NAME_ATTRIBUTE + " is a required attribute");
70             logger.debug("name is null");
71         }
72
73         // Validate that the class name or the repository id is specified
74
if (!(StringTools.isEmpty(values.className) ^
75               StringTools.isEmpty(values.repositoryId)))
76         {
77             errors.addError("Either the " + Constants.CLASS_ATTRIBUTE +
78                 " or the " + Constants.REPOSITORY_ID_ATTRIBUTE +
79                 " must be specified and not both");
80         }
81
82         // If there were errors, throw them
83
if (!errors.isEmpty()) {
84             throw new ConfigurationException(errors);
85         }
86
87         BaseNode node = new ActionHandlerNode(values, namespace);
88         node.setElement(element);
89         return node;
90     }
91 }
92
93
Popular Tags