KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > wings > externalizer > SystemExternalizeManager


1 /*
2  * $Id: SystemExternalizeManager.java,v 1.4 2004/12/01 07:54:08 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.externalizer;
15
16 import java.util.Collections JavaDoc;
17 import java.util.HashMap JavaDoc;
18 import java.util.Map JavaDoc;
19
20 /**
21  * This singleton externalizes
22  * {#link AbstractExternalizeManager#GLOBAL global} scope. Every object
23  * externalized by the SystemExternalizeManager (global scope) is available
24  * over the life time of the servlet container and is not garbage collected.
25  * <p/>
26  * Created: Sat Nov 10 15:49:15 2001
27  *
28  * @author <a HREF="mailto:armin@hyperion.intranet.mercatis.de">Armin Haaf</a>
29  * @version $Revision: 1.4 $
30  */

31
32 public class SystemExternalizeManager extends AbstractExternalizeManager {
33     /**
34      * singleton implementation
35      */

36     private static final SystemExternalizeManager sharedInstance = new SystemExternalizeManager();
37
38     private final String JavaDoc MY_PREFIX_TIMESLICE_STRING = "-" + PREFIX_TIMESLICE_STRING;
39
40     protected final Map JavaDoc/*<String, ExternalizedResource>*/ externalized;
41
42
43     private SystemExternalizeManager() {
44         externalized = Collections.synchronizedMap(new HashMap JavaDoc());
45     }
46
47     /**
48      * get the single system wide instance.
49      *
50      * @return the SystemExternalizeManager instance.
51      */

52     public static SystemExternalizeManager getSharedInstance() {
53         return sharedInstance;
54     }
55
56
57     protected String JavaDoc getPrefix() {
58         return MY_PREFIX_TIMESLICE_STRING;
59     }
60
61     protected void storeExternalizedResource(String JavaDoc identifier,
62                                              ExternalizedResource extInfo) {
63         if (log.isDebugEnabled()) {
64             log.debug("store identifier " + identifier + " " + extInfo.getObject().getClass());
65             log.debug("flags " + extInfo.getFlags());
66         }
67
68         externalized.put(identifier, extInfo);
69     }
70
71     public ExternalizedResource getExternalizedResource(String JavaDoc identifier) {
72         if (identifier == null || identifier.length() < 1)
73             return null;
74
75         log.debug("system externalizer: " + identifier);
76
77         int pos = identifier.indexOf(".");
78         if (pos > -1) {
79             identifier = identifier.substring(0, pos);
80         }
81
82         log.debug("system externalizer " + identifier);
83         return (ExternalizedResource) externalized.get(identifier);
84     }
85
86     public final void removeExternalizedResource(String JavaDoc identifier) {
87         externalized.remove(identifier);
88     }
89 }
90
91
92
93
Popular Tags