/*******************************************************************************
$Source: /cvs/repositories/openii3/project/java/examples/org/any_openeai_enterprise/services/i2s/commands/I2sRequestCommand.java,v $
$Revision: 1.1 $
*******************************************************************************/
/**********************************************************************
This file is part of the OpenEAI sample, reference implementation,
and deployment management suite created by Tod Jackson
(tod@openeai.org) and Steve Wheat (steve@openeai.org).
Copyright (C) 2002 The OpenEAI Software Foundation
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
For specific licensing details and examples of how this software
can be used to implement integrations for your enterprise, visit
http://www.OpenEai.org/licensing.
*/
package org.any_openeai_enterprise.services.i2s.commands;
// Core Java and extensions
import java.util.Properties;
// Log4j
import org.apache.log4j.Category;
import org.apache.log4j.PropertyConfigurator;
// JDOM
import org.jdom.Element;
import org.jdom.Document;
// General OpenEAI foundation
import org.openeai.config.PropertyConfig;
import org.openeai.config.CommandConfig;
import org.openeai.config.EnterpriseConfigurationObjectException;
import org.openeai.config.LoggerConfig;
import org.openeai.jms.consumer.commands.RequestCommandImpl;
import org.openeai.jms.consumer.commands.CommandException;
import org.openeai.xml.XmlDocumentReader;
import org.openeai.xml.XmlDocumentReaderException;
// OpenEAI I2S Repository foundation
import org.any_openeai_enterprise.services.i2s.repository.*;
/**
* This class is the ancestor of EnterpriseApplicationService commands defining
* fields and behavior common to all EnterpriseApplicationServiceCommands.
* <P>
* The majority of these methods are data persistence and retrieval methods
* used by multiple EnterpriseApplicationService commands for persisting and
* retrieving data from the EnterpriseApplicationService database and
* directory server tree. There are also some general convenience methods that
* are used by multiple EnterpriseApplicationService commands.
* <P>
* See the EnterpriseApplicationService database generation scripts for the
* complete definition of the structures of the EnterpriseApplicationService
* database.
*
* @author Steve Wheat (steve@openeai.org)
* @version 1.0 beta - 18 October 2002
*/
public abstract class I2sRequestCommand
extends RequestCommandImpl {
protected Document m_responseDoc = null;
protected Document m_provideDoc = null;
protected boolean m_allowPurge = false;
protected boolean m_authenticateMessages = true;
protected I2sRepository m_i2sRepository = null;
/**
* The constructor of all InstitutionalIdentityService commands retrieves one
* PropertyConfig object from AppConfig by type and gets and sets the
* command properties using that PropertyConfig object. This means that
* all InstitutionalIdentityService commands must have one PropertyConfig
* object in their deployment descriptor. The name of that PropertyConfig
* object is irrelevant, because it is retrieved from AppConfig by type.
* <P>
*/
public I2sRequestCommand(CommandConfig cConfig) throws
InstantiationException {
super(cConfig);
// Reinitialize the logger to get the logger configuration specified with
// this command.
try {
logger.info("[I2sRequestCommand] Configuring a logger for the command. " +
"If no logger configuration is specified with this command, the " +
"command will set its logger to be that of org.openeai.OpenEaiObject.");
LoggerConfig lConfig = new LoggerConfig();
lConfig = (LoggerConfig)getAppConfig()
.getObjectByType(lConfig.getClass().getName());
logger = Category.getInstance(getClass().getName());
PropertyConfigurator.configure(lConfig.getProperties());
}
catch (Exception e) {
logger.warn("[I2sRequestCommand] There was an error configuring the " +
"logger or a logger configuration for this command does not exist, " +
"setting logger to be org.openeai.OpenEaiObject.logger.");
logger = org.openeai.OpenEaiObject.logger;
}
// Get and set the general properties for this command.
PropertyConfig pConfig = new PropertyConfig();
try {
pConfig = (PropertyConfig)getAppConfig()
.getObject("I2sRequestCommandProperties");
}
catch (EnterpriseConfigurationObjectException eoce) {
String errMsg = "Error retrieving a PropertyConfig object from " +
"AppConfig: The exception is: " + eoce.getMessage();
logger.fatal("[I2sRequestCommand] " + errMsg);
throw new InstantiationException(errMsg);
}
setProperties(pConfig.getProperties());
// Initialize response and provide documents.
XmlDocumentReader xmlReader = new XmlDocumentReader();
try {
logger.debug("[I2sRequestCommand] " +
"responseDocumentUri: " + getProperties()
.getProperty("responseDocumentUri"));
m_responseDoc = xmlReader.initializeDocument(getProperties()
.getProperty("responseDocumentUri"), getOutboundXmlValidation());
if (m_responseDoc == null) {
String errMsg = "Missing 'responseDocumentUri' " +
"property in the deployment descriptor. Can't continue.";
logger.fatal("[I2sRequestCommand] " + errMsg);
throw new InstantiationException(errMsg);
}
logger.debug("[I2sRequestCommand] " +
"provideDocumentUri: " + getProperties()
.getProperty("provideDocumentUri"));
m_provideDoc = xmlReader.initializeDocument(getProperties()
.getProperty("provideDocumentUri"), getOutboundXmlValidation());
if (m_provideDoc == null) {
String errMsg = "Missing 'provideDocumentUri' " +
"property in the deployment descriptor. Can't continue.";
logger.fatal("[I2sRequestCommand] " + errMsg);
throw new InstantiationException(errMsg);
}
}
catch (XmlDocumentReaderException e) {
logger.fatal("[I2sRequestCommand] Error initializing" +
" the primed documents.");
e.printStackTrace();
throw new InstantiationException(e.getMessage());
}
// Get the I2sRepositoryProperties from AppConfig.
PropertyConfig i2spConfig = new PropertyConfig();
try {
i2spConfig = (PropertyConfig)getAppConfig()
.getObject("I2sRepositoryProperties");
}
catch (EnterpriseConfigurationObjectException eoce) {
String errMsg = "Error retrieving PropertyConfig object from " +
"AppConfig for the I2sRepositoryProperties. The exception is: " +
eoce.getMessage();
logger.fatal("[I2sRequestCommand] " + errMsg);
throw new InstantiationException(errMsg);
}
Properties i2sRepositoryProps = i2spConfig.getProperties();
// Determine which I2sRepository implementation to use.
String repositoryClassName = i2sRepositoryProps
.getProperty("repositoryClassName");
if (repositoryClassName == null) {
String errMsg = "[i2sRequestCommand] Missing 'repositoryClassName' " +
"property in the deployment descriptor. Can't continue.";
logger.fatal(errMsg);
throw new InstantiationException(errMsg);
}
logger.info("[I2sRequestCommand] Using I2sRepository implementation: " +
repositoryClassName);
// Initialize an i2sRepository.
try {
m_i2sRepository = I2sRepositoryWrapper.getInstance(repositoryClassName,
i2sRepositoryProps);
}
catch (I2sRepositoryException i2re) {
String errMsg = "[I2sRequestCommand] Error initializing the " +
"I2sRepository object. The exception is: " + i2re.getMessage();
logger.fatal(errMsg);
throw new InstantiationException(errMsg);
}
}
protected final I2sRepository getI2sRepository() {
return m_i2sRepository;
}
}