|
From: <tr...@us...> - 2003-08-27 03:15:34
|
Update of /cvsroot/babeldoc/babeldoc/modules/j2ee/src/com/babeldoc/j2ee
In directory sc8-pr-cvs1:/tmp/cvs-serv27662/src/com/babeldoc/j2ee
Added Files:
BaseSessionBean.java ServiceLocator.java
Log Message:
Re-adding of the J2ee module. THe most you can say about this is that it compiles.
--- NEW FILE: BaseSessionBean.java ---
/*
* $Header: /cvsroot/babeldoc/babeldoc/modules/j2ee/src/com/babeldoc/j2ee/BaseSessionBean.java,v 1.1 2003/08/27 03:15:30 triphop Exp $
* $DateTime: 2002/07/21 17:01:20 $
*
*
* babeldoc: universal document processor
* Copyright (C) 2002 Bruce McDonald, Elogex Inc.
*
* 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.
*/
package com.babeldoc.j2ee;
import java.rmi.RemoteException;
import javax.ejb.EJBException;
import javax.ejb.CreateException;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
/**
* Implementation of the SessionBean interface. Acts a rundimentary
* parent class to concrete classes in babel.
*
* <p>Title: Babel</p>
* <p>Description: Universal Document Processor</p>
* <p>Copyright: Copyright (c) 2002</p>
* @author Bmcdonald
* @version 1.0
*/
public class BaseSessionBean
implements SessionBean {
/**
* Session context - set by container.
*/
protected SessionContext sessionCtx = null;
/**
* Null implementation.
*
* @throws EJBException
* @throws RemoteException
*/
public void ejbCreate()
throws CreateException, RemoteException {
}
/**
* Null implementation.
*
* @throws EJBException
* @throws RemoteException
*/
public void ejbActivate()
throws EJBException, RemoteException {
}
/**
* Null implementation.
*
* @throws EJBException
* @throws RemoteException
*/
public void ejbPassivate()
throws EJBException, RemoteException {
}
/**
* Null implementation.
*
* @throws EJBException
* @throws RemoteException
*/
public void ejbRemove()
throws EJBException, RemoteException {
}
/**
* Set the session context
*
* @param sessionContext the context argument.
*
* @throws EJBException
* @throws RemoteException
*/
public void setSessionContext(SessionContext sessionContext)
throws EJBException, RemoteException {
sessionCtx = sessionContext;
}
}
--- NEW FILE: ServiceLocator.java ---
/*
* Copyright 2002 Sun Microsystems, Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistribution in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* Neither the name of Sun Microsystems, Inc. or the names of
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* This software is provided "AS IS," without a warranty of any
* kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
* WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
* EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES
* SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
* DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN
* OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR
* FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR
* PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF
* LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE SOFTWARE,
* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
*
* You acknowledge that Software is not designed, licensed or intended
* for use in the design, construction, operation or maintenance of
* any nuclear facility.
*/
package com.babeldoc.j2ee;
import com.babeldoc.core.GeneralException;
import com.babeldoc.core.LogService;
import java.util.HashMap;
import java.util.Map;
import java.util.Collections;
import java.util.Hashtable;
import java.net.URL;
import javax.ejb.EJBHome;
import javax.ejb.EJBLocalHome;
import javax.jms.QueueConnectionFactory;
import javax.jms.Queue;
import javax.jms.TopicConnectionFactory;
import javax.jms.Topic;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.naming.Context;
import javax.rmi.PortableRemoteObject;
import javax.sql.DataSource;
/**
* This class is an implementation of the Service Locator pattern. It is
* used to looukup resources such as EJBHomes, JMS Destinations, etc.
* This implementation uses the "singleton" strategy and also the "caching"
* strategy.
* This implementation is intended to be used on the web tier and
* not on the ejb tier.
*/
public class ServiceLocator {
private InitialContext ic;
private Map cache; //used to hold references to EJBHomes/JMS Resources for re-use
private static ServiceLocator global;
/**
* Get the global service locator - this is the service locator with not factory
* or url provided explicitly
*
* @return existing (or created new) global service locator
*/
public static synchronized ServiceLocator getGlobal() {
if(global==null) {
try {
global = new ServiceLocator();
} catch (GeneralException e) {
LogService.getInstance().logError(e);
}
}
return global;
}
/**
* Private constructor - setup the cache and the initial context.
*
* @throws GeneralException
*/
public ServiceLocator() throws GeneralException {
try {
ic = new InitialContext();
cache = Collections.synchronizedMap(new HashMap());
} catch (NamingException ne) {
throw new GeneralException("", ne);
} catch (Exception e) {
throw new GeneralException("", e);
}
}
/**
* Private constructor - setup the cache and the initial context.
*
* @throws GeneralException
*/
public ServiceLocator(String url, String factory)
throws GeneralException {
try {
Hashtable env = new Hashtable(5);
env.put(Context.INITIAL_CONTEXT_FACTORY, factory);
env.put(Context.PROVIDER_URL, url);
ic = new InitialContext(env);
cache = Collections.synchronizedMap(new HashMap());
} catch (NamingException ne) {
throw new GeneralException("", ne);
} catch (Exception e) {
throw new GeneralException("", e);
}
}
/**
* will get the ejb Local home factory. If this ejb home factory has already been
* clients need to cast to the type of EJBHome they desire
*
* @return the EJB Home corresponding to the homeName
*/
public EJBLocalHome getLocalHome(String jndiHomeName)
throws GeneralException {
EJBLocalHome home = null;
try {
if (cache.containsKey(jndiHomeName)) {
home = (EJBLocalHome) cache.get(jndiHomeName);
} else {
home = (EJBLocalHome) ic.lookup(jndiHomeName);
cache.put(jndiHomeName, home);
}
} catch (NamingException ne) {
throw new GeneralException("", ne);
} catch (Exception e) {
throw new GeneralException("", e);
}
return home;
}
/**
* will get the ejb Remote home factory. If this ejb home factory has already been
* clients need to cast to the type of EJBHome they desire
*
* @return the EJB Home corresponding to the homeName
*/
public EJBHome getRemoteHome(String jndiHomeName, Class className)
throws GeneralException {
EJBHome home = null;
try {
if (cache.containsKey(jndiHomeName)) {
home = (EJBHome) cache.get(jndiHomeName);
} else {
Object objref = ic.lookup(jndiHomeName);
Object obj = PortableRemoteObject.narrow(objref, className);
home = (EJBHome) obj;
cache.put(jndiHomeName, home);
}
} catch (NamingException ne) {
throw new GeneralException("", ne);
} catch (Exception e) {
throw new GeneralException("", e);
}
return home;
}
/**
* @return the factory for the factory to get queue connections from
*/
public QueueConnectionFactory getQueueConnectionFactory(String qConnFactoryName)
throws GeneralException {
QueueConnectionFactory factory = null;
try {
if (cache.containsKey(qConnFactoryName)) {
factory = (QueueConnectionFactory) cache.get(qConnFactoryName);
} else {
factory = (QueueConnectionFactory) ic.lookup(qConnFactoryName);
cache.put(qConnFactoryName, factory);
}
} catch (NamingException ne) {
throw new GeneralException("", ne);
} catch (Exception e) {
throw new GeneralException("", e);
}
return factory;
}
/**
* @return the Queue Destination to send messages to
*/
public Queue getQueue(String queueName) throws GeneralException {
Queue queue = null;
try {
if (cache.containsKey(queueName)) {
queue = (Queue) cache.get(queueName);
} else {
queue = (Queue) ic.lookup(queueName);
cache.put(queueName, queue);
}
} catch (NamingException ne) {
throw new GeneralException("", ne);
} catch (Exception e) {
throw new GeneralException("", e);
}
return queue;
}
/**
* This method helps in obtaining the topic factory
* @return the factory for the factory to get topic connections from
*/
public TopicConnectionFactory getTopicConnectionFactory(String topicConnFactoryName) throws GeneralException {
TopicConnectionFactory factory = null;
try {
if (cache.containsKey(topicConnFactoryName)) {
factory = (TopicConnectionFactory) cache.get(topicConnFactoryName);
} else {
factory = (TopicConnectionFactory) ic.lookup(topicConnFactoryName);
cache.put(topicConnFactoryName, factory);
}
} catch (NamingException ne) {
throw new GeneralException("", ne);
} catch (Exception e) {
throw new GeneralException("", e);
}
return factory;
}
/**
* This method obtains the topc itself for a caller
* @return the Topic Destination to send messages to
*/
public Topic getTopic(String topicName) throws GeneralException {
Topic topic = null;
try {
if (cache.containsKey(topicName)) {
topic = (Topic) cache.get(topicName);
} else {
topic = (Topic) ic.lookup(topicName);
cache.put(topicName, topic);
}
} catch (NamingException ne) {
throw new GeneralException("", ne);
} catch (Exception e) {
throw new GeneralException("", e);
}
return topic;
}
/**
* This method obtains the datasource itself for a caller
* @return the DataSource corresponding to the name parameter
*/
public DataSource getDataSource(String dataSourceName) throws GeneralException {
DataSource dataSource = null;
try {
if (cache.containsKey(dataSourceName)) {
dataSource = (DataSource) cache.get(dataSourceName);
} else {
dataSource = (DataSource) ic.lookup(dataSourceName);
cache.put(dataSourceName, dataSource);
}
} catch (NamingException ne) {
throw new GeneralException("", ne);
} catch (Exception e) {
throw new GeneralException("", e);
}
return dataSource;
}
/**
* @return the URL value corresponding
* to the env entry name.
*/
public URL getUrl(String envName) throws GeneralException {
URL url = null;
try {
url = (URL) ic.lookup(envName);
} catch (NamingException ne) {
throw new GeneralException("", ne);
} catch (Exception e) {
throw new GeneralException("", e);
}
return url;
}
/**
* @return the boolean value corresponding
* to the env entry such as SEND_CONFIRMATION_MAIL property.
*/
public boolean getBoolean(String envName)
throws GeneralException {
Boolean bool = null;
try {
bool = (Boolean) ic.lookup(envName);
} catch (NamingException ne) {
throw new GeneralException("", ne);
} catch (Exception e) {
throw new GeneralException("", e);
}
return bool.booleanValue();
}
/**
* @return the String value corresponding
* to the env entry name.
*/
public String getString(String envName)
throws GeneralException {
String envEntry = null;
try {
envEntry = (String) ic.lookup(envName);
} catch (NamingException ne) {
throw new GeneralException("", ne);
} catch (Exception e) {
throw new GeneralException("", e);
}
return envEntry;
}
}
|