Package de.danet.an.workflow.rmsimpls.dbrms

Source Code of de.danet.an.workflow.rmsimpls.dbrms.DatabaseRmsFactory

/*
* This file is part of the WfMOpen project.
* Copyright (C) 2001-2005 Danet GmbH (www.danet.de), BU BTS.
* 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: DatabaseRmsFactory.java 1753 2006-10-15 19:29:51Z mlipp $
*
* $Log$
* Revision 1.6.2.1  2006/10/14 21:34:05  mlipp
* Simplified resource assignment service implementation.
*
* Revision 1.6  2006/10/03 11:13:05  mlipp
* Improved.
*
* Revision 1.5  2006/09/29 14:01:17  drmlipp
* Improved property names.
*
* Revision 1.4  2006/09/29 12:32:11  drmlipp
* Consistently using WfMOpen as projct name now.
*
* Revision 1.3  2006/09/29 11:39:16  drmlipp
* Various fixes.
*
* Revision 1.2  2006/09/28 21:28:09  mlipp
* Implementation continued.
*
* Revision 1.1  2006/09/28 15:03:56  drmlipp
* Getting started with db RMS.
*
*/
package de.danet.an.workflow.rmsimpls.dbrms;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import javax.naming.NamingException;

import de.danet.an.util.EJBUtil;
import de.danet.an.workflow.spis.rms.FactoryConfigurationError;
import de.danet.an.workflow.spis.rms.ResourceManagementService;
import de.danet.an.workflow.spis.rms.ResourceManagementServiceFactory;

/**
* This class provides an implementaion of the factory API based on
* information obtained from a database.<P>
*
* Usage of this class as service factory requires several
* configuration parameters for accessing the database.  The
* factory uses the following ordered lookup procedure to determine
* these parameters:
*
* <ul>
*   <li>Look for parameters in JNDI. Lookup parameters in
*     <code>java:comp/env/de.danet.an.workflow.rmsimpls.dbrms.<i>parameter</i></code>.
*     The configuration for a parameter using
*     this mechanism thus looks like:
* <PRE> &lt;env-entry&gt;
*   &lt;description&gt;Configure database parameter <i>parameter</i>&lt;/description&gt;
*   &lt;env-entry-name&gt;de.danet.an.workflow.rmsimpls.dbrms.<i>parameter</i>&lt;/env-entry-name&gt;
*   &lt;env-entry-type&gt;java.lang.String&lt;/env-entry-type&gt;
*   &lt;env-entry-value&gt;<i>Value of parameter</i>&lt;/env-entry-value&gt;
* &lt;/env-entry&gt;</PRE>
*     Note that the environment entries must be inserted in the
*     <code>ejb-jar.xml</code> or <code>web.xml</code> for every EJB
*     resp. servlet that calls the
*     {@link de.danet.an.workflow.spis.rms.ResourceManagementServiceFactory#newInstance
*     <code>newInstance</code>} method of
*     <code>ResourceManagementServiceFactory</code>.</li>
*
*   <li>Find the application resource file
*     <code>de.danet.an.workflow.rmsimpls.dbrms-factory.properties</code>
*     and look for entries "<code><i>parameter</i>
*     = <i>Value of parameter</i></code>".</li>
* </ul><P>
*
* The following parameters are used:
* <dl>
*   <dt><code>dataSource</code></dt>
*   <dd>The lookup name of the data source in JNDI
*      (e.g. <code>java:/DefaultDS</code>).</dd>
*   <dt><code>allUsersQuery</code>
*   <dd>The query that returns the known users as a two column result with
*     the user's entry's primary key in the first column and the user's
*     display name in the second.</dd>
*   <dt><code>allRolesQuery</code>
*   <dd>The query that returns the known roles as a two column result with
*     the role's entry's primary key in the first column and the role's
*     display name in the second.</dd>
*   <dt><code>allGroupsQuery</code>
*   <dd>The query that returns the known groups as a two column result with
*     the group's entry's primary key in the first column and group's
*     display name in the second.</dd>
*   <dt><code>userNameQuery</code></dt>
*   <dd>The query that returns user data as a single column result with the
*     user's display name in the only column. The user's entry's primary key
*     is set as query parameter.</dd>
*   <dt><code>roleNameQuery</code></dt>
*   <dd>The query that returns role data as a single column result with the
*     role's display name in the only column. The role's entry's primary key
*     is set as query parameter.</dd>
*   <dt><code>groupNameQuery</code></dt>
*   <dd>The query that returns group data as a single column result with the
*     group's display name in the only column. The group's entry's primary key
*     is set as query parameter.</dd>
*   <dt><code>userLookupQuery</code></dt>
*   <dd>The query that returns a user's data as a two column result with the
*     user's entry's primary key in the first column and the user's display
*     name in the second. The user's account name (usually the login name) is
*     set as query parameter.</dd>
*   <dt><code>roleLookupQuery</code></dt>
*   <dd>The query that returns a role's data as a two column result with the
*     role's entry's primary key in the first column and the role's display
*     name in the second. The role's "account" name (clear text name) is set
*     as query parameter.</dd>
*   <dt><code>groupLookupQuery</code></dt>
*   <dd>The query that returns a group's data as a two column result with the
*     group's entry's primary key in the first column and the group's name
*     display in the second. The groups's "account" name (clear text name) is
*     set as query parameter.</dd>
*   <dt><code>rolesQuery</code></dt>
*   <dd>The query that returns a user's roles as a two column result with the
*     role's entry's primary key in the first column and the role's display
*     name in the second. The user's entry's primary key is set as query
*     parameter.</dd>
*   <dt><code>groupsQuery</code></dt>
*   <dd>The query that returns a user's groups as a two column result with the
*     group's entry's primary key in the first column and the group's display
*     name in the second. The user's entry's primary key is set as query
*     parameter.</dd>
* </dl><P>
*
* @author <a href="mailto:lipp@danet.de">Michael Lipp</a>
* @version $Revision: 1753 $
*/
public class DatabaseRmsFactory extends ResourceManagementServiceFactory {

    private static final org.apache.commons.logging.Log logger
        = org.apache.commons.logging.LogFactory.getLog(DatabaseRmsFactory.class);

    /**
     * Create a new instance of this factory.
     *
     * @throws FactoryConfigurationError if configuration information is
     * missing or invalid.
     */
    public DatabaseRmsFactory () throws FactoryConfigurationError {
    }

    /* Comment copied from interface. */
    public ResourceManagementService newResourceManagementService ()
  throws FactoryConfigurationError {
  if (getResourceAssignmentContext() == null) {
      throw new FactoryConfigurationError
    ("Resource assignment context not configured.");
  }

  // make fallbacks
  Properties fallbacks = new Properties ();

  // try to get properties from file
  Properties baseProps = new Properties(fallbacks);
  try {
      InputStream is = DatabaseRmsFactory.class.getResourceAsStream
    ("/de.danet.an.workflow.rmsimpls.dbrms-factory.properties");
      if (is != null) {
    baseProps.load (is);
      }
  } catch (IOException ex) {
  }

  // Overrides from JNDI
  Properties props = new Properties (baseProps);
  String[] knownProps = {
      "dataSource",
            "allUsersQuery",
            "allRolesQuery",
            "allGroupsQuery",
            "userNameQuery",
            "roleNameQuery",
            "groupNameQuery",
            "userLookupQuery",
            "roleLookupQuery",
            "groupLookupQuery",
            "rolesQuery",
            "groupsQuery"
  };
  for (int i = 0; i < knownProps.length; i++) {
      try {
    String entry = (String)EJBUtil.lookupJNDIEntry
        ("java:comp/env/de.danet.an.workflow.rmsimpls.dbrms."
                     + knownProps[i]);
    props.setProperty (knownProps[i], entry);
      } catch (NamingException ne) {
    // Name not defined
      }
  }
        for (int i = 0; i < knownProps.length; i++) {
            if (props.getProperty(knownProps[i]) == null) {
                throw new FactoryConfigurationError
                    ("Missing property: " + knownProps[i]);
            }
        }

  return new DatabaseRmsService (props, getResourceAssignmentContext());
    }   
}
TOP

Related Classes of de.danet.an.workflow.rmsimpls.dbrms.DatabaseRmsFactory

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.