Package org.apache.hivemind.examples

Source Code of org.apache.hivemind.examples.ExampleUtils

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

package org.apache.hivemind.examples;

import java.util.Locale;

import org.apache.hivemind.ClassResolver;
import org.apache.hivemind.Registry;
import org.apache.hivemind.impl.DefaultClassResolver;
import org.apache.hivemind.impl.RegistryBuilder;
import org.apache.hivemind.impl.XmlModuleDescriptorProvider;
import org.apache.hivemind.util.FileResource;

/**
* Utilities needed by the examples.
*
* @author Howard Lewis Ship
*/
public class ExampleUtils
{
    /**
     * Builds a Registry for a file stored in the src/descriptor/META-INF directory.
     *
     * @param fileName --
     *            the name of the module descriptor file.
     */
    public static Registry buildRegistry(String fileName)
    {
        // The examples package is structured oddly (so that it doesn't interfere with
        // the main HiveMind framework tests), so we have to go through some gyrations
        // here that aren't necessary in an ordinary HiveMind application.

        String projectRoot = System.getProperty("PROJECT_ROOT", ".");
        String path = projectRoot + "/examples/src/descriptor/META-INF/" + fileName;

        ClassResolver resolver = new DefaultClassResolver();
        RegistryBuilder builder = new RegistryBuilder();

        builder.addModuleDescriptorProvider(new XmlModuleDescriptorProvider(resolver));

        // Register the examples.xml file, which (given its non-standard name)
        // is not visible.
        builder.addModuleDescriptorProvider(new XmlModuleDescriptorProvider(resolver,
                new FileResource(path)));

        return builder.constructRegistry(Locale.getDefault());
    }

}
TOP

Related Classes of org.apache.hivemind.examples.ExampleUtils

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.