You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by sf...@apache.org on 2006/07/20 11:36:50 UTC

svn commit: r423855 [1/5] - in /incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector: ./ 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...

Author: sfrenot
Date: Thu Jul 20 02:36:47 2006
New Revision: 423855

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

Added:
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/   (with props)
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/pom.xml
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/HttpConnectorActivator.java
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/mx4j/
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/mx4j/tools/
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/mx4j/tools/adaptor/
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/mx4j/tools/adaptor/AdaptorServerSocketFactory.java
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/mx4j/tools/adaptor/PlainAdaptorServerSocketFactory.java
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/mx4j/tools/adaptor/http/
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/mx4j/tools/adaptor/http/CommandProcessorUtil.java
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/mx4j/tools/adaptor/http/ConstructorsCommandProcessor.java
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/mx4j/tools/adaptor/http/CreateMBeanCommandProcessor.java
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/mx4j/tools/adaptor/http/DefaultProcessor.java
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/mx4j/tools/adaptor/http/DeleteMBeanCommandProcessor.java
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/mx4j/tools/adaptor/http/EmptyCommandProcessor.java
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/mx4j/tools/adaptor/http/GetAttributeCommandProcessor.java
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/mx4j/tools/adaptor/http/HttpAdaptor.java
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/mx4j/tools/adaptor/http/HttpAdaptorMBean.java
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/mx4j/tools/adaptor/http/HttpCommandProcessor.java
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/mx4j/tools/adaptor/http/HttpCommandProcessorAdaptor.java
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/mx4j/tools/adaptor/http/HttpConstants.java
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/mx4j/tools/adaptor/http/HttpException.java
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/mx4j/tools/adaptor/http/HttpInputStream.java
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/mx4j/tools/adaptor/http/HttpOutputStream.java
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/mx4j/tools/adaptor/http/HttpUtil.java
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/mx4j/tools/adaptor/http/InvokeOperationCommandProcessor.java
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/mx4j/tools/adaptor/http/MBeanCommandProcessor.java
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/mx4j/tools/adaptor/http/ProcessorMBean.java
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/mx4j/tools/adaptor/http/ServerByDomainCommandProcessor.java
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/mx4j/tools/adaptor/http/ServerCommandProcessor.java
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/mx4j/tools/adaptor/http/SetAttributeCommandProcessor.java
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/mx4j/tools/adaptor/http/SetAttributesCommandProcessor.java
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/mx4j/tools/adaptor/http/XSLTProcessor.java
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/mx4j/tools/adaptor/http/XSLTProcessorMBean.java
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/mx4j/tools/adaptor/http/xsl/
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/mx4j/tools/adaptor/http/xsl/about.xsl
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/mx4j/tools/adaptor/http/xsl/common.xsl
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/mx4j/tools/adaptor/http/xsl/constructors.xsl
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/mx4j/tools/adaptor/http/xsl/create.xsl
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/mx4j/tools/adaptor/http/xsl/delete.xsl
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/mx4j/tools/adaptor/http/xsl/emptymbean.xsl
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/mx4j/tools/adaptor/http/xsl/error.xsl
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/mx4j/tools/adaptor/http/xsl/favicon.ico   (with props)
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/mx4j/tools/adaptor/http/xsl/identity.xsl
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/mx4j/tools/adaptor/http/xsl/invoke.xsl
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/mx4j/tools/adaptor/http/xsl/logo.gif   (with props)
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/mx4j/tools/adaptor/http/xsl/mbean.xsl
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/mx4j/tools/adaptor/http/xsl/mbean_attributes.xsl
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/mx4j/tools/adaptor/http/xsl/mlet.xsl
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/mx4j/tools/adaptor/http/xsl/monitor.xsl
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/mx4j/tools/adaptor/http/xsl/monitor_create.xsl
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/mx4j/tools/adaptor/http/xsl/relation.xsl
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/mx4j/tools/adaptor/http/xsl/server.xsl
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/mx4j/tools/adaptor/http/xsl/serverbydomain.xsl
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/mx4j/tools/adaptor/http/xsl/setattribute.xsl
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/mx4j/tools/adaptor/http/xsl/setattributes.xsl
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/mx4j/tools/adaptor/http/xsl/strings_en.xml
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/mx4j/tools/adaptor/http/xsl/stylesheet.css
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/mx4j/tools/adaptor/http/xsl/timer.xsl
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/mx4j/tools/adaptor/http/xsl/timer_create.xsl
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/mx4j/tools/adaptor/http/xsl/viewarray.xsl
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/mx4j/tools/adaptor/http/xsl/viewcollection.xsl
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/mx4j/tools/adaptor/http/xsl/viewmap.xsl
    incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/mx4j/tools/adaptor/http/xsl/xalan-ext.xsl

Propchange: incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Thu Jul 20 02:36:47 2006
@@ -0,0 +1,16 @@
+classes
+target
+*.log
+*.ipr
+*.iws
+*.iml
+lib
+bundle
+dist
+.project
+.classpath
+bin
+build
+.settings
+.wtpmodules
+.deployables

Added: incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/pom.xml
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/pom.xml?rev=423855&view=auto
==============================================================================
--- incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/pom.xml (added)
+++ incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/pom.xml Thu Jul 20 02:36:47 2006
@@ -0,0 +1,68 @@
+<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 httpconnector</name>
+  <artifactId>org.apache.felix.mosgi.jmx.httpconnector</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>
+    <dependency>
+      <groupId>${pom.groupId}</groupId>
+      <artifactId>org.apache.felix.mosgi.jmx.agent</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 http connector</bundleName>
+            <bundleDescription>MOSGi JMX-MX4J http connector</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>
+	    <importPackage>
+  	      org.osgi.service.log;specification-version="1.0.0",
+	      org.osgi.framework;specification-version="1.0.0",
+	      javax.management;specification-version="1.0.0",
+	      org.w3c.dom;specification-version="1.0.0",
+	      javax.xml.parsers;specification-version="1.0.0",
+	      javax.xml.transform;specification-version="1.0.0",
+	      javax.xml.transform.stream;specification-version="1.0.0",
+	      javax.xml.transform.dom;specification-version="1.0.0"
+	    </importPackage>
+          </osgiManifest>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+</project>

Added: incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/HttpConnectorActivator.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/HttpConnectorActivator.java?rev=423855&view=auto
==============================================================================
--- incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/HttpConnectorActivator.java (added)
+++ incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/HttpConnectorActivator.java Thu Jul 20 02:36:47 2006
@@ -0,0 +1,101 @@
+/*
+ *   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.httpconnector;
+
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.BundleException;
+
+import org.osgi.service.log.LogService;
+
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+
+import org.apache.felix.mosgi.jmx.httpconnector.mx4j.tools.adaptor.http.HttpAdaptor;
+import org.apache.felix.mosgi.jmx.httpconnector.mx4j.tools.adaptor.http.XSLTProcessor;
+
+
+public class HttpConnectorActivator implements BundleActivator{
+  public static BundleContext bc;
+  private HttpAdaptor http;
+  private ObjectName httpName;
+  private ObjectName processorName;
+  private String version=null;
+
+  public void start(BundleContext bc) throws Exception{
+    this.version=(String)bc.getBundle().getHeaders().get(Constants.BUNDLE_VERSION);
+    ServiceReference sr = bc.getServiceReference(javax.management.MBeanServer.class.getName());
+    if (sr!=null){
+      HttpConnectorActivator.bc=bc;
+
+      HttpConnectorActivator.log(LogService.LOG_INFO, "Starting JMX Http Connector "+version,null);
+      MBeanServer server= (MBeanServer)bc.getService(sr);
+      
+      String httpPort = bc.getProperty("insa.jmx.httpconnector.port");
+      if (httpPort==null){
+        httpPort="8080";
+      }
+
+      httpName = new ObjectName("HtmlAdaptor:name=HttpAdaptor,port=" + httpPort);
+      http = new HttpAdaptor();
+
+      http.setPort((new Integer(httpPort)).intValue());
+      http.setHost("0.0.0.0"); //For external access 
+  
+      processorName = new ObjectName("HtmlAdaptor:name=XSLTProcessor");
+      XSLTProcessor processor=new XSLTProcessor();
+
+      server.registerMBean(processor, processorName);
+      server.registerMBean(http, httpName);
+
+      http.setProcessorName(processorName);
+      http.start();
+      HttpConnectorActivator.log(LogService.LOG_INFO, "Started JMX Http Connector "+version,null);
+    }else {
+      throw new BundleException("No JMX Agent found");
+    }
+  }
+
+  public void stop(BundleContext bc) throws Exception {
+    HttpConnectorActivator.log(LogService.LOG_INFO, "Stopping JMX Http connector "+version,null);
+    this.http.stop();
+    ServiceReference sr = bc.getServiceReference(javax.management.MBeanServer.class.getName());
+    if (sr!=null){
+      MBeanServer server= (MBeanServer)bc.getService(sr);
+      server.unregisterMBean(processorName);
+      server.unregisterMBean(httpName);
+    }
+    HttpConnectorActivator.log(LogService.LOG_INFO, "JMX Http Connector stopped "+version,null);
+    HttpConnectorActivator.bc=null;
+  }
+
+  private static void log(int prio, String message, Throwable t){
+    if (HttpConnectorActivator.bc!=null){
+      ServiceReference logSR=HttpConnectorActivator.bc.getServiceReference(LogService.class.getName());
+      if (logSR!=null){
+        ((LogService)HttpConnectorActivator.bc.getService(logSR)).log(prio, message, t);
+      }else{
+        System.out.println("No Log Service");
+      }
+    }else{
+      System.out.println(org.apache.felix.mosgi.jmx.httpconnector.HttpConnectorActivator.class.getName()+": No bundleContext");
+    }
+  }
+
+}

Added: incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/mx4j/tools/adaptor/AdaptorServerSocketFactory.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/mx4j/tools/adaptor/AdaptorServerSocketFactory.java?rev=423855&view=auto
==============================================================================
--- incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/mx4j/tools/adaptor/AdaptorServerSocketFactory.java (added)
+++ incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/mx4j/tools/adaptor/AdaptorServerSocketFactory.java Thu Jul 20 02:36:47 2006
@@ -0,0 +1,44 @@
+/*
+ * 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.httpconnector.mx4j.tools.adaptor;
+
+import java.net.ServerSocket;
+import java.io.IOException;
+
+/**
+ * The ServerSocket factory interface. <p>
+ * It allows to create ServerSocket for JMX adaptors
+ *
+ * @author <a href="mailto:tibu@users.sourceforge.net">Carlos Quiroz</a>
+ * @author <a href="mailto:biorn_steedom@users.sourceforge.net">Simone Bordet</a>
+ * @version $Revision: 1.1.1.1 $
+ */
+public interface AdaptorServerSocketFactory
+{
+	/**
+	 * Creates a new ServerSocket on the specified port, with the specified backlog and on the given host. <br>
+	 * The last parameter is useful for hosts with more than one IP address.
+	 */
+	public ServerSocket createServerSocket(int port, int backlog, String host) throws IOException;
+}

Added: incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/mx4j/tools/adaptor/PlainAdaptorServerSocketFactory.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/mx4j/tools/adaptor/PlainAdaptorServerSocketFactory.java?rev=423855&view=auto
==============================================================================
--- incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/mx4j/tools/adaptor/PlainAdaptorServerSocketFactory.java (added)
+++ incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/mx4j/tools/adaptor/PlainAdaptorServerSocketFactory.java Thu Jul 20 02:36:47 2006
@@ -0,0 +1,43 @@
+/*
+ * 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.httpconnector.mx4j.tools.adaptor;
+
+import java.net.ServerSocket;
+import java.net.InetAddress;
+import java.io.IOException;
+
+/**
+ * Creates plain ServerSockets.
+ *
+ * @author <a href="mailto:tibu@users.sourceforge.net">Carlos Quiroz</a>
+ * @author <a href="mailto:biorn_steedom@users.sourceforge.net">Simone Bordet</a>
+ * @version $Revision: 1.1.1.1 $
+ */
+public class PlainAdaptorServerSocketFactory implements AdaptorServerSocketFactory
+{
+	public ServerSocket createServerSocket(int port, int backlog, String host) throws IOException
+	{
+		return new ServerSocket(port, backlog, InetAddress.getByName(host));
+	}
+}

Added: incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/mx4j/tools/adaptor/http/CommandProcessorUtil.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/mx4j/tools/adaptor/http/CommandProcessorUtil.java?rev=423855&view=auto
==============================================================================
--- incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/mx4j/tools/adaptor/http/CommandProcessorUtil.java (added)
+++ incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/mx4j/tools/adaptor/http/CommandProcessorUtil.java Thu Jul 20 02:36:47 2006
@@ -0,0 +1,350 @@
+/*
+ * 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.httpconnector.mx4j.tools.adaptor.http;
+
+import java.lang.reflect.Constructor;
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.util.Comparator;
+import java.util.Date;
+
+import javax.management.ObjectInstance;
+
+//SFR import javax.management.openmbean.OpenType;
+
+/**
+ * Contains utilities common to CommandProcessor objects
+ *
+ * @author <a href="mailto:tibu@users.sourceforge.net">Carlos Quiroz</a>
+ * @author <a href="mailto:l.dobrev@lsnsoft.com">Lachezar Dobrev</a>
+ * @version $Revision: 1.2 $
+ */
+public class CommandProcessorUtil
+{
+  // contains all date and date time format instances
+  // for the current locale
+  private static final DateFormat[] allFormats = new DateFormat[] {
+    DateFormat.getDateInstance(),
+    DateFormat.getTimeInstance(),
+    DateFormat.getDateTimeInstance(),
+    // first pure date format
+    DateFormat.getDateInstance(DateFormat.SHORT),
+    DateFormat.getDateInstance(DateFormat.MEDIUM),
+    DateFormat.getDateInstance(DateFormat.LONG),
+    DateFormat.getDateInstance(DateFormat.FULL),
+    // pure time format
+    DateFormat.getTimeInstance(DateFormat.SHORT),
+    DateFormat.getTimeInstance(DateFormat.MEDIUM),
+    DateFormat.getTimeInstance(DateFormat.LONG),
+    DateFormat.getTimeInstance(DateFormat.FULL),
+    // combinations
+    DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT),
+    DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM),
+    DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.LONG),
+    DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.FULL),
+
+    DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT),
+    DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM),
+    DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.LONG),
+    DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.FULL),
+
+    DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.SHORT),
+    DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.MEDIUM),
+    DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG),
+    DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.FULL),
+
+    DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.SHORT),
+    DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.MEDIUM),
+    DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.LONG),
+    DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL)
+  };
+
+  private static final String[] BASIC_TYPES = new String[] {
+    "int", "long", "short", "byte", "float", "double", "boolean"
+  };
+
+  /**
+   * Creates a parameter object of the given type containing a given value.
+   * If the type is unknown null is returned
+   *
+   * @param parameterType Indicates the type of the parameter, for instance java.lang.String
+   * @param parameterValue The value of the parameter as a String
+   * @return an object of parameterType type and value parameterValue or null if the type is unknown
+   * @exception Thrown in case there is a data conversion error
+   */
+  protected static Object createParameterValue(String parameterType, String parameterValue)
+    throws Exception
+  {
+    if (parameterType.equals("java.lang.String"))
+    {
+      return parameterValue;
+    }
+    else if (parameterType.equals("java.lang.Integer") || parameterType.equals("int"))
+    {
+      return Integer.valueOf(parameterValue);
+    }
+    else if (parameterType.equals("java.lang.Long") || parameterType.equals("long"))
+    {
+      return Long.valueOf(parameterValue);
+    }
+    else if (parameterType.equals("java.lang.Short") || parameterType.equals("short"))
+    {
+      return Short.valueOf(parameterValue);
+    }
+    else if (parameterType.equals("java.lang.Byte") || parameterType.equals("byte"))
+    {
+      return Byte.valueOf(parameterValue);
+    }
+    else if (parameterType.equals("java.lang.Float") || parameterType.equals("float"))
+    {
+      return Float.valueOf(parameterValue);
+    }
+    // changed java.lang.dobule to java.lang.double bronwen
+    else if (parameterType.equals("java.lang.Double") || parameterType.equals("double"))
+    {
+      return Double.valueOf(parameterValue);
+    }
+    else if (parameterType.equals("java.lang.Boolean") || parameterType.equals("boolean"))
+    {
+      return Boolean.valueOf(parameterValue);
+    }
+    else if (parameterType.equals("java.lang.Void"))
+    {
+      return Void.TYPE;
+    }
+    else if (parameterType.equals("java.util.Date"))
+    {
+      // this is tricky since Date can be written in many formats
+      // will use the Date format with current locale and several
+      // different formats
+      Date value = null;
+      for (int i=0;i<allFormats.length;i++) {
+        synchronized (allFormats[i]) {
+          try {
+            System.out.println(parameterValue + " " + allFormats[i]);
+            value = allFormats[i].parse(parameterValue);
+            // if succeful then break
+            break;
+          } catch (ParseException e) {
+            // ignore, the format wasn't appropriate
+          }
+        }
+      }
+      if (value == null) {
+        throw new ParseException("Not possible to parse", 0);
+      }
+      return value;
+    }
+    else if (parameterType.equals("java.lang.Number"))
+    {
+      Number value = null;
+      // try first as a long
+      try
+      {
+        value = Long.valueOf(parameterValue);
+      }
+      catch (NumberFormatException e)
+      {
+      }
+      // if not try as a double
+      if (value == null) {
+        try {
+          value = Double.valueOf(parameterValue);
+        }
+        catch (NumberFormatException e)
+        {
+        }
+      }
+      if (value == null) {
+        throw new NumberFormatException("Not possible to parse");
+      }
+      return value;
+    }
+    if (parameterType.equals("java.lang.Character") || parameterType.equals("char"))
+    {
+      if ( parameterValue.length() > 0 )
+      {
+        return new Character(parameterValue.charAt(0));
+      }
+      else
+      {
+        throw new NumberFormatException("Can not initialize Character from empty String");
+      }
+    }
+    // tests whether the classes have a single string parameter value
+    // constructor. That covers the classes
+    // javax.management.ObjectName
+    // java.math.BigInteger
+    // java.math.BigDecimal
+
+    Class cls = null;
+    java.lang.reflect.Constructor ctor = null;
+    try
+    {
+      cls  = Class.forName(parameterType);
+      ctor  = cls.getConstructor(new Class[] {String.class});
+      return ctor.newInstance(new Object[] {parameterValue});
+    }
+    catch (ClassNotFoundException cnfe)
+    {
+      // Can not find class. Not in our ClassLoader?
+      /** @todo Ask the MBeanServer to instantiate this class??? */
+      throw new IllegalArgumentException("Invalid parameter type: " + parameterType);
+    }
+    catch (NoSuchMethodException nsme)
+    {
+      // No public String constructor.
+      throw new IllegalArgumentException("Invalid parameter type: " + parameterType);
+    }
+    catch (Exception ex)
+    {
+      // Constructor might have thrown an exception?
+      // Security Exception ?
+      // IllegalAccessException? .... etc.
+      // Just rethrow. We can do little here <shrug>
+      /** @todo Log the exception */
+      throw ex;
+    }
+  }
+
+  /**
+   * Checks if the given type is primitive of can be initialized from String.<br>
+   * This is done by trying to load the class and checking if there is a public String
+   * only constructor.
+   *
+   * @param parameterType Indicates the type of the parameter, for instance java.lang.String
+   * @return true if the type is primitive or String initializable
+   * @exception Thrown in case there is a data conversion error
+   */
+
+  protected static boolean canCreateParameterValue(String parameterType)
+  {
+    int count;
+  /*
+    count = OpenType.ALLOWED_CLASSNAMES.length;
+    for (int i=0;i<count;i++)
+    {
+      if (OpenType.ALLOWED_CLASSNAMES[i].equals(parameterType))
+      {
+        return true;
+      }
+    }
+    */
+    count = BASIC_TYPES.length;
+    for (int i=0;i<count;i++)
+    {
+      if (BASIC_TYPES[i].equals(parameterType))
+      {
+        return true;
+      }
+    }
+
+    Class cls = null ;
+    try
+    {
+      cls  = Class.forName(parameterType);
+      cls.getConstructor(new Class[] {String.class});
+      // Yes we can load the class and it has a public String constructor.
+      return true;
+    }
+    catch (ClassNotFoundException cnfe)
+    {
+      // Can not find class. Not in our ClassLoader?
+      return false;
+    }
+    catch (NoSuchMethodException nsme)
+    {
+      // No public String constructor.
+      return false;
+    }
+    catch (Exception ex)
+    {
+      // Constructor might have thrown an exception?
+      // Security Exception ?
+      // IllegalAccessException? .... etc.
+      // Just rethrow. We can do little here <shrug>
+      return false;
+    }
+  }
+
+  public static Comparator createObjectNameComparator()
+  {
+    return new ToStringComparator();
+  }
+
+  public static Comparator createObjectInstanceComparator()
+  {
+    return new ObjectInstanceComparator();
+  }
+
+  public static Comparator createConstructorComparator()
+  {
+    return new ConstructorComparator();
+  }
+
+  public static Comparator createClassComparator()
+  {
+    return new ToStringComparator();
+  }
+
+  private static class ToStringComparator implements Comparator {
+    public int compare(Object o1, Object o2) {
+      return o1.toString().compareTo(o2.toString());
+    }
+  }
+
+  private static class ObjectInstanceComparator implements Comparator {
+    private ToStringComparator comp = new ToStringComparator();
+    public int compare(Object o1, Object o2) {
+      ObjectInstance oi1 = (ObjectInstance)o1;
+      ObjectInstance oi2 = (ObjectInstance)o2;
+      return comp.compare(oi1.getObjectName(), oi2.getObjectName());
+    }
+  }
+
+  private static class ConstructorComparator implements Comparator {
+    public int compare(Object o1, Object o2) {
+      Constructor c1 = (Constructor)o1;
+      Constructor c2 = (Constructor)o2;
+      // sort them by the parameter types;
+      Class[] params1 = c1.getParameterTypes();
+      Class[] params2 = c2.getParameterTypes();
+      if (params1.length == params2.length)
+      {
+        for (int i=0;i<params1.length;i++)
+        {
+          if (!params1[i].equals(params2[i])) {
+            return params2[i].toString().compareTo(params1[i].toString());
+          }
+        }
+        return 0;
+      }
+      else
+      {
+        return params1.length - params2.length;
+      }
+    }
+  }
+
+}

Added: incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/mx4j/tools/adaptor/http/ConstructorsCommandProcessor.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/mx4j/tools/adaptor/http/ConstructorsCommandProcessor.java?rev=423855&view=auto
==============================================================================
--- incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/mx4j/tools/adaptor/http/ConstructorsCommandProcessor.java (added)
+++ incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/mx4j/tools/adaptor/http/ConstructorsCommandProcessor.java Thu Jul 20 02:36:47 2006
@@ -0,0 +1,128 @@
+/*
+ * 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.httpconnector.mx4j.tools.adaptor.http;
+
+import java.io.IOException;
+import java.lang.reflect.Constructor;
+import java.util.Arrays;
+
+import javax.management.JMException;
+import javax.management.loading.DefaultLoaderRepository;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+/**
+ * ConstructorsCommandProcessor, processes a request to query the available
+ * constructors for a classname
+ *
+ * @author <a href="mailto:tibu@users.sourceforge.net">Carlos Quiroz</a>
+ * @author <a href="mailto:l.dobrev@lsnsoft.com">Lachezar Dobrev</a>
+ * @version $Revision: 1.1.1.1 $
+ */
+public class ConstructorsCommandProcessor extends HttpCommandProcessorAdaptor
+{
+  public ConstructorsCommandProcessor()
+  {
+  }
+
+  public Document executeRequest(HttpInputStream in) throws IOException, JMException
+  {
+    Document document = builder.newDocument();
+
+    String classname = in.getVariable("classname");
+    if (classname == null || classname.trim().length() == 0)
+    {
+      return createException(document, "", "classname parameter required");
+    }
+    else
+    {
+      // look class in default classloader
+      Class targetClass = null;
+      try
+      {
+        targetClass = DefaultLoaderRepository.loadClass(classname);
+      }
+      catch (ClassNotFoundException e) {}
+      try
+      {
+        if (targetClass == null)
+        {
+          targetClass = ClassLoader.getSystemClassLoader().loadClass(classname);
+        }
+      }
+      catch (ClassNotFoundException e) {}
+      try
+      {
+        if (targetClass == null)
+        {
+          targetClass = getClass().getClassLoader().loadClass(classname);
+        }
+      }
+      catch (ClassNotFoundException e) {}
+
+      if (targetClass == null) {
+        return createException(document, classname, "class " + classname + " not found");
+      }
+
+      Element root = document.createElement("Class");
+      root.setAttribute("classname", classname);
+      document.appendChild(root);
+      Constructor[] constructors = targetClass.getConstructors();
+      Arrays.sort(constructors, CommandProcessorUtil.createConstructorComparator());
+      for (int i=0;i<constructors.length;i++)
+      {
+        System.out.println("Constructor " + constructors[i]);
+        Element constructor = document.createElement("Constructor");
+        constructor.setAttribute("name", constructors[i].getName());
+        addParameters(constructor, document, constructors[i].getParameterTypes());
+        root.appendChild(constructor);
+      }
+    }
+    return document;
+  }
+
+  protected void addParameters(Element node, Document document, Class[] parameters)
+  {
+    for (int j=0;j<parameters.length;j++)
+    {
+      Element parameter = document.createElement("Parameter");
+      parameter.setAttribute("type", parameters[j].getName());
+      parameter.setAttribute("strinit", String.valueOf(CommandProcessorUtil.canCreateParameterValue(parameters[j].getName())));
+      // add id since order is relevant
+      parameter.setAttribute("id", ""+j);
+      node.appendChild(parameter);
+     }
+  }
+
+  private Document createException(Document document, String classname, String message)
+  {
+    Element exceptionElement = document.createElement("Exception");
+    document.appendChild(exceptionElement);
+    exceptionElement.setAttribute("classname", classname);
+    exceptionElement.setAttribute("errorMsg", message);
+    return document;
+  }
+
+}

Added: incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/mx4j/tools/adaptor/http/CreateMBeanCommandProcessor.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/mx4j/tools/adaptor/http/CreateMBeanCommandProcessor.java?rev=423855&view=auto
==============================================================================
--- incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/mx4j/tools/adaptor/http/CreateMBeanCommandProcessor.java (added)
+++ incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/mx4j/tools/adaptor/http/CreateMBeanCommandProcessor.java Thu Jul 20 02:36:47 2006
@@ -0,0 +1,170 @@
+/*
+ *  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.httpconnector.mx4j.tools.adaptor.http;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.management.JMException;
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+/**
+ * CreateMBeanCommandProcessor, processes a request for creating and registering
+ * an MBean
+ *
+ * @author    <a href="mailto:tibu@users.sourceforge.net">Carlos Quiroz</a>
+ * @version   $Revision: 1.1.1.1 $
+ */
+public class CreateMBeanCommandProcessor extends HttpCommandProcessorAdaptor
+{
+
+	/**
+	 * Constructs a new CreateMBeanCommandProcessor
+	 *
+	 */
+	public CreateMBeanCommandProcessor()
+	{
+	}
+
+
+	public Document executeRequest(HttpInputStream in)
+		throws IOException, JMException
+	{
+		Document document = builder.newDocument();
+
+		Element root = document.createElement("MBeanOperation");
+		document.appendChild(root);
+		Element operationElement = document.createElement("Operation");
+		operationElement.setAttribute("name", "create");
+		root.appendChild(operationElement);
+
+		String objectVariable = in.getVariable("objectname");
+		String classVariable = in.getVariable("class");
+		if (objectVariable == null || objectVariable.equals("")
+				 || classVariable == null || classVariable.equals(""))
+		{
+			operationElement.setAttribute("result", "error");
+			operationElement.setAttribute("errorMsg", "Incorrect parameters in the request");
+			return document;
+		}
+		operationElement.setAttribute("objectname", objectVariable);
+		List types = new ArrayList();
+		List values = new ArrayList();
+		int i = 0;
+		boolean unmatchedParameters = false;
+		boolean valid = false;
+		do
+		{
+			String parameterType = in.getVariable("type" + i);
+			String parameterValue = in.getVariable("value" + i);
+			valid = (parameterType != null && parameterValue != null);
+			if (valid)
+			{
+				types.add(parameterType);
+				Object value = null;
+				try
+				{
+					value = CommandProcessorUtil.createParameterValue(parameterType, parameterValue);
+				}
+				catch (Exception e)
+				{
+					operationElement.setAttribute("result", "error");
+					operationElement.setAttribute("errorMsg", "Parameter " + i + ": " + parameterValue + " cannot be converted to type " + parameterType);
+					return document;
+				}
+				if (value != null)
+				{
+					values.add(value);
+				}
+			}
+			if (parameterType == null ^ parameterValue == null)
+			{
+				unmatchedParameters = true;
+				break;
+			}
+			i++;
+		} while (valid);
+		if (objectVariable == null || objectVariable.equals(""))
+		{
+			operationElement.setAttribute("result", "error");
+			operationElement.setAttribute("errorMsg", "Incorrect parameters in the request");
+			return document;
+		}
+		if (unmatchedParameters)
+		{
+			operationElement.setAttribute("result", "error");
+			operationElement.setAttribute("errorMsg", "count of parameter types doesn't match count of parameter values");
+			return document;
+		}
+		ObjectName name = null;
+		try
+		{
+			name = new ObjectName(objectVariable);
+		}
+		catch (MalformedObjectNameException e)
+		{
+			operationElement.setAttribute("result", "error");
+			operationElement.setAttribute("errorMsg", "Malformed object name");
+			return document;
+		}
+
+		if (server.isRegistered(name))
+		{
+			operationElement.setAttribute("result", "error");
+			operationElement.setAttribute("errorMsg", "A MBean with name " + name + " is already registered");
+			return document;
+		}
+		else
+		{
+			try
+			{
+				if (types.size() > 0)
+				{
+					Object[] params = values.toArray();
+					String[] signature = new String[types.size()];
+					types.toArray(signature);
+					server.createMBean(classVariable, name, null, params, signature);
+				}
+				else
+				{
+					server.createMBean(classVariable, name, null);
+				}
+				operationElement.setAttribute("result", "success");
+			}
+			catch (Exception e)
+			{
+				operationElement.setAttribute("result", "error");
+				operationElement.setAttribute("errorMsg", e.getMessage());
+			}
+		}
+		return document;
+	}
+
+}
+

Added: incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/mx4j/tools/adaptor/http/DefaultProcessor.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/mx4j/tools/adaptor/http/DefaultProcessor.java?rev=423855&view=auto
==============================================================================
--- incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/mx4j/tools/adaptor/http/DefaultProcessor.java (added)
+++ incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/mx4j/tools/adaptor/http/DefaultProcessor.java Thu Jul 20 02:36:47 2006
@@ -0,0 +1,336 @@
+/*
+ *  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.httpconnector.mx4j.tools.adaptor.http;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.PrintWriter;
+
+import org.w3c.dom.Attr;
+import org.w3c.dom.Document;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.log.LogService;
+
+import org.apache.felix.mosgi.jmx.httpconnector.HttpConnectorActivator;
+
+
+/**
+ * DefaultPostProcessor doesn't alter the result, just publising the xml file
+ *
+ * @author    <a href="mailto:tibu@users.sourceforge.net">Carlos Quiroz</a>
+ * @version   $Revision: 1.1.1.1 $
+ */
+
+public class DefaultProcessor implements ProcessorMBean
+{
+
+	private final static String ENCODING = "UTF-8";
+	private boolean canonical = false;
+	public String getName()
+	{
+		return "Default XML Processor";
+	}
+
+	public void writeResponse(HttpOutputStream out, HttpInputStream in, Document document)
+			throws IOException
+	{
+		out.setCode(HttpConstants.STATUS_OKAY);
+		out.setHeader("Content-Type", "text/xml");
+		out.sendHeaders();
+		print(new PrintWriter(out), document);
+		ByteArrayOutputStream o = new ByteArrayOutputStream();
+		print(new PrintWriter(o), document);
+		DefaultProcessor.log(LogService.LOG_INFO,new String(o.toByteArray()),null);
+	}
+
+	public void writeError(HttpOutputStream out, HttpInputStream in, Exception e)
+			throws IOException
+	{
+		if (e instanceof HttpException)
+		{
+			out.setCode(((HttpException)e).getCode());
+			out.setHeader("Content-Type", "text/xml");
+			out.sendHeaders();
+			print(new PrintWriter(out), ((HttpException)e).getResponseDoc());
+		}
+	}
+
+	public String preProcess(String path)
+	{
+		// The only special case. The root is routed to the the server request
+		if (path.equals("/"))
+		{
+			path = "/server";
+		}
+		return path;
+	}
+
+	public String notFoundElement(String path, HttpOutputStream out, HttpInputStream in)
+			throws IOException, HttpException
+	{
+		// no processing. Unknown elements are not found
+		throw new HttpException(HttpConstants.STATUS_NOT_FOUND, "Path " + path + " not found");
+	}
+
+	// ripped from Xerces samples
+	protected void print(PrintWriter out, Node node)
+	{
+		// is there anything to do?
+		if (node == null)
+		{
+			return;
+		}
+		int type = node.getNodeType();
+		switch (type)
+		{
+			// print document
+			case Node.DOCUMENT_NODE:
+				{
+					if (!canonical)
+					{
+						out.println("<?xml version=\"1.0\" encoding=\"" + ENCODING + "\"?>");
+					}
+					NodeList children = node.getChildNodes();
+					for (int iChild = 0; iChild < children.getLength(); iChild++)
+					{
+						print(out, children.item(iChild));
+					}
+					out.flush();
+					break;
+				}
+				// print element with attributes
+			case Node.ELEMENT_NODE:
+				{
+					out.print('<');
+					out.print(node.getNodeName());
+					Attr attrs[] = sortAttributes(node.getAttributes());
+					for (int i = 0; i < attrs.length; i++)
+					{
+						Attr attr = attrs[i];
+						out.print(' ');
+						out.print(attr.getNodeName());
+						out.print("=\"");
+						out.print(normalize(attr.getNodeValue()));
+						out.print('"');
+					}
+					out.print('>');
+					NodeList children = node.getChildNodes();
+					if (children != null)
+					{
+						int len = children.getLength();
+						for (int i = 0; i < len; i++)
+						{
+							print(out, children.item(i));
+						}
+					}
+					break;
+				}
+				// handle entity reference nodes
+			case Node.ENTITY_REFERENCE_NODE:
+				{
+					if (canonical)
+					{
+						NodeList children = node.getChildNodes();
+						if (children != null)
+						{
+							int len = children.getLength();
+							for (int i = 0; i < len; i++)
+							{
+								print(out, children.item(i));
+							}
+						}
+					}
+					else
+					{
+						out.print('&');
+						out.print(node.getNodeName());
+						out.print(';');
+					}
+					break;
+				}
+			// print cdata sections
+			case Node.CDATA_SECTION_NODE:
+				{
+					if (canonical)
+					{
+						out.print(normalize(node.getNodeValue()));
+					}
+					else
+					{
+						out.print("<![CDATA[");
+						out.print(node.getNodeValue());
+						out.print("]]>");
+					}
+					break;
+				}
+				// print text
+			case Node.TEXT_NODE:
+				{
+					out.print(normalize(node.getNodeValue()));
+					break;
+				}
+				// print processing instruction
+			case Node.PROCESSING_INSTRUCTION_NODE:
+				{
+					out.print("<?");
+					out.print(node.getNodeName());
+					String data = node.getNodeValue();
+					if (data != null && data.length() > 0)
+					{
+						out.print(' ');
+						out.print(data);
+					}
+					out.println("?>");
+					break;
+				}
+		}
+		if (type == Node.ELEMENT_NODE)
+		{
+			out.print("</");
+			out.print(node.getNodeName());
+			out.print('>');
+		}
+		out.flush();
+	}
+	// print(Node)
+
+	/**
+	 * Returns a sorted list of attributes.
+	 *
+	 * @param attrs  Description of Parameter
+	 * @return       Description of the Returned Value
+	 * @since
+	 */
+
+	protected Attr[] sortAttributes(NamedNodeMap attrs)
+	{
+		int len = (attrs != null) ? attrs.getLength() : 0;
+		Attr array[] = new Attr[len];
+		for (int i = 0; i < len; i++)
+		{
+			array[i] = (Attr)attrs.item(i);
+		}
+		for (int i = 0; i < len - 1; i++)
+		{
+			String name = array[i].getNodeName();
+			int index = i;
+			for (int j = i + 1; j < len; j++)
+			{
+				String curName = array[j].getNodeName();
+				if (curName.compareTo(name) < 0)
+				{
+					name = curName;
+					index = j;
+				}
+			}
+			if (index != i)
+			{
+				Attr temp = array[i];
+				array[i] = array[index];
+				array[index] = temp;
+			}
+		}
+		return (array);
+	}
+
+	/**
+	 * Normalizes the given string.
+	 *
+	 * @param s  Description of Parameter
+	 * @return   Description of the Returned Value
+	 * @since
+	 */
+
+	protected String normalize(String s)
+	{
+		StringBuffer str = new StringBuffer();
+		int len = (s != null) ? s.length() : 0;
+		for (int i = 0; i < len; i++)
+		{
+			char ch = s.charAt(i);
+			switch (ch)
+			{
+				case '<':
+					{
+						str.append("&lt;");
+						break;
+					}
+				case '>':
+					{
+						str.append("&gt;");
+						break;
+					}
+				case '&':
+					{
+						str.append("&amp;");
+						break;
+					}
+				case '"':
+					{
+						str.append("&quot;");
+						break;
+					}
+				case '\'':
+					{
+						str.append("&apos;");
+						break;
+					}
+				case '\r':
+				case '\n':
+					{
+						if (canonical)
+						{
+							str.append("&#");
+							str.append(Integer.toString(ch));
+							str.append(';');
+							break;
+						}
+					// else, default append char
+					}
+				default:
+					{
+						str.append(ch);
+					}
+			}
+		}
+		return (str.toString());
+	}
+
+  private static void log(int prio, String message, Throwable t){
+    if (HttpConnectorActivator.bc!=null){
+      ServiceReference logSR=HttpConnectorActivator.bc.getServiceReference(LogService.class.getName());
+      if (logSR!=null){
+        ((LogService)HttpConnectorActivator.bc.getService(logSR)).log(prio, message, t);
+      }else{
+        System.out.println("No Log Service");
+      }
+    }else{
+      System.out.println(DefaultProcessor.class.getName()+".log: No bundleContext");
+    }
+  }
+}

Added: incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/mx4j/tools/adaptor/http/DeleteMBeanCommandProcessor.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/mx4j/tools/adaptor/http/DeleteMBeanCommandProcessor.java?rev=423855&view=auto
==============================================================================
--- incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/mx4j/tools/adaptor/http/DeleteMBeanCommandProcessor.java (added)
+++ incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/mx4j/tools/adaptor/http/DeleteMBeanCommandProcessor.java Thu Jul 20 02:36:47 2006
@@ -0,0 +1,105 @@
+/*
+ *  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.httpconnector.mx4j.tools.adaptor.http;
+
+import java.io.IOException;
+
+import javax.management.JMException;
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+/**
+ * DeleteMBeanCommandProcessor, processes a request for unregistering an MBean
+ *
+ * @author    <a href="mailto:tibu@users.sourceforge.net">Carlos Quiroz</a>
+ * @version   $Revision: 1.1.1.1 $
+ */
+public class DeleteMBeanCommandProcessor extends HttpCommandProcessorAdaptor
+{
+
+ public DeleteMBeanCommandProcessor()
+ {
+ }
+
+
+ public Document executeRequest(HttpInputStream in)
+  throws IOException, JMException
+ {
+  Document document = builder.newDocument();
+
+  Element root = document.createElement("MBeanOperation");
+  document.appendChild(root);
+  Element operationElement = document.createElement("Operation");
+  operationElement.setAttribute("operation", "delete");
+  root.appendChild(operationElement);
+
+  String objectVariable = in.getVariable("objectname");
+  operationElement.setAttribute("objectname", objectVariable);
+  if (objectVariable == null || objectVariable.equals(""))
+  {
+   operationElement.setAttribute("result", "error");
+   operationElement.setAttribute("errorMsg", "Incorrect parameters in the request");
+   return document;
+  }
+  ObjectName name = null;
+  try
+  {
+   name = new ObjectName(objectVariable);
+  }
+  catch (MalformedObjectNameException e)
+  {
+   operationElement.setAttribute("result", "error");
+   operationElement.setAttribute("errorMsg", "Malformed object name");
+   return document;
+  }
+
+  if (server.isRegistered(name))
+  {
+   try
+   {
+    server.unregisterMBean(name);
+    operationElement.setAttribute("result", "success");
+   }
+   catch (Exception e)
+   {
+    operationElement.setAttribute("result", "error");
+    operationElement.setAttribute("errorMsg", e.getMessage());
+   }
+  }
+  else
+  {
+   if (name != null)
+   {
+    operationElement.setAttribute("result", "error");
+    operationElement.setAttribute("errorMsg", "MBean " + name + " not registered");
+   }
+  }
+  return document;
+ }
+
+}
+

Added: incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/mx4j/tools/adaptor/http/EmptyCommandProcessor.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/mx4j/tools/adaptor/http/EmptyCommandProcessor.java?rev=423855&view=auto
==============================================================================
--- incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/mx4j/tools/adaptor/http/EmptyCommandProcessor.java (added)
+++ incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/mx4j/tools/adaptor/http/EmptyCommandProcessor.java Thu Jul 20 02:36:47 2006
@@ -0,0 +1,63 @@
+/*
+ *  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.httpconnector.mx4j.tools.adaptor.http;
+
+import java.io.IOException;
+
+import javax.management.JMException;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+/**
+ * EmptyCommandProcessor, returns an empty xml tree
+ *
+ * @author    <a href="mailto:tibu@users.sourceforge.net">Carlos Quiroz</a>
+ * @version   $Revision: 1.2 $
+ */
+public class EmptyCommandProcessor extends HttpCommandProcessorAdaptor
+{
+
+  /**
+   * Constructs a new EmptyCommandProcessor
+   *
+   */
+  public EmptyCommandProcessor()
+  {
+  }
+
+
+  public Document executeRequest(HttpInputStream in)
+    throws IOException, JMException
+  {
+    Document document = builder.newDocument();
+
+    Element root = document.createElement("empty");
+    document.appendChild(root);
+
+    return document;
+  }
+
+}
+

Added: incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/mx4j/tools/adaptor/http/GetAttributeCommandProcessor.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/mx4j/tools/adaptor/http/GetAttributeCommandProcessor.java?rev=423855&view=auto
==============================================================================
--- incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/mx4j/tools/adaptor/http/GetAttributeCommandProcessor.java (added)
+++ incubator/felix/trunk/org.apache.felix.mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/mx4j/tools/adaptor/http/GetAttributeCommandProcessor.java Thu Jul 20 02:36:47 2006
@@ -0,0 +1,195 @@
+/*
+ * 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.httpconnector.mx4j.tools.adaptor.http;
+
+import java.io.IOException;
+import java.lang.reflect.Array;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.Map;
+
+import javax.management.JMException;
+import javax.management.MBeanAttributeInfo;
+import javax.management.MBeanInfo;
+import javax.management.ObjectName;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+/**
+ * GetAttributeCommandProcessor, processes a request for getting one attribute
+ * of a specific MBean. It also support some formats for types like Arrays
+ *
+ * @author <a href="mailto:tibu@users.sourceforge.net">Carlos Quiroz</a>
+ * @version $Revision: 1.1.1.1 $
+ */
+public class GetAttributeCommandProcessor extends HttpCommandProcessorAdaptor
+{
+	public GetAttributeCommandProcessor()
+	{
+	}
+
+	public Document executeRequest(HttpInputStream in) throws IOException, JMException
+	{
+		Document document = builder.newDocument();
+
+		String name = in.getVariable("objectname");
+		String attributeVariable = in.getVariable("attribute");
+		String formatVariable = in.getVariable("format");
+		ObjectName objectName = null;
+		MBeanAttributeInfo targetAttribute = null;
+		// special case
+		boolean validMBean = false;
+		if (name != null)
+		{
+			objectName = new ObjectName(name);
+			if (server.isRegistered(objectName))
+			{
+				validMBean = true;
+			}
+		}
+		if (validMBean && attributeVariable != null)
+		{
+			validMBean = false;
+			MBeanInfo info = server.getMBeanInfo(objectName);
+			MBeanAttributeInfo[] attributes = info.getAttributes();
+
+			if (attributes != null)
+			{
+				for (int i=0;i<attributes.length;i++)
+				{
+					if (attributes[i].getName().equals(attributeVariable))
+					{
+						targetAttribute = attributes[i];
+						validMBean = true;
+						break;
+					}
+				}
+			}
+		}
+		if (validMBean)
+		{
+			Element root = document.createElement("MBean");
+			document.appendChild(root);
+
+			root.setAttribute("objectname", objectName.toString());
+			MBeanInfo info = server.getMBeanInfo(objectName);
+			root.setAttribute("classname", info.getClassName());
+			root.setAttribute("description", info.getDescription());
+
+			Element attribute = document.createElement("Attribute");
+			attribute.setAttribute("name", attributeVariable);
+			attribute.setAttribute("classname", targetAttribute.getType());
+			Object attributeValue = server.getAttribute(objectName, attributeVariable);
+			attribute.setAttribute("isnull", (attributeValue==null)?"true":"false");
+			root.appendChild(attribute);
+
+			if ("array".equals(formatVariable) && attributeValue.getClass().isArray())
+			{
+				Element array = document.createElement("Array");
+				array.setAttribute("componentclass", attributeValue.getClass().getComponentType().getName());
+				int length = Array.getLength(attributeValue);
+				array.setAttribute("length", "" + length);
+				for (int i=0;i<length;i++) {
+					Element arrayElement = document.createElement("Element");
+					arrayElement.setAttribute("index", "" + i);
+					if (Array.get(attributeValue, i) != null)
+					{
+						arrayElement.setAttribute("element", Array.get(attributeValue, i).toString());
+						arrayElement.setAttribute("isnull", "false");
+					}
+					else
+					{
+						arrayElement.setAttribute("element", "null");
+						arrayElement.setAttribute("isnull", "true");
+					}
+					array.appendChild(arrayElement);
+				}
+				attribute.appendChild(array);
+			}
+			else if ("collection".equals(formatVariable) && attributeValue instanceof Collection)
+			{
+				Collection collection = (Collection)attributeValue;
+				Element collectionElement = document.createElement("Collection");
+				collectionElement.setAttribute("length", "" + collection.size());
+				Iterator i=collection.iterator();
+				int j=0;
+				while (i.hasNext())
+				{
+					Element collectionEntry = document.createElement("Element");
+					collectionEntry.setAttribute("index", "" + j++);
+					Object obj = i.next();
+					if (obj != null)
+					{
+						collectionEntry.setAttribute("elementclass", obj.getClass().getName());
+						collectionEntry.setAttribute("element", obj.toString());
+					}
+					else
+					{
+						collectionEntry.setAttribute("elementclass", "null");
+						collectionEntry.setAttribute("element", "null");
+					}
+					collectionElement.appendChild(collectionEntry);
+				}
+				attribute.appendChild(collectionElement);
+			}
+			else if ("map".equals(formatVariable) && attributeValue instanceof Map)
+			{
+				Map map = (Map)attributeValue;
+				Element mapElement = document.createElement("Map");
+				mapElement.setAttribute("length", "" + map.size());
+				Iterator i=map.keySet().iterator();
+				int j=0;
+				while (i.hasNext())
+				{
+					Element mapEntry = document.createElement("Element");
+					mapEntry.setAttribute("index", "" + j++);
+					Object key = i.next();
+					Object entry = map.get(key);
+					if (entry != null && key != null)
+					{
+						mapEntry.setAttribute("keyclass", key.getClass().getName());
+						mapEntry.setAttribute("key", key.toString());
+						mapEntry.setAttribute("elementclass", entry.getClass().getName());
+						mapEntry.setAttribute("element", entry.toString());
+					}
+					else
+					{
+						mapEntry.setAttribute("keyclass", "null");
+						mapEntry.setAttribute("key", "null");
+						mapEntry.setAttribute("elementclass", "null");
+						mapEntry.setAttribute("element", "null");
+					}
+					mapElement.appendChild(mapEntry);
+				}
+				attribute.appendChild(mapElement);
+			}
+			else
+			{
+				attribute.setAttribute("value", attributeValue.toString());
+			}
+
+		}
+		return document;
+	}
+}