⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 abstractmanager.java

📁 一套会员管理系统组件
💻 JAVA
字号:
package com.airinbox.member;

import org.apache.avalon.framework.logger.AbstractLogEnabled;

import org.apache.avalon.framework.component.Composable;
import org.apache.avalon.framework.component.Component;
import org.apache.avalon.framework.component.ComponentException;
import org.apache.avalon.framework.component.ComponentManager;

import org.apache.avalon.framework.context.Contextualizable;
import org.apache.avalon.framework.context.ContextException;
import org.apache.avalon.framework.context.Context;
import org.apache.avalon.framework.context.DefaultContext;

import org.apache.avalon.framework.configuration.Configurable;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;

import org.apache.avalon.framework.activity.Initializable;
import org.apache.avalon.framework.activity.Disposable;
import org.apache.avalon.framework.activity.Startable;

import org.apache.avalon.framework.thread.ThreadSafe;

/**
 * Abstract Manager for each manager.
 * your manager can extends this class so that to obtain logger,configuration,
 * context,other manager for ComponentManager.
 * We strongly suggest that you should use this class.<br>
 * Here has some example:
 * <pre>
 *		// your manager class interface named as AlbumManager
 *		//
 *		public class AlbumManagerImpl extends AbstractManager
 *			implement AlbumManager //,other interfaces
 *		{
 *			protected SmsGatewayEntryPeer m_smsGateway = null;
 * 
 *			protected MmsGatewayEntryPeer m_mmsGateway = null;
 * 
 *			public void compose( ComponentManager componentManager ) throws ComponentException
 *			{
 *				super.compose(componentManager);
 *				if(componentManager.hasComponent(SmsGatewayEntryPeer.ROLE))
 *				{
 *					m_smsGateway = (SmsGatewayEntryPeer)componentManager.lookup(SmsGatewayEntryPeer.ROLE);
 *				}
 *	
 *				if(componentManager.hasComponent(MmsGatewayEntryPeer.ROLE))
 *				{
 *					m_mmsGateway = (MmsGatewayEntryPeer)componentManager.lookup(MmsGatewayEntryPeer.ROLE);
 *				}
 *			}	
 * 
 *			public void contextualize( Context context )  throws ContextException
 *			{	
 *				super.contextualize(context);
 *			}
 * 
 *			public void configure( Configuration configuration ) throws ConfigurationException
 *			{
 *				super.configure(configuration);
 *				String name = configuration.getAttribute("name","album");
 *				int port = configuration.getAttributeAsInteger("port",80);
 *			}
 *		}
 * </pre>
 */
public abstract class AbstractManager extends AbstractLogEnabled 
	implements Component,Composable,Contextualizable,Configurable,Initializable,Startable,Disposable,ThreadSafe
{
	protected boolean initialized = false;
	protected boolean disposed = false;
	protected ComponentManager	m_componentManager = null;
	protected DefaultContext	m_context = null;	
	
	/**
     * Pass the <code>ComponentManager</code> to the <code>composer</code>.
     * The <code>Composable</code> implementation should use the specified
     * <code>ComponentManager</code> to acquire the components it needs for
     * execution.
     *
     * @param manager The <code>ComponentManager</code> which this
     *                <code>Composable</code> uses.
     */
    public void compose( ComponentManager componentManager ) throws ComponentException
	{
		if(initialized || disposed)
			throw new ComponentException("compose failed cause initialized or disposed");
		if(this.m_componentManager == null)
			this.m_componentManager = componentManager;
	}
	
	/**
     * Pass the Context to the component. 
     * This method is called after the Loggable.setLogger() (if present) 
     * method and before any other method.
     *
     * @param context the context
     * @exception ContextException if context is invalid
     */
    public void contextualize( Context context )  throws ContextException
	{
		if(initialized || disposed)
			throw new ContextException("contextualize failed cause initialized or disposed");
		
		m_context = new DefaultContext(context);
	}

   /**
     * Pass the <code>Configuration</code> to the <code>Configurable</code>
     * class. This method must always be called after the constructor
     * and before any other method.
     *
     * @param configuration the class configurations.
     */
    public void configure( Configuration configuration ) throws ConfigurationException
	{
		if(initialized || disposed)
			throw  new ConfigurationException("configure failed cause initialized or disposed");
	}
	
	/**
     * Initialialize the component. Initialization includes 
     * allocating any resources required throughout the 
     * components lifecycle.
     *
     * @exception Exception if an error occurs
     */
    public void initialize() throws Exception
	{
		if(initialized || disposed)
			throw  new Exception("initialize failed cause initialized or disposed");
		
		initialized = true;
	}
	
   /**
     * Starts the component.
     *
     * @exception Exception if Component can not be started
     */
    public void start() throws Exception
	{
		if(!initialized || disposed)
			throw  new Exception("start failed cause not initialized or disposed");
	}

    /**
     * Stops the component.
     *
     * @exception Exception if the Component can not be Stopped.
     */
    public void stop()  throws Exception
	{
		if(!initialized || disposed)
			throw  new Exception("stop failed cause not initialized or disposed");
	}
	
	/**
     * The dispose operation is called at the end of a components lifecycle.
     * This method will be called after Startable.stop() method (if implemented
     * by component). Components use this method to release and destroy any
     * resources that the Component owns.
     */
    public void dispose()
	{
		disposed = true;
		m_context = null;
		m_componentManager = null;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -