01: /*
02: * Copyright 2000,2005 wingS development team.
03: *
04: * This file is part of wingS (http://wingsframework.org).
05: *
06: * wingS is free software; you can redistribute it and/or modify
07: * it under the terms of the GNU Lesser General Public License
08: * as published by the Free Software Foundation; either version 2.1
09: * of the License, or (at your option) any later version.
10: *
11: * Please see COPYING for the complete licence.
12: */
13: package org.wings.externalizer;
14:
15: import java.util.Collections;
16: import java.util.HashMap;
17: import java.util.Map;
18:
19: /**
20: * This singleton externalizes
21: * {#link AbstractExternalizeManager#GLOBAL global} scope. Every object
22: * externalized by the SystemExternalizeManager (global scope) is available
23: * over the life time of the servlet container and is not garbage collected.
24: * <p/>
25: * Created: Sat Nov 10 15:49:15 2001
26: *
27: * @author <a href="mailto:armin@hyperion.intranet.mercatis.de">Armin Haaf</a>
28: */
29:
30: public class SystemExternalizeManager extends
31: AbstractExternalizeManager {
32: /**
33: * singleton implementation
34: */
35: private static final SystemExternalizeManager SHARED_INSTANCE = new SystemExternalizeManager();
36:
37: protected final Map<String, ExternalizedResource> externalized;
38:
39: private SystemExternalizeManager() {
40: externalized = Collections
41: .synchronizedMap(new HashMap<String, ExternalizedResource>());
42: }
43:
44: /**
45: * get the single system wide instance.
46: *
47: * @return the SystemExternalizeManager instance.
48: */
49: public static SystemExternalizeManager getSharedInstance() {
50: return SHARED_INSTANCE;
51: }
52:
53: public void setPrefix(final String prefix) {
54: if (prefix.startsWith("-"))
55: super .setPrefix(prefix);
56: else
57: // The prefix MUST start with a - as this is the identifiert for global resources.
58: super .setPrefix("-" + prefix);
59: }
60:
61: protected void storeExternalizedResource(String identifier,
62: ExternalizedResource extInfo) {
63: if (LOG.isDebugEnabled()) {
64: LOG.debug("store identifier " + identifier + " "
65: + extInfo.getObject().getClass());
66: LOG.debug("flags " + extInfo.getFlags());
67: }
68:
69: externalized.put(identifier, extInfo);
70: }
71:
72: public ExternalizedResource getExternalizedResource(
73: String identifier) {
74: if (identifier == null || identifier.length() < 1)
75: return null;
76:
77: LOG.debug("system externalizer: " + identifier);
78: return externalized.get(identifier);
79: }
80:
81: public final void removeExternalizedResource(String identifier) {
82: externalized.remove(identifier);
83: }
84: }
|