001: /*
002: * This file is part of the WfMOpen project.
003: * Copyright (C) 2001-2003 Danet GmbH (www.danet.de), GS-AN.
004: * All rights reserved.
005: *
006: * This program is free software; you can redistribute it and/or modify
007: * it under the terms of the GNU General Public License as published by
008: * the Free Software Foundation; either version 2 of the License, or
009: * (at your option) any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019: *
020: * $Id: StandardResourceAssignmentServiceFactory.java,v 1.6 2006/10/15 19:29:51 mlipp Exp $
021: *
022: * $Log: StandardResourceAssignmentServiceFactory.java,v $
023: * Revision 1.6 2006/10/15 19:29:51 mlipp
024: * Merged changes from 1.4.x up to 1.4ea3pre1.
025: *
026: * Revision 1.4.2.1 2006/10/14 21:34:06 mlipp
027: * Simplified resource assignment service implementation.
028: *
029: * Revision 1.5 2006/10/09 21:29:01 mlipp
030: * Improved assignment service EJB lookup.
031: *
032: * Revision 1.4 2006/09/29 12:32:12 drmlipp
033: * Consistently using WfMOpen as projct name now.
034: *
035: * Revision 1.3 2005/06/29 08:15:21 drmlipp
036: * Improved error reporting.
037: *
038: * Revision 1.2 2004/12/20 22:27:10 drmlipp
039: * Updated JNDI names.
040: *
041: * Revision 1.1.1.2 2003/12/19 13:01:23 drmlipp
042: * Updated to 1.1rc1
043: *
044: * Revision 1.15 2003/09/08 20:59:22 lipp
045: * Javadoc fix.
046: *
047: * Revision 1.14 2003/06/27 08:51:46 lipp
048: * Fixed copyright/license information.
049: *
050: * Revision 1.13 2003/04/25 14:50:59 lipp
051: * Fixed javadoc errors and warnings.
052: *
053: * Revision 1.12 2002/12/19 21:37:43 lipp
054: * Reorganized interfaces.
055: *
056: * Revision 1.11 2002/06/27 10:55:59 lipp
057: * Delayed initialization even more.
058: *
059: * Revision 1.10 2002/01/09 14:00:01 lipp
060: * Cleaned up relation between wfcore, resource assignment and resource
061: * management service.
062: *
063: * Revision 1.9 2002/01/09 11:53:01 lipp
064: * Clarified documentation.
065: *
066: * Revision 1.8 2001/12/17 19:56:03 lipp
067: * Implementation of equality checking improved.
068: *
069: * Revision 1.7 2001/12/17 12:14:04 lipp
070: * Adapted to configurable ResourceManagement/AssignmentServices.
071: *
072: * Revision 1.6 2001/12/17 10:52:13 lipp
073: * Added configurable resource management service.
074: *
075: * Revision 1.5 2001/12/17 09:15:50 lipp
076: * Javadoc fixes.
077: *
078: * Revision 1.4 2001/12/17 08:43:58 lipp
079: * Added configurable resource management service.
080: *
081: * Revision 1.3 2001/12/16 21:48:57 lipp
082: * addAssignment implemented.
083: *
084: * Revision 1.2 2001/12/16 10:37:35 lipp
085: * Assignment service implemented.
086: *
087: * Revision 1.1 2001/12/09 20:43:57 lipp
088: * First try.
089: *
090: */
091: package de.danet.an.workflow.assignment;
092:
093: import javax.naming.NamingException;
094: import javax.sql.DataSource;
095:
096: import de.danet.an.util.EJBUtil;
097: import de.danet.an.util.ResourceNotAvailableException;
098:
099: import de.danet.an.workflow.ejbs.WorkflowEngineHome;
100: import de.danet.an.workflow.spis.ras.FactoryConfigurationError;
101: import de.danet.an.workflow.spis.ras.ResourceAssignmentService;
102: import de.danet.an.workflow.spis.ras.ResourceAssignmentServiceFactory;
103: import de.danet.an.workflow.spis.rms.ResourceAssignmentContext;
104: import de.danet.an.workflow.spis.rms.ResourceManagementServiceFactory;
105:
106: /**
107: * Implements a simple resource assignment service factory.<P>
108: *
109: * This implementation uses an instance of {@link
110: * de.danet.an.workflow.spis.rms.ResourceManagementService
111: * <code>ResourceManagementService</code>} to access a resource
112: * management facility. To obtain the service it calls the {@link
113: * de.danet.an.workflow.spis.rms.ResourceManagementServiceFactory#newInstance
114: * <code>newInstance</code>} method of {@link
115: * de.danet.an.workflow.spis.rms.ResourceManagementServiceFactory
116: * <code>ResourceManagementServiceFactory</code>}. Thus if this
117: * factory (<code>StandardResourceAssignmentServiceFactory</code>) is
118: * configured as resource assignment service factory, all
119: * configuration information required by
120: * <code>ResourceManagementServiceFactory.newInstance</code> (and by
121: * the actually configured resource management service factory
122: * implementation) must be available when the {@link
123: * de.danet.an.workflow.spis.ras.ResourceAssignmentServiceFactory#newInstance
124: * <code>newInstance</code>} method of
125: * <code>ResourceAssignmentServiceFactory</code> is called.
126: */
127: public class StandardResourceAssignmentServiceFactory extends
128: ResourceAssignmentServiceFactory {
129:
130: /** Database name */
131: private static final String DB_NAME = "java:comp/env/jdbc/WfEngine";
132:
133: /** Database name */
134: private static final String ENGINE_NAME = "java:comp/env/ejb/WorkflowEngine";
135:
136: /** The configured resource management factory. */
137: private ResourceManagementServiceFactory rmsf = null;
138:
139: /**
140: * Constructor.
141: *
142: * @throws FactoryConfigurationError if the required resources cannot
143: * be obtained.
144: */
145: public StandardResourceAssignmentServiceFactory()
146: throws FactoryConfigurationError {
147: // obtain base resource management service factory
148: try {
149: rmsf = ResourceManagementServiceFactory.newInstance();
150: } catch (de.danet.an.workflow.spis.rms.FactoryConfigurationError e) {
151: throw (FactoryConfigurationError) (new FactoryConfigurationError(
152: "Required ResourceManagementServiceFactory not configured "
153: + "properly: " + e.getMessage()))
154: .initCause(e);
155: }
156: }
157:
158: /* Comment copied from interface. */
159: public ResourceAssignmentService newResourceAssignmentService()
160: throws FactoryConfigurationError {
161: if (rmsf == null) {
162: throw new FactoryConfigurationError(
163: "Resource management service factory not configured.");
164: }
165: ResourceAssignmentContext rasCtx = null;
166: try {
167: rasCtx = (ResourceAssignmentContext) EJBUtil.createSession(
168: WorkflowEngineHome.class, ENGINE_NAME);
169: } catch (ResourceNotAvailableException e) {
170: throw (FactoryConfigurationError) (new FactoryConfigurationError(
171: "Required WorkflowEngine EJB not available: "
172: + e.getMessage())).initCause(e);
173:
174: }
175: DataSource ds = null;
176: try {
177: ds = (DataSource) EJBUtil.lookupJNDIEntry(DB_NAME);
178: } catch (NamingException e) {
179: throw (FactoryConfigurationError) (new FactoryConfigurationError(
180: "Required datasource available: " + e.getMessage()))
181: .initCause(e);
182:
183: }
184: return new StandardResourceAssignmentService(rmsf, rasCtx, ds);
185: }
186:
187: /**
188: * Two resource assignment service factories are equal if they are
189: * identically configured.
190: *
191: * @param obj the factory to compare with.
192: * @return <code>true</code> if the objects are equal.
193: */
194: public boolean equals(Object obj) {
195: StandardResourceAssignmentServiceFactory other = (StandardResourceAssignmentServiceFactory) obj;
196: return (rmsf == other.rmsf);
197: }
198:
199: /**
200: * Generate a hash code.
201: *
202: * @return the hash code.
203: */
204: public int hashCode() {
205: return 1;
206: }
207: }
|