KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > webman > acl > ContextFactory


1 package de.webman.acl;
2
3 import com.teamkonzept.lib.ConfigurationManager;
4 import com.teamkonzept.lib.TKException;
5 import com.teamkonzept.lib.TKVector;
6 import de.webman.acl.db.*;
7 import de.webman.acl.resolver.ResolverFactory;
8
9 /**
10  * Factory for context objects.
11  *
12  * @version 1.0
13  * @since 1.0
14  * @author © 2001 Webman AG
15  */

16 public class ContextFactory
17     extends ObjectFactoryBase
18     implements ObjectFactory
19 {
20
21     // $Header: /cvsroot/webman-cms/source/webman/de/webman/acl/ContextFactory.java,v 1.1 2001/08/20 08:25:07 mischa Exp $
22

23     // Constants
24

25     /**
26      * Singleton instance.
27      */

28     private static ContextFactory SINGLETON = null;
29
30
31     // Constructors
32

33     /**
34      * Inhibits instantiation from outside.
35      */

36     private ContextFactory ()
37     {
38         super();
39     }
40
41
42     // Instance
43

44     /**
45      * Returns the singleton instance of the factory.
46      *
47      * @return the singleton instance of the factory.
48      * @exception com.teamkonzept.lib.TKException if an error occured during initialization.
49      */

50     public static synchronized final ContextFactory getInstance ()
51         throws TKException
52     {
53         if (SINGLETON == null)
54         {
55             SINGLETON = new ContextFactory();
56             SINGLETON.configurationChanged();
57             ConfigurationManager.getInstance()
58                                 .registerConfigurationListener(SINGLETON,
59                                                                PROPERTY_GROUP_NAME);
60         }
61
62         return SINGLETON;
63     }
64
65
66     // Method implementations
67

68     /**
69      * Returns the context database interface.
70      *
71      * @return the context database interface.
72      */

73     public final ObjectDBInterface getDBInterface ()
74     {
75         return ContextDBInterface.getInstance();
76     }
77
78     /**
79      * Returns a context data wrapper.
80      *
81      * @param id the ID of the context.
82      * @return a context data wrapper.
83      */

84     public final ObjectDBData getDBData (Integer JavaDoc id)
85     {
86         return new ContextDBData(id, null, null);
87     }
88
89     /**
90      * Returns a context data wrapper.
91      *
92      * @param object the context.
93      * @return a context data wrapper.
94      */

95     public final ObjectDBData getDBData (WMObject object)
96     {
97         return new ContextDBData((Context) object);
98     }
99
100     /**
101      * Builds a concrete context object.
102      *
103      * @param data the initial context data.
104      * @return a concrete context object.
105      */

106     public final WMObject buildObject (ObjectDBData data)
107     {
108         return new Context((ContextDBData) data);
109     }
110
111
112     // Convenience methods
113

114     /**
115      * Retrieves the specified context.
116      *
117      * @param id the ID of the context.
118      * @return the specified context.
119      * @exception com.teamkonzept.lib.TKException if an error occured during context retrieval.
120      */

121     public final Context getContext (Integer JavaDoc id)
122         throws TKException
123     {
124         return (Context) getObject(id);
125     }
126
127     /**
128      * Retrieves all known contexts.
129      *
130      * @return all known contexts.
131      * @exception com.teamkonzept.lib.TKException if an error occured during context retrieval.
132      */

133     public final TKVector getContexts ()
134         throws TKException
135     {
136         return getObjects();
137     }
138
139     /**
140      * Creates the specified context.
141      *
142      * @param name the name of the context.
143      * @param shortcut the shortcut of the context.
144      * @return the specified context.
145      * @exception com.teamkonzept.lib.TKException if an error occured during context creation.
146      */

147     public final Context createContext (String JavaDoc name,
148                                           String JavaDoc shortcut)
149         throws TKException
150     {
151         return (Context) createObject(new ContextDBData(null,
152                                                             name,
153                                                             shortcut));
154     }
155
156     /**
157      * Modifies the given context.
158      *
159      * @param context the context to be modified.
160      * @exception com.teamkonzept.lib.TKException if an error occured during context modification.
161      */

162     public final void modifyContext (Context context)
163         throws TKException
164     {
165         if (context.isModifiedAssociations())
166         {
167             ResolverFactory.getInstance().removeResolvers();
168         }
169
170         modifyObject(context);
171     }
172
173     /**
174      * Deletes the given context.
175      *
176      * @param context the context to be deleted.
177      * @exception com.teamkonzept.lib.TKException if an error occured during context deletion.
178      */

179     public final void deleteContext (Context context)
180         throws TKException
181     {
182         ResolverFactory.getInstance().removeResolvers();
183
184         deleteObject(context);
185     }
186
187 }
188
Popular Tags