Clover coverage report - brownies library - 1.0-beta-1 Coverage timestamp: 月 8 16 2004 17:14:42 GMT+09:00 FRAMES NO FRAMES |
file stats: | LOC: | 125 |  | Methods: | 8
| NCLOC: | 93 |  | Classes: | 1
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover
Source file | Conditionals | Statements | Methods | TOTAL
BrownieS2ContainerFactory.java | 0% | 0% | 0% | 0% |

1 |  |
     /*
2 |  |
      * brownies and its relative products are published under the terms
3 |  |
      * of the Apache Software License.
4 |  |
      *
5 |  |
      * Created on 2004/06/11 1:59:34
6 |  |
      */
7 |  |
     package org.asyrinx.brownie.seasar.container.factory;
8 |  |
9 |  |
     import java.util.HashMap;
10 |  |
     import java.util.Map;
11 |  |
     import java.util.Properties;
12 |  |
13 |  |
     import org.asyrinx.brownie.core.io.sf.StreamFactoryFacade;
14 |  |
     import org.seasar.framework.container.ExtensionNotFoundRuntimeException;
15 |  |
     import org.seasar.framework.container.S2Container;
16 |  |
     import org.seasar.framework.container.factory.S2ContainerBuilder;
17 |  |
     import org.seasar.framework.container.factory.S2ContainerFactory;
18 |  |
     import org.seasar.framework.util.ClassUtil;
19 |  |
     import org.seasar.framework.util.PropertiesUtil;
20 |  |
     import org.seasar.framework.util.ResourceUtil;
21 |  |
     import org.seasar.framework.util.StringUtil;
22 |  |
23 |  |
     /**
24 |  |
      * @author akima
25 |  |
      */
26 |  |
     public final class BrownieS2ContainerFactory {
27 |  |
28 |  |
         private static Properties builderProps_ = new Properties();
29 |  |
30 |  |
         private static Map defaultBuilders = new HashMap();
31 |  |
32 |  |
         /*
33 |  |
          * ここが変わってます。
34 |  |
          */
35 |  |
         private static S2ContainerBuilder defaultBuilder_ = new BrownieXmlS2ContainerBuilder();
36 |  |
37 |  |
         static {
38 | 0 |
             if (ResourceUtil.isExist(S2ContainerFactory.BUILDER_CONFIG_PATH)) {
39 | 0 |
                 PropertiesUtil
40 |  |
                         .load(
41 |  |
                                 builderProps_,
42 |  |
                                 ResourceUtil
43 |  |
                                         .getResourceAsStream(S2ContainerFactory.BUILDER_CONFIG_PATH));
44 |  |
             }
45 | 0 |
             defaultBuilders.put("xml", defaultBuilder_);
46 | 0 |
             defaultBuilders.put("dicon", defaultBuilder_);
47 |  |
         }
48 |  |
49 | 0 |
         private static S2ContainerBuilder getDefaultBuilder(String ext) {
50 | 0 |
             S2ContainerBuilder builder = (S2ContainerBuilder) defaultBuilders
51 |  |
                     .get(ext);
52 | 0 |
             if (builder != null) {
53 | 0 |
                 return builder;
54 |  |
             }
55 | 0 |
             synchronized (defaultBuilders) {
56 | 0 |
                 builder = (S2ContainerBuilder) defaultBuilders.get(ext);
57 | 0 |
                 if (builder != null) {
58 | 0 |
                     return builder;
59 |  |
                 }
60 | 0 |
                 final String className = builderProps_.getProperty(ext);
61 | 0 |
                 if (className != null) {
62 | 0 |
                     builder = (S2ContainerBuilder) ClassUtil.newInstance(className);
63 | 0 |
                     defaultBuilders.put(ext, builder);
64 |  |
                 } else {
65 | 0 |
                     builder = defaultBuilder_;
66 |  |
                 }
67 |  |
             }
68 | 0 |
             return builder;
69 |  |
         }
70 |  |
71 |  |
         private final Map builders = new HashMap();
72 |  |
73 | 0 |
         private BrownieS2ContainerFactory() {
74 |  |
             //do nothing
75 |  |
         }
76 |  |
77 | 0 |
         private BrownieS2ContainerFactory(String baseDirs) {
78 | 0 |
             this();
79 | 0 |
             final S2ContainerBuilder diconBuilder = new BrownieXmlS2ContainerBuilder(
80 |  |
                     StreamFactoryFacade.newFacade(baseDirs));
81 | 0 |
             builders.put("xml", diconBuilder);
82 | 0 |
             builders.put("dicon", diconBuilder);
83 |  |
         }
84 |  |
85 | 0 |
         private S2ContainerBuilder getBuilder(String ext) {
86 | 0 |
             final S2ContainerBuilder builder = (S2ContainerBuilder) builders
87 |  |
                     .get(ext);
88 | 0 |
             return (builder != null) ? builder : getDefaultBuilder(ext);
89 |  |
         }
90 |  |
91 |  |
         private static final Map factories = new HashMap();
92 |  |
93 | 0 |
         private static BrownieS2ContainerFactory getFactory(String baseDirs) {
94 | 0 |
             BrownieS2ContainerFactory factory = (BrownieS2ContainerFactory) factories
95 |  |
                     .get(Thread.currentThread());
96 | 0 |
             if (factory == null) {
97 | 0 |
                 if (StringUtil.isEmpty(baseDirs))
98 | 0 |
                     factory = new BrownieS2ContainerFactory();
99 |  |
                 else
100 | 0 |
                     factory = new BrownieS2ContainerFactory(baseDirs);
101 |  |
             }
102 | 0 |
             factories.put(Thread.currentThread(), factory);
103 | 0 |
             return factory;
104 |  |
         }
105 |  |
106 | 0 |
         protected S2Container doCreate(String path) {
107 | 0 |
             final String ext = ResourceUtil.getExtension(path);
108 | 0 |
             if (ext == null) {
109 | 0 |
                 throw new ExtensionNotFoundRuntimeException(path);
110 |  |
             }
111 | 0 |
             S2ContainerBuilder builder = getBuilder(ext);
112 | 0 |
             return builder.build(path);
113 |  |
         }
114 |  |
115 | 0 |
         public static S2Container create(String path) {
116 | 0 |
             final BrownieS2ContainerFactory factory = getFactory(null);
117 | 0 |
             return factory.doCreate(path);
118 |  |
         }
119 |  |
120 | 0 |
         public static S2Container create(String path, String baseDirs) {
121 | 0 |
             final BrownieS2ContainerFactory factory = getFactory(baseDirs);
122 | 0 |
             return factory.doCreate(path);
123 |  |
         }
124 |  |
125 |  |
     }