1 package de.webman.generator; 2 3 import com.teamkonzept.lib.*; 4 import java.io.*; 5 import java.util.LinkedList ; 6 7 import org.apache.log4j.Category; 8 9 17 public class GeneratorContext 18 { 19 20 21 private static Category cat = Category.getInstance(GeneratorContext.class); 22 23 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 42 private LinkedList cycleLookup = new LinkedList (); 43 44 private static TKHashtable lookup = null; 45 46 private static boolean share = false; 47 private static boolean sharingSetup = false; 48 private static Thread initialThread = Thread.currentThread(); 49 50 51 52 53 private static GenDocument currentDocument; 54 55 56 private static boolean isIncremental = false; 57 58 59 private boolean ignoreWorkflow = false; 60 61 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 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 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 preview = man.getValue("PREVIEW_SHARE", ""); 145 share = preview.equalsIgnoreCase("TRUE"); 146 sharingSetup = true; 147 } 148 catch (Exception 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 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 getCycle(Integer 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 o = clt.get(instanceID); 173 174 if (o != null) 175 return o; 176 } 177 } 178 return null; 179 } 180 181 public void setCycle(Integer 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 196 public void push() 197 { 198 pushCycleScope(); 199 } 200 201 204 public void pop() 205 { 206 popCycleScope(); 207 } 208 209 210 213 private TKHashtable currentCycleScope() { 214 TKHashtable clt = null; 215 216 if (cycleLookup.size() == 0) { 217 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 241 public static boolean isIncremental() 242 { 243 return isIncremental; 244 } 245 246 250 public static void setIncremental(boolean incremental) 251 { 252 isIncremental = incremental; 253 } 254 255 258 public static GenDocument getCurrentDocument() 259 { 260 return currentDocument; 261 } 262 263 266 public static void setCurrentDocument(GenDocument document) 267 { 268 currentDocument = document; 269 } 270 } 271
| Popular Tags
|