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.internal.compendium;
 
 
 
 import  org.apache.felix.scr.Component;
 import  org.apache.felix.scr.Reference;
 import  org.apache.felix.scr.ScrService;
 import  org.osgi.framework.Constants;
 import  org.osgi.framework.ServiceReference;
 import  org.osgi.service.component.ComponentConstants;
 
 
 {
 
     public String getTitle()
     {
         return "Declarative Services Components";
     }
 
 
     public void printConfigurationPrintWriter pw )
     {
         ServiceReference sr = getBundleContext().getServiceReference( "org.apache.felix.scr.ScrService" );
         if ( sr == null )
         {
             pw.println"  Apache Felix Declarative Service not installed" );
         }
         else
         {
             ScrService scrService = ( ScrService ) getBundleContext().getService( sr );
             try
             {
                 printComponentspwscrService.getComponents() );
             }
             finally
             {
                 getBundleContext().ungetService( sr );
             }
         }
     }
 
 
     public void printComponentsfinal PrintWriter pwfinal Component[] components )
     {
         if ( components == null || components.length == 0 )
         {
             pw.println"  No Components Registered" );
         }
         else
         {
             // order components by id
             TreeMap componentMap = new TreeMap();
             for ( int i = 0; i < components.length; i++ )
             {
                 Component component = components[i];
                 componentMap.putnew Longcomponent.getId() ), component );
             }
 
             // render components
             for ( Iterator ci = componentMap.values().iterator(); ci.hasNext(); )
             {
                 Component component = ( Component ) ci.next();
                 componentpwcomponent );
             }
         }
     }
 
 
     private void componentPrintWriter pw, Component component )
     {
 
         pw.printcomponent.getId() );
        pw.print"=[" );
        pw.printcomponent.getName() );
        pw.println"]" );
        pw.println"  Bundle" + component.getBundle().getSymbolicName() + " (" + component.getBundle().getBundleId()
            + ")" );
        pw.println"  State=" + ComponentsServlet.toStateStringcomponent.getState() ) );
        pw.println"  DefaultState=" + ( component.isDefaultEnabled() ? "enabled" : "disabled" ) );
        pw.println"  Activation=" + ( component.isImmediate() ? "immediate" : "delayed" ) );
        listServicespwcomponent );
        listReferencespwcomponent );
        listPropertiespwcomponent );
        pw.println();
    }
    private void listServicesPrintWriter pw, Component component )
    {
        String[] services = component.getServices();
        if ( services == null )
        {
            return;
        }
        pw.println"  ServiceType=" + ( component.isServiceFactory() ? "service factory" : "service" ) );
        StringBuffer buf = new StringBuffer();
        for ( int i = 0; i < services.lengthi++ )
        {
            if ( i > 0 )
            {
                buf.append", " );
            }
            buf.appendservices[i] );
        }
        pw.println"  Services=" + buf );
    }
    private void listReferencesPrintWriter 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" ) );
                // 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.printboundRefs[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.printname );
                            pw.print")" );
                        }
                        pw.println();
                    }
                }
                else
                {
                    pw.println"    No Services bound" );
                }
            }
        }
    }
    private void listPropertiesPrintWriter pw, Component component )
    {
        Dictionary props = component.getProperties();
        if ( props != null )
        {
            pw.println"  Properties=" );
            TreeSet keys = new TreeSet( Collections.listprops.keys() ) );
            for ( Iterator ki = keys.iterator(); ki.hasNext(); )
            {
                String key = ( String ) ki.next();
                Object value = props.getkey );
                if ( value.getClass().isArray() )
                {
                    value = Arrays.asList( ( Object[] ) value );
                }
                pw.println"    " + key + "=" + value );
            }
        }
    }
New to GrepCode? Check out our FAQ X