//----------------------------BEGIN LICENSE----------------------------
/*
* Willow : the Open Source WorkFlow Project
* Distributable under GNU LGPL license by gun.org
*
* Copyright (C) 2004-2010 huihoo.org
* Copyright (C) 2004-2010 ZosaTapo <dertyang@hotmail.com>
*
* ====================================================================
* Project Homepage : http://www.huihoo.org/willow
* Source Forge : http://sourceforge.net/projects/huihoo
* Mailing list : willow@lists.sourceforge.net
*/
//----------------------------END LICENSE-----------------------------
package org.huihoo.willow.store;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.huihoo.willow.Engine;
import org.huihoo.willow.Lifecycle;
import org.huihoo.willow.LifecycleException;
import org.huihoo.willow.LifecycleListener;
import org.huihoo.willow.Logger;
import org.huihoo.willow.util.LifecycleSupport;
import org.huihoo.willow.util.StringManager;
import org.huihoo.workflow.store.RealmDatabase;
import org.huihoo.workflow.usermodel.WorkflowParticipant;
import org.huihoo.workflow.impl.usermodel.WorkflowParticipantImpl;
import com.zosatapo.commons.store.Store;
/**
* @author reic
*
* To change the template for this generated type comment go to
* Window - Preferences - Java - Code Generation - Code and Comments
*/
public class NoneRealmDatabase implements RealmDatabase, Lifecycle
{
private static Log log = LogFactory.getLog(UserDatabaseRealm.class);
//----------------------------------------------------- Instance Variables
/**
* The Engine with which this RealmDatabase is associated.
*/
protected Engine engine = null;
/**
* The debugging detail level for this component.
*/
protected int debug = 0;
protected Store store;
/**
* Descriptive information about this RealmDatabase implementation.
*/
protected static final String info = "org.huihoo.willow.store.UserDatabaseRealm/1.0";
/**
* The lifecycle event support for this component.
*/
protected LifecycleSupport lifecycle = new LifecycleSupport(this);
/**
* The string manager for this package.
*/
protected static StringManager sm = StringManager.getManager(Constants.PACKAGE);
/**
* Has this component been started?
*/
protected boolean started = false;
/**
* The property change support for this component.
*/
protected PropertyChangeSupport support = new PropertyChangeSupport(this);
//------------------------------------------------------------- Properties
/**
* Return the Engine with which this Realm has been associated.
*/
public Engine getEngine()
{
return (engine);
}
/**
* Set the Provider with which this Realm has been associated.
*
* @param engine The associated this
*/
public void setEngine(Engine engine)
{
Engine oldEngine = this.engine;
this.engine = engine;
support.firePropertyChange("engine", oldEngine, this.engine);
}
/**
* Return the debugging detail level for this component.
*/
public int getDebug()
{
return (this.debug);
}
/**
* Set the debugging detail level for this component.
*
* @param debug The new debugging detail level
*/
public void setDebug(int debug)
{
this.debug = debug;
}
//------------------------------------------------------------------------------------
// Store utilities
//------------------------------------------------------------------------------------
public Store getStore()
{
return this.store;
}
public void setStore(Store store)
{
this.store=store;
}
/**
* Return descriptive information about this Realm implementation and
* the corresponding version number, in the format
* <code><description>/<version></code>.
*/
public String getInfo()
{
return info;
}
// --------------------------------------------------------- Public Methods
public WorkflowParticipant authenticate(String username, String credentials)
{
// Construct a GenericPrincipal that represents this user
if (debug >= 2)
{
log(sm.getString("userDatabaseRealm.authenticateSuccess", username));
}
return new WorkflowParticipantImpl(null,username,null,credentials,null);
}
/**
* Add a property change listener to this component.
*
* @param listener The listener to add
*/
public void addPropertyChangeListener(PropertyChangeListener listener)
{
support.addPropertyChangeListener(listener);
}
/**
* Remove a property change listener from this component.
*
* @param listener The listener to remove
*/
public void removePropertyChangeListener(PropertyChangeListener listener)
{
support.removePropertyChangeListener(listener);
}
// ------------------------------------------------------ Lifecycle Methods
/**
* Add a lifecycle event listener to this component.
*
* @param listener The listener to add
*/
public void addLifecycleListener(LifecycleListener listener)
{
lifecycle.addLifecycleListener(listener);
}
/**
* Get the lifecycle listeners associated with this lifecycle. If this
* Lifecycle has no listeners registered, a zero-length array is returned.
*/
public LifecycleListener[] findLifecycleListeners()
{
return lifecycle.findLifecycleListeners();
}
/**
* Remove a lifecycle event listener from this component.
*
* @param listener The listener to remove
*/
public void removeLifecycleListener(LifecycleListener listener)
{
lifecycle.removeLifecycleListener(listener);
}
/**
* Prepare for the beginning of active use of the public methods of this
* component. This method should be called before any of the public
* methods of this component are utilized. It should also send a
* LifecycleEvent of type START_EVENT to any registered listeners.
*
* @exception LifecycleException if this component detects a fatal error
* that prevents this component from being used
*/
public void start() throws LifecycleException
{
// Validate and update our current component state
if (started)
{
log.info(sm.getString("userdatabaseRealm.alreadyStarted"));
return;
}
lifecycle.fireLifecycleEvent(START_EVENT, null);
started = true;
}
/**
* Gracefully terminate the active use of the public methods of this
* component. This method should be the last one called on a given
* instance of this component. It should also send a LifecycleEvent
* of type STOP_EVENT to any registered listeners.
*
* @exception LifecycleException if this component detects a fatal error
* that needs to be reported
*/
public void stop() throws LifecycleException
{
// Validate and update our current component state
if (!started)
{
log.info(sm.getString("userdatabaseRealm.notStarted"));
return;
}
lifecycle.fireLifecycleEvent(STOP_EVENT, null);
started = false;
}
protected Logger getLogger()
{
return engine.getLogger();
}
/**
* Log a message on the Logger associated with our Engine (if any)
*
* @param message Message to be logged
*/
protected void log(String message)
{
Logger logger = getLogger();
String localName = "NoneRealmDatabase";
if (logger != null)
{
logger.log(localName + " " + message);
}
else
{
System.out.println(localName + " " + message);
}
}
}