KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > infohazard > maverick > flow > CommandFactory


1 /*
2  * $Id: CommandFactory.java,v 1.7 2004/06/27 17:42:14 eelco12 Exp $
3  * $Source: /cvsroot/mav/maverick/src/java/org/infohazard/maverick/flow/CommandFactory.java,v $
4  */

5 package org.infohazard.maverick.flow;
6
7 import java.util.Map JavaDoc;
8 import org.jdom.Element;
9
10 /**
11  * Factory for creating Command objects based on some preloaded context
12  * (such as global views) and an XML command node.
13  *
14  * created January 28, 2002
15  * @author Jeff Schnitzer
16  * @version $Revision: 1.7 $ $Date: 2004/06/27 17:42:14 $
17  */

18 class CommandFactory
19 {
20     /** tag for views. */
21     protected final static String JavaDoc TAG_VIEW = "view";
22
23     /** tag for the controller. */
24     protected final static String JavaDoc TAG_CONTROLLER = "controller";
25
26     /** view registry. */
27     protected ViewRegistry viewRegistry;
28
29     /** the controller factory. */
30     protected ControllerFactory controllerFactory = new DefaultControllerFactory();
31
32     /**
33      * @param viewRegistry
34      */

35     public CommandFactory(ViewRegistry viewReg)
36     {
37         this.viewRegistry = viewReg;
38     }
39
40     /**
41      * Creates a command from the commandNode.
42      *
43      * @param commandNode
44      * @return
45      * @exception ConfigException
46      */

47     public Command createCommand(Element commandNode) throws ConfigException
48     {
49         Controller ctl = this.controllerFactory.createController(commandNode.getChild(TAG_CONTROLLER));
50
51         Map JavaDoc viewsMap = this.viewRegistry.createViewsMap(commandNode.getChildren(TAG_VIEW));
52         if (viewsMap.size() > 1)
53             return new CommandMultipleViews(ctl, viewsMap);
54         else
55         {
56             // Optimize with a Command that doesn't do a map lookup.
57
// This is also how nameless views are resolved.
58
View theView = (View)viewsMap.values().iterator().next();
59             return new CommandSingleView(ctl, theView);
60         }
61     }
62
63     /**
64      * Get view registry.
65      * @return ViewRegistry Returns the viewRegistry.
66      */

67     public ViewRegistry getViewRegistry()
68     {
69         return viewRegistry;
70     }
71     /**
72      * Set view registry.
73      * @param viewRegistry viewRegistry to set.
74      */

75     public void setViewRegistry(ViewRegistry viewReg)
76     {
77         this.viewRegistry = viewReg;
78     }
79     /**
80      * Get controllerFactory.
81      * @return ControllerFactory Returns the controllerFactory.
82      */

83     public ControllerFactory getControllerFactory()
84     {
85         return controllerFactory;
86     }
87     /**
88      * Set controllerFactory.
89      * @param controllerFactory controllerFactory to set.
90      */

91     public void setControllerFactory(ControllerFactory controllerFactory)
92     {
93         this.controllerFactory = controllerFactory;
94     }
95 }
96
97
Popular Tags