KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > wings > DefaultReloadManager


1 /*
2  * $Id: DefaultReloadManager.java,v 1.6 2004/12/01 07:54:06 hengels Exp $
3  * Copyright 2000,2005 wingS development team.
4  *
5  * This file is part of wingS (http://www.j-wings.org).
6  *
7  * wingS is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU Lesser General Public License
9  * as published by the Free Software Foundation; either version 2.1
10  * of the License, or (at your option) any later version.
11  *
12  * Please see COPYING for the complete licence.
13  */

14 package org.wings;
15
16 import org.wings.resource.DynamicCodeResource;
17 import org.wings.resource.DynamicResource;
18 import org.wings.script.DynamicScriptResource;
19 import org.wings.style.DynamicStyleSheetResource;
20
21 import java.util.HashSet JavaDoc;
22 import java.util.Iterator JavaDoc;
23 import java.util.Set JavaDoc;
24
25 /**
26  * This is the default implementation of the reload manager.
27  *
28  * @author <a HREF="mailto:engels@mercatis.de">Holger Engels</a>
29  * @version $Revision: 1.6 $
30  */

31 public class DefaultReloadManager
32         implements ReloadManager {
33     private final transient static org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory.getLog("org.wings");
34     /**
35      * a set of all resources, manged by this ReloadManager, that are marked
36      * dirty.
37      */

38     protected final Set JavaDoc dirtyResources;
39
40     public DefaultReloadManager() {
41         dirtyResources = new HashSet JavaDoc();
42     }
43
44     public void reload(SComponent component) {
45         SFrame parent = component.getParentFrame();
46
47         if (parent == null) {
48             return;
49         }
50
51         markDirty(parent.getDynamicResource(DynamicCodeResource.class));
52         markDirty(parent.getDynamicResource(DynamicStyleSheetResource.class));
53         markDirty(parent.getDynamicResource(DynamicScriptResource.class));
54     }
55
56     public synchronized void markDirty(DynamicResource d) {
57         if (d == null) {
58             log.warn("markDirty: null");
59             return;
60         }
61         dirtyResources.add(d);
62     }
63
64     public Set JavaDoc getDirtyResources() {
65         return dirtyResources;
66     }
67
68     public synchronized void clear() {
69         dirtyResources.clear();
70     }
71
72     public synchronized void invalidateResources() {
73         //Set frames = new HashSet();
74
Iterator JavaDoc it = dirtyResources.iterator();
75         while (it.hasNext()) {
76             DynamicResource resource = (DynamicResource) it.next();
77             resource.invalidate();
78             it.remove();
79         }
80     }
81 }
82
83
84
Popular Tags