You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by fm...@apache.org on 2008/05/19 09:36:39 UTC
svn commit: r657742 [1/4] - in
/felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole: ./
internal/ internal/compendium/ internal/core/ internal/misc/ internal/obr/
internal/servlet/ internal/system/
Author: fmeschbe
Date: Mon May 19 00:36:38 2008
New Revision: 657742
URL: http://svn.apache.org/viewvc?rev=657742&view=rev
Log:
Organize imports and format according to Apache Felix code conventions
Modified:
felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/Action.java
felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/ConfigurationPrinter.java
felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/Render.java
felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/BaseManagementPlugin.java
felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/OsgiManagerActivator.java
felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/Util.java
felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/compendium/AbstractScrPlugin.java
felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/compendium/AjaxConfigManagerAction.java
felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/compendium/ComponentConfigurationPrinter.java
felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/compendium/ComponentRenderAction.java
felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/compendium/ConfigManager.java
felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/compendium/ConfigManagerBase.java
felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/AjaxBundleDetailsAction.java
felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/BundleAction.java
felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/BundleListRender.java
felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/InstallAction.java
felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/RefreshPackagesAction.java
felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/SetStartLevelAction.java
felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/StartAction.java
felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/StopAction.java
felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/UninstallAction.java
felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/UpdateAction.java
felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/AssemblyListRender.java
felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/ConfigurationRender.java
felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/obr/AbstractObrPlugin.java
felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/obr/BundleRepositoryRender.java
felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/obr/InstallFromRepoAction.java
felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/obr/RefreshRepoAction.java
felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/ConfigurationListener.java
felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/Logger.java
felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/OsgiManager.java
felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/OsgiManagerHttpContext.java
felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/system/GCAction.java
felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/system/ShutdownAction.java
felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/system/ShutdownRender.java
felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/system/VMStatRender.java
Modified: felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/Action.java
URL: http://svn.apache.org/viewvc/felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/Action.java?rev=657742&r1=657741&r2=657742&view=diff
==============================================================================
--- felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/Action.java (original)
+++ felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/Action.java Mon May 19 00:36:38 2008
@@ -16,26 +16,32 @@
*/
package org.apache.felix.webconsole;
+
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-public interface Action {
+
+public interface Action
+{
static final String SERVICE = Action.class.getName();
-
+
/**
* The name of a request attribute, which may be set by performAction if
* redirecting.
*/
- static final String ATTR_REDIRECT_PARAMETERS= "redirectParameters";
+ static final String ATTR_REDIRECT_PARAMETERS = "redirectParameters";
+
String getName();
+
String getLabel();
+
/**
* Performs the action the request data optionally sending a response to
* the HTTP Servlet Response.
@@ -53,7 +59,7 @@
* processing the action. The <code>rootCause</code> of the exception
* should contain the cause of the error.
*/
- boolean performAction(HttpServletRequest request,
- HttpServletResponse response) throws IOException, ServletException;
+ boolean performAction( HttpServletRequest request, HttpServletResponse response ) throws IOException,
+ ServletException;
}
Modified: felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/ConfigurationPrinter.java
URL: http://svn.apache.org/viewvc/felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/ConfigurationPrinter.java?rev=657742&r1=657741&r2=657742&view=diff
==============================================================================
--- felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/ConfigurationPrinter.java (original)
+++ felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/ConfigurationPrinter.java Mon May 19 00:36:38 2008
@@ -18,14 +18,19 @@
*/
package org.apache.felix.webconsole;
+
import java.io.PrintWriter;
-public interface ConfigurationPrinter {
+
+public interface ConfigurationPrinter
+{
static final String SERVICE = ConfigurationPrinter.class.getName();
+
String getTitle();
- void printConfiguration(PrintWriter printWriter);
+
+ void printConfiguration( PrintWriter printWriter );
}
Modified: felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/Render.java
URL: http://svn.apache.org/viewvc/felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/Render.java?rev=657742&r1=657741&r2=657742&view=diff
==============================================================================
--- felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/Render.java (original)
+++ felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/Render.java Mon May 19 00:36:38 2008
@@ -16,23 +16,29 @@
*/
package org.apache.felix.webconsole;
+
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+
/**
* The <code>Render</code> TODO
*/
-public interface Render {
+public interface Render
+{
static final String SERVICE = Render.class.getName();
+
String getName();
+
String getLabel();
- void render(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException;
+
+ void render( HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException;
}
Modified: felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/BaseManagementPlugin.java
URL: http://svn.apache.org/viewvc/felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/BaseManagementPlugin.java?rev=657742&r1=657741&r2=657742&view=diff
==============================================================================
--- felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/BaseManagementPlugin.java (original)
+++ felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/BaseManagementPlugin.java Mon May 19 00:36:38 2008
@@ -18,13 +18,16 @@
*/
package org.apache.felix.webconsole.internal;
+
import org.apache.felix.webconsole.internal.servlet.Logger;
import org.osgi.framework.BundleContext;
import org.osgi.service.packageadmin.PackageAdmin;
import org.osgi.service.startlevel.StartLevel;
import org.osgi.util.tracker.ServiceTracker;
-public class BaseManagementPlugin {
+
+public class BaseManagementPlugin
+{
private BundleContext bundleContext;
private Logger log;
@@ -33,42 +36,55 @@
private ServiceTracker packageAdmin;
- protected BaseManagementPlugin() {
+
+ protected BaseManagementPlugin()
+ {
}
- public void setBundleContext(BundleContext bundleContext) {
+
+ public void setBundleContext( BundleContext bundleContext )
+ {
this.bundleContext = bundleContext;
}
-
- public void setLogger(Logger log) {
+
+
+ public void setLogger( Logger log )
+ {
this.log = log;
}
- protected BundleContext getBundleContext() {
+
+ protected BundleContext getBundleContext()
+ {
return bundleContext;
}
-
- protected Logger getLog() {
+
+
+ protected Logger getLog()
+ {
return log;
}
-
- protected StartLevel getStartLevel() {
- if (startLevelService == null) {
- startLevelService = new ServiceTracker(getBundleContext(),
- StartLevel.class.getName(), null);
+
+
+ protected StartLevel getStartLevel()
+ {
+ if ( startLevelService == null )
+ {
+ startLevelService = new ServiceTracker( getBundleContext(), StartLevel.class.getName(), null );
startLevelService.open();
}
- return (StartLevel) startLevelService.getService();
+ return ( StartLevel ) startLevelService.getService();
}
- protected PackageAdmin getPackageAdmin() {
- if (packageAdmin == null) {
- packageAdmin = new ServiceTracker(getBundleContext(),
- PackageAdmin.class.getName(), null);
+
+ protected PackageAdmin getPackageAdmin()
+ {
+ if ( packageAdmin == null )
+ {
+ packageAdmin = new ServiceTracker( getBundleContext(), PackageAdmin.class.getName(), null );
packageAdmin.open();
}
- return (PackageAdmin) packageAdmin.getService();
+ return ( PackageAdmin ) packageAdmin.getService();
}
-
}
Modified: felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/OsgiManagerActivator.java
URL: http://svn.apache.org/viewvc/felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/OsgiManagerActivator.java?rev=657742&r1=657741&r2=657742&view=diff
==============================================================================
--- felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/OsgiManagerActivator.java (original)
+++ felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/OsgiManagerActivator.java Mon May 19 00:36:38 2008
@@ -18,20 +18,28 @@
*/
package org.apache.felix.webconsole.internal;
+
import org.apache.felix.webconsole.internal.servlet.OsgiManager;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
-public class OsgiManagerActivator implements BundleActivator {
+
+public class OsgiManagerActivator implements BundleActivator
+{
private OsgiManager osgiManager;
-
- public void start(BundleContext bundleContext) {
- osgiManager = new OsgiManager(bundleContext);
+
+
+ public void start( BundleContext bundleContext )
+ {
+ osgiManager = new OsgiManager( bundleContext );
}
- public void stop(BundleContext arg0) {
- if (osgiManager != null) {
+
+ public void stop( BundleContext arg0 )
+ {
+ if ( osgiManager != null )
+ {
osgiManager.dispose();
}
}
Modified: felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/Util.java
URL: http://svn.apache.org/viewvc/felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/Util.java?rev=657742&r1=657741&r2=657742&view=diff
==============================================================================
--- felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/Util.java (original)
+++ felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/Util.java Mon May 19 00:36:38 2008
@@ -16,6 +16,7 @@
*/
package org.apache.felix.webconsole.internal;
+
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
@@ -30,10 +31,12 @@
import org.apache.commons.io.IOUtils;
import org.apache.felix.webconsole.Render;
+
/**
* The <code>Util</code> TODO
*/
-public class Util {
+public class Util
+{
/** web apps subpage */
public static final String PAGE_WEBAPPS = "/webapps";
@@ -87,8 +90,10 @@
/** The name of the request attribute containig the map of FileItems from the POST request */
public static final String ATTR_FILEUPLOAD = "org.apache.felix.webconsole.fileupload";
- public static PrintWriter startHtml(HttpServletResponse resp, String pageTitle) throws IOException {
- resp.setContentType("text/html; utf-8");
+
+ public static PrintWriter startHtml( HttpServletResponse resp, String pageTitle ) throws IOException
+ {
+ resp.setContentType( "text/html; utf-8" );
PrintWriter pw = resp.getWriter();
@@ -102,69 +107,90 @@
long totalMem = Runtime.getRuntime().totalMemory() / 1024;
long usedMem = totalMem - freeMem;
- String header = MessageFormat.format(HEADER, new Object[] {
- adminTitle,
- "1.0.0-SNAPSHOT", // ServletEngine.VERSION.getFullVersion(),
- System.getProperty("java.runtime.version"),
- System.getProperty("java.runtime.name"),
- System.getProperty("java.vm.name"),
- System.getProperty("java.vm.version"),
- System.getProperty("java.vm.info"), new Long(totalMem),
- new Long(usedMem), new Long(freeMem), vendorWeb, productName,
- pageTitle, productWeb, vendorName});
- pw.println(header);
+ String header = MessageFormat.format( HEADER, new Object[]
+ {
+ adminTitle,
+ "1.0.0-SNAPSHOT", // ServletEngine.VERSION.getFullVersion(),
+ System.getProperty( "java.runtime.version" ), System.getProperty( "java.runtime.name" ),
+ System.getProperty( "java.vm.name" ), System.getProperty( "java.vm.version" ),
+ System.getProperty( "java.vm.info" ), new Long( totalMem ), new Long( usedMem ), new Long( freeMem ),
+ vendorWeb, productName, pageTitle, productWeb, vendorName } );
+ pw.println( header );
return pw;
}
- public static void navigation(PrintWriter pw, Collection renders, String current, boolean disabled) {
- pw.println("<p id='technav'>");
+
+ public static void navigation( PrintWriter pw, Collection renders, String current, boolean disabled )
+ {
+ pw.println( "<p id='technav'>" );
SortedMap map = new TreeMap();
- for (Iterator ri=renders.iterator(); ri.hasNext(); ) {
- Render render = (Render) ri.next();
- if (render.getLabel() == null) {
+ for ( Iterator ri = renders.iterator(); ri.hasNext(); )
+ {
+ Render render = ( Render ) ri.next();
+ if ( render.getLabel() == null )
+ {
// ignore renders without a label
- } else if (disabled || current.equals(render.getName())) {
- map.put(render.getLabel(), "<span class='technavat'>" + render.getLabel() + "</span>");
- } else {
- map.put(render.getLabel(), "<a href='" + render.getName() + "'>" + render.getLabel() + "</a></li>");
+ }
+ else if ( disabled || current.equals( render.getName() ) )
+ {
+ map.put( render.getLabel(), "<span class='technavat'>" + render.getLabel() + "</span>" );
+ }
+ else
+ {
+ map.put( render.getLabel(), "<a href='" + render.getName() + "'>" + render.getLabel() + "</a></li>" );
}
}
- for (Iterator li=map.values().iterator(); li.hasNext(); ) {
- pw.println(li.next());
+ for ( Iterator li = map.values().iterator(); li.hasNext(); )
+ {
+ pw.println( li.next() );
}
- pw.println("</p>");
+ pw.println( "</p>" );
}
- public static void endHhtml(PrintWriter pw) {
- pw.println("</body>");
- pw.println("</html>");
+
+ public static void endHhtml( PrintWriter pw )
+ {
+ pw.println( "</body>" );
+ pw.println( "</html>" );
}
- public static void startScript(PrintWriter pw) {
- pw.println("<script type='text/javascript'>");
- pw.println("// <![CDATA[");
+
+ public static void startScript( PrintWriter pw )
+ {
+ pw.println( "<script type='text/javascript'>" );
+ pw.println( "// <![CDATA[" );
}
- public static void endScript(PrintWriter pw) {
- pw.println("// ]]>");
- pw.println("</script>");
+
+ public static void endScript( PrintWriter pw )
+ {
+ pw.println( "// ]]>" );
+ pw.println( "</script>" );
}
- public static void spool(String res, HttpServletResponse resp) throws IOException {
- InputStream ins = getResource(res);
- if (ins != null) {
- try {
- IOUtils.copy(ins, resp.getOutputStream());
- } finally {
- IOUtils.closeQuietly(ins);
+
+ public static void spool( String res, HttpServletResponse resp ) throws IOException
+ {
+ InputStream ins = getResource( res );
+ if ( ins != null )
+ {
+ try
+ {
+ IOUtils.copy( ins, resp.getOutputStream() );
+ }
+ finally
+ {
+ IOUtils.closeQuietly( ins );
}
}
}
- private static InputStream getResource(String resource) {
- return Util.class.getResourceAsStream(resource);
+
+ private static InputStream getResource( String resource )
+ {
+ return Util.class.getResourceAsStream( resource );
}
}
Modified: felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/compendium/AbstractScrPlugin.java
URL: http://svn.apache.org/viewvc/felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/compendium/AbstractScrPlugin.java?rev=657742&r1=657741&r2=657742&view=diff
==============================================================================
--- felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/compendium/AbstractScrPlugin.java (original)
+++ felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/compendium/AbstractScrPlugin.java Mon May 19 00:36:38 2008
@@ -18,27 +18,35 @@
*/
package org.apache.felix.webconsole.internal.compendium;
+
import org.apache.felix.scr.ScrService;
import org.apache.felix.webconsole.internal.BaseManagementPlugin;
import org.osgi.util.tracker.ServiceTracker;
-public class AbstractScrPlugin extends BaseManagementPlugin {
+
+public class AbstractScrPlugin extends BaseManagementPlugin
+{
private ServiceTracker scrServiceTracker;
- protected ScrService getScrService() {
- if (scrServiceTracker == null) {
- try {
- scrServiceTracker = new ServiceTracker(getBundleContext(),
- ScrService.class.getName(), null);
+
+ protected ScrService getScrService()
+ {
+ if ( scrServiceTracker == null )
+ {
+ try
+ {
+ scrServiceTracker = new ServiceTracker( getBundleContext(), ScrService.class.getName(), null );
scrServiceTracker.open();
- } catch (Throwable t) {
+ }
+ catch ( Throwable t )
+ {
// missing ScrService class ??
return null;
}
}
- return (ScrService) scrServiceTracker.getService();
+ return ( ScrService ) scrServiceTracker.getService();
}
}
Modified: felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/compendium/AjaxConfigManagerAction.java
URL: http://svn.apache.org/viewvc/felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/compendium/AjaxConfigManagerAction.java?rev=657742&r1=657741&r2=657742&view=diff
==============================================================================
--- felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/compendium/AjaxConfigManagerAction.java (original)
+++ felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/compendium/AjaxConfigManagerAction.java Mon May 19 00:36:38 2008
@@ -16,6 +16,7 @@
*/
package org.apache.felix.webconsole.internal.compendium;
+
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.lang.reflect.Array;
@@ -45,202 +46,249 @@
import org.osgi.service.metatype.AttributeDefinition;
import org.osgi.service.metatype.ObjectClassDefinition;
+
/**
* The <code>AjaxConfigManagerAction</code> TODO
*/
-public class AjaxConfigManagerAction extends ConfigManagerBase implements
- Action {
+public class AjaxConfigManagerAction extends ConfigManagerBase implements Action
+{
public static final String NAME = "ajaxConfigManager";
- public String getName() {
+
+ public String getName()
+ {
return NAME;
}
- public String getLabel() {
+
+ public String getLabel()
+ {
return NAME;
}
- public boolean performAction(HttpServletRequest request,
- HttpServletResponse response) throws IOException {
+
+ public boolean performAction( HttpServletRequest request, HttpServletResponse response ) throws IOException
+ {
// should actually apply the configuration before redirecting
- if (request.getParameter("apply") != null) {
- return applyConfiguration(request);
+ if ( request.getParameter( "apply" ) != null )
+ {
+ return applyConfiguration( request );
}
JSONObject result = new JSONObject();
- String pid = request.getParameter(ConfigManager.PID);
+ String pid = request.getParameter( ConfigManager.PID );
boolean isFactory = pid == null;
- if (isFactory) {
- pid = request.getParameter("factoryPid");
+ if ( isFactory )
+ {
+ pid = request.getParameter( "factoryPid" );
}
- if (pid != null) {
- try {
- this.configForm(result, pid, isFactory, getLocale(request));
- } catch (Exception e) {
+ if ( pid != null )
+ {
+ try
+ {
+ this.configForm( result, pid, isFactory, getLocale( request ) );
+ }
+ catch ( Exception e )
+ {
// add message
}
}
// send the result
- response.setContentType("text/javascript");
- response.getWriter().print(result.toString());
+ response.setContentType( "text/javascript" );
+ response.getWriter().print( result.toString() );
return false;
}
- private void configForm(JSONObject json, String pid, boolean isFactory,
- Locale loc) throws IOException, JSONException {
- String locale = (loc == null) ? null : loc.toString();
+
+ private void configForm( JSONObject json, String pid, boolean isFactory, Locale loc ) throws IOException,
+ JSONException
+ {
+ String locale = ( loc == null ) ? null : loc.toString();
ConfigurationAdmin ca = this.getConfigurationAdmin();
- if (ca == null) {
+ if ( ca == null )
+ {
// should print message
return;
}
Configuration config = null;
- try {
- Configuration[] configs = ca.listConfigurations("("
- + Constants.SERVICE_PID + "=" + pid + ")");
- if (configs != null && configs.length > 0) {
+ try
+ {
+ Configuration[] configs = ca.listConfigurations( "(" + Constants.SERVICE_PID + "=" + pid + ")" );
+ if ( configs != null && configs.length > 0 )
+ {
config = configs[0];
}
- } catch (InvalidSyntaxException ise) {
+ }
+ catch ( InvalidSyntaxException ise )
+ {
// should print message
return;
}
- json.put(ConfigManager.PID, pid);
- json.put("isFactory", isFactory);
+ json.put( ConfigManager.PID, pid );
+ json.put( "isFactory", isFactory );
Dictionary props = null;
ObjectClassDefinition ocd;
- if (config != null) {
+ if ( config != null )
+ {
props = config.getProperties();
- ocd = this.getObjectClassDefinition(config, locale);
- } else {
- ocd = this.getObjectClassDefinition(pid, locale);
+ ocd = this.getObjectClassDefinition( config, locale );
+ }
+ else
+ {
+ ocd = this.getObjectClassDefinition( pid, locale );
}
- props = this.mergeWithMetaType(props, ocd, json);
+ props = this.mergeWithMetaType( props, ocd, json );
- if (props != null) {
+ if ( props != null )
+ {
JSONObject properties = new JSONObject();
- for (Enumeration pe = props.keys(); pe.hasMoreElements();) {
+ for ( Enumeration pe = props.keys(); pe.hasMoreElements(); )
+ {
Object key = pe.nextElement();
// ignore well known special properties
- if (!key.equals(Constants.SERVICE_PID)
- && !key.equals(Constants.SERVICE_DESCRIPTION)
- && !key.equals(Constants.SERVICE_ID)
- && !key.equals(Constants.SERVICE_RANKING)
- && !key.equals(Constants.SERVICE_VENDOR)
- && !key.equals(ConfigurationAdmin.SERVICE_BUNDLELOCATION)
- && !key.equals(ConfigurationAdmin.SERVICE_FACTORYPID)) {
- properties.put(String.valueOf(key), props.get(key));
+ if ( !key.equals( Constants.SERVICE_PID ) && !key.equals( Constants.SERVICE_DESCRIPTION )
+ && !key.equals( Constants.SERVICE_ID ) && !key.equals( Constants.SERVICE_RANKING )
+ && !key.equals( Constants.SERVICE_VENDOR )
+ && !key.equals( ConfigurationAdmin.SERVICE_BUNDLELOCATION )
+ && !key.equals( ConfigurationAdmin.SERVICE_FACTORYPID ) )
+ {
+ properties.put( String.valueOf( key ), props.get( key ) );
}
}
- json.put("title", pid);
- json.put(
- "description",
- "Please enter configuration properties for this configuration in the field below. This configuration has no associated description");
+ json.put( "title", pid );
+ json
+ .put(
+ "description",
+ "Please enter configuration properties for this configuration in the field below. This configuration has no associated description" );
- json.put("propertylist", "properties");
- json.put("properties", properties);
+ json.put( "propertylist", "properties" );
+ json.put( "properties", properties );
}
- if (config != null) {
- this.addConfigurationInfo(config, json, locale);
+ if ( config != null )
+ {
+ this.addConfigurationInfo( config, json, locale );
}
}
- private Dictionary mergeWithMetaType(Dictionary props,
- ObjectClassDefinition ocd, JSONObject json) throws JSONException {
- if (props == null) {
+ private Dictionary mergeWithMetaType( Dictionary props, ObjectClassDefinition ocd, JSONObject json )
+ throws JSONException
+ {
+
+ if ( props == null )
+ {
props = new Hashtable();
}
- if (ocd != null) {
+ if ( ocd != null )
+ {
- json.put("title", ocd.getName());
+ json.put( "title", ocd.getName() );
- if (ocd.getDescription() != null) {
- json.put("description", ocd.getDescription());
+ if ( ocd.getDescription() != null )
+ {
+ json.put( "description", ocd.getDescription() );
}
- AttributeDefinition[] ad = ocd.getAttributeDefinitions(ObjectClassDefinition.ALL);
- if (ad != null) {
+ AttributeDefinition[] ad = ocd.getAttributeDefinitions( ObjectClassDefinition.ALL );
+ if ( ad != null )
+ {
JSONArray propertyList = new JSONArray();
- for (int i = 0; i < ad.length; i++) {
+ for ( int i = 0; i < ad.length; i++ )
+ {
JSONObject entry = new JSONObject();
- Object value = props.get(ad[i].getID());
- if (value == null) {
+ Object value = props.get( ad[i].getID() );
+ if ( value == null )
+ {
value = ad[i].getDefaultValue();
- if (value == null) {
- if (ad[i].getCardinality() == 0) {
+ if ( value == null )
+ {
+ if ( ad[i].getCardinality() == 0 )
+ {
value = "";
- } else {
+ }
+ else
+ {
value = new String[0];
}
}
}
- entry.put("name", ad[i].getName());
+ entry.put( "name", ad[i].getName() );
- if (ad[i].getOptionLabels() != null
- && ad[i].getOptionLabels().length > 0) {
+ if ( ad[i].getOptionLabels() != null && ad[i].getOptionLabels().length > 0 )
+ {
JSONObject type = new JSONObject();
- type.put("labels",
- Arrays.asList(ad[i].getOptionLabels()));
- type.put("values",
- Arrays.asList(ad[i].getOptionValues()));
- entry.put("type", type);
- } else {
- entry.put("type", ad[i].getType());
+ type.put( "labels", Arrays.asList( ad[i].getOptionLabels() ) );
+ type.put( "values", Arrays.asList( ad[i].getOptionValues() ) );
+ entry.put( "type", type );
+ }
+ else
+ {
+ entry.put( "type", ad[i].getType() );
}
- if (ad[i].getCardinality() == 0) {
+ if ( ad[i].getCardinality() == 0 )
+ {
// scalar
- if (value instanceof Vector) {
- value = ((Vector) value).get(0);
- } else if (value.getClass().isArray()) {
- value = Array.get(value, 0);
- }
- entry.put("value", value);
- } else {
- if (value instanceof Vector) {
- value = new JSONArray((Vector) value);
- } else if (value.getClass().isArray()) {
- value = new JSONArray(
- Arrays.asList((Object[]) value));
- } else {
+ if ( value instanceof Vector )
+ {
+ value = ( ( Vector ) value ).get( 0 );
+ }
+ else if ( value.getClass().isArray() )
+ {
+ value = Array.get( value, 0 );
+ }
+ entry.put( "value", value );
+ }
+ else
+ {
+ if ( value instanceof Vector )
+ {
+ value = new JSONArray( ( Vector ) value );
+ }
+ else if ( value.getClass().isArray() )
+ {
+ value = new JSONArray( Arrays.asList( ( Object[] ) value ) );
+ }
+ else
+ {
JSONArray tmp = new JSONArray();
- tmp.put(value);
+ tmp.put( value );
value = tmp;
}
- entry.put("values", value);
+ entry.put( "values", value );
}
- if (ad[i].getDescription() != null) {
- entry.put("description", ad[i].getDescription());
+ if ( ad[i].getDescription() != null )
+ {
+ entry.put( "description", ad[i].getDescription() );
}
- json.put(ad[i].getID(), entry);
- propertyList.put(ad[i].getID());
+ json.put( ad[i].getID(), entry );
+ propertyList.put( ad[i].getID() );
}
- json.put("propertylist", propertyList);
+ json.put( "propertylist", propertyList );
}
// nothing more to display
@@ -250,149 +298,182 @@
return props;
}
- private void addConfigurationInfo(Configuration config, JSONObject json,
- String locale) throws JSONException {
- if (config.getFactoryPid() != null) {
- json.put("factoryPID", config.getFactoryPid());
+ private void addConfigurationInfo( Configuration config, JSONObject json, String locale ) throws JSONException
+ {
+
+ if ( config.getFactoryPid() != null )
+ {
+ json.put( "factoryPID", config.getFactoryPid() );
}
String location;
- if (config.getBundleLocation() == null) {
+ if ( config.getBundleLocation() == null )
+ {
location = "None";
- } else {
- Bundle bundle = this.getBundle(config.getBundleLocation());
-
- Dictionary headers = bundle.getHeaders(locale);
- String name = (String) headers.get(Constants.BUNDLE_NAME);
- if (name == null) {
+ }
+ else
+ {
+ Bundle bundle = this.getBundle( config.getBundleLocation() );
+
+ Dictionary headers = bundle.getHeaders( locale );
+ String name = ( String ) headers.get( Constants.BUNDLE_NAME );
+ if ( name == null )
+ {
location = bundle.getSymbolicName();
- } else {
+ }
+ else
+ {
location = name + " (" + bundle.getSymbolicName() + ")";
}
- Version v = Version.parseVersion((String) headers.get(Constants.BUNDLE_VERSION));
+ Version v = Version.parseVersion( ( String ) headers.get( Constants.BUNDLE_VERSION ) );
location += ", Version " + v.toString();
}
- json.put("bundleLocation", location);
+ json.put( "bundleLocation", location );
}
- private boolean applyConfiguration(HttpServletRequest request)
- throws IOException {
+
+ private boolean applyConfiguration( HttpServletRequest request ) throws IOException
+ {
ConfigurationAdmin ca = this.getConfigurationAdmin();
- if (ca == null) {
+ if ( ca == null )
+ {
return false;
}
- String pid = request.getParameter("pid");
+ String pid = request.getParameter( "pid" );
- if (request.getParameter("delete") != null) {
+ if ( request.getParameter( "delete" ) != null )
+ {
// TODO: should log this here !!
- Configuration config = ca.getConfiguration(pid, null);
+ Configuration config = ca.getConfiguration( pid, null );
config.delete();
return true;
- } else if (request.getParameter("create") != null) {
+ }
+ else if ( request.getParameter( "create" ) != null )
+ {
// pid is a factory PID and we have to create a new configuration
// we should actually also display that one !
- Configuration config = ca.createFactoryConfiguration(pid, null);
+ Configuration config = ca.createFactoryConfiguration( pid, null );
// request.setAttribute(ATTR_REDIRECT_PARAMETERS, "pid=" +
// config.getPid());
return true;
}
- String propertyList = request.getParameter("propertylist");
- if (propertyList == null) {
- String propertiesString = request.getParameter("properties");
-
- if (propertiesString != null) {
- byte[] propBytes = propertiesString.getBytes("ISO-8859-1");
- ByteArrayInputStream bin = new ByteArrayInputStream(propBytes);
+ String propertyList = request.getParameter( "propertylist" );
+ if ( propertyList == null )
+ {
+ String propertiesString = request.getParameter( "properties" );
+
+ if ( propertiesString != null )
+ {
+ byte[] propBytes = propertiesString.getBytes( "ISO-8859-1" );
+ ByteArrayInputStream bin = new ByteArrayInputStream( propBytes );
Properties props = new Properties();
- props.load(bin);
+ props.load( bin );
- Configuration config = ca.getConfiguration(pid, null);
- config.update(props);
+ Configuration config = ca.getConfiguration( pid, null );
+ config.update( props );
}
- } else {
- Configuration config = ca.getConfiguration(pid, null);
+ }
+ else
+ {
+ Configuration config = ca.getConfiguration( pid, null );
Dictionary props = config.getProperties();
- if (props == null) {
+ if ( props == null )
+ {
props = new Hashtable();
}
- Map adMap = (Map) this.getAttributeDefinitionMap(config, null);
- if (adMap != null) {
- StringTokenizer propTokens = new StringTokenizer(propertyList,
- ",");
- while (propTokens.hasMoreTokens()) {
+ Map adMap = ( Map ) this.getAttributeDefinitionMap( config, null );
+ if ( adMap != null )
+ {
+ StringTokenizer propTokens = new StringTokenizer( propertyList, "," );
+ while ( propTokens.hasMoreTokens() )
+ {
String propName = propTokens.nextToken();
- AttributeDefinition ad = (AttributeDefinition) adMap.get(propName);
- if (ad == null
- || (ad.getCardinality() == 0 && ad.getType() == AttributeDefinition.STRING)) {
- String prop = request.getParameter(propName);
- if (prop != null) {
- props.put(propName, prop);
+ AttributeDefinition ad = ( AttributeDefinition ) adMap.get( propName );
+ if ( ad == null || ( ad.getCardinality() == 0 && ad.getType() == AttributeDefinition.STRING ) )
+ {
+ String prop = request.getParameter( propName );
+ if ( prop != null )
+ {
+ props.put( propName, prop );
}
- } else if (ad.getCardinality() == 0) {
+ }
+ else if ( ad.getCardinality() == 0 )
+ {
// scalar of non-string
- String prop = request.getParameter(propName);
- props.put(propName, this.toType(ad.getType(), prop));
- } else {
+ String prop = request.getParameter( propName );
+ props.put( propName, this.toType( ad.getType(), prop ) );
+ }
+ else
+ {
// array or vector of any type
Vector vec = new Vector();
- String[] properties = request.getParameterValues(propName);
- if (properties != null) {
- for (int i = 0; i < properties.length; i++) {
- vec.add(this.toType(ad.getType(), properties[i]));
+ String[] properties = request.getParameterValues( propName );
+ if ( properties != null )
+ {
+ for ( int i = 0; i < properties.length; i++ )
+ {
+ vec.add( this.toType( ad.getType(), properties[i] ) );
}
}
// but ensure size
- int maxSize = Math.abs(ad.getCardinality());
- if (vec.size() > maxSize) {
- vec.setSize(maxSize);
+ int maxSize = Math.abs( ad.getCardinality() );
+ if ( vec.size() > maxSize )
+ {
+ vec.setSize( maxSize );
}
- if (ad.getCardinality() < 0) {
+ if ( ad.getCardinality() < 0 )
+ {
// keep the vector
- props.put(propName, vec);
- } else {
+ props.put( propName, vec );
+ }
+ else
+ {
// convert to an array
- props.put(propName, this.toArray(ad.getType(), vec));
+ props.put( propName, this.toArray( ad.getType(), vec ) );
}
}
}
}
- config.update(props);
+ config.update( props );
}
// request.setAttribute(ATTR_REDIRECT_PARAMETERS, "pid=" + pid);
return true;
}
- private Object toType(int type, String value) {
- switch (type) {
+
+ private Object toType( int type, String value )
+ {
+ switch ( type )
+ {
case AttributeDefinition.BOOLEAN:
- return Boolean.valueOf(value);
+ return Boolean.valueOf( value );
case AttributeDefinition.BYTE:
- return Byte.valueOf(value);
+ return Byte.valueOf( value );
case AttributeDefinition.CHARACTER:
- char c = (value.length() > 0) ? value.charAt(0) : 0;
- return new Character(c);
+ char c = ( value.length() > 0 ) ? value.charAt( 0 ) : 0;
+ return new Character( c );
case AttributeDefinition.DOUBLE:
- return Double.valueOf(value);
+ return Double.valueOf( value );
case AttributeDefinition.FLOAT:
- return Float.valueOf(value);
+ return Float.valueOf( value );
case AttributeDefinition.LONG:
- return Long.valueOf(value);
+ return Long.valueOf( value );
case AttributeDefinition.INTEGER:
- return Integer.valueOf(value);
+ return Integer.valueOf( value );
case AttributeDefinition.SHORT:
- return Short.valueOf(value);
+ return Short.valueOf( value );
default:
// includes AttributeDefinition.STRING
@@ -400,16 +481,20 @@
}
}
- private Object toArray(int type, Vector values) {
+
+ private Object toArray( int type, Vector values )
+ {
int size = values.size();
// short cut for string array
- if (type == AttributeDefinition.STRING) {
- return values.toArray(new String[size]);
+ if ( type == AttributeDefinition.STRING )
+ {
+ return values.toArray( new String[size] );
}
Object array;
- switch (type) {
+ switch ( type )
+ {
case AttributeDefinition.BOOLEAN:
array = new boolean[size];
case AttributeDefinition.BYTE:
@@ -431,8 +516,9 @@
array = new String[size];
}
- for (int i = 0; i < size; i++) {
- Array.set(array, i, values.get(i));
+ for ( int i = 0; i < size; i++ )
+ {
+ Array.set( array, i, values.get( i ) );
}
return array;
Modified: felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/compendium/ComponentConfigurationPrinter.java
URL: http://svn.apache.org/viewvc/felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/compendium/ComponentConfigurationPrinter.java?rev=657742&r1=657741&r2=657742&view=diff
==============================================================================
--- felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/compendium/ComponentConfigurationPrinter.java (original)
+++ felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/compendium/ComponentConfigurationPrinter.java Mon May 19 00:36:38 2008
@@ -18,6 +18,7 @@
*/
package org.apache.felix.webconsole.internal.compendium;
+
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Collections;
@@ -36,156 +37,187 @@
import org.osgi.framework.ServiceRegistration;
import org.osgi.service.component.ComponentConstants;
-public class ComponentConfigurationPrinter extends AbstractScrPlugin implements
- ConfigurationPrinter {
+
+public class ComponentConfigurationPrinter extends AbstractScrPlugin implements ConfigurationPrinter
+{
private ServiceRegistration registration;
- public void setBundleContext(BundleContext bundleContext) {
- super.setBundleContext(bundleContext);
- registration = bundleContext.registerService(
- ConfigurationPrinter.SERVICE, this, null);
+ public void setBundleContext( BundleContext bundleContext )
+ {
+ super.setBundleContext( bundleContext );
+
+ registration = bundleContext.registerService( ConfigurationPrinter.SERVICE, this, null );
}
- public String getTitle() {
+
+ public String getTitle()
+ {
return "Declarative Services Components";
}
- public void printConfiguration(PrintWriter pw) {
+
+ public void printConfiguration( PrintWriter pw )
+ {
ScrService scrService = getScrService();
- if (scrService != null) {
+ if ( scrService != null )
+ {
Component[] components = scrService.getComponents();
- if (components == null || components.length == 0) {
+ if ( components == null || components.length == 0 )
+ {
- pw.println(" No Components Registered");
+ pw.println( " No Components Registered" );
- } else {
+ }
+ else
+ {
// order components by id
TreeMap componentMap = new TreeMap();
- for (int i=0; i < components.length; i++) {
+ for ( int i = 0; i < components.length; i++ )
+ {
Component component = components[1];
- componentMap.put(new Long(component.getId()), component);
+ componentMap.put( new Long( component.getId() ), component );
}
// render components
- for (Iterator ci = componentMap.values().iterator(); ci.hasNext();) {
- Component component = (Component) ci.next();
- component(pw, component);
+ for ( Iterator ci = componentMap.values().iterator(); ci.hasNext(); )
+ {
+ Component component = ( Component ) ci.next();
+ component( pw, component );
}
}
- } else {
- pw.println(" Apache Felix Declarative Service not installed");
+ }
+ else
+ {
+ pw.println( " Apache Felix Declarative Service not installed" );
}
}
- private void component(PrintWriter pw, Component component) {
- pw.print(component.getId());
- pw.print("=[");
- pw.print(component.getName());
- pw.println("]");
-
- pw.println(" Bundle" + component.getBundle().getSymbolicName() + " ("
- + component.getBundle().getBundleId() + ")");
- pw.println(" State="
- + ComponentRenderAction.toStateString(component.getState()));
- pw.println(" DefaultState="
- + (component.isDefaultEnabled() ? "enabled" : "disabled"));
- pw.println(" Activation="
- + (component.isImmediate() ? "immediate" : "delayed"));
-
- listServices(pw, component);
- listReferences(pw, component);
- listProperties(pw, component);
+ private void component( PrintWriter pw, Component component )
+ {
+
+ pw.print( component.getId() );
+ pw.print( "=[" );
+ pw.print( component.getName() );
+ pw.println( "]" );
+
+ pw.println( " Bundle" + component.getBundle().getSymbolicName() + " (" + component.getBundle().getBundleId()
+ + ")" );
+ pw.println( " State=" + ComponentRenderAction.toStateString( component.getState() ) );
+ pw.println( " DefaultState=" + ( component.isDefaultEnabled() ? "enabled" : "disabled" ) );
+ pw.println( " Activation=" + ( component.isImmediate() ? "immediate" : "delayed" ) );
+
+ listServices( pw, component );
+ listReferences( pw, component );
+ listProperties( pw, component );
pw.println();
}
- private void listServices(PrintWriter pw, Component component) {
+
+ private void listServices( PrintWriter pw, Component component )
+ {
String[] services = component.getServices();
- if (services == null) {
+ if ( services == null )
+ {
return;
}
- pw.println(" ServiceType="
- + (component.isServiceFactory() ? "service factory" : "service"));
+ pw.println( " ServiceType=" + ( component.isServiceFactory() ? "service factory" : "service" ) );
StringBuffer buf = new StringBuffer();
- for (int i = 0; i < services.length; i++) {
- if (i > 0) {
- buf.append(", ");
+ for ( int i = 0; i < services.length; i++ )
+ {
+ if ( i > 0 )
+ {
+ buf.append( ", " );
}
- buf.append(services[i]);
+ buf.append( services[i] );
}
- pw.println(" Services=" + buf);
+ pw.println( " Services=" + buf );
}
- private void listReferences(PrintWriter pw, Component component) {
- Reference[] refs = component.getReferences();
- if (refs != null) {
- for (int i = 0; i < refs.length; i++) {
-
- pw.println(" Reference=" + refs[i].getName() + ", "
- + (refs[i].isSatisfied() ? "Satisfied" : "Unsatisfied"));
-
- pw.println(" Service Name: " + refs[i].getServiceName());
- if (refs[i].getTarget() != null) {
- pw.println(" Target Filter: " + refs[i].getTarget());
+ private void listReferences( PrintWriter pw, Component component )
+ {
+ Reference[] refs = component.getReferences();
+ if ( refs != null )
+ {
+ for ( int i = 0; i < refs.length; i++ )
+ {
+
+ pw.println( " Reference=" + refs[i].getName() + ", "
+ + ( refs[i].isSatisfied() ? "Satisfied" : "Unsatisfied" ) );
+
+ pw.println( " Service Name: " + refs[i].getServiceName() );
+
+ if ( refs[i].getTarget() != null )
+ {
+ pw.println( " Target Filter: " + refs[i].getTarget() );
}
- pw.println(" Multiple: "
- + (refs[i].isMultiple() ? "multiple" : "single"));
- pw.println(" Optional: "
- + (refs[i].isOptional() ? "optional" : "mandatory"));
- pw.println(" Policy: "
- + (refs[i].isStatic() ? "static" : "dynamic"));
+ pw.println( " Multiple: " + ( refs[i].isMultiple() ? "multiple" : "single" ) );
+ pw.println( " Optional: " + ( refs[i].isOptional() ? "optional" : "mandatory" ) );
+ pw.println( " Policy: " + ( refs[i].isStatic() ? "static" : "dynamic" ) );
// list bound services
ServiceReference[] boundRefs = refs[i].getServiceReferences();
- if (boundRefs != null && boundRefs.length > 0) {
- for (int j = 0; j < boundRefs.length; j++) {
- pw.print(" Bound Service: ID ");
- pw.print(boundRefs[j].getProperty(Constants.SERVICE_ID));
-
- String name = (String) boundRefs[j].getProperty(ComponentConstants.COMPONENT_NAME);
- if (name == null) {
- name = (String) boundRefs[j].getProperty(Constants.SERVICE_PID);
- if (name == null) {
- name = (String) boundRefs[j].getProperty(Constants.SERVICE_DESCRIPTION);
+ if ( boundRefs != null && boundRefs.length > 0 )
+ {
+ for ( int j = 0; j < boundRefs.length; j++ )
+ {
+ pw.print( " Bound Service: ID " );
+ pw.print( boundRefs[j].getProperty( Constants.SERVICE_ID ) );
+
+ String name = ( String ) boundRefs[j].getProperty( ComponentConstants.COMPONENT_NAME );
+ if ( name == null )
+ {
+ name = ( String ) boundRefs[j].getProperty( Constants.SERVICE_PID );
+ if ( name == null )
+ {
+ name = ( String ) boundRefs[j].getProperty( Constants.SERVICE_DESCRIPTION );
}
}
- if (name != null) {
- pw.print(" (");
- pw.print(name);
- pw.print(")");
+ if ( name != null )
+ {
+ pw.print( " (" );
+ pw.print( name );
+ pw.print( ")" );
}
}
- } else {
- pw.print(" No Services bound");
+ }
+ else
+ {
+ pw.print( " No Services bound" );
}
pw.println();
}
}
}
- private void listProperties(PrintWriter pw, Component component) {
+
+ private void listProperties( PrintWriter pw, Component component )
+ {
Dictionary props = component.getProperties();
- if (props != null) {
+ if ( props != null )
+ {
- pw.println(" Properties=");
- TreeSet keys = new TreeSet(Collections.list(props.keys()));
- for (Iterator ki = keys.iterator(); ki.hasNext();) {
- String key = (String) ki.next();
- Object value = props.get(key);
- if (value.getClass().isArray()) {
- value = Arrays.asList((Object[]) value);
+ pw.println( " Properties=" );
+ TreeSet keys = new TreeSet( Collections.list( props.keys() ) );
+ for ( Iterator ki = keys.iterator(); ki.hasNext(); )
+ {
+ String key = ( String ) ki.next();
+ Object value = props.get( key );
+ if ( value.getClass().isArray() )
+ {
+ value = Arrays.asList( ( Object[] ) value );
}
- pw.println(" " + key + "=" + value);
+ pw.println( " " + key + "=" + value );
}
}
Modified: felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/compendium/ComponentRenderAction.java
URL: http://svn.apache.org/viewvc/felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/compendium/ComponentRenderAction.java?rev=657742&r1=657741&r2=657742&view=diff
==============================================================================
--- felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/compendium/ComponentRenderAction.java (original)
+++ felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/compendium/ComponentRenderAction.java Mon May 19 00:36:38 2008
@@ -16,6 +16,7 @@
*/
package org.apache.felix.webconsole.internal.compendium;
+
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Arrays;
@@ -41,8 +42,9 @@
import org.osgi.framework.ServiceReference;
import org.osgi.service.component.ComponentConstants;
-public class ComponentRenderAction extends AbstractScrPlugin implements Render,
- Action {
+
+public class ComponentRenderAction extends AbstractScrPlugin implements Render, Action
+{
public static final String NAME = "components";
@@ -58,30 +60,42 @@
public static final String OPERATION_DISABLE = "disable";
- public String getName() {
+
+ public String getName()
+ {
return NAME;
}
- public String getLabel() {
+
+ public String getLabel()
+ {
return LABEL;
}
- public boolean performAction(HttpServletRequest request,
- HttpServletResponse response) throws IOException {
+
+ public boolean performAction( HttpServletRequest request, HttpServletResponse response ) throws IOException
+ {
ScrService scrService = getScrService();
- if (scrService != null) {
+ if ( scrService != null )
+ {
- long componentId = getComponentId(request);
- Component component = scrService.getComponent(componentId);
+ long componentId = getComponentId( request );
+ Component component = scrService.getComponent( componentId );
- if (component != null) {
- String op = request.getParameter(OPERATION);
- if (OPERATION_DETAILS.equals(op)) {
- return sendAjaxDetails(component, response);
- } else if (OPERATION_ENABLE.equals(op)) {
+ if ( component != null )
+ {
+ String op = request.getParameter( OPERATION );
+ if ( OPERATION_DETAILS.equals( op ) )
+ {
+ return sendAjaxDetails( component, response );
+ }
+ else if ( OPERATION_ENABLE.equals( op ) )
+ {
component.enable();
- } else if (OPERATION_DISABLE.equals(op)) {
+ }
+ else if ( OPERATION_DISABLE.equals( op ) )
+ {
component.disable();
}
}
@@ -91,306 +105,339 @@
return true;
}
- public void render(HttpServletRequest request, HttpServletResponse response)
- throws IOException {
+
+ public void render( HttpServletRequest request, HttpServletResponse response ) throws IOException
+ {
PrintWriter pw = response.getWriter();
- this.header(pw);
+ this.header( pw );
- pw.println("<tr class='content'>");
- pw.println("<td colspan='5' class='content'> </th>");
- pw.println("</tr>");
+ pw.println( "<tr class='content'>" );
+ pw.println( "<td colspan='5' class='content'> </th>" );
+ pw.println( "</tr>" );
- this.tableHeader(pw);
+ this.tableHeader( pw );
ScrService scrService = getScrService();
- if (scrService == null) {
- pw.println("<tr class='content'>");
- pw.println("<td class='content' colspan='5'>Apache Felix Declarative Service required for this function</td>");
- pw.println("</tr>");
- } else {
+ if ( scrService == null )
+ {
+ pw.println( "<tr class='content'>" );
+ pw
+ .println( "<td class='content' colspan='5'>Apache Felix Declarative Service required for this function</td>" );
+ pw.println( "</tr>" );
+ }
+ else
+ {
Component[] components = scrService.getComponents();
- if (components == null || components.length == 0) {
- pw.println("<tr class='content'>");
- pw.println("<td class='content' colspan='5'>No "
- + this.getLabel() + " installed currently</td>");
- pw.println("</tr>");
+ if ( components == null || components.length == 0 )
+ {
+ pw.println( "<tr class='content'>" );
+ pw.println( "<td class='content' colspan='5'>No " + this.getLabel() + " installed currently</td>" );
+ pw.println( "</tr>" );
- } else {
+ }
+ else
+ {
// order components by id
TreeMap componentMap = new TreeMap();
- for (int i=0; i < components.length; i++) {
+ for ( int i = 0; i < components.length; i++ )
+ {
Component component = components[i];
- componentMap.put(component.getName(), component);
+ componentMap.put( component.getName(), component );
}
// render components
long previousComponent = -1;
- for (Iterator ci = componentMap.values().iterator(); ci.hasNext();) {
- Component component = (Component) ci.next();
- if (previousComponent >= 0) {
+ for ( Iterator ci = componentMap.values().iterator(); ci.hasNext(); )
+ {
+ Component component = ( Component ) ci.next();
+ if ( previousComponent >= 0 )
+ {
// prepare for injected table information row
- pw.println("<tr id='component" + previousComponent
- + "'></tr>");
+ pw.println( "<tr id='component" + previousComponent + "'></tr>" );
}
- component(pw, component);
+ component( pw, component );
previousComponent = component.getId();
}
- if (previousComponent >= 0) {
+ if ( previousComponent >= 0 )
+ {
// prepare for injected table information row
- pw.println("<tr id='component" + previousComponent
- + "'></tr>");
+ pw.println( "<tr id='component" + previousComponent + "'></tr>" );
}
}
}
- pw.println("<tr class='content'>");
- pw.println("<td colspan='5' class='content'> </th>");
- pw.println("</tr>");
-
- this.footer(pw);
- }
-
- private void header(PrintWriter pw) {
- Util.startScript(pw);
- pw.println("function showDetails(componentId) {");
- pw.println(" var span = document.getElementById('component' + componentId);");
- pw.println(" if (!span) {");
- pw.println(" return;");
- pw.println(" }");
- pw.println(" if (span.innerHTML) {");
- pw.println(" span.innerHTML = '';");
- pw.println(" return;");
- pw.println(" }");
- pw.println(" var parm = '?" + Util.PARAM_ACTION + "=" + NAME + "&"
- + OPERATION + "=" + OPERATION_DETAILS + "&" + COMPONENT_ID
- + "=' + componentId;");
- pw.println(" sendRequest('GET', parm, displayComponentDetails);");
- pw.println("}");
- pw.println("function displayComponentDetails(obj) {");
- pw.println(" var span = document.getElementById('component' + obj."
- + COMPONENT_ID + ");");
- pw.println(" if (!span) {");
- pw.println(" return;");
- pw.println(" }");
- pw.println(" var innerHtml = '<td class=\"content\"> </td><td class=\"content\" colspan=\"4\"><table broder=\"0\">';");
- pw.println(" var props = obj.props;");
- pw.println(" for (var i=0; i < props.length; i++) {");
- pw.println(" innerHtml += '<tr><td valign=\"top\" noWrap>' + props[i].key + '</td><td valign=\"top\">' + props[i].value + '</td></tr>';");
- pw.println(" }");
- pw.println(" innerHtml += '</table></td>';");
- pw.println(" span.innerHTML = innerHtml;");
- pw.println("}");
- Util.endScript(pw);
-
- pw.println("<table class='content' cellpadding='0' cellspacing='0' width='100%'>");
- }
-
- private void tableHeader(PrintWriter pw) {
-
- pw.println("<tr class='content'>");
- pw.println("<th class='content'>ID</th>");
- pw.println("<th class='content' width='100%'>Name</th>");
- pw.println("<th class='content'>Status</th>");
- pw.println("<th class='content' colspan='2'>Actions</th>");
- pw.println("</tr>");
+ pw.println( "<tr class='content'>" );
+ pw.println( "<td colspan='5' class='content'> </th>" );
+ pw.println( "</tr>" );
+
+ this.footer( pw );
+ }
+
+
+ private void header( PrintWriter pw )
+ {
+ Util.startScript( pw );
+ pw.println( "function showDetails(componentId) {" );
+ pw.println( " var span = document.getElementById('component' + componentId);" );
+ pw.println( " if (!span) {" );
+ pw.println( " return;" );
+ pw.println( " }" );
+ pw.println( " if (span.innerHTML) {" );
+ pw.println( " span.innerHTML = '';" );
+ pw.println( " return;" );
+ pw.println( " }" );
+ pw.println( " var parm = '?" + Util.PARAM_ACTION + "=" + NAME + "&" + OPERATION + "=" + OPERATION_DETAILS
+ + "&" + COMPONENT_ID + "=' + componentId;" );
+ pw.println( " sendRequest('GET', parm, displayComponentDetails);" );
+ pw.println( "}" );
+ pw.println( "function displayComponentDetails(obj) {" );
+ pw.println( " var span = document.getElementById('component' + obj." + COMPONENT_ID + ");" );
+ pw.println( " if (!span) {" );
+ pw.println( " return;" );
+ pw.println( " }" );
+ pw
+ .println( " var innerHtml = '<td class=\"content\"> </td><td class=\"content\" colspan=\"4\"><table broder=\"0\">';" );
+ pw.println( " var props = obj.props;" );
+ pw.println( " for (var i=0; i < props.length; i++) {" );
+ pw
+ .println( " innerHtml += '<tr><td valign=\"top\" noWrap>' + props[i].key + '</td><td valign=\"top\">' + props[i].value + '</td></tr>';" );
+ pw.println( " }" );
+ pw.println( " innerHtml += '</table></td>';" );
+ pw.println( " span.innerHTML = innerHtml;" );
+ pw.println( "}" );
+ Util.endScript( pw );
+
+ pw.println( "<table class='content' cellpadding='0' cellspacing='0' width='100%'>" );
+ }
+
+
+ private void tableHeader( PrintWriter pw )
+ {
+
+ pw.println( "<tr class='content'>" );
+ pw.println( "<th class='content'>ID</th>" );
+ pw.println( "<th class='content' width='100%'>Name</th>" );
+ pw.println( "<th class='content'>Status</th>" );
+ pw.println( "<th class='content' colspan='2'>Actions</th>" );
+ pw.println( "</tr>" );
+ }
+
+
+ private void footer( PrintWriter pw )
+ {
+ pw.println( "</table>" );
}
- private void footer(PrintWriter pw) {
- pw.println("</table>");
- }
- private void component(PrintWriter pw, Component component) {
+ private void component( PrintWriter pw, Component component )
+ {
String name = component.getName();
- pw.println("<tr>");
- pw.println("<td class='content right'>" + component.getId() + "</td>");
- pw.println("<td class='content'><a href='javascript:showDetails("
- + component.getId() + ")'>" + name + "</a></td>");
- pw.println("<td class='content center'>"
- + toStateString(component.getState()) + "</td>");
+ pw.println( "<tr>" );
+ pw.println( "<td class='content right'>" + component.getId() + "</td>" );
+ pw.println( "<td class='content'><a href='javascript:showDetails(" + component.getId() + ")'>" + name
+ + "</a></td>" );
+ pw.println( "<td class='content center'>" + toStateString( component.getState() ) + "</td>" );
boolean enabled = component.getState() == Component.STATE_DISABLED;
- this.actionForm(pw, enabled, component.getId(), OPERATION_ENABLE,
- "Enable");
+ this.actionForm( pw, enabled, component.getId(), OPERATION_ENABLE, "Enable" );
+
+ enabled = component.getState() != Component.STATE_DISABLED && component.getState() != Component.STATE_DESTROYED;
+ this.actionForm( pw, enabled, component.getId(), OPERATION_DISABLE, "Disable" );
+
+ pw.println( "</tr>" );
+ }
- enabled = component.getState() != Component.STATE_DISABLED
- && component.getState() != Component.STATE_DESTROYED;
- this.actionForm(pw, enabled, component.getId(), OPERATION_DISABLE,
- "Disable");
-
- pw.println("</tr>");
- }
-
- private void actionForm(PrintWriter pw, boolean enabled, long componentId,
- String op, String opLabel) {
- pw.println("<form name='form" + componentId + "' method='post'>");
- pw.println("<td class='content' align='right'>");
- pw.println("<input type='hidden' name='" + Util.PARAM_ACTION
- + "' value='" + NAME + "' />");
- pw.println("<input type='hidden' name='" + OPERATION + "' value='" + op
- + "' />");
- pw.println("<input type='hidden' name='" + COMPONENT_ID + "' value='"
- + componentId + "' />");
- pw.println("<input class='submit' type='submit' value='" + opLabel
- + "'" + (enabled ? "" : "disabled") + " />");
- pw.println("</td>");
- pw.println("</form>");
+
+ private void actionForm( PrintWriter pw, boolean enabled, long componentId, String op, String opLabel )
+ {
+ pw.println( "<form name='form" + componentId + "' method='post'>" );
+ pw.println( "<td class='content' align='right'>" );
+ pw.println( "<input type='hidden' name='" + Util.PARAM_ACTION + "' value='" + NAME + "' />" );
+ pw.println( "<input type='hidden' name='" + OPERATION + "' value='" + op + "' />" );
+ pw.println( "<input type='hidden' name='" + COMPONENT_ID + "' value='" + componentId + "' />" );
+ pw.println( "<input class='submit' type='submit' value='" + opLabel + "'" + ( enabled ? "" : "disabled" )
+ + " />" );
+ pw.println( "</td>" );
+ pw.println( "</form>" );
}
- private boolean sendAjaxDetails(Component component,
- HttpServletResponse response) throws IOException {
+
+ private boolean sendAjaxDetails( Component component, HttpServletResponse response ) throws IOException
+ {
JSONObject result = null;
- try {
- if (component != null) {
+ try
+ {
+ if ( component != null )
+ {
JSONArray props = new JSONArray();
- keyVal(props, "Bundle", component.getBundle().getSymbolicName()
- + " (" + component.getBundle().getBundleId() + ")");
- keyVal(props, "Default State", component.isDefaultEnabled()
- ? "enabled"
- : "disabled");
- keyVal(props, "Activation", component.isImmediate()
- ? "immediate"
- : "delayed");
-
- listServices(props, component);
- listReferences(props, component);
- listProperties(props, component);
+ keyVal( props, "Bundle", component.getBundle().getSymbolicName() + " ("
+ + component.getBundle().getBundleId() + ")" );
+ keyVal( props, "Default State", component.isDefaultEnabled() ? "enabled" : "disabled" );
+ keyVal( props, "Activation", component.isImmediate() ? "immediate" : "delayed" );
+
+ listServices( props, component );
+ listReferences( props, component );
+ listProperties( props, component );
result = new JSONObject();
- result.put(ComponentRenderAction.COMPONENT_ID,
- component.getId());
- result.put("props", props);
+ result.put( ComponentRenderAction.COMPONENT_ID, component.getId() );
+ result.put( "props", props );
}
- } catch (Exception exception) {
+ }
+ catch ( Exception exception )
+ {
// create an empty result on problems
result = new JSONObject();
}
// send the result
- response.setContentType("text/javascript");
- response.getWriter().print(result.toString());
+ response.setContentType( "text/javascript" );
+ response.getWriter().print( result.toString() );
return false;
}
- private void listServices(JSONArray props, Component component) {
+
+ private void listServices( JSONArray props, Component component )
+ {
String[] services = component.getServices();
- if (services == null) {
+ if ( services == null )
+ {
return;
}
- keyVal(props, "Service Type", component.isServiceFactory()
- ? "service factory"
- : "service");
+ keyVal( props, "Service Type", component.isServiceFactory() ? "service factory" : "service" );
StringBuffer buf = new StringBuffer();
- for (int i = 0; i < services.length; i++) {
- if (i > 0) {
- buf.append("<br />");
+ for ( int i = 0; i < services.length; i++ )
+ {
+ if ( i > 0 )
+ {
+ buf.append( "<br />" );
}
- buf.append(services[i]);
+ buf.append( services[i] );
}
- keyVal(props, "Services", buf.toString());
+ keyVal( props, "Services", buf.toString() );
}
- private void listReferences(JSONArray props, Component component) {
+
+ private void listReferences( JSONArray props, Component component )
+ {
Reference[] refs = component.getReferences();
- if (refs != null) {
- for (int i = 0; i < refs.length; i++) {
+ if ( refs != null )
+ {
+ for ( int i = 0; i < refs.length; i++ )
+ {
StringBuffer buf = new StringBuffer();
- buf.append(refs[i].isSatisfied() ? "Satisfied" : "Unsatisfied").append(
- "<br />");
- buf.append("Service Name: ").append(refs[i].getServiceName()).append(
- "<br />");
- if (refs[i].getTarget() != null) {
- buf.append("Target Filter: ").append(refs[i].getTarget()).append(
- "<br />");
- }
- buf.append("Multiple: ").append(
- refs[i].isMultiple() ? "multiple" : "single").append(
- "<br />");
- buf.append("Optional: ").append(
- refs[i].isOptional() ? "optional" : "mandatory").append(
- "<br />");
- buf.append("Policy: ").append(
- refs[i].isStatic() ? "static" : "dynamic").append("<br />");
+ buf.append( refs[i].isSatisfied() ? "Satisfied" : "Unsatisfied" ).append( "<br />" );
+ buf.append( "Service Name: " ).append( refs[i].getServiceName() ).append( "<br />" );
+ if ( refs[i].getTarget() != null )
+ {
+ buf.append( "Target Filter: " ).append( refs[i].getTarget() ).append( "<br />" );
+ }
+ buf.append( "Multiple: " ).append( refs[i].isMultiple() ? "multiple" : "single" ).append( "<br />" );
+ buf.append( "Optional: " ).append( refs[i].isOptional() ? "optional" : "mandatory" ).append( "<br />" );
+ buf.append( "Policy: " ).append( refs[i].isStatic() ? "static" : "dynamic" ).append( "<br />" );
// list bound services
ServiceReference[] boundRefs = refs[i].getServiceReferences();
- if (boundRefs != null && boundRefs.length > 0) {
- for (int j = 0; j < boundRefs.length; j++) {
- buf.append("Bound Service ID ");
- buf.append(boundRefs[j].getProperty(Constants.SERVICE_ID));
-
- String name = (String) boundRefs[j].getProperty(ComponentConstants.COMPONENT_NAME);
- if (name == null) {
- name = (String) boundRefs[j].getProperty(Constants.SERVICE_PID);
- if (name == null) {
- name = (String) boundRefs[j].getProperty(Constants.SERVICE_DESCRIPTION);
+ if ( boundRefs != null && boundRefs.length > 0 )
+ {
+ for ( int j = 0; j < boundRefs.length; j++ )
+ {
+ buf.append( "Bound Service ID " );
+ buf.append( boundRefs[j].getProperty( Constants.SERVICE_ID ) );
+
+ String name = ( String ) boundRefs[j].getProperty( ComponentConstants.COMPONENT_NAME );
+ if ( name == null )
+ {
+ name = ( String ) boundRefs[j].getProperty( Constants.SERVICE_PID );
+ if ( name == null )
+ {
+ name = ( String ) boundRefs[j].getProperty( Constants.SERVICE_DESCRIPTION );
}
}
- if (name != null) {
- buf.append(" (");
- buf.append(name);
- buf.append(")");
+ if ( name != null )
+ {
+ buf.append( " (" );
+ buf.append( name );
+ buf.append( ")" );
}
}
- } else {
- buf.append("No Services bound");
}
- buf.append("<br />");
+ else
+ {
+ buf.append( "No Services bound" );
+ }
+ buf.append( "<br />" );
- keyVal(props, "Reference " + refs[i].getName(), buf.toString());
+ keyVal( props, "Reference " + refs[i].getName(), buf.toString() );
}
}
}
- private void listProperties(JSONArray jsonProps, Component component) {
+
+ private void listProperties( JSONArray jsonProps, Component component )
+ {
Dictionary props = component.getProperties();
- if (props != null) {
+ if ( props != null )
+ {
StringBuffer buf = new StringBuffer();
- TreeSet keys = new TreeSet(Collections.list(props.keys()));
- for (Iterator ki = keys.iterator(); ki.hasNext();) {
- String key = (String) ki.next();
- buf.append(key).append(" = ");
-
- Object prop = props.get(key);
- if (prop.getClass().isArray()) {
- prop = Arrays.asList((Object[]) prop);
+ TreeSet keys = new TreeSet( Collections.list( props.keys() ) );
+ for ( Iterator ki = keys.iterator(); ki.hasNext(); )
+ {
+ String key = ( String ) ki.next();
+ buf.append( key ).append( " = " );
+
+ Object prop = props.get( key );
+ if ( prop.getClass().isArray() )
+ {
+ prop = Arrays.asList( ( Object[] ) prop );
}
- buf.append(prop);
- if (ki.hasNext()) {
- buf.append("<br />");
+ buf.append( prop );
+ if ( ki.hasNext() )
+ {
+ buf.append( "<br />" );
}
}
- keyVal(jsonProps, "Properties", buf.toString());
+ keyVal( jsonProps, "Properties", buf.toString() );
}
}
- private void keyVal(JSONArray props, String key, Object value) {
- if (key != null && value != null) {
- try {
+
+ private void keyVal( JSONArray props, String key, Object value )
+ {
+ if ( key != null && value != null )
+ {
+ try
+ {
JSONObject obj = new JSONObject();
- obj.put("key", key);
- obj.put("value", value);
- props.put(obj);
- } catch (JSONException je) {
+ obj.put( "key", key );
+ obj.put( "value", value );
+ props.put( obj );
+ }
+ catch ( JSONException je )
+ {
// don't care
}
}
}
- static String toStateString(int state) {
- switch (state) {
+
+ static String toStateString( int state )
+ {
+ switch ( state )
+ {
case Component.STATE_DISABLED:
return "disabled";
case Component.STATE_ENABLED:
@@ -410,16 +457,22 @@
case Component.STATE_DESTROYED:
return "destroyed";
default:
- return String.valueOf(state);
+ return String.valueOf( state );
}
}
- protected long getComponentId(HttpServletRequest request) {
- String componentIdPar = request.getParameter(ComponentRenderAction.COMPONENT_ID);
- if (componentIdPar != null) {
- try {
- return Long.parseLong(componentIdPar);
- } catch (NumberFormatException nfe) {
+
+ protected long getComponentId( HttpServletRequest request )
+ {
+ String componentIdPar = request.getParameter( ComponentRenderAction.COMPONENT_ID );
+ if ( componentIdPar != null )
+ {
+ try
+ {
+ return Long.parseLong( componentIdPar );
+ }
+ catch ( NumberFormatException nfe )
+ {
// TODO: log
}
}