// Path: src/main/java/com/adeptj/runtime/common/BridgeServletConfigHolder.java
// public enum BridgeServletConfigHolder {
// 
//     INSTANCE;
// 
//     private ServletConfig bridgeServletConfig;
// 
//     public void setBridgeServletConfig(ServletConfig bridgeServletConfig) { // NOSONAR
//         if (this.bridgeServletConfig == null) {
//             this.bridgeServletConfig = bridgeServletConfig;
//         }
//     }
// 
//     public ServletConfig getBridgeServletConfig() {
//         return bridgeServletConfig;
//     }
// 
//     public static BridgeServletConfigHolder getInstance() {
//         return INSTANCE;
//     }
// }


import com.adeptj.runtime.common.BridgeServletConfigHolder;
import org.apache.felix.http.base.internal.dispatch.DispatcherServlet;
import org.osgi.framework.BundleContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.servlet.ServletConfig;
import javax.servlet.http.HttpServlet;
/*
###############################################################################
#                                                                             # 
#    Copyright 2016, AdeptJ (http://www.adeptj.com)                           #
#                                                                             #
#    Licensed 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 com.adeptj.runtime.osgi;



/**
 * OSGi ServiceTracker for Felix {@link org.apache.felix.http.base.internal.dispatch.DispatcherServlet}.
 *
 * @author Rakesh.Kumar, AdeptJ
 */
public class DispatcherServletTracker extends BridgeServiceTracker<HttpServlet> {

    private static final Logger LOGGER = LoggerFactory.getLogger(DispatcherServletTracker.class);

    private static final String EXCEPTION_MSG = "Exception adding Felix DispatcherServlet OSGi Service!!";

    private DispatcherServletWrapper dispatcherServletWrapper;

    /**
     * Create the {@link org.osgi.util.tracker.ServiceTracker} for {@link HttpServlet}
     *
     * @param context the {@link BundleContext}
     */
    DispatcherServletTracker(BundleContext context) {
        super(context, HttpServlet.class);
    }

    /**
     * Initializes the Felix {@link org.apache.felix.http.base.internal.dispatch.DispatcherServlet}
     *
     * @param dispatcherServlet the Felix {@link org.apache.felix.http.base.internal.dispatch.DispatcherServlet}
     */
    @Override
    protected HttpServlet addingService(HttpServlet dispatcherServlet) {
        this.dispatcherServletWrapper = new DispatcherServletWrapper(dispatcherServlet);
        try {
// Path: src/main/java/com/adeptj/runtime/common/BridgeServletConfigHolder.java
// public enum BridgeServletConfigHolder {
// 
//     INSTANCE;
// 
//     private ServletConfig bridgeServletConfig;
// 
//     public void setBridgeServletConfig(ServletConfig bridgeServletConfig) { // NOSONAR
//         if (this.bridgeServletConfig == null) {
//             this.bridgeServletConfig = bridgeServletConfig;
//         }
//     }
// 
//     public ServletConfig getBridgeServletConfig() {
//         return bridgeServletConfig;
//     }
// 
//     public static BridgeServletConfigHolder getInstance() {
//         return INSTANCE;
//     }
// }


// Path: src/main/java/com/adeptj/runtime/osgi/DispatcherServletTracker.java
import com.adeptj.runtime.common.BridgeServletConfigHolder;
import org.apache.felix.http.base.internal.dispatch.DispatcherServlet;
import org.osgi.framework.BundleContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.servlet.ServletConfig;
import javax.servlet.http.HttpServlet;

/*
###############################################################################
#                                                                             # 
#    Copyright 2016, AdeptJ (http://www.adeptj.com)                           #
#                                                                             #
#    Licensed 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 com.adeptj.runtime.osgi;



/**
 * OSGi ServiceTracker for Felix {@link org.apache.felix.http.base.internal.dispatch.DispatcherServlet}.
 *
 * @author Rakesh.Kumar, AdeptJ
 */
public class DispatcherServletTracker extends BridgeServiceTracker<HttpServlet> {

    private static final Logger LOGGER = LoggerFactory.getLogger(DispatcherServletTracker.class);

    private static final String EXCEPTION_MSG = "Exception adding Felix DispatcherServlet OSGi Service!!";

    private DispatcherServletWrapper dispatcherServletWrapper;

    /**
     * Create the {@link org.osgi.util.tracker.ServiceTracker} for {@link HttpServlet}
     *
     * @param context the {@link BundleContext}
     */
    DispatcherServletTracker(BundleContext context) {
        super(context, HttpServlet.class);
    }

    /**
     * Initializes the Felix {@link org.apache.felix.http.base.internal.dispatch.DispatcherServlet}
     *
     * @param dispatcherServlet the Felix {@link org.apache.felix.http.base.internal.dispatch.DispatcherServlet}
     */
    @Override
    protected HttpServlet addingService(HttpServlet dispatcherServlet) {
        this.dispatcherServletWrapper = new DispatcherServletWrapper(dispatcherServlet);
        try {
            ServletConfig bridgeServletConfig = BridgeServletConfigHolder.getInstance().getBridgeServletConfig();