Coverage Report - org.seasar.uruma.desc.FormDescFactory
 
Classes in this File Line Coverage Branch Coverage Complexity
FormDescFactory
93%
13/14
50%
2/4
0
FormDescFactory$1
100%
3/3
N/A
0
 
 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.FormDescImpl;
 24  
 
 25  
 /**
 26  
  * {@link FormDesc} を取得するためのファクトリクラスです。<br />
 27  
  * 
 28  
  * @author y-komori
 29  
  */
 30  0
 public class FormDescFactory {
 31  
     private static volatile boolean initialized;
 32  
 
 33  4
     protected static final ConcurrentMap<Class<?>, FormDesc> formDescs = CollectionsUtil
 34  
             .newConcurrentHashMap();
 35  
 
 36  
     /**
 37  
      * 本ファクトリの初期化を行います。<br />
 38  
      */
 39  
     public static void initialize() {
 40  112
         DisposableUtil.add(new Disposable() {
 41  112
             public void dispose() {
 42  112
                 FormDescFactory.dispose();
 43  112
             }
 44  
         });
 45  112
         initialized = true;
 46  112
     }
 47  
 
 48  
     /**
 49  
      * 本ファクトリが保持するキャッシュをクリアします。<br />
 50  
      */
 51  
     public static synchronized void dispose() {
 52  112
         formDescs.clear();
 53  112
         initialized = false;
 54  112
     }
 55  
 
 56  
     /**
 57  
      * 指定したクラスに対応する {@link FormDesc} オブジェクトを取得します。<br />
 58  
      * 
 59  
      * @param formClass
 60  
      *            {@link FormDesc} を取得するクラス
 61  
      * @return {@link FormDesc} オブジェクト
 62  
      */
 63  
     public static FormDesc getFormDesc(final Class<?> formClass) {
 64  112
         if (!initialized) {
 65  112
             initialize();
 66  
         }
 67  112
         FormDesc formDesc = formDescs.get(formClass);
 68  112
         if (formDesc == null) {
 69  112
             formDesc = CollectionsUtil.putIfAbsent(formDescs, formClass,
 70  
                     new FormDescImpl(formClass));
 71  
         }
 72  112
         return formDesc;
 73  
     }
 74  
 }