1 /*
2 * Copyright 2004-2008 the Seasar Foundation and the Others.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13 * either express or implied. See the License for the specific language
14 * governing permissions and limitations under the License.
15 */
16 package org.seasar.uruma.desc;
17
18 import java.util.concurrent.ConcurrentMap;
19
20 import org.seasar.framework.util.Disposable;
21 import org.seasar.framework.util.DisposableUtil;
22 import org.seasar.framework.util.tiger.CollectionsUtil;
23 import org.seasar.uruma.desc.impl.PartActionDescImpl;
24
25 /**
26 * {@link PartActionDesc} オブジェクトを取得するためのファクトリクラスです。<br />
27 *
28 * @author y-komori
29 */
30 public class PartActionDescFactory {
31 private static volatile boolean initialized;
32
33 protected static final ConcurrentMap<Class<?>, PartActionDesc> partActionDescs = CollectionsUtil
34 .newConcurrentHashMap();
35
36 /**
37 * 本ファクトリの初期化を行います。<br />
38 */
39 public static void initialize() {
40 DisposableUtil.add(new Disposable() {
41 public void dispose() {
42 PartActionDescFactory.dispose();
43 }
44 });
45 initialized = true;
46 }
47
48 /**
49 * 本ファクトリが保持するキャッシュをクリアします。<br />
50 */
51 public static synchronized void dispose() {
52 partActionDescs.clear();
53 initialized = false;
54 }
55
56 /**
57 * 指定したクラスに対応する {@link PartActionDesc} オブジェクトを取得します。<br />
58 *
59 * @param partActionClass
60 * {@link PartActionDesc} を取得するクラス
61 * @return {@link PartActionDesc} オブジェクト
62 */
63 public static PartActionDesc getPartActionDesc(
64 final Class<?> partActionClass) {
65 if (!initialized) {
66 initialize();
67 }
68 PartActionDesc partActionDesc = partActionDescs.get(partActionClass);
69 if (partActionDesc == null) {
70 partActionDesc = CollectionsUtil.putIfAbsent(partActionDescs,
71 partActionClass, new PartActionDescImpl(partActionClass));
72 }
73 return partActionDesc;
74 }
75 }