FELIX-1132: remove dependency from gshell-features on spring jmx

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@773517 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/karaf/gshell/gshell-features/src/main/java/org/apache/felix/karaf/gshell/features/management/ManagedFeature.java b/karaf/gshell/gshell-features/src/main/java/org/apache/felix/karaf/gshell/features/management/ManagedFeature.java
index cfcb0d3..ed95215 100644
--- a/karaf/gshell/gshell-features/src/main/java/org/apache/felix/karaf/gshell/features/management/ManagedFeature.java
+++ b/karaf/gshell/gshell-features/src/main/java/org/apache/felix/karaf/gshell/features/management/ManagedFeature.java
@@ -20,15 +20,11 @@
 
 import org.apache.felix.karaf.gshell.features.Feature;
 import org.apache.felix.karaf.gshell.features.FeaturesService;
-import org.springframework.jmx.export.annotation.ManagedAttribute;
-import org.springframework.jmx.export.annotation.ManagedOperation;
-import org.springframework.jmx.export.annotation.ManagedResource;
 
 /**
  * Managed Repository MBean
  */
-@ManagedResource(description = "Feature")
-public class ManagedFeature {
+public class ManagedFeature implements ManagedFeatureMBean {
     private Feature feature;
     private FeaturesService featuresService;
     private String id;
@@ -39,40 +35,33 @@
         this.featuresService = featuresService;
     }
 
-    @ManagedAttribute
     public String getId() {
         return id;    
     }
 
-    @ManagedAttribute
     public String getName() {
         return feature.getName();
     }
 
-    @ManagedAttribute
     public String getVersion() {
         return feature.getVersion();
     }
 
-    @ManagedAttribute
     public List<Feature> getDependencies() {
         return feature.getDependencies();
     }
 
-    @ManagedAttribute
     public List<String> getBundles() {
         return feature.getBundles();
     }
 
-    @ManagedOperation
-    public void uninstallFeature() throws Exception {
-        featuresService.uninstallFeature(feature.getName(), feature.getVersion());
-    }
-
-    @ManagedOperation
     public void installFeature() throws Exception {
         featuresService.installFeature(feature.getName(), feature.getVersion());
     }
 
+    public void uninstallFeature() throws Exception {
+        featuresService.uninstallFeature(feature.getName(), feature.getVersion());
+    }
+
 }
 
diff --git a/karaf/gshell/gshell-features/src/main/java/org/apache/felix/karaf/gshell/features/management/ManagedFeatureMBean.java b/karaf/gshell/gshell-features/src/main/java/org/apache/felix/karaf/gshell/features/management/ManagedFeatureMBean.java
new file mode 100644
index 0000000..953dfad
--- /dev/null
+++ b/karaf/gshell/gshell-features/src/main/java/org/apache/felix/karaf/gshell/features/management/ManagedFeatureMBean.java
@@ -0,0 +1,39 @@
+/*
+ * 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.felix.karaf.gshell.features.management;
+
+import java.util.List;
+
+import org.apache.felix.karaf.gshell.features.Feature;
+
+public interface ManagedFeatureMBean {
+
+    String getId();
+
+    String getName();
+
+    String getVersion();
+
+    List<Feature> getDependencies();
+
+    List<String> getBundles();
+
+    void installFeature() throws Exception;
+
+    void uninstallFeature() throws Exception;
+
+}
diff --git a/karaf/gshell/gshell-features/src/main/java/org/apache/felix/karaf/gshell/features/management/ManagedFeaturesRegistry.java b/karaf/gshell/gshell-features/src/main/java/org/apache/felix/karaf/gshell/features/management/ManagedFeaturesRegistry.java
index d62eed9..2b0d00e 100644
--- a/karaf/gshell/gshell-features/src/main/java/org/apache/felix/karaf/gshell/features/management/ManagedFeaturesRegistry.java
+++ b/karaf/gshell/gshell-features/src/main/java/org/apache/felix/karaf/gshell/features/management/ManagedFeaturesRegistry.java
@@ -28,16 +28,12 @@
 import org.apache.felix.karaf.gshell.features.FeaturesRegistry;
 import org.apache.felix.karaf.gshell.features.FeaturesService;
 import org.apache.felix.karaf.gshell.features.Repository;
-import org.springframework.beans.factory.InitializingBean;
-import org.springframework.jmx.export.annotation.ManagedOperation;
-import org.springframework.jmx.export.annotation.ManagedResource;
 
 /**
  * The FeaturesServiceRegistry maintains the managed Features and Repositories
  * for JMX management.
  */
-@ManagedResource(description = "Features Service Registry and Management")
-public class ManagedFeaturesRegistry implements FeaturesRegistry {
+public class ManagedFeaturesRegistry implements FeaturesRegistry, ManagedFeaturesRegistryMBean {
 
     private static final transient Log LOG = LogFactory.getLog(ManagedFeaturesRegistry.class);
 
@@ -50,17 +46,14 @@
     private FeaturesService featuresService;
     private MBeanServer mbeanServer;
 
-    @ManagedOperation
     public void installFeature(String name) throws Exception {
         featuresService.installFeature(name);
     }
 
-    @ManagedOperation
     public void installFeature(String name, String version) throws Exception {
         featuresService.installFeature(name, version);
     }
 
-    @ManagedOperation
     public void installRepository(String repositoryUri) throws Exception {
         featuresService.addRepository(new URI(repositoryUri));
     }
diff --git a/karaf/gshell/gshell-features/src/main/java/org/apache/felix/karaf/gshell/features/management/ManagedFeaturesRegistryMBean.java b/karaf/gshell/gshell-features/src/main/java/org/apache/felix/karaf/gshell/features/management/ManagedFeaturesRegistryMBean.java
new file mode 100644
index 0000000..a30b98f
--- /dev/null
+++ b/karaf/gshell/gshell-features/src/main/java/org/apache/felix/karaf/gshell/features/management/ManagedFeaturesRegistryMBean.java
@@ -0,0 +1,27 @@
+/*
+ * 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.felix.karaf.gshell.features.management;
+
+public interface ManagedFeaturesRegistryMBean {
+
+    void installFeature(String name) throws Exception;
+
+    void installFeature(String name, String version) throws Exception;
+
+    void installRepository(String repositoryUri) throws Exception;
+
+}
diff --git a/karaf/gshell/gshell-features/src/main/java/org/apache/felix/karaf/gshell/features/management/ManagedRepository.java b/karaf/gshell/gshell-features/src/main/java/org/apache/felix/karaf/gshell/features/management/ManagedRepository.java
index 19734db..ddaa6b5 100644
--- a/karaf/gshell/gshell-features/src/main/java/org/apache/felix/karaf/gshell/features/management/ManagedRepository.java
+++ b/karaf/gshell/gshell-features/src/main/java/org/apache/felix/karaf/gshell/features/management/ManagedRepository.java
@@ -21,12 +21,9 @@
 import org.apache.felix.karaf.gshell.features.Feature;
 import org.apache.felix.karaf.gshell.features.FeaturesService;
 import org.apache.felix.karaf.gshell.features.Repository;
-import org.springframework.jmx.export.annotation.ManagedAttribute;
-import org.springframework.jmx.export.annotation.ManagedOperation;
-import org.springframework.jmx.export.annotation.ManagedResource;
 
-@ManagedResource(description = "Features Repository")
-public class ManagedRepository {
+public class ManagedRepository implements ManagedRepositoryMBean {
+
     private Repository repository;
     private FeaturesService featuresService;
 
@@ -35,22 +32,18 @@
         this.featuresService = featuresService;
     }
 
-    @ManagedAttribute
     public URI getUri() {
         return repository.getURI();
     }
 
-    @ManagedAttribute
     public URI[] getRepositories() throws Exception {
         return repository.getRepositories();
     }
 
-    @ManagedAttribute
     public Feature[] getFeatures() throws Exception {
         return repository.getFeatures();
     }
 
-    @ManagedOperation
     public void removeRepository() throws Exception {
         featuresService.removeRepository(repository.getURI());
     }
diff --git a/karaf/gshell/gshell-features/src/main/java/org/apache/felix/karaf/gshell/features/management/ManagedRepositoryMBean.java b/karaf/gshell/gshell-features/src/main/java/org/apache/felix/karaf/gshell/features/management/ManagedRepositoryMBean.java
new file mode 100644
index 0000000..ae2ae63
--- /dev/null
+++ b/karaf/gshell/gshell-features/src/main/java/org/apache/felix/karaf/gshell/features/management/ManagedRepositoryMBean.java
@@ -0,0 +1,33 @@
+/*
+ * 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.felix.karaf.gshell.features.management;
+
+import java.net.URI;
+
+import org.apache.felix.karaf.gshell.features.Feature;
+
+public interface ManagedRepositoryMBean {
+
+    URI getUri();
+
+    URI[] getRepositories() throws Exception;
+
+    Feature[] getFeatures() throws Exception;
+
+    void removeRepository() throws Exception;
+
+}
diff --git a/karaf/gshell/gshell-features/src/main/java/org/apache/felix/karaf/gshell/features/management/ManagementAgent.java b/karaf/gshell/gshell-features/src/main/java/org/apache/felix/karaf/gshell/features/management/ManagementAgent.java
index e5b2720..8c4f054 100644
--- a/karaf/gshell/gshell-features/src/main/java/org/apache/felix/karaf/gshell/features/management/ManagementAgent.java
+++ b/karaf/gshell/gshell-features/src/main/java/org/apache/felix/karaf/gshell/features/management/ManagementAgent.java
@@ -25,30 +25,21 @@
 import javax.management.NotCompliantMBeanException;
 import javax.management.ObjectInstance;
 import javax.management.ObjectName;
-import javax.management.modelmbean.InvalidTargetObjectTypeException;
-import javax.management.modelmbean.ModelMBeanInfo;
-import javax.management.modelmbean.RequiredModelMBean;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.springframework.beans.factory.DisposableBean;
-import org.springframework.jmx.export.annotation.AnnotationJmxAttributeSource;
-import org.springframework.jmx.export.assembler.MetadataMBeanInfoAssembler;
 
 /**
  * Management Agent that registers MBeans with JMX MBeanServer.
  */
-public class ManagementAgent implements DisposableBean {
+public class ManagementAgent {
 
     private static final transient Log LOG = LogFactory.getLog(ManagementAgent.class);
 
     private MBeanServer mbeanServer;
-    private MetadataMBeanInfoAssembler assembler;
     private Set<ObjectName> mbeans = new HashSet<ObjectName>();
 
     public ManagementAgent() {
-        assembler = new MetadataMBeanInfoAssembler();
-        assembler.setAttributeSource(new AnnotationJmxAttributeSource());
     }
 
     public MBeanServer getMbeanServer() {
@@ -85,6 +76,7 @@
     }
 
     public void register(Object obj, ObjectName name, boolean forceRegistration) throws JMException {
+        /*
         try {
             registerMBeanWithServer(obj, name, forceRegistration);
         } catch (NotCompliantMBeanException e) {
@@ -100,6 +92,8 @@
             }
             registerMBeanWithServer(mbean, name, forceRegistration);
         }
+        */
+        registerMBeanWithServer(obj, name, forceRegistration);
     }
 
     public synchronized void unregister(ObjectName name) throws JMException {
diff --git a/karaf/gshell/gshell-features/src/main/resources/META-INF/spring/gshell-features.xml b/karaf/gshell/gshell-features/src/main/resources/META-INF/spring/gshell-features.xml
index d1b851d..5121ed5 100644
--- a/karaf/gshell/gshell-features/src/main/resources/META-INF/spring/gshell-features.xml
+++ b/karaf/gshell/gshell-features/src/main/resources/META-INF/spring/gshell-features.xml
@@ -39,7 +39,14 @@
   http://servicemix.apache.org/schema/servicemix-gshell/servicemix-gshell.xsd">
 
     <bean id="placeholderConfig" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
-      <property name="location" value="file:${karaf.home}/etc/org.apache.felix.karaf.features.cfg"/>
+        <property name="location" value="file:${karaf.home}/etc/org.apache.felix.karaf.features.cfg"/>
+        <property name="ignoreResourceNotFound" value="true"/>
+        <property name="properties">
+            <props>
+                <prop key="featuresRepositories"></prop>
+                <prop key="featuresBoot"></prop>
+            </props>
+        </property>
     </bean>
 
     <gshell:command-bundle>
@@ -97,38 +104,12 @@
         <property name="featuresServiceRegistry" ref="featureServiceRegistry" />
     </bean>
 
-    <bean id="namingStrategy" class="org.apache.felix.karaf.gshell.features.management.DefaultNamingStrategy">
-        <property name="jmxDomainName" value="org.apache.servicemix" />
-    </bean>
-
-    <bean id="managementAgent" class="org.apache.felix.karaf.gshell.features.management.ManagementAgent">
-        <property name="mbeanServer" ref="mbeanServer" />
-    </bean>
-
-    <bean id="featureServiceRegistry" class="org.apache.felix.karaf.gshell.features.management.ManagedFeaturesRegistry" init-method="init">
-        <property name="managementAgent" ref="managementAgent" />
-        <property name="namingStrategy" ref="namingStrategy" />
-    </bean>
-
     <osgi:reference id="configAdmin" interface="org.osgi.service.cm.ConfigurationAdmin" />
 
     <osgi:reference id="preferences" interface="org.osgi.service.prefs.PreferencesService" cardinality="0..1" />
 
     <osgi:service ref="featuresService" interface="org.apache.felix.karaf.gshell.features.FeaturesService" />
 
-    <osgix:cm-properties id="cmProps" persistent-id="org.apache.felix.karaf.features">
-        <prop key="featuresRepositories"></prop>
-        <prop key="featuresBoot"></prop>
-    </osgix:cm-properties>
-
-    <!-- <ctx:property-placeholder properties-ref="cmProps" /> -->
-
-    <osgi:reference id="mbeanServer"
-                    interface="javax.management.MBeanServer"
-                    cardinality="0..1" >
-        <osgi:listener ref="featureServiceRegistry" bind-method="registerMBeanServer" />
-    </osgi:reference>
-
     <bean id="installFeatureCompleter" class="org.apache.felix.karaf.gshell.features.completers.AvailableFeatureCompleter">
         <property name="featuresRegistry" ref="featureServiceRegistry" />
     </bean>
@@ -141,4 +122,26 @@
         <property name="featuresRegistry" ref="featureServiceRegistry" />
     </bean>
 
+    <!-- Management -->
+
+    <bean id="namingStrategy" class="org.apache.felix.karaf.gshell.features.management.DefaultNamingStrategy">
+        <property name="jmxDomainName" value="org.apache.felix.karaf" />
+    </bean>
+
+    <bean id="managementAgent" class="org.apache.felix.karaf.gshell.features.management.ManagementAgent" destroy-method="destroy">
+        <property name="mbeanServer" ref="mbeanServer" />
+    </bean>
+
+    <bean id="featureServiceRegistry" class="org.apache.felix.karaf.gshell.features.management.ManagedFeaturesRegistry" init-method="init">
+        <property name="managementAgent" ref="managementAgent" />
+        <property name="namingStrategy" ref="namingStrategy" />
+    </bean>
+
+    <osgi:reference id="mbeanServer"
+                    interface="javax.management.MBeanServer"
+                    cardinality="0..1" >
+        <osgi:listener ref="featureServiceRegistry" bind-method="registerMBeanServer"/>
+    </osgi:reference>
+
+
 </beans>