/*
* This file is part of the WfMOpen project.
* Copyright (C) 2001-2003 Danet GmbH (www.danet.de), GS-AN.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* $Id: ActivityFinder.java 2909 2009-02-02 22:52:20Z mlipp $
*
* $Log$
* Revision 1.3 2006/09/29 12:32:10 drmlipp
* Consistently using WfMOpen as projct name now.
*
* Revision 1.2 2005/10/17 10:44:15 drmlipp
* Added serial version id.
*
* Revision 1.1.1.2 2004/08/18 15:17:38 drmlipp
* Update to 1.2
*
* Revision 1.10 2004/02/21 21:52:11 lipp
* Moved ActivityFinder and ProcessMgrStub back to admin package.
*
* Revision 1.1 2004/02/21 21:31:00 lipp
* Some more refactoring to resolve cyclic dependencies.
*
* Revision 1.8 2003/06/27 08:51:45 lipp
* Fixed copyright/license information.
*
* Revision 1.7 2003/05/02 14:55:59 lipp
* Resolved some more package dependencies.
*
* Revision 1.12 2003/04/25 14:50:58 lipp
* Fixed javadoc errors and warnings.
*
* Revision 1.11 2003/03/31 16:50:28 huaiyang
* Logging using common-logging.
*
* Revision 1.10 2002/12/19 21:37:42 lipp
* Reorganized interfaces.
*
* Revision 1.9 2002/11/26 11:23:29 lipp
* Modified RemoteException comment.
*
* Revision 1.8 2002/10/15 13:22:32 huaiyang
* Remove system.out.println and printStackTrace.
*
* Revision 1.7 2002/08/30 13:37:05 lipp
* Using Workflow engine facade now.
*
* Revision 1.6 2002/02/04 22:42:44 lipp
* Moved initProcessDefinitions and findActivity from Configuration user
* api to EJB remote interface.
*
* Revision 1.5 2002/01/26 19:17:55 lipp
* Optimized.
*
* Revision 1.4 2002/01/25 22:07:14 lipp
* Removed no longer needed code.
*
* Revision 1.3 2002/01/16 09:21:34 robert
* replace ConfigurationHome interface
* from workflow/ejbs/admin to workflow/api/ejbhomes
*
* Revision 1.2 2002/01/15 15:07:08 robert
* replace Configuration interface from workflow/domain to workflow/api
*
* Revision 1.1 2001/12/19 10:04:59 lipp
* ActivityFinder moved to ejbs/util.
*
* Revision 1.5 2001/12/18 22:58:47 lipp
* equals implementation redone.
*
* Revision 1.4 2001/12/16 21:48:11 lipp
* Fixed equals and hashCode
*
* Revision 1.3 2001/12/15 16:42:08 lipp
* Cleand up exception declaration for finder methods in home interfaces.
*
* Revision 1.2 2001/12/15 12:47:07 lipp
* Getting an ActivityFinder implemented.
*
* Revision 1.1 2001/12/14 16:05:45 lipp
* Partial implementation of ActivityFinder.
*
*/
package de.danet.an.workflow.ejbs.admin;
import java.io.IOException;
import java.io.Serializable;
import java.rmi.RemoteException;
import javax.ejb.FinderException;
import javax.ejb.Handle;
import javax.naming.NamingException;
import javax.rmi.PortableRemoteObject;
import de.danet.an.util.EJBUtil;
import de.danet.an.workflow.omgcore.WfActivity;
import de.danet.an.workflow.ejbs.admin.Configuration;
import de.danet.an.workflow.ejbs.admin.ConfigurationHome;
import de.danet.an.workflow.spis.ras.NoSuchActivityException;
/**
* The implementation of {@link
* de.danet.an.workflow.spis.ras.ActivityFinder
* <code>ActivityFinder</code>} for this workflow package.
*/
public class ActivityFinder
implements de.danet.an.workflow.spis.ras.ActivityFinder, Serializable {
/** Serial version UID. */
static final long serialVersionUID = -3457954784067616090L;
private static final org.apache.commons.logging.Log logger
= org.apache.commons.logging.LogFactory.getLog(ActivityFinder.class);
private static transient Handle handleCache = null;
private static transient String instIdCache = null;
private Handle handle = null;
private String installationId = null;
private transient Configuration conf = null;
/**
* Construct a new <code>ActivityFinder</code>. This
* implementation of <code>ActivityFinder</code> relies on the
* {@link de.danet.an.workflow.api.Configuration
* configuration EJB}. It stores this entity EJB's handle as attribute
* and uses the
* {@link de.danet.an.workflow.ejbs.admin.Configuration#findActivity
* <code>findActivity</code>} method to restore an activity in
* {@link #find <code>find</code>}. We "abuse" the configuration EJB
* for this purpose as it provides an ever lasting object.
*
* @param confHome the JNDI name (usually
* <code>java:comp/env/ejb/Configuration</code>) used to lookup the
* configuration EJB. Passing the name as parameter is not so much
* motivated by the desire for flexibility, it will rarely be anything
* but <code>java:comp/env/ejb/Configuration</code>. It should, however,
* remind the user of this constructor that an appropriate entry
* has to be made in the <code>ejb-jar.xml</code>.
*/
public ActivityFinder (String confHome) {
synchronized (ActivityFinder.class) {
if (handleCache == null || instIdCache == null) {
try {
ConfigurationHome ch
= (ConfigurationHome)EJBUtil.lookupEJBHome
(ConfigurationHome.class, confHome);
Configuration conf
= (Configuration)ch.findByPrimaryKey(new Integer(0));
// first get all data ...
Handle handle = conf.getHandle();
String installationId = conf.workflowEngineInstanceKey();
// ... now change all cached information
// (prevents incomplete initialization)
handleCache = handle;
instIdCache = installationId;
} catch (NamingException nex) {
logger.error("NamingException in calling "
+ "ActivityFinder()!");
} catch (FinderException onf) {
logger.error("FinderException in calling "
+ "ActivityFinder()!");
} catch (RemoteException rex) {
throw new RuntimeException (rex.getMessage());
} catch (IOException ioe) {
throw new RuntimeException (ioe.getMessage());
}
}
handle = handleCache;
installationId = instIdCache;
}
}
/**
* Return the activity that is associated with the given id.
* As activity ids in this implementation are unique not only
* with respect to the containing process but within the complete
* workflow engine, the implementation is rather simple.
*
* @param actId the activity id (unique in the scope of this
* <code>ActivityFinder</code>.
* @return the <code>WfActivity</code> found.
* @throws NoSuchActivityException if no activity with the given
* <code>actId</code> can be found.
* @throws RemoteException if a system-level error occurs.
*/
public WfActivity find (String actId)
throws NoSuchActivityException, RemoteException {
if (conf == null) {
conf = (Configuration)PortableRemoteObject.narrow
(handle.getEJBObject(), Configuration.class);
}
return conf.findActivity (actId);
}
/**
* Two <code>ActivityFinder</code>s are equal if the installation ids
* are identical.
*
* @param obj the object to compare with.
* @return <code>true</code> if the objects are equal.
*/
public boolean equals (Object obj) {
return installationId.equals
(((ActivityFinder)obj).installationId);
}
/**
* The hash code is the hash code of the installation id.
* @return the hash code.
*/
public int hashCode () {
return installationId.hashCode();
}
/**
* For debugging purposes only.
* @return a string representation
*/
public String toString () {
return "ActivityFinder/id=" + installationId;
}
}