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: ResourceAssignmentServiceFactory.java,v 1.4 2006/09/29 12:32:07 drmlipp Exp $
021: *
022: * $Log: ResourceAssignmentServiceFactory.java,v $
023: * Revision 1.4 2006/09/29 12:32:07 drmlipp
024: * Consistently using WfMOpen as projct name now.
025: *
026: * Revision 1.3 2005/11/30 22:30:08 mlipp
027: * Merged changes from 1.3.3p2.
028: *
029: * Revision 1.2.4.1 2005/11/24 09:54:21 drmlipp
030: * Improved exception messages.
031: *
032: * Revision 1.2 2004/09/15 07:29:53 drmlipp
033: * Fixed name used in JNDI lookup.
034: *
035: * Revision 1.1.1.1 2003/06/30 20:05:17 drmlipp
036: * Initial import
037: *
038: * Revision 1.3 2003/06/27 08:51:44 lipp
039: * Fixed copyright/license information.
040: *
041: * Revision 1.2 2003/04/25 14:50:58 lipp
042: * Fixed javadoc errors and warnings.
043: *
044: * Revision 1.1 2002/12/19 21:37:42 lipp
045: * Reorganized interfaces.
046: *
047: * Revision 1.15 2002/10/15 13:22:32 huaiyang
048: * Remove system.out.println and printStackTrace.
049: *
050: * Revision 1.14 2002/09/15 12:06:44 lipp
051: * Renamed ServiceLookup to ServiceMgmt.
052: *
053: * Revision 1.13 2002/08/17 11:24:36 lipp
054: * Fixed class loading.
055: *
056: * Revision 1.12 2002/01/09 14:00:01 lipp
057: * Cleaned up relation between wfcore, resource assignment and resource
058: * management service.
059: *
060: * Revision 1.11 2002/01/09 11:53:01 lipp
061: * Clarified documentation.
062: *
063: * Revision 1.10 2001/12/17 10:51:25 lipp
064: * Improved comment.
065: *
066: * Revision 1.9 2001/12/17 09:15:50 lipp
067: * Javadoc fixes.
068: *
069: * Revision 1.8 2001/12/17 08:43:58 lipp
070: * Added configurable resource management service.
071: *
072: * Revision 1.7 2001/12/16 21:48:57 lipp
073: * addAssignment implemented.
074: *
075: * Revision 1.6 2001/12/16 10:36:28 lipp
076: * Optimized.
077: *
078: * Revision 1.5 2001/12/12 14:11:45 lipp
079: * Added environment lookup.
080: *
081: * Revision 1.4 2001/12/09 20:42:16 lipp
082: * Coment fixed / sample newInstance.
083: *
084: * Revision 1.3 2001/12/09 14:03:08 lipp
085: * Improved design of workflow/resource management interface.
086: *
087: * Revision 1.2 2001/11/30 11:43:26 lipp
088: * javadoc fixes.
089: *
090: * Revision 1.1 2001/11/27 18:26:42 lipp
091: * Resource handling redesigned.
092: *
093: */
094: package de.danet.an.workflow.spis.ras;
095:
096: import java.util.List;
097:
098: import javax.naming.NamingException;
099:
100: import de.danet.an.util.EJBUtil;
101: import de.danet.an.util.ServiceMgmt;
102:
103: /**
104: * Defines a factory API that enables the workflow component to obtain a
105: * resource assignment facility.
106: */
107: public abstract class ResourceAssignmentServiceFactory {
108:
109: /**
110: * Constructor. Must be overridden with a parameterless public
111: * constructor by derived class.
112: */
113: protected ResourceAssignmentServiceFactory() {
114: }
115:
116: /**
117: * Obtain a new instance of a
118: * <code>ResourceAssignmentServiceFactory</code>. This static method
119: * creates a new factory instance. The method uses the following
120: * ordered lookup procedure to determine the
121: * <code>ResourceAssignmentServiceFactory</code> implementation class
122: * to load:
123: * <ul>
124: * <li>If an {@link javax.naming.InitialContext initial naming context}
125: * is available, look for a a classname in
126: * <code>java:comp/env/de.danet.an.workflow.spis.ras.ResourceAssignmentServiceFactory</code>.
127: * The configuration for a class as resource assignment service
128: * thus looks like:
129: * <PRE><env-entry>
130: * <description>Configure the resource assignment factory</description>
131: * <env-entry-name>de.danet.an.workflow.spis.ras.ResourceAssignmentServiceFactory</env-entry-name>
132: * <env-entry-type>java.lang.String</env-entry-type>
133: * <env-entry-value><i>FactoryImplementationClass</i></env-entry-value>
134: * </env-entry></PRE>
135: * Note that this environment entry must be inserted in the
136: * <code>ejb-jar.xml</code> or <code>web.xml</code> for every EJB
137: * resp. servlet that calls the
138: * {@link de.danet.an.workflow.spis.ras.ResourceAssignmentServiceFactory#newInstance
139: * <code>newInstance</code>} method of
140: * <code>ResourceAssignmentServiceFactory</code>.</li>
141: *
142: * <li>Use the services API (as detailed in the JAR specification),
143: * if available, to determine the classname. The Services API
144: * will look for a classname in the file
145: * <code>META-INF/services/de.danet.an.workflow.spis.ras.ResourceAssignmentServiceFactory</code>.
146: * in jars available to the runtime.</li>
147: * </ul>
148: *
149: * @return an instance of the
150: * <code>ResourceAssignmentServiceFactory</code>.
151: * @throws FactoryConfigurationError if a factory instance can't be
152: * created.
153: */
154: public static ResourceAssignmentServiceFactory newInstance()
155: throws FactoryConfigurationError {
156: if (factoryClass == null) {
157: factoryClass = findFactoryClass();
158: }
159: try {
160: return ((ResourceAssignmentServiceFactory) factoryClass
161: .newInstance());
162: } catch (InstantiationException ie) {
163: throw new FactoryConfigurationError();
164: } catch (IllegalAccessException iae) {
165: throw new FactoryConfigurationError();
166: }
167: }
168:
169: private static Class factoryClass = null;
170:
171: private static Class findFactoryClass()
172: throws FactoryConfigurationError {
173: // Lookup in JNDI
174: String clsname = null;
175: try {
176: clsname = (String) EJBUtil
177: .lookupJNDIEntry("java:comp/env/de.danet.an.workflow.spis.ras"
178: + ".ResourceAssignmentServiceFactory");
179: ClassLoader cl = Thread.currentThread()
180: .getContextClassLoader();
181: return cl.loadClass(clsname);
182: } catch (NamingException ne) {
183: // Name not defined
184: } catch (ClassNotFoundException e) {
185: throw new FactoryConfigurationError("Class " + clsname
186: + " specified in environment not loadable: "
187: + e.getMessage());
188: }
189: // Lookup as service in JARs
190: List cls = ServiceMgmt
191: .providerClassesFromJARs(ResourceAssignmentServiceFactory.class);
192: if (cls.size() > 0) {
193: return (Class) cls.get(0);
194: }
195: throw new FactoryConfigurationError(
196: "No resource assignment service provider found");
197: }
198:
199: /**
200: * Creates a new instance of a {@link ResourceAssignmentService
201: * <code>ResourceAssignmentService</code>}.
202: *
203: * @return the resource assignment service.
204: * @throws FactoryConfigurationError if not all required resources
205: * can be obtained.
206: */
207: public abstract ResourceAssignmentService newResourceAssignmentService()
208: throws FactoryConfigurationError;
209:
210: }
|