Package org.xdoclet.plugin.ejb

Source Code of org.xdoclet.plugin.ejb.EjbRuntime

/*
* Copyright (c) 2005
* XDoclet Team
* All rights reserved.
*/
package org.xdoclet.plugin.ejb;

import org.xdoclet.plugin.ejb.descriptor.EjbJarXmlPlugin;
import org.xdoclet.plugin.ejb.entity.PrimaryKeyClassPlugin;
import org.xdoclet.plugin.ejb.interfaces.LocalHomeInterfacePlugin;
import org.xdoclet.plugin.ejb.interfaces.LocalInterfacePlugin;
import org.xdoclet.plugin.ejb.interfaces.RemoteHomeInterfacePlugin;
import org.xdoclet.plugin.ejb.interfaces.RemoteInterfacePlugin;
import org.xdoclet.plugin.ejb.interfaces.ServiceEndpointPlugin;

/**
* A singleton class to manage the needed relationship between ejb generating plugins,
* without constructing then and using the plugin constructor.
* This enables the user not set the usage of a plugin he doesn't want
*
* @author Diogo Quintela
* @version $Revision: 538 $
*
* TODO: Is this the better pattern to resolve the problem ? Should we support any subclassing ?
*/
public class EjbRuntime {
    protected static EjbRuntime instance;
    protected final EjbConfig config;
    protected EjbJarXmlPlugin ejbJarXmlPlugin;
    protected PrimaryKeyClassPlugin primaryKeyClassPlugin;
    protected LocalHomeInterfacePlugin localHomeInterfacePlugin;
    protected LocalInterfacePlugin localInterfacePlugin;
    protected RemoteHomeInterfacePlugin remoteHomeInterfacePlugin;
    protected RemoteInterfacePlugin remoteInterfacePlugin;
    protected ServiceEndpointPlugin serviceEndpointPlugin;

    protected EjbRuntime(EjbConfig config) {
        // No public instantiation
        this.config = config;
    }

    public static synchronized void init(EjbConfig config) {
        if (config == null) {
            throw new Error("NullPointerException");
        }

        if (instance == null) {
            instance = new EjbRuntime(config);
        }

        // else: We have already been initialized ignore values
    }

    public static LocalInterfacePlugin getLocalInterfacePlugin() {
        checkInit();
        return instance._getLocalInterfacePlugin();
    }

    public static RemoteHomeInterfacePlugin getRemoteHomeInterfacePlugin() {
        checkInit();
        return instance._getRemoteHomeInterfacePlugin();
    }

    public static RemoteInterfacePlugin getRemoteInterfacePlugin() {
        checkInit();
        return instance._getRemoteInterfacePlugin();
    }

    public static ServiceEndpointPlugin getServiceEndpointPlugin() {
        checkInit();
        return instance._getServiceEndpointPlugin();
    }

    protected synchronized ServiceEndpointPlugin _getServiceEndpointPlugin() {
        if (this.serviceEndpointPlugin == null) {
            this.serviceEndpointPlugin =
              new ServiceEndpointPlugin(null, null, config);
        }

        return this.serviceEndpointPlugin;
    }

    protected synchronized LocalInterfacePlugin _getLocalInterfacePlugin() {
        if (this.localInterfacePlugin == null) {
            this.localInterfacePlugin =
              new LocalInterfacePlugin(null, null, config);
        }

        return this.localInterfacePlugin;
    }

    protected synchronized RemoteHomeInterfacePlugin _getRemoteHomeInterfacePlugin() {
        if (this.remoteHomeInterfacePlugin == null) {
            this.remoteHomeInterfacePlugin =
              new RemoteHomeInterfacePlugin(null, null, config);
        }

        return this.remoteHomeInterfacePlugin;
    }

    protected synchronized RemoteInterfacePlugin _getRemoteInterfacePlugin() {
        if (this.remoteInterfacePlugin == null) {
            this.remoteInterfacePlugin =
              new RemoteInterfacePlugin(null, null, config);
        }

        return this.remoteInterfacePlugin;
    }

    public static EjbJarXmlPlugin getEjbJarXmlPlugin() {
        checkInit();
        return instance._getEjbJarXmlPlugin();
    }

    protected synchronized EjbJarXmlPlugin _getEjbJarXmlPlugin() {
        if (this.ejbJarXmlPlugin == null) {
            this.ejbJarXmlPlugin = new EjbJarXmlPlugin(null, null, config);
        }

        return this.ejbJarXmlPlugin;
    }

    public static PrimaryKeyClassPlugin getPrimaryKeyClassPlugin() {
        checkInit();
        return instance._getPrimaryKeyClassPlugin();
    }

    protected synchronized PrimaryKeyClassPlugin _getPrimaryKeyClassPlugin() {
        if (this.primaryKeyClassPlugin == null) {
            this.primaryKeyClassPlugin =
              new PrimaryKeyClassPlugin(null, null, config);
        }

        return this.primaryKeyClassPlugin;
    }

    public static LocalHomeInterfacePlugin getLocalHomeInterfacePlugin() {
        checkInit();
        return instance._getLocalHomeInterfacePlugin();
    }

    protected synchronized LocalHomeInterfacePlugin _getLocalHomeInterfacePlugin() {
        if (this.localHomeInterfacePlugin == null) {
            this.localHomeInterfacePlugin =
              new LocalHomeInterfacePlugin(null, null, config);
        }

        return this.localHomeInterfacePlugin;
    }

    public static void setPlugin(PrimaryKeyClassPlugin plugin) {
        if (plugin == null) {
            throw new Error("NullPointerException");
        }

        checkInit();
        instance._setPlugin(plugin);
    }

    public static void setPlugin(EjbJarXmlPlugin plugin) {
        if (plugin == null) {
            throw new Error("NullPointerException");
        }

        checkInit();
        instance._setPlugin(plugin);
    }

    public static void setPlugin(LocalHomeInterfacePlugin plugin) {
        if (plugin == null) {
            throw new Error("NullPointerException");
        }

        checkInit();
        instance._setPlugin(plugin);
    }

    public static void setPlugin(LocalInterfacePlugin plugin) {
        if (plugin == null) {
            throw new Error("NullPointerException");
        }

        checkInit();
        instance._setPlugin(plugin);
    }

    public static void setPlugin(RemoteHomeInterfacePlugin plugin) {
        if (plugin == null) {
            throw new Error("NullPointerException");
        }

        checkInit();
        instance._setPlugin(plugin);
    }

    public static void setPlugin(RemoteInterfacePlugin plugin) {
        if (plugin == null) {
            throw new Error("NullPointerException");
        }

        checkInit();
        instance._setPlugin(plugin);
    }

    public static void setPlugin(ServiceEndpointPlugin plugin) {
        if (plugin == null) {
            throw new Error("NullPointerException");
        }

        checkInit();
        instance._setPlugin(plugin);
    }

    protected synchronized void _setPlugin(ServiceEndpointPlugin plugin) {
        this.serviceEndpointPlugin = plugin;
    }

    protected synchronized void _setPlugin(RemoteInterfacePlugin plugin) {
        this.remoteInterfacePlugin = plugin;
    }

    protected synchronized void _setPlugin(RemoteHomeInterfacePlugin plugin) {
        this.remoteHomeInterfacePlugin = plugin;
    }

    protected synchronized void _setPlugin(LocalInterfacePlugin plugin) {
        this.localInterfacePlugin = plugin;
    }

    protected synchronized void _setPlugin(LocalHomeInterfacePlugin plugin) {
        this.localHomeInterfacePlugin = plugin;
    }

    protected synchronized void _setPlugin(EjbJarXmlPlugin plugin) {
        this.ejbJarXmlPlugin = plugin;
    }

    protected synchronized void _setPlugin(PrimaryKeyClassPlugin plugin) {
        this.primaryKeyClassPlugin = plugin;
    }

    protected synchronized static void checkInit() {
        if (instance == null) {
            throw new Error("EjbRuntime wasn't initialized");
        }
    }

    public static EjbConfig getConfig() {
        checkInit();
        return instance._getConfig();
    }

    protected EjbConfig _getConfig() {
        return this.config;
    }
}
TOP

Related Classes of org.xdoclet.plugin.ejb.EjbRuntime

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.