KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > webman > generator > GeneratorContext


1 package de.webman.generator;
2
3 import com.teamkonzept.lib.*;
4 import java.io.*;
5 import java.util.LinkedList JavaDoc;
6
7 import org.apache.log4j.Category;
8
9 /**
10
11     Diese Klasse haelt alle Status Informationen
12     eines Previews, damit mehrere Previews threadsicher
13     ablaufen koennen
14     * @author $Author: alex $
15     * @version $Revision: 1.6 $
16  */

17 public class GeneratorContext
18 {
19
20     /** Logging Category */
21     private static Category cat = Category.getInstance(GeneratorContext.class);
22     
23     /**
24      * cache f�r bereits geladene content forms
25      **/

26     public ContentFormStatics contentForms;
27
28     public SiteContentStatics siteContents;
29     public SiteContentIntegrationStatics integrations;
30     public ContentCallStatics contentCalls;
31     public SiteContentNodeStatics contentNodes;
32     public ReferenceTypeStatics referenceTypes;
33     public SiteNodeStatics siteNodes;
34     public GenNodeStatics genNodes;
35     public GenDocumentStatics genDocuments;
36     public SiteReferenceStatics siteReferences;
37     
38     /**
39      * zum Auffinden von Zyklen bei referenzen. cycleLookup is used as a
40      * stack (contains TKHashtable denoting the current scope)
41      */

42     private LinkedList JavaDoc cycleLookup = new LinkedList JavaDoc();
43
44     private static TKHashtable lookup = null;
45
46     private static boolean share = false;
47     private static boolean sharingSetup = false;
48     private static Thread JavaDoc initialThread = Thread.currentThread();
49
50
51
52     /** aktuell generiertes Dokument */
53     private static GenDocument currentDocument;
54
55     /** wird inkrementell generiert ? */
56     private static boolean isIncremental = false;
57
58     /** wird der Workflow beachtet ? */
59     private boolean ignoreWorkflow = false;
60     
61     /**
62     Indicates, if the site tree generation is used for the generator (default)
63     or preview. In the latter case, all content is generated, else only
64     the content which status is marked 'generate' in the database
65     VERSION_STATUS attributes. From now on only important for the references,
66      Workflow is managed by ignoreWorkflow
67     */

68     private static boolean isPreviewMode;
69
70     public GeneratorContext ()
71     {
72         contentForms = new ContentFormStatics (this);
73         siteContents = new SiteContentStatics (this);
74         integrations = new SiteContentIntegrationStatics (this);
75         contentCalls = new ContentCallStatics (this);
76         contentNodes = new SiteContentNodeStatics (this);
77         referenceTypes = new ReferenceTypeStatics (this);
78         siteNodes = new SiteNodeStatics (this);
79         genNodes = new GenNodeStatics (this);
80         genDocuments = new GenDocumentStatics (this);
81         siteReferences = new SiteReferenceStatics (this);
82     }
83
84     /**
85      * @return ob der der Generator im Preview Modus betrieben wird
86      */

87     public static boolean isPreviewMode()
88     {
89         return isPreviewMode;
90     }
91     
92     public static void setPreviewMode(boolean mode)
93     {
94         isPreviewMode = mode;
95     }
96     
97     public boolean isWorkflowIgnored()
98     {
99         return ignoreWorkflow;
100     }
101     
102     public void setWorkflowIgnored(boolean ignore)
103     {
104         ignoreWorkflow = ignore;
105     }
106     
107     public static boolean isShared()
108     {
109         return share;
110     }
111     
112     public static synchronized GeneratorContext setup (Thread JavaDoc myThread)
113     {
114         if (share) myThread = initialThread;
115
116         if (myThread == null) myThread = Thread.currentThread();
117         if (lookup == null) lookup = new TKHashtable();
118
119         GeneratorContext statics = (GeneratorContext) lookup.get(myThread);
120         if (statics != null) return statics;
121         
122         statics = new GeneratorContext();
123         lookup.put( myThread, statics );
124         
125         return statics;
126     }
127     
128     public static GeneratorContext setup ()
129     {
130         return setup (Thread.currentThread());
131     }
132
133     static
134     {
135         setupSharing();
136     }
137
138     public synchronized static void setupSharing ()
139     {
140         if (sharingSetup) return;
141         try
142         {
143             PropertyManager man = PropertyManager.getPropertyManager("GENERATION");
144             String JavaDoc preview = man.getValue("PREVIEW_SHARE", "");
145             share = preview.equalsIgnoreCase("TRUE");
146             sharingSetup = true;
147         }
148         catch (Exception JavaDoc e)
149         {
150             cat.info("No Preview Property Set");
151         }
152     }
153     
154     public static void cleanup ()
155     {
156         cleanup (Thread.currentThread());
157     }
158     
159     public static void cleanup (Thread JavaDoc myThread)
160     {
161         if (share) return;
162         if (myThread == null) myThread = Thread.currentThread();
163         if (lookup != null) lookup.remove ( myThread );
164     }
165     
166     public Object JavaDoc getCycle(Integer JavaDoc instanceID)
167     {
168         if (cycleLookup.size() != 0) {
169             int sm = cycleLookup.size();
170             for (int sc = 0; sc < sm; sc++) {
171                 TKHashtable clt = (TKHashtable)cycleLookup.get(sc);
172                 Object JavaDoc o = clt.get(instanceID);
173
174                 if (o != null)
175                     return o;
176             }
177         }
178         return null;
179     }
180     
181     public void setCycle(Integer JavaDoc instanceID)
182     {
183         TKHashtable clt = currentCycleScope();
184         clt.put(instanceID, "1");
185     }
186     
187     public void clearCycle()
188     {
189         cat.debug("Cycle cleared");
190         cycleLookup.clear();
191     }
192     
193     /**
194      * Referenz wird weiter verschachtelt
195      */

196     public void push()
197     {
198         pushCycleScope();
199     }
200     
201     /**
202      * Referenz ist beendet
203      */

204     public void pop()
205     {
206         popCycleScope();
207     }
208     
209
210     /* ----------------------------------------------------------------------
211        functions for the cycle detection stack
212        ---------------------------------------------------------------------- */

213     private TKHashtable currentCycleScope() {
214         TKHashtable clt = null;
215
216         if (cycleLookup.size() == 0) {
217             // lazy initialization
218
clt = new TKHashtable();
219             cycleLookup.addFirst(clt);
220         }
221         else
222             clt = (TKHashtable)cycleLookup.getFirst();
223         
224         return clt;
225     }
226
227     private void pushCycleScope() {
228         TKHashtable clt = new TKHashtable();
229         cycleLookup.addFirst(clt);
230     }
231
232     private void popCycleScope() {
233         if (cycleLookup.size() > 0)
234             cycleLookup.removeFirst();
235     }
236
237     /**
238      * getter fuer isIncremental
239      * @return ob inkrementell generiert wird
240      */

241     public static boolean isIncremental()
242     {
243         return isIncremental;
244     }
245
246     /**
247      * Setzen der inkr. Generierung
248      * @param incremental boolscher Wert fuer inkr. Generierung
249      */

250     public static void setIncremental(boolean incremental)
251     {
252         isIncremental = incremental;
253     }
254
255     /**
256      * @return das aktuell generierte Dokument, null falls nicht vorhanden
257      */

258     public static GenDocument getCurrentDocument()
259     {
260         return currentDocument;
261     }
262
263     /**
264      * @param document das aktuell generierte Dokument
265      */

266     public static void setCurrentDocument(GenDocument document)
267     {
268         currentDocument = document;
269     }
270 }
271
Free Books   Free Magazines  
Popular Tags