Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: de/danet/an/staffmgmt/resource/StaffMgmtResourceManagementServiceFactory.java


1   /*
2    * This file is part of the WfMCore/WfMOpen project.
3    * Copyright (C) 2001-2003 Danet GmbH (www.danet.de), GS-AN.
4    * All rights reserved.
5    *
6    * This program is free software; you can redistribute it and/or modify
7    * it under the terms of the GNU General Public License as published by
8    * the Free Software Foundation; either version 2 of the License, or
9    * (at your option) any later version.
10   *
11   * This program is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   * GNU General Public License for more details.
15   *
16   * You should have received a copy of the GNU General Public License
17   * along with this program; if not, write to the Free Software
18   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19   *
20   * $Id: StaffMgmtResourceManagementServiceFactory.java,v 1.16 2003/06/27 08:51:47 lipp Exp $
21   *
22   * $Log: StaffMgmtResourceManagementServiceFactory.java,v $
23   * Revision 1.16  2003/06/27 08:51:47  lipp
24   * Fixed copyright/license information.
25   *
26   * Revision 1.15  2003/05/23 15:42:41  lipp
27   * Fixed deployment unit dependencies.
28   *
29   * Revision 1.14  2003/04/25 14:50:59  lipp
30   * Fixed javadoc errors and warnings.
31   *
32   * Revision 1.13  2002/12/19 21:37:43  lipp
33   * Reorganized interfaces.
34   *
35   * Revision 1.12  2002/06/27 10:54:17  lipp
36   * Moved attributes to base class.
37   *
38   * Revision 1.11  2002/06/24 17:29:12  lipp
39   * Fixed resource path.
40   *
41   * Revision 1.10  2002/01/09 11:53:01  lipp
42   * Clarified documentation.
43   *
44   * Revision 1.9  2001/12/18 13:22:28  robert
45   * JavaDoc
46   *
47   * Revision 1.8  2001/12/17 19:56:03  lipp
48   * Implementation of equality checking improved.
49   *
50   * Revision 1.7  2001/12/17 12:14:04  lipp
51   * Adapted to configurable ResourceManagement/AssignmentServices.
52   *
53   * Revision 1.6  2001/12/17 10:52:41  lipp
54   * Merged changes.
55   *
56   * Revision 1.5  2001/12/17 10:14:54  robert
57   * User preferences service implemented.
58   *
59   * Revision 1.4  2001/12/17 08:44:19  lipp
60   * Added configurable resource assignment service.
61   *
62   * Revision 1.3  2001/12/13 16:19:59  robert
63   * Temporary test method for resource management service.
64   *
65   * Revision 1.2  2001/12/06 14:07:15  robert
66   * removes newInstance
67   *
68   * Revision 1.1  2001/12/05 13:49:28  robert
69   * initial version
70   *
71   * Revision 1.2  2001/11/30 11:43:26  lipp
72   * javadoc fixes.
73   *
74   * Revision 1.1  2001/11/27 18:26:42  lipp
75   * Resource handling redesigned.
76   *
77   */
78  package de.danet.an.staffmgmt.resource;
79  
80  import java.io.IOException;
81  import java.io.InputStream;
82  import java.io.Serializable;
83  
84  import java.util.Properties;
85  
86  import java.rmi.RemoteException;
87  
88  import javax.ejb.CreateException;
89  import javax.naming.NamingException;
90  
91  import de.danet.an.util.EJBUtil;
92  
93  import de.danet.an.staffmgmt.domain.StaffDirectory;
94  import de.danet.an.staffmgmt.ejbs.StaffDirectoryHome;
95  import de.danet.an.workflow.spis.rms.FactoryConfigurationError;
96  import de.danet.an.workflow.spis.rms.ResourceManagementService;
97  import de.danet.an.workflow.spis.rms.ResourceManagementServiceFactory;
98  
99  /**
100  * Implements the factory API that enables a workflow component to
101  * obtain a workflow resource management service.
102  *
103  * Usage of this class as service factory requires an additional
104  * configuration parameter. The service factory implementation needs to
105  * connect to the staff management EJBs. In order to do so, it needs a
106  * JNDI name to look up the home interface. As JNDI names must be changeable
107  * by the application deployer, the name can't be hard coded.<P>
108  *
109  * This factory therefore uses the following ordered lookup procedure 
110  * to determine the JNDI name of the staff management EJB home interface:
111  * <ul>
112  *   <li>Look for a name in
113  *   <code>java:comp/env/de.danet.an.staffmgmt.resource.staffDirectory</code>. 
114  *     The configuration for
115  *     <code>StaffMgmtResourceManagementServiceFactory</code> using 
116  *     this mechanism thus looks like:
117  * <PRE>&lt;env-entry&gt;
118  *   &lt;description&gt;Configure the chosen factory&lt;/description&gt;
119  *   &lt;env-entry-name&gt;de.danet.an.staffmgmt.resource.staffDirectory&lt;/env-entry-name&gt;
120  *   &lt;env-entry-type&gt;java.lang.String&lt;/env-entry-type&gt;
121  *   &lt;env-entry-value&gt;<i>JNDI name of staff directory EJB home</i>&lt;/env-entry-value&gt;
122  * &lt;/env-entry&gt;</PRE>
123  *     Note that this environment entry must be inserted in the
124  *     <code>ejb-jar.xml</code> or <code>web.xml</code> for every EJB
125  *     resp. servlet that calls the
126  *     {@link de.danet.an.workflow.spis.rms.ResourceManagementServiceFactory#newInstance
127  *     <code>newInstance</code>} method of 
128  *     <code>ResourceManagementServiceFactory</code>.</li>
129  *
130  *   <li>Find the application resource file 
131  *     <code>de.danet.an.staffmgmt-rms.properties</code>
132  *     and look for an entry "<code>staffDirectory
133  *     = <i>JNDI name of assignment service EJB home</i></code>".</li>
134  *
135  *   <li>Use the fallback JNDI name
136  *     <code>de.danet.an.staffmgmt.StaffDirectory</code>.</li>
137  * </ul>
138  */
139 public class StaffMgmtResourceManagementServiceFactory 
140     extends ResourceManagementServiceFactory implements Serializable {
141     
142     /** The staff directory home passed to service instances. */
143     private StaffDirectory sd = null;
144 
145     /** The home interface name of the staff management service. */
146     private static String homeName = null;
147 
148     /**
149      * Constructor, called by the {@link
150      * ResourceManagementServiceFactory#newInstance
151      * <code>newInstance</code>} method of
152      * <code>ResourceManagementServiceFactory</code>.
153      * @throws FactoryConfigurationError if the required resources cannot 
154      * be found.
155      */
156     public StaffMgmtResourceManagementServiceFactory ()
157   throws FactoryConfigurationError {
158   // get home name
159   if (homeName == null) {
160       homeName = findHomeName();
161   }
162   // Lookup staff management service home JNDI name in JNDI
163   try {
164       StaffDirectoryHome sdh = (StaffDirectoryHome)EJBUtil.lookupEJBHome
165     (StaffDirectoryHome.class, homeName);
166       sd = sdh.create ();
167   } catch (NamingException nex) {
168       throw new FactoryConfigurationError 
169     ("StaffDirectory home not bound: " + nex.getMessage());
170   } catch (CreateException cex) {
171       throw new FactoryConfigurationError 
172     ("Cannot create StaffDirectoryEJB: " + cex.getMessage());
173   } catch (RemoteException rex) {
174       throw new FactoryConfigurationError 
175     ("Cannot create StaffDirectoryEJB: " + rex.getMessage());
176   }
177     }
178 
179     /**
180      * Tries to find the name of the staff management service home interface
181      * as described {@link StaffMgmtResourceManagementServiceFactory
182      * for the class}.
183      */
184     private static String findHomeName () {
185   String home = null;
186   try {
187       home = (String)EJBUtil.lookupJNDIEntry
188     ("java:comp/env/de.danet.an.staffmgmt.resource"
189      + ".staffDirectory");
190       return home;
191   } catch (NamingException ne) {
192       // Name not defined
193   }
194   // try properties
195   try {
196       InputStream is = StaffMgmtResourceManagementServiceFactory.class
197     .getResourceAsStream
198     ("/de.danet.an.staffmgmt-rms.properties");
199       if (is != null) {
200     Properties props = new Properties();
201     props.load (is);
202     home = props.getProperty("staffDirectory");
203     if (home != null) {
204         return home;
205     }
206       }
207   } catch (IOException ioe) {
208   } 
209   // fallback
210   return "de.danet.an.staffmgmt.StaffDirectory";
211     }
212     
213     /* Comment copied from interface. */
214     public ResourceManagementService newResourceManagementService ()
215   throws FactoryConfigurationError {
216   if (getResourceAssignmentService() == null) {
217       throw new FactoryConfigurationError
218     ("Resource assignment service not configured.");
219   }
220   return new StaffMgmtResourceManagementService
221       (sd, getResourceAssignmentService());
222     }
223 
224     /**
225      * Two resource management service factories are equal if they are
226      * identically configured.
227      *
228      * @param obj the factory to compare with.
229      * @return <code>true</code> if the objects are equal.
230      */
231     public boolean equals (Object obj) {
232   StaffMgmtResourceManagementServiceFactory other
233       = (StaffMgmtResourceManagementServiceFactory)obj;
234   return (getResourceAssignmentService() 
235     .equals (other.getResourceAssignmentService()));
236     }
237 
238     /**
239      * Generate a hash code.
240      *
241      * @return the hash code.
242      */
243     public int hashCode () {
244   return homeName.hashCode();
245     }
246 }
247     
248