KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > oddjob > designer > factory > DesignFactory


1 /*
2  * (c) Rob Gordon 2005.
3  */

4 package org.oddjob.designer.factory;
5
6 import org.apache.log4j.Logger;
7 import org.oddjob.arooa.ArooaException;
8 import org.oddjob.arooa.ObjectFactory;
9 import org.oddjob.designer.model.DesignComponent;
10 import org.oddjob.designer.model.DesignElementType;
11
12 /**
13  * A factory which can create DesignComponents and DesignElements.
14  */

15 public class DesignFactory {
16     public static Logger logger = Logger.getLogger(DesignFactory.class);
17     
18     public static final String JavaDoc UNKNOWN_TAG = "other";
19     
20     private static DesignFactoryBean instance ;
21     
22     private static DesignFactoryBean getInstance() {
23         if (instance == null) {
24             instance = new DesignFactoryBean(
25                     DesignFactory.class.getResourceAsStream("factory.xml"));
26         }
27         return instance;
28     }
29     
30     /**
31      * Returns a hierarchy of ComponentAction objects which can be used in a
32      * hierarchical menu structure for creating and adding components.
33      *
34      * @param subject The object the new component will be added to.
35      * @param element The element name the child appears under.
36      *
37      * @return A SimpleHierarchy of ComponentAction objects.
38      */

39     public static SimpleHierarchy childActions(final Object JavaDoc subject, final String JavaDoc element) {
40         return getInstance().childActions(subject, element);
41     }
42     
43     /**
44      * Create a component for the given name.
45      *
46      * @param name The name of the tag identifiying the component.
47      * @return A created component. Never null.
48      *
49      * @throws ArooaException If the component can't be created.
50      */

51     public static DesignComponent createComponent(String JavaDoc name) throws ArooaException {
52         return getInstance().createComponent(name);
53     }
54     
55     /**
56      * Creates a ObjectFactory which creates components.
57      *
58      * @return An ObjectFactory.
59      */

60     public static ObjectFactory componentFactory() {
61         return getInstance().componentFactory();
62     }
63
64     /**
65      * Return supported child type for a given type.
66      *
67      * @param type The type.
68      * @return A list of supported types.
69      */

70     public static String JavaDoc[] supportedTypes(Class JavaDoc type) {
71         return getInstance().supportedTypes(type);
72     }
73     
74     /**
75      * Creat a type for the given type name.
76      *
77      * @param name The type name.
78      * @return The created type.
79      *
80      * @throws ArooaException If the type can't be created.
81      */

82     public static DesignElementType createType(String JavaDoc name) throws ArooaException {
83         return getInstance().createType(name);
84     }
85     
86     public static ObjectFactory valueFactory() {
87         return getInstance().valueFactory();
88     }
89
90 }
91
Popular Tags