package org.jboss.axis;
import org.jboss.axis.encoding.TypeMappingRegistry;
import org.jboss.axis.handlers.BasicHandler;
import org.jboss.axis.handlers.soap.SOAPService;
import org.jboss.axis.session.Session;
import org.jboss.axis.session.SimpleSession;
import org.jboss.axis.utils.JavaUtils;
import org.jboss.axis.utils.Messages;
import org.jboss.axis.utils.cache.ClassCache;
import org.jboss.logging.Logger;
import javax.xml.namespace.QName;
import javax.xml.rpc.server.ServiceLifecycle;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Hashtable;
public abstract class AxisEngine extends BasicHandler
{
private static Logger log = Logger.getLogger(AxisEngine.class.getName());
public static final String PROP_XML_DECL = "sendXMLDeclaration";
public static final String PROP_DEBUG_LEVEL = "debugLevel";
public static final String PROP_DEBUG_FILE = "debugFile";
public static final String PROP_DOMULTIREFS = "sendMultiRefs";
public static final String PROP_PASSWORD = "adminPassword";
public static final String PROP_SYNC_CONFIG = "syncConfiguration";
public static final String PROP_SEND_XSI = "sendXsiTypes";
public static final String PROP_ATTACHMENT_DIR = "attachments.Directory";
public static final String PROP_ATTACHMENT_IMPLEMENTATION = "attachments.implementation";
public static final String PROP_ATTACHMENT_CLEANUP = "attachment.DirectoryCleanUp";
public static final String PROP_DEFAULT_CONFIG_CLASS = "axis.engineConfigClass";
public static final String PROP_SOAP_VERSION = "defaultSOAPVersion";
public static final String PROP_SOAP_ALLOWED_VERSION = "singleSOAPVersion";
public static final String PROP_TWOD_ARRAY_ENCODING = "enable2DArrayEncoding";
public static final String PROP_SEND_MINIMIZED_ELEMENTS = "axis.sendMinimizedElements";
public static final String PROP_XML_ENCODING = "axis.xmlEncoding";
public static final String DEFAULT_ATTACHMENT_IMPL = "org.jboss.axis.attachments.AttachmentsImpl";
public static final String ENV_ATTACHMENT_DIR = "axis.attachments.Directory";
public static final String ENV_SERVLET_REALPATH = "servlet.realpath";
public static final String ENV_SERVLET_CONTEXT = "servletContext";
private static final String DEFAULT_ADMIN_PASSWORD = "admin";
protected EngineConfiguration config;
protected boolean _hasSafePassword = false;
protected boolean shouldSaveConfig = false;
private Session session = new SimpleSession();
private ArrayList actorURIs = new ArrayList();
private static ThreadLocal currentMessageContext = new ThreadLocal();
public static void setCurrentMessageContext(MessageContext mc)
{
currentMessageContext.set(mc);
}
public static MessageContext getCurrentMessageContext()
{
return (MessageContext)currentMessageContext.get();
}
public AxisEngine(EngineConfiguration config)
{
this.config = config;
init();
}
public void init()
{
if (log.isDebugEnabled())
{
log.debug("Enter: AxisEngine::init");
}
try
{
config.configureEngine(this);
}
catch (Exception e)
{
throw new InternalException(e);
}
setOptionDefault(PROP_ATTACHMENT_IMPLEMENTATION,
AxisProperties.getProperty("axis." + PROP_ATTACHMENT_IMPLEMENTATION));
setOptionDefault(PROP_ATTACHMENT_IMPLEMENTATION, DEFAULT_ATTACHMENT_IMPL);
if (log.isDebugEnabled())
{
log.debug("Exit: AxisEngine::init");
}
}
public void cleanup()
{
super.cleanup();
Enumeration keys = session.getKeys();
if (keys != null)
{
while (keys.hasMoreElements())
{
String key = (String)keys.nextElement();
Object obj = session.get(key);
if (obj != null && obj instanceof ServiceLifecycle)
{
((ServiceLifecycle)obj).destroy();
}
session.remove(key);
}
}
}
public void saveConfiguration()
{
if (!shouldSaveConfig)
return;
try
{
config.writeEngineConfig(this);
}
catch (Exception e)
{
log.error(Messages.getMessage("saveConfigFail00"), e);
}
}
public EngineConfiguration getConfig()
{
return config;
}
public boolean hasSafePassword()
{
return _hasSafePassword;
}
public void setAdminPassword(String pw)
{
setOption(PROP_PASSWORD, pw);
_hasSafePassword = true;
saveConfiguration();
}
public void setShouldSaveConfig(boolean shouldSaveConfig)
{
this.shouldSaveConfig = shouldSaveConfig;
}
public Handler getHandler(String name) throws AxisFault
{
try
{
return config.getHandler(new QName(null, name));
}
catch (ConfigurationException e)
{
throw AxisFault.makeFault(e);
}
}
public SOAPService getService(String name) throws AxisFault
{
try
{
return config.getService(new QName(null, name));
}
catch (ConfigurationException e)
{
throw AxisFault.makeFault(e);
}
}
public Handler getTransport(String name) throws AxisFault
{
try
{
return config.getTransport(new QName(null, name));
}
catch (ConfigurationException e)
{
throw AxisFault.makeFault(e);
}
}
public TypeMappingRegistry getTypeMappingRegistry()
{
TypeMappingRegistry tmr = null;
try
{
tmr = config.getTypeMappingRegistry();
}
catch (ConfigurationException e)
{
log.error(Messages.getMessage("axisConfigurationException00"), e);
}
return tmr;
}
public Handler getGlobalRequest()
throws ConfigurationException
{
return config.getGlobalRequest();
}
public Handler getGlobalResponse()
throws ConfigurationException
{
return config.getGlobalResponse();
}
public ArrayList getActorURIs()
{
return actorURIs;
}
public void addActorURI(String uri)
{
actorURIs.add(uri);
}
public void removeActorURI(String uri)
{
actorURIs.remove(uri);
}
public abstract AxisEngine getClientEngine();
private static final String[] BOOLEAN_OPTIONS = new String[]{
PROP_DOMULTIREFS, PROP_SEND_XSI, PROP_XML_DECL, PROP_SEND_MINIMIZED_ELEMENTS
};
public static void normaliseOptions(Handler handler)
{
for (int i = 0; i < BOOLEAN_OPTIONS.length; i++)
{
Object val = handler.getOption(BOOLEAN_OPTIONS[i]);
if (val != null)
{
if (val instanceof Boolean)
continue;
if (JavaUtils.isFalse(val))
{
handler.setOption(BOOLEAN_OPTIONS[i], Boolean.FALSE);
continue;
}
}
else
{
if (!(handler instanceof AxisEngine))
continue;
}
handler.setOption(BOOLEAN_OPTIONS[i], Boolean.TRUE);
}
if (handler instanceof AxisEngine)
{
AxisEngine engine = (AxisEngine)handler;
if (!engine.setOptionDefault(PROP_PASSWORD,
DEFAULT_ADMIN_PASSWORD))
{
engine.setAdminPassword((String)engine.getOption(PROP_PASSWORD));
}
}
}
public void refreshGlobalOptions() throws ConfigurationException
{
Hashtable globalOptions = config.getGlobalOptions();
if (globalOptions != null)
setOptions(globalOptions);
normaliseOptions(this);
}
public Session getApplicationSession()
{
return session;
}
public ClassCache getClassCache()
{
return null;
}
}