KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > hivemind > examples > ExampleUtils


1 // Copyright 2004, 2005 The Apache Software Foundation
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14

15 package org.apache.hivemind.examples;
16
17 import java.util.Locale JavaDoc;
18
19 import org.apache.hivemind.ClassResolver;
20 import org.apache.hivemind.Registry;
21 import org.apache.hivemind.impl.DefaultClassResolver;
22 import org.apache.hivemind.impl.RegistryBuilder;
23 import org.apache.hivemind.impl.XmlModuleDescriptorProvider;
24 import org.apache.hivemind.util.FileResource;
25
26 /**
27  * Utilities needed by the examples.
28  *
29  * @author Howard Lewis Ship
30  */

31 public class ExampleUtils
32 {
33     /**
34      * Builds a Registry for a file stored in the src/descriptor/META-INF directory.
35      *
36      * @param fileName --
37      * the name of the module descriptor file.
38      */

39     public static Registry buildRegistry(String JavaDoc fileName)
40     {
41         // The examples package is structured oddly (so that it doesn't interfere with
42
// the main HiveMind framework tests), so we have to go through some gyrations
43
// here that aren't necessary in an ordinary HiveMind application.
44

45         String JavaDoc projectRoot = System.getProperty("PROJECT_ROOT", ".");
46         String JavaDoc path = projectRoot + "/examples/src/descriptor/META-INF/" + fileName;
47
48         ClassResolver resolver = new DefaultClassResolver();
49         RegistryBuilder builder = new RegistryBuilder();
50
51         builder.addModuleDescriptorProvider(new XmlModuleDescriptorProvider(resolver));
52
53         // Register the examples.xml file, which (given its non-standard name)
54
// is not visible.
55
builder.addModuleDescriptorProvider(new XmlModuleDescriptorProvider(resolver,
56                 new FileResource(path)));
57
58         return builder.constructRegistry(Locale.getDefault());
59     }
60
61 }
Popular Tags