    001package org.apache.turbine.services.assemblerbroker;
    002
    003
    004/*
    005 * Licensed to the Apache Software Foundation (ASF) under one
    006 * or more contributor license agreements.  See the NOTICE file
    007 * distributed with this work for additional information
    008 * regarding copyright ownership.  The ASF licenses this file
    009 * to you under the Apache License, Version 2.0 (the
    010 * "License"); you may not use this file except in compliance
    011 * with the License.  You may obtain a copy of the License at
    012 *
    013 *   http://www.apache.org/licenses/LICENSE-2.0
    014 *
    015 * Unless required by applicable law or agreed to in writing,
    016 * software distributed under the License is distributed on an
    017 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    018 * KIND, either express or implied.  See the License for the
    019 * specific language governing permissions and limitations
    020 * under the License.
    021 */
    022
    023
    024import org.apache.turbine.modules.Assembler;
    025import org.apache.turbine.modules.Loader;
    026import org.apache.turbine.services.TurbineServices;
    027import org.apache.turbine.services.assemblerbroker.util.AssemblerFactory;
    028import org.apache.turbine.util.TurbineException;
    029
    030/**
    031 * An interface the Turbine Assembler service.
    032 * See TurbineAssemblerBrokerService for more info.
    033 *
    034 * @author <a href="mailto:leon@opticode.co.za">Leon Messerschmidt</a>
    035 * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
    036 * @version $Id: TurbineAssemblerBroker.java 1199089 2011-11-08 03:14:28Z tv $
    037 */
    038public abstract class TurbineAssemblerBroker
    039{
    040    /**
    041     * Utility method for accessing the service
    042     * implementation
    043     *
    044     * @return An AssemblerBroker implementation instance
    045     */
    046    public static AssemblerBrokerService getService()
    047    {
    048        return (AssemblerBrokerService) TurbineServices.getInstance()
    049            .getService(AssemblerBrokerService.SERVICE_NAME);
    050    }
    051
    052    /**
    053     * Register a new Assembler factory with this service.
    054     *
    055     * @param factory The actual Factory Object
    056     */
    057    public static <T extends Assembler> void registerFactory(AssemblerFactory<T> factory)
    058    {
    059        getService().registerFactory(factory);
    060    }
    061
    062    /**
    063     * Return an Assembler for a given type and object name.
    064     *
    065     * @param type The Type of Assembler we want
    066     * @param name The name of the Assembler
    067     *
    068     * @return An Assembler Object.
    069     *
    070     * @throws TurbineException If a problem locating the Assembler occurred.
    071     */
    072    public static <T extends Assembler> T getAssembler(Class<T> type, String name)
    073        throws TurbineException
    074    {
    075        return getService().getAssembler(type, name);
    076    }
    077
    078    /**
    079     * Get a Loader for the given assembler type
    080     *
    081     * @param type The Type of the Assembler
    082     * @return A Loader instance for the requested type
    083     */
    084    public static <T extends Assembler> Loader<T> getLoader(Class<T> type)
    085    {
    086        return getService().getLoader(type);
    087    }
    088}