SLING-2601 - more robust mechanism for disabling StartupFilter, based on the presence of a disabling service

git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1387008 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/pom.xml b/pom.xml
index 4987be9..97bd3f2 100644
--- a/pom.xml
+++ b/pom.xml
@@ -31,7 +31,7 @@
 
   <name>Apache Sling Startup Filter Disabler</name>
   <description> 
-    The Activator of this bundle disables the Sling Startup Filter.
+    Registers a StartupFilterDisabler to disable the Sling Startup Filter.
     Configure this bundle with a high enough run level to remove the
     startup filter once the system is ready. 
   </description>
@@ -55,7 +55,6 @@
         <configuration>
           <instructions>
             <Private-Package>org.apache.sling.startupfilterdisabler.impl.*</Private-Package>
-            <Bundle-Activator>org.apache.sling.startupfilterdisabler.impl.Activator</Bundle-Activator>
           </instructions>
         </configuration>
       </plugin>
@@ -68,6 +67,10 @@
       <artifactId>org.osgi.core</artifactId>
     </dependency>
     <dependency>
+      <groupId>org.apache.felix</groupId>
+      <artifactId>org.apache.felix.scr.annotations</artifactId>
+    </dependency>
+    <dependency>
       <groupId>org.slf4j</groupId>
       <artifactId>slf4j-api</artifactId>
     </dependency>
diff --git a/src/main/java/org/apache/sling/startupfilterdisabler/impl/Activator.java b/src/main/java/org/apache/sling/startupfilterdisabler/impl/Activator.java
deleted file mode 100644
index e2b45c2..0000000
--- a/src/main/java/org/apache/sling/startupfilterdisabler/impl/Activator.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * 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.sling.startupfilterdisabler.impl;
-
-import org.apache.sling.startupfilter.StartupFilter;
-import org.osgi.framework.BundleActivator;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceReference;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class Activator implements BundleActivator {
-
-    private final Logger log = LoggerFactory.getLogger(getClass());
-    
-    public void start(BundleContext context) throws Exception {
-        final ServiceReference ref = context.getServiceReference(StartupFilter.class.getName());
-        if(ref == null) {
-            log.warn("No StartupFilter service found to disable");
-        } else {
-            final StartupFilter filter = (StartupFilter)context.getService(ref);
-            if(filter.isEnabled()) {
-                filter.disable();
-                log.info("StartupFilter disabled: {}", filter);
-            } else {
-                log.info("StartupFilter already disabled, nothing to do: {}", filter);
-            }
-        }
-    }
-
-    public void stop(BundleContext context) throws Exception {
-    }
-}
diff --git a/src/main/java/org/apache/sling/startupfilterdisabler/impl/StartupFilterDisablerImpl.java b/src/main/java/org/apache/sling/startupfilterdisabler/impl/StartupFilterDisablerImpl.java
new file mode 100644
index 0000000..69e9710
--- /dev/null
+++ b/src/main/java/org/apache/sling/startupfilterdisabler/impl/StartupFilterDisablerImpl.java
@@ -0,0 +1,37 @@
+/*
+ * 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.sling.startupfilterdisabler.impl;
+
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Service;
+import org.apache.sling.startupfilter.StartupFilterDisabler;
+
+@Component
+@Service
+/** The StartupFilter will be disabled if this service is active. The idea
+ *  is to start the bundle that contains this service at a run level where
+ *  it is safe to let HTTP requests pass through. 
+ */
+public class StartupFilterDisablerImpl implements StartupFilterDisabler {
+
+    public String getReason() {
+        return this + " is active";
+    }
+
+}