KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Copyright (c) 2002, Inversoft Corporation, All Rights Reserved
3  */

4 package com.inversoft.verge.mvc.controller.actionflow.config;
5
6
7 import org.apache.log4j.Logger;
8 import org.jdom.Element;
9
10 import com.inversoft.config.ConfigurationException;
11 import com.inversoft.error.ErrorList;
12 import com.inversoft.util.StringTools;
13
14
15 /**
16  * This class is the factory that builds the PresentationNode
17  * objects
18  *
19  * @author Brian Pontarelli
20  * @since 2.0
21  * @version 2.0
22  */

23 public class PresentationNodeBuilder extends BaseNodeBuilder {
24
25     /**
26      * This classes logger
27      */

28     private static final Logger logger = Logger.getLogger(PresentationNodeBuilder.class);
29
30
31     /**
32      * Constructs a new <code>PresentationNodeBuilder</code>.
33      */

34     public PresentationNodeBuilder() {
35     }
36
37
38     /**
39      * Constructs a PresentationNode by calling BaseNodeFactorys build method
40      * to construct a BaseNode and then using that Object to construct a new
41      * PresentationNode. This method also checks that the name is a valid URL
42      * to a file. This is a simple check that makes certain that the name does
43      * not contain any back-slashes. This DOES NOT check that the name is a
44      * valid file on the file-system.
45      *
46      * @param namespace The namespace the new Node belongs to
47      * @param element The Element to build from
48      * @return The PresentationNode built
49      * @throws ConfigurationException If the XML was invalid
50      */

51     public Node build(Namespace namespace, Element element)
52     throws ConfigurationException {
53
54         ErrorList errors = new ErrorList();
55         BaseNode.BaseValues values = super.buildValues(element, errors);
56
57         // Validate the name value exists and is not empty
58
if (StringTools.isEmpty(values.name)) {
59             errors.addError(Constants.NAME_ATTRIBUTE + " is a required attribute");
60             logger.debug("name is null");
61         } else if (values.name.indexOf("\\") != -1) {
62             errors.addError("Presentation node named: " + values.name +
63                 " can not contain '\\' characters in the " +
64                 Constants.NAME_ATTRIBUTE);
65         } else if (values.name.lastIndexOf("/") == (values.name.length() - 1)) {
66             errors.addError("Presentation node named: " + values.name +
67                 " does not have a name that describes a presentation path and" +
68                 " file name");
69         }
70
71         // If there were errors, throw them
72
if (!errors.isEmpty()) {
73             throw new ConfigurationException(errors);
74         }
75
76         BaseNode node = new PresentationNode(values, namespace);
77         node.setElement(element);
78         return node;
79     }
80 }
81
82
Popular Tags