|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| package org.apache.examples; |
|
16 |
| |
|
17 |
| import java.net.URL; |
|
18 |
| import java.util.ArrayList; |
|
19 |
| import java.util.List; |
|
20 |
| import java.util.Locale; |
|
21 |
| |
|
22 |
| import org.apache.hivemind.ClassResolver; |
|
23 |
| import org.apache.hivemind.ModuleDescriptorProvider; |
|
24 |
| import org.apache.hivemind.Registry; |
|
25 |
| import org.apache.hivemind.Resource; |
|
26 |
| import org.apache.hivemind.impl.DefaultClassResolver; |
|
27 |
| import org.apache.hivemind.impl.RegistryBuilder; |
|
28 |
| import org.apache.hivemind.impl.XmlModuleDescriptorProvider; |
|
29 |
| import org.apache.hivemind.util.FileResource; |
|
30 |
| import org.apache.hivemind.util.URLResource; |
|
31 |
| |
|
32 |
| |
|
33 |
| |
|
34 |
| |
|
35 |
| |
|
36 |
| |
|
37 |
| public class ExampleUtils |
|
38 |
| { |
|
39 |
| |
|
40 |
| |
|
41 |
| |
|
42 |
| |
|
43 |
| |
|
44 |
| |
|
45 |
0
| public static Registry buildRegistry(String fileName)
|
|
46 |
| { |
|
47 |
| |
|
48 |
| |
|
49 |
| |
|
50 |
| |
|
51 |
0
| String projectRoot = System.getProperty("PROJECT_ROOT", ".");
|
|
52 |
0
| String path = projectRoot + "/examples/src/descriptor/META-INF/" + fileName;
|
|
53 |
| |
|
54 |
0
| ClassResolver resolver = new DefaultClassResolver();
|
|
55 |
| |
|
56 |
| |
|
57 |
| |
|
58 |
0
| ModuleDescriptorProvider provider = new XmlModuleDescriptorProvider(resolver,
|
|
59 |
| new FileResource(path)); |
|
60 |
0
| return buildRegistry(provider);
|
|
61 |
| } |
|
62 |
| |
|
63 |
| |
|
64 |
| |
|
65 |
| |
|
66 |
| |
|
67 |
1
| public static Registry buildClasspathRegistry(String file) throws Exception
|
|
68 |
| { |
|
69 |
1
| return buildClasspathRegistry(new String[] { file });
|
|
70 |
| } |
|
71 |
| |
|
72 |
| |
|
73 |
| |
|
74 |
| |
|
75 |
1
| public static Registry buildClasspathRegistry(String[] files) throws Exception
|
|
76 |
| { |
|
77 |
1
| ClassResolver resolver = new DefaultClassResolver();
|
|
78 |
| |
|
79 |
1
| List descriptorResources = new ArrayList();
|
|
80 |
1
| for (int i = 0; i < files.length; i++)
|
|
81 |
| { |
|
82 |
1
| Resource resource = getResource(files[i]);
|
|
83 |
1
| descriptorResources.add(resource);
|
|
84 |
| } |
|
85 |
| |
|
86 |
1
| ModuleDescriptorProvider provider = new XmlModuleDescriptorProvider(resolver,
|
|
87 |
| descriptorResources); |
|
88 |
| |
|
89 |
1
| return buildRegistry(provider);
|
|
90 |
| } |
|
91 |
| |
|
92 |
1
| protected static Registry buildRegistry(ModuleDescriptorProvider customProvider)
|
|
93 |
| { |
|
94 |
1
| ClassResolver resolver = new DefaultClassResolver();
|
|
95 |
| |
|
96 |
1
| RegistryBuilder builder = new RegistryBuilder();
|
|
97 |
| |
|
98 |
1
| builder.addModuleDescriptorProvider(new XmlModuleDescriptorProvider(resolver));
|
|
99 |
1
| builder.addModuleDescriptorProvider(customProvider);
|
|
100 |
| |
|
101 |
1
| return builder.constructRegistry(Locale.getDefault());
|
|
102 |
| } |
|
103 |
| |
|
104 |
| |
|
105 |
| |
|
106 |
| |
|
107 |
| |
|
108 |
1
| protected static Resource getResource(String file)
|
|
109 |
| { |
|
110 |
1
| URL url = ExampleUtils.class.getResource(file);
|
|
111 |
| |
|
112 |
1
| if (url == null)
|
|
113 |
0
| throw new NullPointerException("No resource named '" + file + "'.");
|
|
114 |
| |
|
115 |
1
| return new URLResource(url);
|
|
116 |
| } |
|
117 |
| |
|
118 |
| } |