Package de.danet.an.xformstool.portletapp

Source Code of de.danet.an.xformstool.portletapp.WorkflowServiceConnection

/*
* 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: WorkflowServiceConnection.java 2062 2006-12-12 14:22:10Z drmlipp $
*
* $Log$
* Revision 1.5.2.1  2006/12/05 14:18:42  drmlipp
* Initial display working.
*
* Revision 1.5  2006/10/22 20:13:30  mlipp
* Added preferences for workflow service.
*
* Revision 1.4  2006/09/29 12:32:12  drmlipp
* Consistently using WfMOpen as projct name now.
*
* Revision 1.3  2006/09/27 12:49:14  drmlipp
* Removed specific configurability (done using JNDI environement entries).
*
* Revision 1.2  2006/09/26 16:12:45  drmlipp
* Made JNDI configurable.
*
* Revision 1.1  2006/09/21 11:52:00  drmlipp
* Added editor.
*
* Revision 1.3  2005/11/07 14:36:11  drmlipp
* Adapted to revised request attribute handling.
*
* Revision 1.2  2005/10/14 12:45:35  drmlipp
* Added information.
*
* Revision 1.1  2005/09/28 15:11:00  drmlipp
* Optimized and simplified.
*
* Revision 1.4  2005/09/16 15:06:51  drmlipp
* Fixed typo.
*
* Revision 1.3  2005/06/22 15:14:27  drmlipp
* Improved lifecycle handling.
*
* Revision 1.2  2005/05/11 15:17:40  drmlipp
* Changed scope to session.
*
* Revision 1.1  2005/05/11 14:28:07  drmlipp
* Started JSF utility package.
*
*/
package de.danet.an.xformstool.portletapp;

import java.io.Serializable;
import java.util.Hashtable;

import javax.faces.context.FacesContext;
import javax.faces.el.EvaluationException;
import javax.naming.Context;
import javax.portlet.PortletRequest;

import de.danet.an.util.ResourceNotAvailableException;
import de.danet.an.workflow.api.FactoryConfigurationError;
import de.danet.an.workflow.api.WorkflowService;
import de.danet.an.workflow.api.WorkflowServiceFactory;

/**
* This class implements a managed bean that holds the connection to the
* workflow service.
*/
public class WorkflowServiceConnection implements Serializable {

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

    private transient WorkflowService wfs = null;

    /**
     * Create a new instance initializing all attributes to default values.
     */
    public WorkflowServiceConnection() {
        if (logger.isDebugEnabled()) {
            logger.debug ("Created managed bean");
        }
    }

    /**
     * Utility function to get the workflow engine.
     * @return the workflow engine stub.
     * @throws ResourceNotAvailableException if the engine is not available.
     */
    public WorkflowService getWorkflowService()  throws EvaluationException {
  try {
      if (wfs == null) {
          if (logger.isDebugEnabled()) {
              logger.debug ("Creating connection to workflow service");
          }
                // Get workflow service
                WorkflowServiceFactory wfsf
                    = WorkflowServiceFactory.newInstance ();
                Object req = FacesContext.getCurrentInstance()
                    .getExternalContext().getRequest();
                if (req instanceof PortletRequest) {
                    String wejn = ((PortletRequest)req).getPreferences()
                        .getValue("workflowEngineJndiName", "");
                    if (wejn != null && wejn.length() > 0) {
                        wfsf.setProperty("de.danet.an.workflow.engine", wejn);
                    }
                    String icf = ((PortletRequest)req).getPreferences()
                        .getValue("initialContextFactory", "");
                    String icu = ((PortletRequest)req).getPreferences()
                        .getValue("initialContextUrl", "");
                    if (icf != null && icf.length() > 0
                        || icu != null && icu.length() > 0) {
                        Hashtable env = new Hashtable ();
                        if (icf != null && icf.length() > 0) {
                            env.put(Context.INITIAL_CONTEXT_FACTORY, icf);
                        }
                        if (icu != null && icu.length() > 0) {
                            env.put(Context.PROVIDER_URL, icu);
                        }
                        wfsf.setProperty
                            ("javax.naming.InitialContext.Environment", env);
                    }
                }
                wfs = wfsf.newWorkflowService();
      }
      return wfs;
  } catch (FactoryConfigurationError e) {
      logger.error (e.getMessage(), e);
      throw new EvaluationException (e.getMessage());
  }
    }

    /**
     * Convenience method to get an instance of this bean.
     */
    public static WorkflowServiceConnection instance (String beanName)
        throws EvaluationException {
        FacesContext fc = FacesContext.getCurrentInstance();
        return (WorkflowServiceConnection)
                fc.getApplication().getVariableResolver()
                .resolveVariable(fc, beanName);
    }
}
TOP

Related Classes of de.danet.an.xformstool.portletapp.WorkflowServiceConnection

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.