View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.myfaces.trinidad.bean;
20  
21  import java.util.HashMap;
22  import java.util.Map;
23  
24  /**
25   * =-=AEW Can this truly be "static public", or do we need a typed
26   * API registered by class-loader?
27   */
28  public class TypeRepository
29  {
30    
31    // Package-private: called from FacesBean.Type.lockAndRegister()
32    static void registerType(
33      /*String renderKitId,*/
34      String componentFamily,
35      String rendererType,
36      FacesBean.Type type)
37    {
38      String renderKitId = "org.apache.myfaces.trinidad.core";
39  
40      // =-=AEW GLOBAL SYNCHRONIZATION IS NOT GOOD!  We need
41      // to investigate the performance of this approach.  In
42      // theory, 99.9% of both registration and retrieval will happen
43      // in a single thread at startup, so sync waits should be a
44      // non-issue at least given the intended use of this class.
45      synchronized (_repos)
46      {
47        Map<String, Map<String, FacesBean.Type>> rkMap = _repos.get(renderKitId);
48        //Map rkMap = (Map) _repos.get(renderKitId);
49        if (rkMap == null)
50        {
51          rkMap = new HashMap<String, Map<String, FacesBean.Type>>();
52          //rkMap = new HashMap();
53          _repos.put(renderKitId, rkMap);
54        }
55  
56        //Map familyMap = (Map) rkMap.get(componentFamily);
57        Map<String, FacesBean.Type> familyMap = rkMap.get(componentFamily);
58        if (familyMap == null)
59        {
60          //familyMap = new HashMap();
61          familyMap = new HashMap<String, FacesBean.Type>();
62          rkMap.put(componentFamily, familyMap);
63        }
64        
65        familyMap.put(rendererType, type);
66      }
67    }
68  
69    static public FacesBean.Type getType(
70      /* String renderKitId,*/
71      String componentFamily,
72      String rendererType)
73    {
74      String renderKitId = "org.apache.myfaces.trinidad.core";
75  
76      synchronized (_repos)
77      {
78        Map<String, Map<String, FacesBean.Type>> rkMap = _repos.get(renderKitId);
79        //Map rkMap = (Map) _repos.get(renderKitId);
80        if (rkMap == null)
81          return null;
82  
83        Map<String, FacesBean.Type> familyMap = rkMap.get(componentFamily);
84        //Map familyMap = (Map) rkMap.get(componentFamily);
85        if (familyMap == null)
86          return null;
87        
88        return familyMap.get(rendererType);
89      }
90    }
91  
92    // "qdox" doesn't support JDK 1.5 syntax like this.  Hence, all
93    // the commented-out code...
94    // -= Simon Lessard =-
95    // Attempted to switch to JDK 5 on 2006-08-11. We'll see if qdox works fine 
96    // with it now.
97    static private Map<String, Map<String, Map<String, FacesBean.Type>>>
98        _repos = new HashMap<String, Map<String, Map<String, FacesBean.Type>>>();
99    //static private Map _repos = new HashMap();
100 }