|
From: <tr...@us...> - 2003-08-27 03:15:37
|
Update of /cvsroot/babeldoc/babeldoc/modules/j2ee/src/com/babeldoc/j2ee/scanner/worker In directory sc8-pr-cvs1:/tmp/cvs-serv27662/src/com/babeldoc/j2ee/scanner/worker Added Files: JmsScanner.java Log Message: Re-adding of the J2ee module. THe most you can say about this is that it compiles. --- NEW FILE: JmsScanner.java --- /* ==================================================================== * The Apache Software License, Version 1.1 * * Copyright (c) 2000 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions 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. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Apache" and "Apache Software Foundation" must * not be used to endorse or promote products derived from this * software without prior written permission. For written * permission, please contact ap...@ap.... * * 5. Products derived from this software may not be called "Apache", * nor may "Apache" appear in their name, without prior written * permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. * * Portions of this software are based upon public domain software * originally written at the National Center for Supercomputing Applications, * University of Illinois, Urbana-Champaign. * ==================================================================== * * Babeldoc: The Universal Document Processor * * $Header: /cvsroot/babeldoc/babeldoc/modules/j2ee/src/com/babeldoc/j2ee/scanner/worker/JmsScanner.java,v 1.1 2003/08/27 03:15:31 triphop Exp $ * $DateTime$ * $Author: triphop $ * */ package com.babeldoc.j2ee.scanner.worker; import com.babeldoc.core.LogService; import com.babeldoc.core.option.IConfigInfo; import com.babeldoc.core.option.ConfigOption; import com.babeldoc.core.option.IConfigOptionType; import com.babeldoc.scanner.ScannerException; import com.babeldoc.scanner.ScannerWorker; import com.babeldoc.scanner.ScannerWorkerInfo; import javax.jms.*; import javax.naming.Context; import javax.naming.InitialContext; import java.util.*; /** * JMS Queue scanner. THIS IS COMPLETELY UNTESTED CODE * * @author Bmcdonald * @version 1.1 */ public class JmsScanner extends ScannerWorker { /** Constants */ public final static String Q_FACTORY_NAME = "queueFactoryName"; public final static String Q_NAME = "queueName"; /** configuration information object */ private IConfigInfo info; QueueConnection connection; Queue queue; QueueSession queueSession; Context context; public static final int BYTE_BUFFER = 256; /** * Setup the options. Each of the options lives in the hashtable held * by the superclass * */ public void initialize() { String ConnectionFactory = getInfo().getStrValue(Q_FACTORY_NAME); String Queue = getInfo().getStrValue(Q_NAME); // Set up the jms stuff try { context = new InitialContext(); QueueConnectionFactory connectionFactory = (QueueConnectionFactory) context.lookup(ConnectionFactory); connection = connectionFactory.createQueueConnection(); queueSession = connection.createQueueSession(false, Session.CLIENT_ACKNOWLEDGE); queue = (Queue) context.lookup(Queue); } catch (Exception e) { LogService.getInstance().logError(e); } finally { try { connection.close(); queueSession.close(); context.close(); } catch (Exception e) { LogService.getInstance().logError(e); } } } /** * release the held resource. Do nothing - no held resources. */ public void relinquishResources() { LogService.getInstance().logInfo("relinquishResources"); try { connection.close(); queueSession.close(); context.close(); } catch (Exception e) { LogService.getInstance().logError("[relinquishResources]", e); } } /** * Get the information object * * @return information object */ public IConfigInfo getInfo() { if(info==null) { /** * informational class for the ExternalApplicationScanner. */ info = new ScannerWorkerInfo() { public String getDescription() { return "JMS Scanner"; } public String getName() { return "JmsScanner"; } public Collection getTypeSpecificOptions() { ArrayList options = new ArrayList(); //add specific options options.add(new ConfigOption(Q_FACTORY_NAME, IConfigOptionType.STRING, null, true, "JMS Queue factory name")); options.add(new ConfigOption(Q_NAME, IConfigOptionType.STRING, null, true, "JMS Queue name")); return options; } }; } return info; } /** * Do the scan - pull the documents from the JMS queue and submit this * * @throws ScannerException */ public void doScan() throws ScannerException { QueueReceiver receiver = null; try { // Create a QueueReceiver. receiver = queueSession.createReceiver(queue); connection.start(); while (true) { Message m = receiver.receive(1); if (m != null) { handleMessage(m); } } } catch (Exception e) { LogService.getInstance().logError("[doScan]", e); } finally { try { receiver.close(); } catch (Exception e) { LogService.getInstance().logError("[doScan]", e); } } } /** * Only handles text messages at the moment. * * @param m * @throws JMSException */ private void handleMessage(Message m) throws JMSException { Map map = handleMessageMap(m); if (m instanceof TextMessage) { enqueue(((TextMessage)m).getText().getBytes(), map); } else if(m instanceof BytesMessage) { // Not implemented } } /** * Get the message map off the message. * * @param m the message in question * @return message map * * @throws JMSException */ private Map handleMessageMap(Message m) throws JMSException { Map map = new HashMap(); for(Enumeration e = m.getPropertyNames(); e.hasMoreElements();) { String name = (String)e.nextElement(); String value = null; try { value = m.getStringProperty(name); } catch (JMSException e1) { LogService.getInstance().logError(e1); } map.put(name, value); } return map; } } |