Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Licensed to the Apache Software Foundation (ASF) under one
   * or more contributor license agreements.  See the NOTICE file
   * distributed with this work for additional information
   * regarding copyright ownership.  The ASF licenses this file
   * to you under the Apache License, Version 2.0 (the
   * "License"); you may not use this file except in compliance
   * with the License.  You may obtain a copy of the License at
   *
  *   http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing,
  * software distributed under the License is distributed on an
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  * KIND, either express or implied.  See the License for the
  * specific language governing permissions and limitations
  * under the License.
  */
 package org.apache.felix.webconsole;
 
 
 import java.net.URL;
 import java.util.Map;
 
SimpleWebConsolePlugin is an utility class that provides default implementation of the AbstractWebConsolePlugin and supports the following features:
  • Methods for (un)registering the web console plugin service
  • Default implementation for resource loading
 
 public abstract class SimpleWebConsolePlugin extends AbstractWebConsolePlugin
 {
 
     // Serializable UID
     private static final long serialVersionUID = 1500463493078823878L;
 
     // used for standard AbstractWebConsolePlugin implementation
     private final String label;
     private final String title;
     private final String category;
     private final String css[];
     private final String labelRes;
     private final int labelResLen;
 
     // used for service registration
     private final Object regLock = new Object();
     private ServiceRegistration reg;
 
     // used to obtain services. Structure is: service name -> ServiceTracker
     private final Map services = new HashMap();


    
Creates new Simple Web Console Plugin with the default category (null)

Parameters:
label the front label. See AbstractWebConsolePlugin.getLabel()
title the plugin title . See AbstractWebConsolePlugin.getTitle()
css the additional plugin CSS. See AbstractWebConsolePlugin.getCssReferences()
 
     public SimpleWebConsolePluginString labelString titleString css[] )
     {
         thislabeltitlenullcss );
     }


    
Creates new Simple Web Console Plugin with the given category.

Parameters:
label the front label. See AbstractWebConsolePlugin.getLabel()
title the plugin title . See AbstractWebConsolePlugin.getTitle()
category the plugin's navigation category. See AbstractWebConsolePlugin.getCategory()
css the additional plugin CSS. See AbstractWebConsolePlugin.getCssReferences()
 
     public SimpleWebConsolePluginString labelString titleString categoryString css[] )
     {
         if ( label == null )
         {
             throw new NullPointerException"Null label" );
         }
         if ( title == null )
        {
            throw new NullPointerException"Null title" );
        }
        this. = label;
        this. = title;
        this. = category;
        this. = css;
        this. = '/' + label + '/';
        this. = .length() - 1;
    }


    
    public final String getLabel()
    {
        return ;
    }


    
    public final String getTitle()
    {
        return ;
    }


    
    public String getCategory()
    {
        return ;
    }


    
    protected final String[] getCssReferences()
    {
        return ;
    }


    
Called internally by AbstractWebConsolePlugin to load resources. This particular implementation depends on the label. As example, if the plugin is accessed as /system/console/abc, and the plugin resources are accessed like /system/console/abc/res/logo.gif, the code here will try load resource /res/logo.gif from the bundle, providing the plugin.

Parameters:
path the path to read.
Returns:
the URL of the resource or null if not found.
    protected URL getResourceString path )
    {
        return ( path != null && path.startsWith ) ) ? //
        getClass().getResourcepath.substring ) )
            : null;
    }
    // -- begin methods for plugin registration/unregistration
    
This is an utility method. It is used to register the plugin service. Don't forget to call the unregister() when the plugin is no longer needed.

Parameters:
bc the bundle context used for service registration.
Returns:
self
    public final SimpleWebConsolePlugin registerBundleContext bc )
    {
        synchronized (  )
        {
            activatebc ); // don't know why this is needed!
            Hashtable props = new Hashtable();
            props.put.getLabel() );
            props.put.getTitle() );
            if ( getCategory() != null )
            {
                props.put.getCategory() );
            }
             = bc.registerService"javax.servlet.Servlet"thisprops ); //$NON-NLS-1$
        }
        return this;
    }


    
An utility method that removes the service, registered by the register(org.osgi.framework.BundleContext) method.
    public final void unregister()
    {
        synchronized (  )
        {
            deactivate(); // is this needed?
            if (  != null )
                .unregister();
             = null;
        }
    }
    // -- end methods for plugin registration/unregistration
    // -- begin methods for obtaining services

    
Gets the service with the specified class name. Will create a new org.osgi.util.tracker.ServiceTracker if the service is not already got.

Parameters:
serviceName the service name to obtain
Returns:
the service or null if missing.
    public final Object getServiceString serviceName )
    {
        ServiceTracker serviceTracker = ( ServiceTracker ) .getserviceName );
        if ( serviceTracker == null )
        {
            serviceTracker = new ServiceTrackergetBundleContext(), serviceNamenull );
            serviceTracker.open();
            .putserviceNameserviceTracker );
        }
        return serviceTracker.getService();
    }


    
This method will close all service trackers, created by getService(java.lang.String) method. If you override this method, don't forget to call the super.

    public void deactivate()
    {
        for ( Iterator ti = .values().iterator(); ti.hasNext(); )
        {
            ServiceTracker tracker = ( ServiceTracker ) ti.next();
            tracker.close();
            ti.remove();
        }
        super.deactivate();
    }
New to GrepCode? Check out our FAQ X