@Override protected void init(int arg) { BundleContext bundleContext = Activator.getContext(); // 启动时,从ServletContext中读取相关运行时状态 Object filterConfigObject = WebContext.getServletContext().getAttribute(QUICKWEBFRAMEWORK_STATE_FILTERCONFIG); if (filterConfigObject != null) setFilterConfig((FilterConfig) filterConfigObject); // 注册过滤器桥接对象 servletFilterBridgeServiceRegistration = bundleContext.registerService( ServletFilterBridge.class.getName(), new ServletFilterBridge(), null); }
@Override protected void bundleChanged(BundleEvent event) { Bundle bundle = event.getBundle(); int bundleEventType = event.getType(); BundleContext bundleContext = Activator.getContext(); if (bundleContext == null) return; Bundle coreBundle = bundleContext.getBundle(); if (bundleEventType == BundleEvent.STOPPING) { // 移除插件的过滤器 if (bundle.equals(coreBundle)) { ServletFilterContext.unregisterAllFilter(); } else { ServletFilterContext.unregisterBundleAllFilter(bundle); } } }
@Override protected BundleContext getBundleContext() { return Activator.getContext(); }