felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sfre...@apache.org
Subject svn commit: r422696 [1/4] - in /incubator/felix/trunk/org.apache.felix.mosgi.jmx.agent: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/felix/ src/main/java/org/apache/felix/mosgi/ src/main/java/or...
Date Mon, 17 Jul 2006 12:14:33 GMT
Author: sfrenot
Date: Mon Jul 17 05:14:31 2006
New Revision: 422696

URL: http://svn.apache.org/viewvc?rev=422696&view=rev
Log: (empty)

Added:
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.agent/
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.agent/pom.xml
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.agent/src/
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.agent/src/main/
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.agent/src/main/java/
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.agent/src/main/java/org/
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.agent/src/main/java/org/apache/
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.agent/src/main/java/org/apache/felix/
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.agent/src/main/java/org/apache/felix/mosgi/
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.agent/src/main/java/org/apache/felix/mosgi/jmx/
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.agent/src/main/java/org/apache/felix/mosgi/jmx/agent/
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.agent/src/main/java/org/apache/felix/mosgi/jmx/agent/AgentActivator.java
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.agent/src/main/java/org/apache/felix/mosgi/jmx/agent/Constants.java
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.agent/src/main/java/org/apache/felix/mosgi/jmx/agent/mx4j/
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.agent/src/main/java/org/apache/felix/mosgi/jmx/agent/mx4j/AbstractDynamicMBean.java
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.agent/src/main/java/org/apache/felix/mosgi/jmx/agent/mx4j/ImplementationException.java
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.agent/src/main/java/org/apache/felix/mosgi/jmx/agent/mx4j/MBeanDescription.java
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.agent/src/main/java/org/apache/felix/mosgi/jmx/agent/mx4j/MBeanDescriptionAdapter.java
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.agent/src/main/java/org/apache/felix/mosgi/jmx/agent/mx4j/MX4JSystemKeys.java
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.agent/src/main/java/org/apache/felix/mosgi/jmx/agent/mx4j/loading/
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.agent/src/main/java/org/apache/felix/mosgi/jmx/agent/mx4j/loading/ClassLoaderObjectInputStream.java
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.agent/src/main/java/org/apache/felix/mosgi/jmx/agent/mx4j/loading/MLetParseException.java
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.agent/src/main/java/org/apache/felix/mosgi/jmx/agent/mx4j/loading/MLetParser.java
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.agent/src/main/java/org/apache/felix/mosgi/jmx/agent/mx4j/loading/MLetTag.java
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.agent/src/main/java/org/apache/felix/mosgi/jmx/agent/mx4j/log/
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.agent/src/main/java/org/apache/felix/mosgi/jmx/agent/mx4j/log/Log.java
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.agent/src/main/java/org/apache/felix/mosgi/jmx/agent/mx4j/log/Logger.java
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.agent/src/main/java/org/apache/felix/mosgi/jmx/agent/mx4j/server/
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.agent/src/main/java/org/apache/felix/mosgi/jmx/agent/mx4j/server/DefaultClassLoaderRepository.java
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.agent/src/main/java/org/apache/felix/mosgi/jmx/agent/mx4j/server/DefaultMBeanRepository.java
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.agent/src/main/java/org/apache/felix/mosgi/jmx/agent/mx4j/server/MBeanIntrospector.java
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.agent/src/main/java/org/apache/felix/mosgi/jmx/agent/mx4j/server/MBeanInvoker.java
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.agent/src/main/java/org/apache/felix/mosgi/jmx/agent/mx4j/server/MBeanMetaData.java
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.agent/src/main/java/org/apache/felix/mosgi/jmx/agent/mx4j/server/MBeanRepository.java
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.agent/src/main/java/org/apache/felix/mosgi/jmx/agent/mx4j/server/MX4JMBeanServer.java
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.agent/src/main/java/org/apache/felix/mosgi/jmx/agent/mx4j/server/MX4JMBeanServerBuilder.java
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.agent/src/main/java/org/apache/felix/mosgi/jmx/agent/mx4j/server/MX4JMBeanServerDelegate.java
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.agent/src/main/java/org/apache/felix/mosgi/jmx/agent/mx4j/server/ModifiableClassLoaderRepository.java
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.agent/src/main/java/org/apache/felix/mosgi/jmx/agent/mx4j/server/ReflectedMBeanInvoker.java
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.agent/src/main/java/org/apache/felix/mosgi/jmx/agent/mx4j/server/interceptor/
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.agent/src/main/java/org/apache/felix/mosgi/jmx/agent/mx4j/server/interceptor/ContextClassLoaderMBeanServerInterceptor.java
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.agent/src/main/java/org/apache/felix/mosgi/jmx/agent/mx4j/server/interceptor/DefaultMBeanServerInterceptor.java
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.agent/src/main/java/org/apache/felix/mosgi/jmx/agent/mx4j/server/interceptor/DefaultMBeanServerInterceptorMBean.java
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.agent/src/main/java/org/apache/felix/mosgi/jmx/agent/mx4j/server/interceptor/InvokerMBeanServerInterceptor.java
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.agent/src/main/java/org/apache/felix/mosgi/jmx/agent/mx4j/server/interceptor/InvokerMBeanServerInterceptorMBean.java
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.agent/src/main/java/org/apache/felix/mosgi/jmx/agent/mx4j/server/interceptor/MBeanServerInterceptor.java
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.agent/src/main/java/org/apache/felix/mosgi/jmx/agent/mx4j/server/interceptor/MBeanServerInterceptorConfigurator.java
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.agent/src/main/java/org/apache/felix/mosgi/jmx/agent/mx4j/server/interceptor/MBeanServerInterceptorConfiguratorMBean.java
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.agent/src/main/java/org/apache/felix/mosgi/jmx/agent/mx4j/server/interceptor/NotificationListenerMBeanServerInterceptor.java
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.agent/src/main/java/org/apache/felix/mosgi/jmx/agent/mx4j/server/interceptor/SecurityMBeanServerInterceptor.java
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.agent/src/main/java/org/apache/felix/mosgi/jmx/agent/mx4j/server/interceptor/SecurityMBeanServerInterceptorMBean.java
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.agent/src/main/java/org/apache/felix/mosgi/jmx/agent/mx4j/util/
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.agent/src/main/java/org/apache/felix/mosgi/jmx/agent/mx4j/util/Base64Codec.java
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.agent/src/main/java/org/apache/felix/mosgi/jmx/agent/mx4j/util/MethodTernaryTree.java
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.agent/src/main/java/org/apache/felix/mosgi/jmx/agent/mx4j/util/Utils.java

Added: incubator/felix/trunk/org.apache.felix.mosgi.jmx.agent/pom.xml
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/org.apache.felix.mosgi.jmx.agent/pom.xml?rev=422696&view=auto
==============================================================================
--- incubator/felix/trunk/org.apache.felix.mosgi.jmx.agent/pom.xml (added)
+++ incubator/felix/trunk/org.apache.felix.mosgi.jmx.agent/pom.xml Mon Jul 17 05:14:31 2006
@@ -0,0 +1,65 @@
+<project>
+  <parent>
+    <groupId>org.apache.felix</groupId>
+    <artifactId>felix</artifactId>
+    <version>0.8.0-SNAPSHOT</version>
+  </parent>
+  <modelVersion>4.0.0</modelVersion>
+  <packaging>osgi-bundle</packaging>
+  <name>MOSGi JMX agent</name>
+  <artifactId>org.apache.felix.mosgi.jmx.agent</artifactId>
+  <dependencies>
+    <dependency>
+      <groupId>${pom.groupId}</groupId>
+      <artifactId>org.osgi.core</artifactId>
+      <version>${pom.version}</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>${pom.groupId}</groupId>
+      <artifactId>org.osgi.compendium</artifactId>
+      <version>${pom.version}</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>${pom.groupId}</groupId>
+      <artifactId>org.apache.felix.framework</artifactId>
+      <version>${pom.version}</version>
+      <scope>provided</scope>
+    </dependency>
+  </dependencies>
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.felix.plugins</groupId>
+        <artifactId>maven-osgi-plugin</artifactId>
+        <version>${pom.version}</version>
+        <extensions>true</extensions>
+        <configuration>
+          <osgiManifest>
+            <bundleName>MOSGi JMX-MX4J Agent Service</bundleName>
+            <bundleDescription>MOSGi JMX-MX4J Agent Service</bundleDescription>
+            <bundleActivator>auto-detect</bundleActivator>
+            <bundleDocUrl>http://oscar-osgi.sf.net/obr2/${pom.artifactId}/</bundleDocUrl>
+            <bundleUrl>http://oscar-osgi.sf.net/obr2/${pom.artifactId}/${pom.artifactId}-${pom.version}.jar</bundleUrl>
+            <bundleSource>http://oscar-osgi.sf.net/obr2/${pom.artifactId}/${pom.artifactId}-${pom.version}-src.jar</bundleSource>
+            <bundleSymbolicName>${pom.artifactId}</bundleSymbolicName>
+            <exportPackage>
+	                   ${pom.artifactId};specification-version="1.0.0",
+	                         org.apache.felix.mosgi.jmx.agent.mx4j.server;specification-version="1.0.0",
+	             org.apache.felix.mosgi.jmx.agent.mx4j.server.interceptor;specification-version="1.0.0"
+            </exportPackage>
+	    <importPackage>
+  	      org.osgi.service.log;specification-version="1.0.0",
+	      org.osgi.framework;specification-version="1.0.0",
+	      org.apache.felix.mosgi.jmx.agent.mx4j.server;specification-version="1.0.0",
+	      org.apache.felix.mosgi.jmx.agent.mx4j.server.interceptor;specification-version="1.0.0",
+	      javax.management;specification-version="1.0.0",
+	      javax.management.loading;specification-version="1.0.0"
+	    </importPackage>
+          </osgiManifest>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+</project>

Added: incubator/felix/trunk/org.apache.felix.mosgi.jmx.agent/src/main/java/org/apache/felix/mosgi/jmx/agent/AgentActivator.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/org.apache.felix.mosgi.jmx.agent/src/main/java/org/apache/felix/mosgi/jmx/agent/AgentActivator.java?rev=422696&view=auto
==============================================================================
--- incubator/felix/trunk/org.apache.felix.mosgi.jmx.agent/src/main/java/org/apache/felix/mosgi/jmx/agent/AgentActivator.java (added)
+++ incubator/felix/trunk/org.apache.felix.mosgi.jmx.agent/src/main/java/org/apache/felix/mosgi/jmx/agent/AgentActivator.java Mon Jul 17 05:14:31 2006
@@ -0,0 +1,284 @@
+/*
+ * Copyright (C) 2003 Stéphane Frénot
+ * Copyright (C) 2003 INSA Lyon Laboratoire CITI, France
+ * Copyright (C) 2003 INRIA projet ARES, France
+ *
+ * This program is licensed under the Apache Software License
+ * version 1.1; refer to the ASL-LICENSE.txt file included with
+ * this program for details.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * Contact: Stéphane Frénot stephane.frenot@insa-lyon.fr
+ * Contributor(s): Didier Donsez, didier.donsez@imag.fr
+ * 
+ * $Id: AgentActivator.java,v 1.6 2005/09/12 09:52:13 sfrenot Exp $
+ *
+ * TODO : profile should only call bc.getProperty
+**/
+/*
+ *   Copyright 2005 The Apache Software Foundation
+ *
+ *   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 org.apache.felix.mosgi.jmx.agent;
+
+import java.util.StringTokenizer;
+
+import java.lang.management.ManagementFactory;
+
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.Constants;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceListener;
+import org.osgi.framework.ServiceEvent;
+import org.osgi.framework.InvalidSyntaxException;
+
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+import javax.management.MalformedObjectNameException;
+import javax.management.MBeanServerFactory;
+import javax.management.DynamicMBean;
+import javax.management.InstanceAlreadyExistsException;
+import javax.management.InstanceNotFoundException;
+import javax.management.MBeanRegistrationException;
+import javax.management.NotCompliantMBeanException;
+
+import org.osgi.service.log.LogService;
+import org.apache.felix.framework.cache.BundleCache;
+
+public class AgentActivator implements BundleActivator, ServiceListener {
+  private MBeanServer server;
+  private ServiceRegistration serverRegistration;
+  static private BundleContext bc;
+  private String version = null;
+
+  //BundleActivator interface
+
+  public void start(BundleContext context) throws Exception  {
+    AgentActivator.bc=context;
+    this.version=(String)bc.getBundle().getHeaders().get(Constants.BUNDLE_VERSION);
+    AgentActivator.log(LogService.LOG_INFO, "Starting JMX Agent "+version,null);
+    String profile=bc.getProperty(BundleCache.CACHE_PROFILE_PROP);
+    if (profile==null){
+      profile=System.getProperty(BundleCache.CACHE_PROFILE_PROP);
+     }
+    String virtual=bc.getProperty("insa.jmxconsole.core."+profile);
+    StringTokenizer st=new StringTokenizer(System.getProperty("java.version"), ".");
+    st.nextToken();
+    int minor=Integer.parseInt(st.nextToken());
+
+    System.out.println("VIRTUAL OOOO "+virtual+" : "+profile);
+    this.startAgent(virtual, minor);
+    this.registerExistingMBeans();
+    bc.addServiceListener(this);
+  }
+
+  public void stop(BundleContext context) throws Exception {
+    AgentActivator.log(LogService.LOG_INFO, "JMX Agent stopping "+version,null);
+//    MBeanServerFactory.releaseMBeanServer(this.server);
+    this.unregisterExistingMBeans();
+    this.serverRegistration.unregister();
+    AgentActivator.log(LogService.LOG_INFO, "JMX Agent stopped "+version,null);
+    AgentActivator.bc=null;
+    this.serverRegistration=null;
+    this.server=null;
+  }
+
+  // Service Listener Interface
+  public void serviceChanged(ServiceEvent serviceEvent) {
+    ServiceReference serviceReference = serviceEvent.getServiceReference();
+    if (isMBean(serviceReference)) {
+      if (serviceEvent.getType() == ServiceEvent.REGISTERED) {
+         this.register(serviceReference);
+      } else if (serviceEvent.getType() == ServiceEvent.UNREGISTERING) {
+         this.unregister(serviceReference);
+      } else if (serviceEvent.getType() == ServiceEvent.MODIFIED) {
+         this.unregister(serviceReference);
+         this.register(serviceReference);
+      }
+    }
+  }
+  
+  private static void log(int prio, String message, Throwable t){
+    if (AgentActivator.bc!=null){
+      ServiceReference logSR=AgentActivator.bc.getServiceReference(LogService.class.getName());
+      if (logSR!=null){
+        ((LogService)AgentActivator.bc.getService(logSR)).log(prio, message, t);
+      }else{
+        System.out.println("No Log Service");
+      }
+    }else{
+      System.out.println(AgentActivator.class.getName()+": No bundleContext");
+    }
+  }
+
+  private void startAgent(String virtual, int minor){
+    if (virtual==null && minor >=5){
+      Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
+      this.server= ManagementFactory.getPlatformMBeanServer();
+      AgentActivator.log(LogService.LOG_DEBUG, "A jdk1.5 agent started "+this.server,null);
+    }else {
+      Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
+      this.server = MBeanServerFactory.createMBeanServer();
+      AgentActivator.log(LogService.LOG_DEBUG, "A lightweight agent started "+this.server,null);
+    }
+    this.serverRegistration=bc.registerService(MBeanServer.class.getName(), this.server, null);
+    AgentActivator.log(LogService.LOG_INFO, "JMX Agent started "+version,null);
+  }
+
+  private boolean isMBean(ServiceReference serviceReference) {
+    String[] objectClasses = (String[]) serviceReference .getProperty(Constants.OBJECTCLASS);
+    if (objectClasses == null){
+      return false;
+    }
+    int i = 0;
+    for (; i < objectClasses.length; i++) {
+      if (objectClasses[i].endsWith("MBean")){
+        break;
+      }
+        // "Static MBean interfaces" ends by "MBean"
+      if (objectClasses[i].equals(DynamicMBean.class.getName())){
+        break;
+      }
+    }
+    if (i == objectClasses.length){
+      return false;
+    }
+    return true;
+  }
+
+  private void registerExistingMBeans() {
+    ServiceReference[] serviceReferences = null;
+    try {
+      serviceReferences = bc.getServiceReferences(null, null);
+    } catch (InvalidSyntaxException e) {
+      // Never Thrown
+    }
+    if (serviceReferences == null){
+      return;
+    }
+    for (int i = 0; i < serviceReferences.length; i++) {
+      if (isMBean(serviceReferences[i])){
+        this.register(serviceReferences[i]);
+      }
+    }
+  }
+
+  private void unregisterExistingMBeans() {
+    ServiceReference[] serviceReferences = null;
+    try {
+      serviceReferences = bc.getServiceReferences(null, null);
+    } catch (InvalidSyntaxException e) {
+      // never thrown
+    }
+    if (serviceReferences == null){
+      return;
+    }
+    for (int i = 0; i < serviceReferences.length; i++) {
+      if (isMBean(serviceReferences[i])){
+        unregister(serviceReferences[i]);
+      }
+    }
+  } 
+
+  private void register(ServiceReference serviceReference) {
+    String name = this.getObjectNameString(serviceReference);
+
+    Object mbean = bc.getService(serviceReference);
+    ObjectName objectName = null;
+    try {
+      // Unique identification of MBeans
+      objectName = new ObjectName(name);
+    } catch (MalformedObjectNameException e) {
+      e.printStackTrace();
+    } catch (NullPointerException e) {
+      e.printStackTrace();
+    }
+    try {
+      // Uniquely identify the MBean and register it with the MBeanServer
+      server.registerMBean(mbean, objectName);
+    } catch (InstanceAlreadyExistsException e1) {
+      e1.printStackTrace();
+    } catch (MBeanRegistrationException e1) {
+      e1.printStackTrace();
+    } catch (NotCompliantMBeanException e1) {
+      e1.printStackTrace();
+    }
+  }
+
+  private void unregister(ServiceReference serviceReference) {
+    String name = getObjectNameString(serviceReference);
+    try {
+      // TODO check if unregisterMBean occurs really
+      server.unregisterMBean(new ObjectName(name));
+    } catch (InstanceNotFoundException e) {
+      // do nothing;
+    } catch (Exception e) {
+      e.printStackTrace();
+    }
+  }
+
+  private  String getObjectNameString(ServiceReference serviceReference) {
+    String objectName = (String) serviceReference.getProperty(org.apache.felix.mosgi.jmx.agent.Constants.OBJECTNAME);
+    if (objectName != null){
+      // If objectName starts with the colon character (:), the domain part of the object name is the domain of the agent.
+      if(objectName.startsWith(":")){
+        // invokes the getDefaultDomain() method of the Framework class to obtain this information. 
+        objectName=server.getDefaultDomain()+objectName;
+      }
+      return objectName;
+    }
+
+System.out.println("No "+org.apache.felix.mosgi.jmx.agent.Constants.OBJECTNAME+" constant for "+serviceReference+" MBean. Trying to build it");
+
+    String[] objectClasses = (String[]) serviceReference.getProperty(Constants.OBJECTCLASS);
+    if (objectClasses == null){
+      return null;
+    }
+    int i = 0;
+    for (; i < objectClasses.length; i++) {
+      if (objectClasses[i].endsWith("MBean")){
+        break;
+      }
+    }
+    // TODO do nothing if there is several MBean inplemented interfaces
+    if (i == objectClasses.length){
+      return null;
+    }
+    
+    StringBuffer sb=new StringBuffer(server.getDefaultDomain());
+    sb.append(":");
+    sb.append("BundleId=");
+    sb.append(serviceReference.getBundle().getBundleId());
+    sb.append(", ServiceId=");
+    sb.append(serviceReference.getProperty(Constants.SERVICE_ID));
+    sb.append(", ObjectClass=");
+    sb.append(objectClasses[i]);
+    Object servicePID=serviceReference.getProperty(Constants.SERVICE_PID);
+    if (servicePID==null){
+      sb.append(", servicePID=NA");
+    }else{
+      sb.append(", servicePID=");
+      sb.append(servicePID);
+    }
+System.out.println("==>"+sb.toString());
+    return sb.toString();
+    
+  }
+}

Added: incubator/felix/trunk/org.apache.felix.mosgi.jmx.agent/src/main/java/org/apache/felix/mosgi/jmx/agent/Constants.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/org.apache.felix.mosgi.jmx.agent/src/main/java/org/apache/felix/mosgi/jmx/agent/Constants.java?rev=422696&view=auto
==============================================================================
--- incubator/felix/trunk/org.apache.felix.mosgi.jmx.agent/src/main/java/org/apache/felix/mosgi/jmx/agent/Constants.java (added)
+++ incubator/felix/trunk/org.apache.felix.mosgi.jmx.agent/src/main/java/org/apache/felix/mosgi/jmx/agent/Constants.java Mon Jul 17 05:14:31 2006
@@ -0,0 +1,4 @@
+package org.apache.felix.mosgi.jmx.agent;
+public interface Constants {
+   public final static String OBJECTNAME="jmxagent.objectname";
+}

Added: incubator/felix/trunk/org.apache.felix.mosgi.jmx.agent/src/main/java/org/apache/felix/mosgi/jmx/agent/mx4j/AbstractDynamicMBean.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/org.apache.felix.mosgi.jmx.agent/src/main/java/org/apache/felix/mosgi/jmx/agent/mx4j/AbstractDynamicMBean.java?rev=422696&view=auto
==============================================================================
--- incubator/felix/trunk/org.apache.felix.mosgi.jmx.agent/src/main/java/org/apache/felix/mosgi/jmx/agent/mx4j/AbstractDynamicMBean.java (added)
+++ incubator/felix/trunk/org.apache.felix.mosgi.jmx.agent/src/main/java/org/apache/felix/mosgi/jmx/agent/mx4j/AbstractDynamicMBean.java Mon Jul 17 05:14:31 2006
@@ -0,0 +1,519 @@
+/*
+ * Copyright (C) MX4J.
+ * All rights reserved.
+ *
+ * This software is distributed under the terms of the MX4J License version 1.0.
+ * See the terms of the MX4J License in the documentation provided with this software.
+*/
+/*
+ *   Copyright 2005 The Apache Software Foundation
+ *
+ *   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 org.apache.felix.mosgi.jmx.agent.mx4j;
+
+import java.lang.reflect.Method;
+import java.lang.reflect.InvocationTargetException;
+import java.util.Arrays;
+
+import javax.management.DynamicMBean;
+import javax.management.AttributeNotFoundException;
+import javax.management.MBeanException;
+import javax.management.ReflectionException;
+import javax.management.AttributeList;
+import javax.management.MBeanInfo;
+import javax.management.Attribute;
+import javax.management.InvalidAttributeValueException;
+import javax.management.MBeanAttributeInfo;
+import javax.management.MBeanConstructorInfo;
+import javax.management.MBeanOperationInfo;
+import javax.management.MBeanNotificationInfo;
+import javax.management.RuntimeErrorException;
+import javax.management.MBeanParameterInfo;
+import javax.management.RuntimeMBeanException;
+
+import org.apache.felix.mosgi.jmx.agent.mx4j.util.Utils;
+
+/**
+ * Utility class that allow the user to easily write DynamicMBeans. <br>
+ * By extending this class, the developer does not have to implement the methods of the DynamicMBean interface, but
+ * has instead to provide only the metadata (by overriding few methods) and the implementation (by implementing
+ * the methods) of the MBean itself. <br>
+ * The methods to override that provides metadata information are usually the following:
+ * <ul>
+ * <li> <code>createMBeanAttributeInfo</code>, if the MBeans has manageable attributes </li>
+ * <li> <code>createMBeanOperationInfo</code>, if the MBeans has manageable operations </li>
+ * <li> <code>createMBeanNotificationInfo</code>, if the MBeans has manageable notifications </li>
+ * <li> <code>createMBeanConstructorInfo</code>, if the MBeans has manageable constructors </li>
+ * <li> <code>getMBeanDescription</code> </li>
+ * </ul>
+ * For example, the following MBean only has one manageable attribute:
+ * <pre>
+ * public class SimpleDynamic extends AbstractDynamicMBean
+ * {
+ *    protected MBeanAttributeInfo[] createMBeanAttributeInfo()
+ *    {
+ *       return new MBeanAttributeInfo[]
+ *       {
+ *          new MBeanAttributeInfo("Name", String.class.getName(), "The name", true, true, false)
+ *       };
+ *    }
+ *
+ *    protected String getMBeanDescription()
+ *    {
+ *       return "A simple DynamicMBean";
+ *    }
+ *
+ *    public String getName() { ... }
+ *
+ *    public void setName(String name) { ... }
+ * }
+ * </pre>
+ * It is responsibility of the developer to specify the metadata <b>and</b> implement the methods specified by the
+ * metadata, that will be invoked via reflection by the AbstractDynamicMBean class. For this reason, the methods
+ * belonging to the MBean implementation (in the case above <code>getName()</code> and <code>setName(...)</code>)
+ * must be public.
+ *
+ * @author <a href="mailto:biorn_steedom@users.sourceforge.net">Simone Bordet</a>
+ * @version $Revision: 1.1.1.1 $
+ */
+public abstract class AbstractDynamicMBean implements DynamicMBean
+{
+   private MBeanInfo info;
+   private Object resource;
+
+   /**
+    * Only subclasses can create a new instance of an AbstractDynamicMBean.
+    * @see #createMBeanConstructorInfo
+    */
+   protected AbstractDynamicMBean()
+   {
+   }
+
+   /**
+    * Returns the value of the manageable attribute, as specified by the DynamicMBean interface.
+    * @see #createMBeanAttributeInfo
+    */
+   public Object getAttribute(String attribute) throws AttributeNotFoundException, MBeanException, ReflectionException
+   {
+      if (attribute == null) throw new AttributeNotFoundException("Attribute " + attribute + " not found");
+
+      Object resource = null;
+      MBeanInfo info = null;
+      synchronized (this)
+      {
+         resource = getResourceOrThis();
+         info = getMBeanInfo();
+      }
+
+      MBeanAttributeInfo[] attrs = info.getAttributes();
+      if (attrs == null || attrs.length == 0) throw new AttributeNotFoundException("No attributes defined for this MBean");
+
+      for (int i = 0; i < attrs.length; ++i)
+      {
+         MBeanAttributeInfo attr = attrs[i];
+         if (attr == null) continue;
+
+         if (attribute.equals(attr.getName()))
+         {
+            if (!attr.isReadable()) throw new ReflectionException(new NoSuchMethodException("No getter defined for attribute: " + attribute));
+
+            // Found, invoke via reflection
+            String prefix = null;
+            if (attr.isIs())
+               prefix = "is";
+            else
+               prefix = "get";
+
+            try
+            {
+               return invoke(resource, prefix + attr.getName(), new Class[0], new Object[0]);
+            }
+            catch (InvalidAttributeValueException x)
+            {
+               throw new ReflectionException(x);
+            }
+         }
+      }
+
+      throw new AttributeNotFoundException("Attribute " + attribute + " not found");
+   }
+
+   /**
+    * Returns the manageable attributes, as specified by the DynamicMBean interface.
+    */
+   public AttributeList getAttributes(String[] attributes)
+   {
+      AttributeList list = new AttributeList();
+
+      if (attributes != null)
+      {
+         for (int i = 0; i < attributes.length; ++i)
+         {
+            String attribute = attributes[i];
+            try
+            {
+               Object result = getAttribute(attribute);
+               list.add(new Attribute(attribute, result));
+            }
+            catch (AttributeNotFoundException ignored)
+            {
+            }
+            catch (MBeanException ignored)
+            {
+            }
+            catch (ReflectionException ignored)
+            {
+            }
+         }
+      }
+
+      return list;
+   }
+
+   /**
+    * Returns the MBeaInfo, as specified by the DynamicMBean interface; the default implementation caches the value
+    * returned by {@link #createMBeanInfo} (that is thus called only once).
+    * @see #createMBeanInfo
+    * @see #setMBeanInfo
+    */
+   public synchronized MBeanInfo getMBeanInfo()
+   {
+      if (info == null) setMBeanInfo(createMBeanInfo());
+      return info;
+   }
+
+   /**
+    * Returns the value of the manageable operation as specified by the DynamicMBean interface
+    * @see #createMBeanOperationInfo
+    */
+   public Object invoke(String method, Object[] arguments, String[] params) throws MBeanException, ReflectionException
+   {
+      if (method == null) throw new IllegalArgumentException("Method name cannot be null");
+      if (arguments == null) arguments = new Object[0];
+      if (params == null) params = new String[0];
+
+      Object resource = null;
+      MBeanInfo info = null;
+      synchronized (this)
+      {
+         resource = getResourceOrThis();
+         info = getMBeanInfo();
+      }
+
+      MBeanOperationInfo[] opers = info.getOperations();
+      if (opers == null || opers.length == 0) throw new ReflectionException(new NoSuchMethodException("No operations defined for this MBean"));
+
+      for (int i = 0; i < opers.length; ++i)
+      {
+         MBeanOperationInfo oper = opers[i];
+         if (oper == null) continue;
+
+         if (method.equals(oper.getName()))
+         {
+            MBeanParameterInfo[] parameters = oper.getSignature();
+            if (params.length != parameters.length) continue;
+
+            String[] signature = new String[parameters.length];
+            for (int j = 0; j < signature.length; ++j)
+            {
+               MBeanParameterInfo param = parameters[j];
+               if (param == null)
+                  signature[j] = null;
+               else
+                  signature[j] = param.getType();
+            }
+
+            if (Utils.arrayEquals(params, signature))
+            {
+               // Found the right operation
+               try
+               {
+                  Class[] classes = Utils.loadClasses(resource.getClass().getClassLoader(), signature);
+                  return invoke(resource, method, classes, arguments);
+               }
+               catch (ClassNotFoundException x)
+               {
+                  throw new ReflectionException(x);
+               }
+               catch (InvalidAttributeValueException x)
+               {
+                  throw new ReflectionException(x);
+               }
+            }
+         }
+      }
+
+      throw new ReflectionException(new NoSuchMethodException("Operation " + method + " with signature " + Arrays.asList(params) + " is not defined for this MBean"));
+   }
+
+   /**
+    * Sets the value of the manageable attribute, as specified by the DynamicMBean interface.
+    * @see #createMBeanAttributeInfo
+    */
+   public void setAttribute(Attribute attribute) throws AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException
+   {
+      if (attribute == null) throw new AttributeNotFoundException("Attribute " + attribute + " not found");
+
+      Object resource = null;
+      MBeanInfo info = null;
+      synchronized (this)
+      {
+         resource = getResourceOrThis();
+         info = getMBeanInfo();
+      }
+
+      MBeanAttributeInfo[] attrs = info.getAttributes();
+      if (attrs == null || attrs.length == 0) throw new AttributeNotFoundException("No attributes defined for this MBean");
+
+      for (int i = 0; i < attrs.length; ++i)
+      {
+         MBeanAttributeInfo attr = attrs[i];
+         if (attr == null) continue;
+
+         if (attribute.getName().equals(attr.getName()))
+         {
+            if (!attr.isWritable()) throw new ReflectionException(new NoSuchMethodException("No setter defined for attribute: " + attribute));
+
+            try
+            {
+               String signature = attr.getType();
+               Class cls = Utils.loadClass(resource.getClass().getClassLoader(), signature);
+               invoke(resource, "set" + attr.getName(), new Class[]{cls}, new Object[]{attribute.getValue()});
+               return;
+            }
+            catch (ClassNotFoundException x)
+            {
+               throw new ReflectionException(x);
+            }
+         }
+      }
+
+      throw new AttributeNotFoundException("Attribute " + attribute + " not found");
+   }
+
+   /**
+    * Sets the manageable attributes, as specified by the DynamicMBean interface.
+    */
+   public AttributeList setAttributes(AttributeList attributes)
+   {
+      AttributeList list = new AttributeList();
+
+      if (attributes != null)
+      {
+         for (int i = 0; i < attributes.size(); ++i)
+         {
+            Attribute attribute = (Attribute)attributes.get(i);
+            try
+            {
+               setAttribute(attribute);
+               list.add(attribute);
+            }
+            catch (AttributeNotFoundException ignored)
+            {
+            }
+            catch (InvalidAttributeValueException ignored)
+            {
+            }
+            catch (MBeanException ignored)
+            {
+            }
+            catch (ReflectionException ignored)
+            {
+            }
+         }
+      }
+
+      return list;
+   }
+
+   /**
+    * @deprecated Replaced by {@link #invoke(Object,String,Class[],Object[])}. <br>
+    * The resource passed is the resource as set by {@link #setResource} or - if it is null - 'this' instance. <br>
+    * This method is deprecated because it is not thread safe.
+    */
+   protected Object invoke(String name, Class[] params, Object[] args) throws InvalidAttributeValueException, MBeanException, ReflectionException
+   {
+      Object resource = getResourceOrThis();
+      return invoke(resource, name, params, args);
+   }
+
+   /**
+    * Looks up the method to call on given resource and invokes it.
+    * The default implementation requires that the methods that implement attribute and operation behavior
+    * on the resource object are public, but it is possible to override this behavior, and call
+    * also private methods.
+    * @see #findMethod
+    * @see #invokeMethod
+    */
+   protected Object invoke(Object resource, String name, Class[] params, Object[] args) throws InvalidAttributeValueException, MBeanException, ReflectionException
+   {
+      try
+      {
+         Class cls = resource.getClass();
+         Method method = findMethod(cls, name, params);
+         return invokeMethod(method, resource, args);
+      }
+      catch (NoSuchMethodException x)
+      {
+         throw new ReflectionException(x);
+      }
+      catch (IllegalAccessException x)
+      {
+         throw new ReflectionException(x);
+      }
+      catch (IllegalArgumentException x)
+      {
+         throw new InvalidAttributeValueException(x.toString());
+      }
+      catch (InvocationTargetException x)
+      {
+         Throwable t = x.getTargetException();
+         if (t instanceof RuntimeException)
+            throw new RuntimeMBeanException((RuntimeException)t);
+         else if (t instanceof Exception) throw new MBeanException((Exception)t);
+         throw new RuntimeErrorException((Error)t);
+      }
+   }
+
+   /**
+    * Returns the (public) method with the given name and signature on the given class. <br>
+    * Override to return non-public methods, or to map methods to other classes, or to map methods with
+    * different signatures
+    * @see #invoke(String, Class[], Object[])
+    * @see #invokeMethod
+    */
+   protected Method findMethod(Class cls, String name, Class[] params) throws NoSuchMethodException
+   {
+      return cls.getMethod(name, params);
+   }
+
+   /**
+    * Invokes the given method on the given resource object with the given arguments. <br>
+    * Override to map methods to other objects, or to map methods with different arguments
+    * @see #invoke(String, Class[], Object[])
+    * @see #findMethod
+    */
+   protected Object invokeMethod(Method method, Object resource, Object[] args) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException
+   {
+      return method.invoke(resource, args);
+   }
+
+   private Object getResourceOrThis()
+   {
+      Object resource = getResource();
+      if (resource == null) resource = this;
+      return resource;
+   }
+
+   /**
+    * Returns the resource object on which invoke attribute's getters, attribute's setters and operation's methods
+    * @see #setResource
+    */
+   protected synchronized Object getResource()
+   {
+      return resource;
+   }
+
+   /**
+    * Specifies the resource object on which invoke attribute's getters, attribute's setters and operation's methods.
+    * @see #getResource
+    */
+   public synchronized void setResource(Object resource)
+   {
+      this.resource = resource;
+   }
+
+   /**
+    * Sets the MBeanInfo object cached by this instance. <br>
+    * The given MBeanInfo is not cloned.
+    * @see #getMBeanInfo
+    */
+   protected synchronized void setMBeanInfo(MBeanInfo info)
+   {
+      this.info = info;
+   }
+
+   /**
+    * Creates the MBeanInfo for this instance, calling in succession factory methods that the user can override.
+    * Information to create MBeanInfo are taken calling the following methods:
+    * <ul>
+    * <li><code>{@link #createMBeanAttributeInfo}</code></li>
+    * <li><code>{@link #createMBeanConstructorInfo}</code></li>
+    * <li><code>{@link #createMBeanOperationInfo}</code></li>
+    * <li><code>{@link #createMBeanNotificationInfo}</code></li>
+    * <li><code>{@link #getMBeanClassName}</code></li>
+    * <li><code>{@link #getMBeanDescription}</code></li>
+    * </ul>
+    */
+   protected MBeanInfo createMBeanInfo()
+   {
+      MBeanAttributeInfo[] attrs = createMBeanAttributeInfo();
+      MBeanConstructorInfo[] ctors = createMBeanConstructorInfo();
+      MBeanOperationInfo[] opers = createMBeanOperationInfo();
+      MBeanNotificationInfo[] notifs = createMBeanNotificationInfo();
+      String className = getMBeanClassName();
+      String description = getMBeanDescription();
+      return new MBeanInfo(className, description, attrs, ctors, opers, notifs);
+   }
+
+   /**
+    * To be overridden to return metadata information about manageable attributes.
+    */
+   protected MBeanAttributeInfo[] createMBeanAttributeInfo()
+   {
+      return new MBeanAttributeInfo[0];
+   }
+
+   /**
+    * To be overridden to return metadata information about manageable constructors.
+    */
+   protected MBeanConstructorInfo[] createMBeanConstructorInfo()
+   {
+      return new MBeanConstructorInfo[0];
+   }
+
+   /**
+    * To be overridden to return metadata information about manageable operations.
+    */
+   protected MBeanOperationInfo[] createMBeanOperationInfo()
+   {
+      return new MBeanOperationInfo[0];
+   }
+
+   /**
+    * To be overridden to return metadata information about manageable notifications.
+    */
+   protected MBeanNotificationInfo[] createMBeanNotificationInfo()
+   {
+      return new MBeanNotificationInfo[0];
+   }
+
+   /**
+    * To be overridden to return metadata information about the class name of this MBean;
+    * by default returns this class' name.
+    */
+   protected String getMBeanClassName()
+   {
+      return getClass().getName();
+   }
+
+   /**
+    * To be overridden to return metadata information about the description of this MBean.
+    */
+   protected String getMBeanDescription()
+   {
+      return null;
+   }
+}

Added: incubator/felix/trunk/org.apache.felix.mosgi.jmx.agent/src/main/java/org/apache/felix/mosgi/jmx/agent/mx4j/ImplementationException.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/org.apache.felix.mosgi.jmx.agent/src/main/java/org/apache/felix/mosgi/jmx/agent/mx4j/ImplementationException.java?rev=422696&view=auto
==============================================================================
--- incubator/felix/trunk/org.apache.felix.mosgi.jmx.agent/src/main/java/org/apache/felix/mosgi/jmx/agent/mx4j/ImplementationException.java (added)
+++ incubator/felix/trunk/org.apache.felix.mosgi.jmx.agent/src/main/java/org/apache/felix/mosgi/jmx/agent/mx4j/ImplementationException.java Mon Jul 17 05:14:31 2006
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) MX4J.
+ * All rights reserved.
+ *
+ * This software is distributed under the terms of the MX4J License version 1.0.
+ * See the terms of the MX4J License in the documentation provided with this software.
+ */
+/*
+ *   Copyright 2005 The Apache Software Foundation
+ *
+ *   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 org.apache.felix.mosgi.jmx.agent.mx4j;
+
+/**
+ * Thrown when an internal error in the MX4J implementation is detected.
+ * Contact the MX4J mailing list for support when this exception is thrown in your programs.
+ *
+ * @author <a href="mailto:biorn_steedom@users.sourceforge.net">Simone Bordet</a>
+ * @version $Revision: 1.1.1.1 $
+ */
+public class ImplementationException extends RuntimeException
+{
+	public ImplementationException() {}
+	public ImplementationException(String message) {super(message);}
+}

Added: incubator/felix/trunk/org.apache.felix.mosgi.jmx.agent/src/main/java/org/apache/felix/mosgi/jmx/agent/mx4j/MBeanDescription.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/org.apache.felix.mosgi.jmx.agent/src/main/java/org/apache/felix/mosgi/jmx/agent/mx4j/MBeanDescription.java?rev=422696&view=auto
==============================================================================
--- incubator/felix/trunk/org.apache.felix.mosgi.jmx.agent/src/main/java/org/apache/felix/mosgi/jmx/agent/mx4j/MBeanDescription.java (added)
+++ incubator/felix/trunk/org.apache.felix.mosgi.jmx.agent/src/main/java/org/apache/felix/mosgi/jmx/agent/mx4j/MBeanDescription.java Mon Jul 17 05:14:31 2006
@@ -0,0 +1,84 @@
+/*
+ * Copyright (C) MX4J.
+ * All rights reserved.
+ *
+ * This software is distributed under the terms of the MX4J License version 1.0.
+ * See the terms of the MX4J License in the documentation provided with this software.
+ */
+/*
+ *   Copyright 2005 The Apache Software Foundation
+ *
+ *   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 org.apache.felix.mosgi.jmx.agent.mx4j;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
+
+/**
+ * Implement this inteface to give descriptions to standard MBean. <p>
+ * The MX4J implementation will look, for every standard MBean, for a class with name composed by
+ * the fully qualified MBean class name + "MBeanDescription".
+ * If such a class is found, the MX4J implementation will call its methods to retrieve description
+ * information about the MBean itself.
+ * MBean descriptions are built-in in DynamicMBean, but not in standard MBeans.
+ * The <a href="http://xdoclet.sourceforge.net">XDoclet</a>  tool is used to automate the process of
+ * generating the MBeanDescription classes for a given MBean, along with the MBean interface.
+ *
+ * @author <a href="mailto:biorn_steedom@users.sourceforge.net">Simone Bordet</a>
+ * @version $Revision: 1.1.1.1 $
+ */
+public interface MBeanDescription
+{
+   /**
+    * Should return the description of the MBean.
+    * For example: "This MBean is the rmiregistry service"
+    */
+	public String getMBeanDescription();
+   /**
+    * Should return the description for the given constructor of the MBean.
+    * For example: "Creates an rmiregistry instance on the specified port"
+    */
+	public String getConstructorDescription(Constructor ctor);
+   /**
+    * Should return the name of the constructor's parameter for the given constructor and parameter index.
+    * For example: "port"
+    */
+	public String getConstructorParameterName(Constructor ctor, int index);
+   /**
+    * Should return the description for the constructor's parameter for the given constructor and parameter index.
+    * For example: "The port on which the rmiregistry will wait on for client requests"
+    */
+	public String getConstructorParameterDescription(Constructor ctor, int index);
+   /**
+    * Should return the description for the specified attribute.
+    * For example: "The port on which the rmiregistry will wait on for client requests"
+    */
+	public String getAttributeDescription(String attribute);
+   /**
+    * Should return the description for the specified operation.
+    * For example: "Binds the given object to the given name"
+    */
+	public String getOperationDescription(Method operation);
+   /**
+    * Should return the name of the operation's parameter for the given operation and parameter index.
+    * For example: "bindName"
+    */
+	public String getOperationParameterName(Method method, int index);
+   /**
+    * Should return the description for the operations's parameter for the given operation and parameter index.
+    * For example: "The name to which the object will be bound to"
+    */
+	public String getOperationParameterDescription(Method method, int index);
+}

Added: incubator/felix/trunk/org.apache.felix.mosgi.jmx.agent/src/main/java/org/apache/felix/mosgi/jmx/agent/mx4j/MBeanDescriptionAdapter.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/org.apache.felix.mosgi.jmx.agent/src/main/java/org/apache/felix/mosgi/jmx/agent/mx4j/MBeanDescriptionAdapter.java?rev=422696&view=auto
==============================================================================
--- incubator/felix/trunk/org.apache.felix.mosgi.jmx.agent/src/main/java/org/apache/felix/mosgi/jmx/agent/mx4j/MBeanDescriptionAdapter.java (added)
+++ incubator/felix/trunk/org.apache.felix.mosgi.jmx.agent/src/main/java/org/apache/felix/mosgi/jmx/agent/mx4j/MBeanDescriptionAdapter.java Mon Jul 17 05:14:31 2006
@@ -0,0 +1,77 @@
+/*
+ * Copyright (C) MX4J.
+ * All rights reserved.
+ *
+ * This software is distributed under the terms of the MX4J License version 1.0.
+ * See the terms of the MX4J License in the documentation provided with this software.
+ */
+/*
+ *   Copyright 2005 The Apache Software Foundation
+ *
+ *   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 org.apache.felix.mosgi.jmx.agent.mx4j;
+
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
+
+/**
+ * Default implementation for the MBeanDescription interface.
+ *
+ * @author <a href="mailto:biorn_steedom@users.sourceforge.net">Simone Bordet</a>
+ * @version $Revision: 1.1.1.1 $
+ */
+public class MBeanDescriptionAdapter implements MBeanDescription
+{
+	public String getMBeanDescription()
+	{
+		return "Manageable Bean";
+	}
+
+	public String getConstructorDescription(Constructor ctor)
+	{
+		return "Constructor exposed for management";
+	}
+
+	public String getConstructorParameterName(Constructor ctor, int index)
+	{
+		return "param" + (index + 1);
+	}
+
+	public String getConstructorParameterDescription(Constructor ctor, int index)
+	{
+		return "Constructor's parameter n. " + (index + 1);
+	}
+
+	public String getAttributeDescription(String attribute)
+	{
+		return "Attribute exposed for management";
+	}
+
+	public String getOperationDescription(Method operation)
+	{
+		return "Operation exposed for management";
+	}
+
+	public String getOperationParameterName(Method method, int index)
+	{
+		return "param" + (index + 1);
+	}
+
+	public String getOperationParameterDescription(Method method, int index)
+	{
+		return "Operation's parameter n. " + (index + 1);
+	}
+}

Added: incubator/felix/trunk/org.apache.felix.mosgi.jmx.agent/src/main/java/org/apache/felix/mosgi/jmx/agent/mx4j/MX4JSystemKeys.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/org.apache.felix.mosgi.jmx.agent/src/main/java/org/apache/felix/mosgi/jmx/agent/mx4j/MX4JSystemKeys.java?rev=422696&view=auto
==============================================================================
--- incubator/felix/trunk/org.apache.felix.mosgi.jmx.agent/src/main/java/org/apache/felix/mosgi/jmx/agent/mx4j/MX4JSystemKeys.java (added)
+++ incubator/felix/trunk/org.apache.felix.mosgi.jmx.agent/src/main/java/org/apache/felix/mosgi/jmx/agent/mx4j/MX4JSystemKeys.java Mon Jul 17 05:14:31 2006
@@ -0,0 +1,100 @@
+/*
+ * Copyright (C) MX4J.
+ * All rights reserved.
+ *
+ * This software is distributed under the terms of the MX4J License version 1.0.
+ * See the terms of the MX4J License in the documentation provided with this software.
+ */
+/*
+ *   Copyright 2005 The Apache Software Foundation
+ *
+ *   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 org.apache.felix.mosgi.jmx.agent.mx4j;
+
+/**
+ * This class holds the system property keys that the MX4J implementation uses to plugin
+ * custom components. <br>
+ * The naming convention is that, for a defined constant, the corrispondent system property
+ * is obtained by converting the constant name to lowercase and by replacing the underscores
+ * with dots so that, for example, the constant <code>MX4J_MBEANSERVER_CLASSLOADER_REPOSITORY</code>
+ * correspond to the system property key <code>mx4j.mbeanserver.classloader.repository</code>
+ *
+ * @author <a href="mailto:biorn_steedom@users.sourceforge.net">Simone Bordet</a>
+ * @version $Revision: 1.1.1.1 $
+ */
+public final class MX4JSystemKeys
+{
+   /**
+    * Specifies a full qualified class name of a class implementing the {@link mx4j.server.MBeanRepository}
+    * interface, that will be used by the MBeanServer to store information about registered MBeans.
+    */
+   public static final String MX4J_MBEANSERVER_REPOSITORY = "mx4j.mbeanserver.repository";
+
+   /**
+    * Specifies a full qualified class name of a class extending the {@link mx4j.server.ModifiableClassLoaderRepository}
+    * class, that will be used by the MBeanServer to store ClassLoader MBeans that wants to be registered in
+    * the MBeanServer's ClassLoaderRepository.
+    */
+   public static final String MX4J_MBEANSERVER_CLASSLOADER_REPOSITORY = "mx4j.mbeanserver.classloader.repository";
+
+   /**
+    * Specifies the level of logging performed by the MX4J JMX implementation.
+    * Possible value are (case insensitive), from most verbose to least verbose:
+    * <ul>
+    * <li>trace</li>
+    * <li>debug</li>
+    * <li>info</li>
+    * <li>warn</li>
+    * <li>error</li>
+    * <li>fatal</li>
+    * </ul>
+    */
+   public static final String MX4J_LOG_PRIORITY = "mx4j.log.priority";
+
+   /**
+    * Specifies a full qualified class name of a class extending the {@link mx4j.log.Logger} class, that
+    * will be used as prototype for new loggers created.
+    */
+   public static final String MX4J_LOG_PROTOTYPE = "mx4j.log.prototype";
+
+   /**
+    * When this property is set to false (as specified by {@link Boolean#valueOf(String)}), the MX4J
+    * JMX implementation will accept as MBean interfaces of standard MBeans also interfaces defined in
+    * different packages or as nested classes of the MBean class.
+    * So for example, will be possible for a com.foo.Service to have a management interface called
+    * com.bar.ServiceMBean.
+    * If not defined, or if set to true, only MBean interfaces of the same package of the MBean class
+    * are considered valid management interfaces.
+    */
+   public static final String MX4J_STRICT_MBEAN_INTERFACE = "mx4j.strict.mbean.interface";
+
+   /**
+    * Specifies a full qualified class name of a class implementing the {@link mx4j.server.MBeanInvoker} interface,
+    * that will be used as invoker for standard MBeans.
+    * Two classes are provided by the MX4J JMX implementation: {@link mx4j.server.BCELMBeanInvoker} and
+    * {@link mx4j.server.ReflectedMBeanInvoker}.
+    * The first one will use BCEL classes (if present) to speed up invocations on standard MBeans, while the second
+    * uses reflection.
+    * If, for any reason, the BCEL invocation fails, then the reflected invoker is used.
+    */
+   public static final String MX4J_MBEAN_INVOKER = "mx4j.mbean.invoker";
+
+   /**
+    * From JMX 1.2, names for attributes and operations, as well as their (return) types, must be valid
+    * Java identifiers, as specified by {@link Character#isJavaIdentifierStart} and {@link Character#isJavaIdentifierPart}.
+    * When set to true, (as specified by {@link Boolean#valueOf(String)}), this property turnes off this check.
+    */
+   public static String MX4J_UNCHECKED_IDENTIFIERS = "jmx.unchecked.identifiers";
+}

Added: incubator/felix/trunk/org.apache.felix.mosgi.jmx.agent/src/main/java/org/apache/felix/mosgi/jmx/agent/mx4j/loading/ClassLoaderObjectInputStream.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/org.apache.felix.mosgi.jmx.agent/src/main/java/org/apache/felix/mosgi/jmx/agent/mx4j/loading/ClassLoaderObjectInputStream.java?rev=422696&view=auto
==============================================================================
--- incubator/felix/trunk/org.apache.felix.mosgi.jmx.agent/src/main/java/org/apache/felix/mosgi/jmx/agent/mx4j/loading/ClassLoaderObjectInputStream.java (added)
+++ incubator/felix/trunk/org.apache.felix.mosgi.jmx.agent/src/main/java/org/apache/felix/mosgi/jmx/agent/mx4j/loading/ClassLoaderObjectInputStream.java Mon Jul 17 05:14:31 2006
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) MX4J.
+ * All rights reserved.
+ *
+ * This software is distributed under the terms of the MX4J License version 1.0.
+ * See the terms of the MX4J License in the documentation provided with this software.
+ */
+
+/*
+ *   Copyright 2005 The Apache Software Foundation
+ *
+ *   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 org.apache.felix.mosgi.jmx.agent.mx4j.loading;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectStreamClass;
+import java.io.StreamCorruptedException;
+import java.lang.reflect.Proxy;
+
+/**
+ * ObjectInputStream that can read serialized java Objects using a supplied classloader
+ * to find the object's classes.
+ *
+ * @author <a href="mailto:biorn_steedom@users.sourceforge.net">Simone Bordet</a>
+ * @version $Revision: 1.1.1.1 $
+ */
+public class ClassLoaderObjectInputStream extends ObjectInputStream
+{
+   private ClassLoader classLoader;
+
+   /**
+    * Creates a new ClassLoaderObjectInputStream
+    * @param stream The decorated stream
+    * @param classLoader The ClassLoader used to load classes
+    */
+   public ClassLoaderObjectInputStream(InputStream stream, ClassLoader classLoader) throws IOException, StreamCorruptedException
+   {
+      super(stream);
+      if (classLoader == null) throw new IllegalArgumentException("Classloader cannot be null");
+      this.classLoader = classLoader;
+   }
+
+   protected Class resolveClass(ObjectStreamClass osc) throws IOException, ClassNotFoundException
+   {
+      String name = osc.getName();
+      return loadClass(name);
+   }
+
+   protected Class resolveProxyClass(String[] interfaces) throws IOException, ClassNotFoundException
+   {
+      Class[] classes = new Class[interfaces.length];
+      for (int i = 0; i < interfaces.length; ++i) classes[i] = loadClass(interfaces[i]);
+
+      return Proxy.getProxyClass(classLoader, classes);
+   }
+
+   private Class loadClass(String name) throws ClassNotFoundException
+   {
+      return classLoader.loadClass(name);
+   }
+}

Added: incubator/felix/trunk/org.apache.felix.mosgi.jmx.agent/src/main/java/org/apache/felix/mosgi/jmx/agent/mx4j/loading/MLetParseException.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/org.apache.felix.mosgi.jmx.agent/src/main/java/org/apache/felix/mosgi/jmx/agent/mx4j/loading/MLetParseException.java?rev=422696&view=auto
==============================================================================
--- incubator/felix/trunk/org.apache.felix.mosgi.jmx.agent/src/main/java/org/apache/felix/mosgi/jmx/agent/mx4j/loading/MLetParseException.java (added)
+++ incubator/felix/trunk/org.apache.felix.mosgi.jmx.agent/src/main/java/org/apache/felix/mosgi/jmx/agent/mx4j/loading/MLetParseException.java Mon Jul 17 05:14:31 2006
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) MX4J.
+ * All rights reserved.
+ *
+ * This software is distributed under the terms of the MX4J License version 1.0.
+ * See the terms of the MX4J License in the documentation provided with this software.
+ */
+
+/*
+ *   Copyright 2005 The Apache Software Foundation
+ *
+ *   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 org.apache.felix.mosgi.jmx.agent.mx4j.loading;
+/**
+ * Thrown when a problem parsing MLet files is encountered
+ *
+ * @author <a href="mailto:biorn_steedom@users.sourceforge.net">Simone Bordet</a>
+ * @version $Revision: 1.1.1.1 $
+ */
+public class MLetParseException extends Exception
+{
+   public MLetParseException()
+   {
+   }
+
+   public MLetParseException(String message)
+   {
+      super(message);
+   }
+}

Added: incubator/felix/trunk/org.apache.felix.mosgi.jmx.agent/src/main/java/org/apache/felix/mosgi/jmx/agent/mx4j/loading/MLetParser.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/org.apache.felix.mosgi.jmx.agent/src/main/java/org/apache/felix/mosgi/jmx/agent/mx4j/loading/MLetParser.java?rev=422696&view=auto
==============================================================================
--- incubator/felix/trunk/org.apache.felix.mosgi.jmx.agent/src/main/java/org/apache/felix/mosgi/jmx/agent/mx4j/loading/MLetParser.java (added)
+++ incubator/felix/trunk/org.apache.felix.mosgi.jmx.agent/src/main/java/org/apache/felix/mosgi/jmx/agent/mx4j/loading/MLetParser.java Mon Jul 17 05:14:31 2006
@@ -0,0 +1,367 @@
+/*
+ * Copyright (C) MX4J.
+ * All rights reserved.
+ *
+ * This software is distributed under the terms of the MX4J License version 1.0.
+ * See the terms of the MX4J License in the documentation provided with this software.
+ */
+
+/*
+ *   Copyright 2005 The Apache Software Foundation
+ *
+ *   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 org.apache.felix.mosgi.jmx.agent.mx4j.loading;
+
+import java.lang.reflect.Constructor;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
+import javax.management.loading.MLet;
+
+/**
+ * The parser for MLet files, as specified in the JMX documentation.
+ * This parser is case insensitive regards to the MLet tags: MLET is equal to mlet and to MLet.
+ * This parser also supports XML-style comments in the file.
+ *
+ * @author <a href="mailto:biorn_steedom@users.sourceforge.net">Simone Bordet</a>
+ * @version $Revision: 1.1.1.1 $
+ */
+public class MLetParser
+{
+   public static final String OPEN_COMMENT = "<!--";
+   public static final String CLOSE_COMMENT = "-->";
+
+   public static final String OPEN_BRACKET = "<";
+   public static final String CLOSE_BRACKET = ">";
+
+   public static final String MLET_TAG = "MLET";
+   public static final String CODE_ATTR = "CODE";
+   public static final String OBJECT_ATTR = "OBJECT";
+   public static final String ARCHIVE_ATTR = "ARCHIVE";
+   public static final String CODEBASE_ATTR = "CODEBASE";
+   public static final String NAME_ATTR = "NAME";
+   public static final String VERSION_ATTR = "VERSION";
+
+   public static final String ARG_TAG = "ARG";
+   public static final String TYPE_ATTR = "TYPE";
+   public static final String VALUE_ATTR = "VALUE";
+
+   private MLet mlet;
+
+   /**
+    * Creates a new MLetParser
+    */
+   public MLetParser()
+   {
+   }
+
+   /**
+    * Creates a new MLetParser
+    * @param mlet The MLet used to resolve classes specified in the ARG tags.
+    */
+   public MLetParser(MLet mlet)
+   {
+      this.mlet = mlet;
+   }
+
+   /**
+    * Parses the given content, that must contains a valid MLet file.
+    *
+    * @param content The content to parse
+    * @return A list of {@link MLetTag}s
+    * @throws MLetParseException If the content is not a valid MLet file
+    */
+   public List parse(String content) throws MLetParseException
+   {
+      if (content == null) throw new MLetParseException("MLet file content cannot be null");
+
+      // Strip comments
+      content = stripComments(content.trim());
+      content = convertToUpperCase(content);
+
+      ArrayList mlets = parseMLets(content);
+      if (mlets.size() < 1) throw new MLetParseException("MLet file is empty");
+
+      ArrayList mletTags = new ArrayList();
+      for (int i = 0; i < mlets.size(); ++i)
+      {
+         String mletTag = (String)mlets.get(i);
+
+         MLetTag tag = parseMLet(mletTag);
+         mletTags.add(tag);
+      }
+
+      return mletTags;
+   }
+
+   private MLetTag parseMLet(String content) throws MLetParseException
+   {
+      MLetTag tag = new MLetTag();
+      parseMLetAttributes(tag, content);
+      parseMLetArguments(tag, content);
+      return tag;
+   }
+
+   private ArrayList parseMLets(String content) throws MLetParseException
+   {
+      ArrayList list = new ArrayList();
+      int start = 0;
+      int current = -1;
+      while ((current = findOpenTag(content, start, MLET_TAG)) >= 0)
+      {
+         int end = findCloseTag(content, current + 1, MLET_TAG, true);
+         if (end < 0) throw new MLetParseException("MLET tag not closed at index: " + current);
+
+         String mlet = content.substring(current, end);
+         list.add(mlet);
+
+         start = end + 1;
+      }
+      return list;
+   }
+
+   private void parseMLetArguments(MLetTag tag, String content) throws MLetParseException
+   {
+      int start = 0;
+      int current = -1;
+      while ((current = findOpenTag(content, start, ARG_TAG)) >= 0)
+      {
+         int end = findCloseTag(content, current + 1, ARG_TAG, false);
+         if (end < 0) throw new MLetParseException("ARG tag not closed");
+
+         String arg = content.substring(current, end);
+
+         int type = arg.indexOf(TYPE_ATTR);
+         if (type < 0) throw new MLetParseException("Missing TYPE attribute");
+
+         int value = arg.indexOf(VALUE_ATTR);
+         if (value < 0) throw new MLetParseException("Missing VALUE attribute");
+
+         String className = findAttributeValue(arg, type, TYPE_ATTR);
+         tag.addArg(className, convertToObject(className, findAttributeValue(arg, value, VALUE_ATTR)));
+
+         start = end + 1;
+      }
+   }
+
+   private void parseMLetAttributes(MLetTag tag, String content) throws MLetParseException
+   {
+      int end = content.indexOf(CLOSE_BRACKET);
+      String attributes = content.substring(0, end);
+
+      // Find mandatory attributes
+      int archive = -1;
+      int object = -1;
+      int code = -1;
+
+      archive = attributes.indexOf(ARCHIVE_ATTR);
+      if (archive < 0) throw new MLetParseException("Missing ARCHIVE attribute");
+
+      code = attributes.indexOf(CODE_ATTR);
+      object = attributes.indexOf(OBJECT_ATTR);
+      if (code < 0 && object < 0) throw new MLetParseException("Missing CODE or OBJECT attribute");
+      if (code > 0 && object > 0) throw new MLetParseException("CODE and OBJECT attributes cannot be both present");
+
+      if (code >= 0)
+         tag.setCode(findAttributeValue(attributes, code, CODE_ATTR));
+      else
+         tag.setObject(findAttributeValue(attributes, object, OBJECT_ATTR));
+
+      tag.setArchive(findAttributeValue(attributes, archive, ARCHIVE_ATTR));
+
+      // Look for optional attributes
+      int codebase = attributes.indexOf(CODEBASE_ATTR);
+      if (codebase >= 0) tag.setCodeBase(findAttributeValue(attributes, codebase, CODEBASE_ATTR));
+
+      int name = attributes.indexOf(NAME_ATTR);
+      if (name >= 0)
+      {
+         String objectName = findAttributeValue(attributes, name, NAME_ATTR);
+         try
+         {
+            tag.setName(new ObjectName(objectName));
+         }
+         catch (MalformedObjectNameException x)
+         {
+            throw new MLetParseException("Invalid ObjectName: " + objectName);
+         }
+      }
+
+      int version = attributes.indexOf(VERSION_ATTR);
+      if (version >= 0) tag.setVersion(findAttributeValue(attributes, version, VERSION_ATTR));
+   }
+
+   private String findAttributeValue(String content, int start, String attribute) throws MLetParseException
+   {
+      int equal = content.indexOf('=', start);
+      if (equal < 0) throw new MLetParseException("Missing '=' for attribute");
+
+      // Ensure no garbage
+      if (!attribute.equals(content.substring(start, equal).trim())) throw new MLetParseException("Invalid attribute");
+
+      int begin = content.indexOf('"', equal + 1);
+      if (begin < 0) throw new MLetParseException("Missing quotes for attribute value");
+
+      // Ensure no garbage
+      if (content.substring(equal + 1, begin).trim().length() != 0) throw new MLetParseException("Invalid attribute value");
+
+      int end = content.indexOf('"', begin + 1);
+      if (end < 0) throw new MLetParseException("Missing quote for attribute value");
+
+      return content.substring(begin + 1, end).trim();
+   }
+
+   private int findOpenTag(String content, int start, String tag)
+   {
+      String opening = new StringBuffer(OPEN_BRACKET).append(tag).toString();
+      return content.indexOf(opening, start);
+   }
+
+   private int findCloseTag(String content, int start, String tag, boolean strictSyntax)
+   {
+      int count = 1;
+
+      do
+      {
+         int close = content.indexOf(CLOSE_BRACKET, start);
+         if (close < 0)
+         {
+            return -1;
+         }
+         int open = content.indexOf(OPEN_BRACKET, start);
+         if (open >= 0 && close > open)
+         {
+            ++count;
+         }
+         else
+         {
+            --count;
+            if (count == 0)
+            {
+               // Either I found the closing bracket of the open tag,
+               // or the closing tag
+               if (!strictSyntax || (strictSyntax && content.charAt(close - 1) == '/'))
+               {
+                  // Found the closing tag
+                  return close + 1;
+               }
+               else
+               {
+                  // Found the closing bracket of the open tag, go for the full closing tag
+                  String closing = new StringBuffer(OPEN_BRACKET).append("/").append(tag).append(CLOSE_BRACKET).toString();
+                  close = content.indexOf(closing, start);
+                  if (close < 0)
+                     return -1;
+                  else
+                     return close + closing.length();
+               }
+            }
+         }
+
+         start = close + 1;
+      }
+      while (true);
+   }
+
+   private String stripComments(String content) throws MLetParseException
+   {
+      StringBuffer buffer = new StringBuffer();
+      int start = 0;
+      int current = -1;
+      while ((current = content.indexOf(OPEN_COMMENT, start)) >= 0)
+      {
+         int end = content.indexOf(CLOSE_COMMENT, current + 1);
+
+         if (end < 0) throw new MLetParseException("Missing close comment tag at index: " + current);
+
+         String stripped = content.substring(start, current);
+         buffer.append(stripped);
+         start = end + CLOSE_COMMENT.length();
+      }
+      String stripped = content.substring(start, content.length());
+      buffer.append(stripped);
+      return buffer.toString();
+   }
+
+   private String convertToUpperCase(String content) throws MLetParseException
+   {
+      StringBuffer buffer = new StringBuffer();
+      int start = 0;
+      int current = -1;
+      while ((current = content.indexOf("\"", start)) >= 0)
+      {
+         int end = content.indexOf("\"", current + 1);
+
+         if (end < 0) throw new MLetParseException("Missing closing quote at index: " + current);
+
+         String converted = content.substring(start, current).toUpperCase();
+         buffer.append(converted);
+         String quoted = content.substring(current, end + 1);
+         buffer.append(quoted);
+         start = end + 1;
+      }
+      String converted = content.substring(start, content.length()).toUpperCase();
+      buffer.append(converted);
+      return buffer.toString();
+   }
+
+   private Object convertToObject(String clsName, String value) throws MLetParseException
+   {
+      try
+      {
+         if (clsName.equals("boolean") || clsName.equals("java.lang.Boolean"))
+            return Boolean.valueOf(value);
+         else if (clsName.equals("byte") || clsName.equals("java.lang.Byte"))
+            return Byte.valueOf(value);
+         else if (clsName.equals("char") || clsName.equals("java.lang.Character"))
+         {
+            char ch = 0;
+            if (value.length() > 0) ch = value.charAt(0);
+            return new Character(ch);
+         }
+         else if (clsName.equals("short") || clsName.equals("java.lang.Short"))
+            return Short.valueOf(value);
+         else if (clsName.equals("int") || clsName.equals("java.lang.Integer"))
+            return Integer.valueOf(value);
+         else if (clsName.equals("long") || clsName.equals("java.lang.Long"))
+            return Long.valueOf(value);
+         else if (clsName.equals("float") || clsName.equals("java.lang.Float"))
+            return Float.valueOf(value);
+         else if (clsName.equals("double") || clsName.equals("java.lang.Double"))
+            return Double.valueOf(value);
+         else if (clsName.equals("java.lang.String"))
+            return value;
+         else if (mlet != null)
+         {
+            try
+            {
+               Class cls = mlet.loadClass(clsName);
+               Constructor ctor = cls.getConstructor(new Class[]{String.class});
+               return ctor.newInstance(new Object[]{value});
+            }
+            catch (Exception ignored)
+            {
+            }
+         }
+      }
+      catch (NumberFormatException x)
+      {
+         throw new MLetParseException("Invalid value: " + value);
+      }
+      return null;
+   }
+}

Added: incubator/felix/trunk/org.apache.felix.mosgi.jmx.agent/src/main/java/org/apache/felix/mosgi/jmx/agent/mx4j/loading/MLetTag.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/org.apache.felix.mosgi.jmx.agent/src/main/java/org/apache/felix/mosgi/jmx/agent/mx4j/loading/MLetTag.java?rev=422696&view=auto
==============================================================================
--- incubator/felix/trunk/org.apache.felix.mosgi.jmx.agent/src/main/java/org/apache/felix/mosgi/jmx/agent/mx4j/loading/MLetTag.java (added)
+++ incubator/felix/trunk/org.apache.felix.mosgi.jmx.agent/src/main/java/org/apache/felix/mosgi/jmx/agent/mx4j/loading/MLetTag.java Mon Jul 17 05:14:31 2006
@@ -0,0 +1,228 @@
+/*
+ * Copyright (C) MX4J.
+ * All rights reserved.
+ *
+ * This software is distributed under the terms of the MX4J License version 1.0.
+ * See the terms of the MX4J License in the documentation provided with this software.
+ */
+
+/*
+ *   Copyright 2005 The Apache Software Foundation
+ *
+ *   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 org.apache.felix.mosgi.jmx.agent.mx4j.loading;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.StringTokenizer;
+
+import javax.management.ObjectName;
+
+/**
+ * Represents an MLET tag, as documented in the JMX specification.
+ *
+ * @author <a href="mailto:biorn_steedom@users.sourceforge.net">Simone Bordet</a>
+ * @version $Revision: 1.1.1.1 $
+ */
+public class MLetTag
+{
+   private String code;
+   private String object;
+   private String archive;
+   private String codebase;
+   private ObjectName objectName;
+   private String version;
+   private ArrayList signature = new ArrayList();
+   private ArrayList arguments = new ArrayList();
+
+   /**
+    * Normalizes the codebase held by this MLetTag (specified in the MLet file) using the
+    * URL of the MLet file as default.
+    * This means that if the codebase in the MLet file is not provided or it is relative, then
+    * the URL of the MLet file will be taken as base for computing the normalized codebase;
+    * otherwise, if a full URL has been specified as codebase in the MLet file, that URL is taken
+    * and the URL of the MLet file is discarded.
+    *
+    * @param mletFileURL The URL of the MLet file
+    * @return The normalized codebase
+    */
+   public URL normalizeCodeBase(URL mletFileURL)
+   {
+      // If the codebase specified in the MLet file is relative, or null,
+      // then the codebase is the one of the mletFileURL, otherwise
+      // the given codebase must be used.
+
+      URL codebaseURL = null;
+      String codebase = getCodeBase();
+      if (codebase != null)
+      {
+         // Try to see if it's a URL
+         try
+         {
+            codebaseURL = new URL(codebase);
+         }
+         catch (MalformedURLException ignored)
+         {
+            // Not a complete URL, use the mletFileURL as a base
+            try
+            {
+               codebaseURL = new URL(mletFileURL, codebase);
+            }
+            catch (MalformedURLException alsoIgnored)
+            {
+            }
+         }
+      }
+
+      // Either codebase not provided or failed to be created, use the mletFileURL
+      if (codebaseURL == null)
+      {
+         String path = mletFileURL.getPath();
+         int index = path.lastIndexOf('/');
+
+         try
+         {
+            codebaseURL = new URL(mletFileURL, path.substring(0, index + 1));
+         }
+         catch (MalformedURLException ignored)
+         {
+            // Cannot fail, we just remove the mlet file name from the path
+            // leaving the directory where it resides as a codebase
+         }
+      }
+      return codebaseURL;
+   }
+
+   /**
+    * Returns the jars file names specified in the ARCHIVE attribute of the MLet tag.
+    */
+   public String[] parseArchive()
+   {
+      String archive = getArchive();
+      ArrayList archives = new ArrayList();
+      StringTokenizer tokenizer = new StringTokenizer(archive, ",");
+      while (tokenizer.hasMoreTokens())
+      {
+         String token = tokenizer.nextToken().trim();
+         if (token.length() > 0)
+         {
+            token.replace('\\', '/');
+            archives.add(token);
+         }
+      }
+      return (String[])archives.toArray(new String[0]);
+   }
+
+   /**
+    * Returns the URL for the given archive file name using the provided URL as a codebase,
+    * or null if the URL cannot be created.
+    */
+   public URL createArchiveURL(URL codebase, String archive)
+   {
+      try
+      {
+         return new URL(codebase, archive);
+      }
+      catch (MalformedURLException ignored)
+      {
+      }
+      return null;
+   }
+
+   public String getVersion()
+   {
+       return version;
+   }
+
+   public String getCodeBase()
+   {
+      return codebase;
+   }
+
+   public String getArchive()
+   {
+      return archive;
+   }
+
+   public String getCode()
+   {
+      return code;
+   }
+
+   public ObjectName getObjectName()
+   {
+      return objectName;
+   }
+
+   public String getObject()
+   {
+      return object;
+   }
+
+   public String[] getSignature()
+   {
+      return signature == null ? new String[0] : (String[])signature.toArray(new String[signature.size()]);
+   }
+
+   public Object[] getArguments()
+   {
+      return arguments == null ? new Object[0] : (Object[])arguments.toArray(new Object[arguments.size()]);
+   }
+
+   //
+   // Setters, called by MLetParser
+   //
+
+   void setArchive(String archive)
+   {
+      this.archive = archive;
+   }
+
+   void setCode(String code)
+   {
+      this.code = code;
+   }
+
+   void setCodeBase(String codebase)
+   {
+      // Important that the codebase ends with a slash, see usages of getCodeBase()
+
+      codebase = codebase.replace('\\', '/');
+      if (!codebase.endsWith("/")) codebase += "/";
+      this.codebase = codebase;
+   }
+
+   void setName(ObjectName name)
+   {
+      objectName = name;
+   }
+
+   void setObject(String object)
+   {
+      this.object = object;
+   }
+
+   void setVersion(String version)
+   {
+      this.version = version;
+   }
+
+   void addArg(String type, Object value)
+   {
+      signature.add(type);
+      arguments.add(value);
+   }
+}



Mime
View raw message