01: /*
02: * JBoss, Home of Professional Open Source
03: * Copyright 2005, JBoss Inc., and individual contributors as indicated
04: * by the @authors tag. See the copyright.txt in the distribution for a
05: * full listing of individual contributors.
06: *
07: * This is free software; you can redistribute it and/or modify it
08: * under the terms of the GNU Lesser General Public License as
09: * published by the Free Software Foundation; either version 2.1 of
10: * the License, or (at your option) any later version.
11: *
12: * This software is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15: * Lesser General Public License for more details.
16: *
17: * You should have received a copy of the GNU Lesser General Public
18: * License along with this software; if not, write to the Free
19: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21: */
22: package org.jbpm.util;
23:
24: import java.util.Collections;
25: import java.util.HashMap;
26: import java.util.Iterator;
27: import java.util.Map;
28:
29: public abstract class StaticUtil {
30:
31: /*
32: public class MyClass ... {
33: static AType aStaticInMyClass = null;
34: static AnotherType anotherStaticInMyClass = null;
35:
36: static {
37: new StaticUtil.Initializer(MyClass.class) {
38: public void init() {
39: // initialize static members here
40: aStaticInMyClass = ...;
41: anotherStaticInMyClass = ...;
42: }
43: };
44: }
45: ...
46: }
47: */
48:
49: static Map initializers = Collections
50: .synchronizedMap(new HashMap());
51:
52: public abstract static class Initializer {
53: public Initializer(Class clazz) {
54: add(clazz, this );
55: init();
56: }
57:
58: public abstract void init();
59: }
60:
61: public static void add(Class clazz, Initializer initializer) {
62: initializers.put(clazz, initializer);
63: }
64:
65: public static void remove(Class clazz) {
66: initializers.remove(clazz);
67: }
68:
69: public static void reinitialize() {
70: Iterator iter = initializers.values().iterator();
71: while (iter.hasNext()) {
72: Initializer initializer = (Initializer) iter.next();
73: initializer.init();
74: }
75: }
76: }
|