KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > jca > ResourceDefault


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  *
23  * Free Software Foundation, Inc.
24  * 59 Temple Place, Suite 330
25  * Boston, MA 02111-1307 USA
26  *
27  * @author Scott Ferguson
28  */

29
30 package com.caucho.jca;
31
32 import com.caucho.config.BuilderProgram;
33 import com.caucho.loader.EnvironmentClassLoader;
34 import com.caucho.loader.EnvironmentLocal;
35 import com.caucho.util.L10N;
36
37 import javax.annotation.PostConstruct;
38 import java.util.ArrayList JavaDoc;
39 import java.util.logging.Logger JavaDoc;
40
41 /**
42  * The configuration for a resource-default.
43  */

44 public class ResourceDefault {
45   private static final L10N L = new L10N(ResourceDefault.class);
46   private static final Logger JavaDoc log
47     = Logger.getLogger(ResourceDefault.class.getName());
48
49   private static EnvironmentLocal<ArrayList JavaDoc<ResourceConfig>> _localConfig
50     = new EnvironmentLocal<ArrayList JavaDoc<ResourceConfig>>();
51
52   private ResourceConfig _config = new ResourceConfig();
53
54
55   /**
56    * Adds to the builder program.
57    */

58   public void addBuilderProgram(BuilderProgram program)
59   {
60     _config.addBuilderProgram(program);
61   }
62
63   @PostConstruct
64   public void init()
65   {
66     ArrayList JavaDoc<ResourceConfig> defaultList = _localConfig.getLevel();
67
68     if (defaultList == null) {
69       defaultList = new ArrayList JavaDoc<ResourceConfig>();
70       _localConfig.set(defaultList);
71     }
72
73     defaultList.add(_config);
74   }
75
76   public static ArrayList JavaDoc<ResourceConfig> getDefaultList()
77   {
78     return getDefaultList(Thread.currentThread().getContextClassLoader());
79   }
80
81   public static ArrayList JavaDoc<ResourceConfig> getDefaultList(ClassLoader JavaDoc loader)
82   {
83     ArrayList JavaDoc<ResourceConfig> defaultList = new ArrayList JavaDoc<ResourceConfig>();
84
85     getDefaultList(defaultList, loader);
86
87     return defaultList;
88   }
89
90   private static void getDefaultList(ArrayList JavaDoc<ResourceConfig> list,
91                      ClassLoader JavaDoc loader)
92   {
93     for (; loader != null; loader = loader.getParent()) {
94       if (loader instanceof EnvironmentClassLoader) {
95     getDefaultList(list, loader.getParent());
96
97     ArrayList JavaDoc<ResourceConfig> defaultList = _localConfig.getLevel(loader);
98
99     if (defaultList != null)
100       list.addAll(defaultList);
101       }
102     }
103   }
104 }
105
Popular Tags