/*
* 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: StandardResourceAssignmentServiceFactory.java 2548 2007-10-22 14:00:52Z $
*
* $Log$
* Revision 1.4.2.1 2006/10/14 21:34:06 mlipp
* Simplified resource assignment service implementation.
*
* Revision 1.5 2006/10/09 21:29:01 mlipp
* Improved assignment service EJB lookup.
*
* Revision 1.4 2006/09/29 12:32:12 drmlipp
* Consistently using WfMOpen as projct name now.
*
* Revision 1.3 2005/06/29 08:15:21 drmlipp
* Improved error reporting.
*
* Revision 1.2 2004/12/20 22:27:10 drmlipp
* Updated JNDI names.
*
* Revision 1.1.1.2 2003/12/19 13:01:23 drmlipp
* Updated to 1.1rc1
*
* Revision 1.15 2003/09/08 20:59:22 lipp
* Javadoc fix.
*
* Revision 1.14 2003/06/27 08:51:46 lipp
* Fixed copyright/license information.
*
* Revision 1.13 2003/04/25 14:50:59 lipp
* Fixed javadoc errors and warnings.
*
* Revision 1.12 2002/12/19 21:37:43 lipp
* Reorganized interfaces.
*
* Revision 1.11 2002/06/27 10:55:59 lipp
* Delayed initialization even more.
*
* Revision 1.10 2002/01/09 14:00:01 lipp
* Cleaned up relation between wfcore, resource assignment and resource
* management service.
*
* Revision 1.9 2002/01/09 11:53:01 lipp
* Clarified documentation.
*
* Revision 1.8 2001/12/17 19:56:03 lipp
* Implementation of equality checking improved.
*
* Revision 1.7 2001/12/17 12:14:04 lipp
* Adapted to configurable ResourceManagement/AssignmentServices.
*
* Revision 1.6 2001/12/17 10:52:13 lipp
* Added configurable resource management service.
*
* Revision 1.5 2001/12/17 09:15:50 lipp
* Javadoc fixes.
*
* Revision 1.4 2001/12/17 08:43:58 lipp
* Added configurable resource management service.
*
* Revision 1.3 2001/12/16 21:48:57 lipp
* addAssignment implemented.
*
* Revision 1.2 2001/12/16 10:37:35 lipp
* Assignment service implemented.
*
* Revision 1.1 2001/12/09 20:43:57 lipp
* First try.
*
*/
package de.danet.an.workflow.assignment;
import javax.naming.NamingException;
import javax.sql.DataSource;
import de.danet.an.util.EJBUtil;
import de.danet.an.util.ResourceNotAvailableException;
import de.danet.an.workflow.ejbs.WorkflowEngineHome;
import de.danet.an.workflow.spis.ras.FactoryConfigurationError;
import de.danet.an.workflow.spis.ras.ResourceAssignmentService;
import de.danet.an.workflow.spis.ras.ResourceAssignmentServiceFactory;
import de.danet.an.workflow.spis.rms.ResourceAssignmentContext;
import de.danet.an.workflow.spis.rms.ResourceManagementServiceFactory;
/**
* Implements a simple resource assignment service factory.<P>
*
* This implementation uses an instance of {@link
* de.danet.an.workflow.spis.rms.ResourceManagementService
* <code>ResourceManagementService</code>} to access a resource
* management facility. To obtain the service it calls the {@link
* de.danet.an.workflow.spis.rms.ResourceManagementServiceFactory#newInstance
* <code>newInstance</code>} method of {@link
* de.danet.an.workflow.spis.rms.ResourceManagementServiceFactory
* <code>ResourceManagementServiceFactory</code>}. Thus if this
* factory (<code>StandardResourceAssignmentServiceFactory</code>) is
* configured as resource assignment service factory, all
* configuration information required by
* <code>ResourceManagementServiceFactory.newInstance</code> (and by
* the actually configured resource management service factory
* implementation) must be available when the {@link
* de.danet.an.workflow.spis.ras.ResourceAssignmentServiceFactory#newInstance
* <code>newInstance</code>} method of
* <code>ResourceAssignmentServiceFactory</code> is called.
*/
public class StandardResourceAssignmentServiceFactory
extends ResourceAssignmentServiceFactory {
/** Database name */
private static final String DB_NAME = "java:comp/env/jdbc/WfEngine";
/** Database name */
private static final
String ENGINE_NAME = "java:comp/env/ejb/WorkflowEngine";
/** The configured resource management factory. */
private ResourceManagementServiceFactory rmsf = null;
/**
* Constructor.
*
* @throws FactoryConfigurationError if the required resources cannot
* be obtained.
*/
public StandardResourceAssignmentServiceFactory ()
throws FactoryConfigurationError {
// obtain base resource management service factory
try {
rmsf = ResourceManagementServiceFactory.newInstance();
} catch (de.danet.an.workflow.spis.rms.FactoryConfigurationError e) {
throw (FactoryConfigurationError)
(new FactoryConfigurationError
("Required ResourceManagementServiceFactory not configured "
+ "properly: " + e.getMessage())).initCause(e);
}
}
/* Comment copied from interface. */
public ResourceAssignmentService newResourceAssignmentService ()
throws FactoryConfigurationError {
if (rmsf == null) {
throw new FactoryConfigurationError
("Resource management service factory not configured.");
}
ResourceAssignmentContext rasCtx = null;
try {
rasCtx = (ResourceAssignmentContext)EJBUtil.createSession
(WorkflowEngineHome.class, ENGINE_NAME);
} catch (ResourceNotAvailableException e) {
throw (FactoryConfigurationError)
(new FactoryConfigurationError
("Required WorkflowEngine EJB not available: "
+ e.getMessage())).initCause(e);
}
DataSource ds = null;
try {
ds = (DataSource)EJBUtil.lookupJNDIEntry(DB_NAME);
} catch (NamingException e) {
throw (FactoryConfigurationError)
(new FactoryConfigurationError
("Required datasource available: " + e.getMessage()))
.initCause(e);
}
return new StandardResourceAssignmentService(rmsf, rasCtx, ds);
}
/**
* Two resource assignment service factories are equal if they are
* identically configured.
*
* @param obj the factory to compare with.
* @return <code>true</code> if the objects are equal.
*/
public boolean equals (Object obj) {
StandardResourceAssignmentServiceFactory other
= (StandardResourceAssignmentServiceFactory)obj;
return (rmsf == other.rmsf);
}
/**
* Generate a hash code.
*
* @return the hash code.
*/
public int hashCode () {
return 1;
}
}