/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.geronimo.jetty7;
import javax.servlet.Servlet;
import org.apache.geronimo.connector.outbound.connectiontracking.ConnectorInstanceContext;
import org.apache.geronimo.connector.outbound.connectiontracking.SharedConnectorInstanceContext;
import org.apache.geronimo.jetty7.handler.IntegrationContext;
import org.eclipse.jetty.servlet.ServletHolder;
/**
* @version $Rev: 1031437 $ $Date: 2010-11-05 13:23:04 +0800 (Fri, 05 Nov 2010) $
*/
public class GeronimoServletHolder extends ServletHolder {
private final IntegrationContext integrationContext;
private final JettyServletRegistration servletRegistration;
public GeronimoServletHolder(IntegrationContext integrationContext, JettyServletRegistration servletRegistration) {
this.integrationContext = integrationContext;
this.servletRegistration = servletRegistration;
}
public synchronized Servlet newInstance() throws InstantiationException, IllegalAccessException {
return (Servlet)servletRegistration.newInstance(_className);
}
public void destroyInstance(Object o) throws Exception {
super.destroyInstance(o);
servletRegistration.destroyInstance(o);
}
@Override
public void doStart() throws Exception {
javax.naming.Context context = integrationContext.setContext();
boolean txActive = integrationContext.isTxActive();
SharedConnectorInstanceContext newContext = integrationContext.newConnectorInstanceContext(null);
ConnectorInstanceContext connectorContext = integrationContext.setConnectorInstance(null, newContext);
try {
try {
super.doStart();
} finally {
integrationContext.restoreConnectorContext(connectorContext, null, newContext);
}
} finally {
integrationContext.restoreContext(context);
integrationContext.completeTx(txActive, null);
}
}
@Override
public void doStop() throws Exception {
javax.naming.Context context = integrationContext.setContext();
boolean txActive = integrationContext.isTxActive();
SharedConnectorInstanceContext newContext = integrationContext.newConnectorInstanceContext(null);
ConnectorInstanceContext connectorContext = integrationContext.setConnectorInstance(null, newContext);
try {
try {
super.doStop();
} finally {
integrationContext.restoreConnectorContext(connectorContext, null, newContext);
}
} finally {
integrationContext.restoreContext(context);
integrationContext.completeTx(txActive, null);
}
}
}