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.core;
  
  
  import java.io.File;
  import java.io.Writer;
  import java.util.Arrays;
  import java.util.Date;
  import java.util.HashMap;
  import java.util.List;
  import java.util.Locale;
  import java.util.Map;
  import java.util.TreeMap;
  
  
The BundlesServlet provides the bundles plugins, used to display the list of bundles, installed on the framework. It also adds ability to control the lifecycle of the bundles, like start, stop, uninstall, install.
  
  {

    
the label of the bundles plugin - used by other plugins to reference to plugin details
  
      public static final String NAME = "bundles";
      private static final String TITLE = "%bundles.pluginTitle";
      private static final String CSS[] = { "/res/ui/bundles.css" };
  
      // an LDAP filter, that is used to search manifest headers, see FELIX-1441
      private static final String FILTER_PARAM = "filter";
  
      private static final String FIELD_STARTLEVEL = "bundlestartlevel";
 
     private static final String FIELD_START = "bundlestart";
 
     private static final String FIELD_BUNDLEFILE = "bundlefile";
 
     // set to ask for PackageAdmin.refreshPackages() after install/update
     private static final String FIELD_REFRESH_PACKAGES = "refreshPackages";
 
     // bootdelegation property entries. wildcards are converted to package
     // name prefixes. whether an entry is a wildcard or not is set as a flag
     // in the bootPkgWildcards array.
     // see #activate and #isBootDelegated
     private String[] bootPkgs;
 
     // a flag for each entry in bootPkgs indicating whether the respective
     // entry was declared as a wildcard or not
     // see #activate and #isBootDelegated
     private boolean[] bootPkgWildcards;
 
 
     // templates
     private final String TEMPLATE_MAIN;

    
Default constructor
 
     public BundlesServlet()
     {
         super();
 
         // load templates
          = readTemplateFile"/templates/bundles.html" );
     }

    
 
     public void activateBundleContext bundleContext )
     {
         super.activatebundleContext );
 
          = new ServiceTrackerbundleContextBundleInfoProvider.class.getName(), null);
         .open();
 
         // bootdelegation property parsing from Apache Felix R4SearchPolicyCore
         String bootDelegation = bundleContext.getProperty. );
         bootDelegation = ( bootDelegation == null ) ? "java.*" : bootDelegation + ",java.*";
         StringTokenizer st = new StringTokenizerbootDelegation" ," );
          = new String[st.countTokens()];
          = new boolean[.];
         for ( int i = 0; i < .i++ )
         {
             bootDelegation = st.nextToken();
             if ( bootDelegation.endsWith"*" ) )
             {
                 [i] = true;
                 bootDelegation = bootDelegation.substring( 0, bootDelegation.length() - 1 );
             }
             [i] = bootDelegation;
         }
 
         Hashtable props = new Hashtable();
             . } );
          = bundleContext.registerService.thisprops );
     }


    
 
     public void deactivate()
     {
         if (  != null )
         {
             .unregister();
              = null;
         }
 
         if (  != null)
         {
             .close();
              = null;
         }
 
         super.deactivate();
     }
 
 
     //---------- ConfigurationPrinter
 
    
 
     public void printConfigurationPrintWriter pw )
     {
         try
         {
             StringWriter w = new StringWriter();
             writeJSONwnullnullnulltrue.nullnull );
             String jsonString = w.toString();
             JSONObject json = new JSONObjectjsonString );
 
             pw.println"Status: " + json.get"status" ) );
             pw.println();
 
             JSONArray data = json.getJSONArray"data" );
             for ( int i = 0; i < data.length(); i++ )
             {
                 if ( !data.isNulli ) )
                 {
                     JSONObject bundle = data.getJSONObjecti );
 
                     pw.println( MessageFormat.format"Bundle {0} - {1} {2} (state: {3})"new Object[]
                         { bundle.get"id" ), bundle.get"name" ), bundle.get"version" ), bundle.get"state" ) } ) );
 
                     JSONArray props = bundle.getJSONArray"props" );
                     for ( int pi = 0; pi < props.length(); pi++ )
                     {
                         if ( !props.isNullpi ) )
                         {
                             JSONObject entry = props.getJSONObjectpi );
                             String key = ( String ) entry.get"key" );
                             if ( "nfo".equalskey ) )
                             {
                                 // BundleInfo (see #bundleInfo & #bundleInfoDetails
                                 JSONObject infos = ( JSONObject ) entry.get"value" );
                                 Iterator infoKeys = infos.keys();
                                 while ( infoKeys.hasNext() )
                                 {
                                     String infoKey = ( String ) infoKeys.next();
                                     pw.println"    " + infoKey + ": " );
 
                                     JSONArray infoA = infos.getJSONArrayinfoKey );
                                     for ( int iai = 0; iai < infoA.length(); iai++ )
                                     {
                                         if ( !infoA.isNulliai ) )
                                         {
                                             JSONObject info = infoA.getJSONObjectiai );
                                             pw.println"        " + info.get"name" ) );
                                         }
                                     }
                                 }
                             }
                             else
                             {
                                 // regular data
                                 pw.print"    " + key + ": " );
 
                                 Object entryValue = entry.get"value" );
                                 if ( entryValue instanceof JSONArray )
                                 {
                                     pw.println();
                                     JSONArray entryArray = ( JSONArray ) entryValue;
                                     for ( int ei = 0; ei < entryArray.length(); ei++ )
                                     {
                                         if ( !entryArray.isNullei ) )
                                         {
                                             pw.println"        " + entryArray.getei ) );
                                         }
                                     }
                                 }
                                 else
                                 {
                                     pw.printlnentryValue );
                                 }
                             }
                         }
                     }
 
                     pw.println();
                 }
             }
         }
         catch ( Exception e )
         {
             log"Problem rendering Bundle details for configuration status"e );
         }
     }
 
 
     //---------- BaseWebConsolePlugin
 
    
 
     protected void doGetHttpServletRequest requestHttpServletResponse response ) throws ServletException,
         IOException
     {
         final RequestInfo reqInfo = new RequestInfo(request);
         if ( "upload".equals(reqInfo.pathInfo) )
         {
             super.doGet(requestresponse);
             return;
         }
         if ( reqInfo.bundle == null && reqInfo.bundleRequested )
         {
             response.sendError(404);
             return;
         }
         if ( reqInfo.extension.equals("json")  )
         {
             final String pluginRoot = ( String ) request.getAttribute. );
             final String servicesRoot = getServicesRootrequest );
             try
             {
                 this.renderJSON(responsereqInfo.bundlepluginRootservicesRootrequest.getLocale(), request.getParameter(), null );
             }
             catch (InvalidSyntaxException e)
             {
                 response.sendError(."Invalid LDAP filter specified");
             }
 
             // nothing more to do
             return;
         }
 
         super.doGetrequestresponse );
     }

    
 
     protected void doPostHttpServletRequest reqHttpServletResponse resp ) throws ServletExceptionIOException
     {
         boolean success = false;
         BundleException bundleException = null;
         final String action = WebConsoleUtil.getParameterreq"action" );
         if ( "refreshPackages".equalsaction ) )
         {
             // refresh packages and give it most 15 seconds to finish
             BaseUpdateInstallHelper.refreshPackagesgetPackageAdmin(), getBundleContext(), 15000L, null );
             success = true;
         }
         else if ( "install".equalsaction ) )
         {
             installBundlesreq );
 
             if (req.getRequestURI().endsWith"/install" )) {
                 // just send 200/OK, no content
                 resp.setContentLength( 0 );
             } else {
                 // redirect to URL
                 resp.sendRedirectreq.getRequestURI() );
             }
 
             return;
         }
         else
         {
             final RequestInfo reqInfo = new RequestInforeq );
             if ( reqInfo.bundle == null && reqInfo.bundleRequested )
             {
                 resp.sendError( 404 );
                 return;
             }
 
             final Bundle bundle = reqInfo.bundle;
             if ( bundle != null )
             {
                 if ( "start".equalsaction ) )
                 {
                     // start bundle
                     try
                     {
                         bundle.start();
                     }
                     catch ( BundleException be )
                     {
                         bundleException = be;
                         log"Cannot start"be );
                     }
                 }
                 else if ( "stop".equalsaction ) )
                 {
                     // stop bundle
                     try
                     {
                         bundle.stop();
                     }
                     catch ( BundleException be )
                     {
                         bundleException = be;
                         log"Cannot stop"be );
                     }
                 }
                 else if ( "refresh".equalsaction ) )
                 {
                     // refresh bundle wiring and give at most 5 seconds to finish
                     BaseUpdateInstallHelper.refreshPackagesgetPackageAdmin(), getBundleContext(), 5000L, bundle );
                 }
                 else if ( "update".equalsaction ) )
                 {
                     // update the bundle
                     updatebundle );
                 }
                 else if ( "uninstall".equalsaction ) )
                 {
                     // uninstall bundle
                     try
                     {
                         bundle.uninstall();
                     }
                     catch ( BundleException be )
                     {
                         bundleException = be;
                         log"Cannot uninstall"be );
                     }
                 }
 
                 // write the state only
                 resp.setContentType"application/json" ); //$NON-NLS-1$
                 resp.setCharacterEncoding"UTF-8" ); //$NON-NLS-1$
                 if ( null == getBundleContext() )
                 {
                   // refresh package on the web console itself or some of it's dependencies
                   resp.getWriter().print("false"); //$NON-NLS-1$
                 }
                 else
                 {
                   resp.getWriter().print"{\"fragment\":" + isFragmentBundlebundle ) //$NON-NLS-1$
                       + ",\"stateRaw\":" + bundle.getState() + "}" ); //$NON-NLS-1$ //$NON-NLS-2$
                 }
                 return;
             }
         }
 
         if ( success && null != getBundleContext() )
         {
             final String pluginRoot = ( String ) req.getAttribute. );
             final String servicesRoot = getServicesRootreq );
             try
             {
                 this.renderJSONrespnullpluginRootservicesRootreq.getLocale(), req.getParameter(), bundleException );
             }
             catch (InvalidSyntaxException e)
             {
                 resp.sendError(."Invalid LDAP filter specified");
             }
         }
         else
         {
             super.doPostreqresp );
         }
     }
 
     private String getServicesRoot(HttpServletRequest request)
     {
         return ( ( String ) request.getAttribute. ) ) +
             "/" + . + "/";
     }
 
     Bundle getBundleString pathInfo )
     {
         // only use last part of the pathInfo
         pathInfo = pathInfo.substringpathInfo.lastIndexOf'/' ) + 1 );
 
         // assume bundle Id
         try
         {
             final long bundleId = Long.parseLongpathInfo );
             if ( bundleId >= 0 )
             {
                 return BundleContextUtil.getWorkingBundleContext(this.getBundleContext()).getBundlebundleId );
             }
         }
         catch ( NumberFormatException nfe )
         {
             // check if this follows the pattern {symbolic-name}[:{version}]
             final int pos = pathInfo.indexOf(':');
             final String symbolicName;
             final String version;
             if ( pos == -1 ) {
                 symbolicName = pathInfo;
                 version = null;
             } else {
                 symbolicName = pathInfo.substring(0, pos);
                 version = pathInfo.substring(pos+1);
             }
 
             // search
             final Bundle[] bundles = BundleContextUtil.getWorkingBundleContext(this.getBundleContext()).getBundles();
             for(int i=0; i<bundles.lengthi++)
             {
                 final Bundle bundle = bundles[i];
                 // check symbolic name first
                 if ( symbolicName.equals(bundle.getSymbolicName()) )
                 {
                     if ( version == null || version.equals(bundle.getHeaders().get(.)) )
                     {
                         return bundle;
                     }
                 }
             }
         }
 
 
         return null;
     }
 
 
     private void appendBundleInfoCountfinal StringBuffer bufString msgint count )
     {
         buf.append(count);
         buf.append(" bundle");
         if ( count != 1 )
             buf.append's' );
         buf.append(' ');
         buf.append(msg);
     }

    
 
     protected void renderContentHttpServletRequest requestHttpServletResponse response ) throws IOException
     {
         // get request info from request attribute
         final RequestInfo reqInfo = getRequestInfo(request);
 
         final int startLevel = getStartLevel().getInitialBundleStartLevel();
 
         // prepare variables
         DefaultVariableResolver vars = ( ( DefaultVariableResolver ) WebConsoleUtil.getVariableResolverrequest ) );
         vars.put"startLevel", String.valueOf(startLevel));
         vars.put"drawDetails"reqInfo.bundleRequested ? . : . );
         vars.put"currentBundle", (reqInfo.bundleRequested && reqInfo.bundle != null ? String.valueOf(reqInfo.bundle.getBundleId()) : "null"));
 
         final String pluginRoot = ( String ) request.getAttribute. );
         final String servicesRoot = getServicesRoot ( request );
         StringWriter w = new StringWriter();
         try
         {
             writeJSON(wreqInfo.bundlepluginRootservicesRootrequest.getLocale(), request.getParameter(), null );
         }
         catch (InvalidSyntaxException e)
         {
             response.sendError(."Invalid LDAP filter specified");
             return;
         }
         vars.put"__bundles__"w.toString());
 
         response.getWriter().print();
     }
 
     private void renderJSONfinal HttpServletResponse responsefinal Bundle bundlefinal String pluginRootfinal String servicesRootfinal Locale localefinal String filterfinal BundleException be )
         throws IOExceptionInvalidSyntaxException
     {
         response.setContentType"application/json" );
         response.setCharacterEncoding"UTF-8" );
 
         final PrintWriter pw = response.getWriter();
         writeJSON(pwbundlepluginRootservicesRootlocalefilterbe);
     }
 
 
     private void writeJSONfinal Writer pwfinal Bundle bundlefinal String pluginRootfinal String servicesRootfinal Locale localefinal String filterfinal BundleException be )
         throws IOExceptionInvalidSyntaxException
     {
         writeJSONpwbundlepluginRootservicesRootfalselocalefilterbe );
     }
 
 
     private void writeJSONfinal Writer pwfinal Bundle bundlefinal String pluginRoot,
         final String servicesRootfinal boolean fullDetailsfinal Locale localefinal String filterfinal BundleException be ) throws IOExceptionInvalidSyntaxException
     {
         final Bundle[] allBundles = this.getBundles();
         final Object[] status = getStatusLine(allBundles);
         final String statusLine = (Stringstatus[5];
         // filter bundles by headers
         final Bundle[] bundles;
         if (bundle != null)
         {
             bundles = new Bundle[] { bundle };
         }
         else if (filter != null)
         {
             Filter f = getBundleContext().createFilter(filter);
             ArrayList list = new ArrayList(allBundles.length);
             final String localeString = locale.toString();
             for (int i = 0, size = allBundles.lengthi < sizei++)
             {
                 if (f.match(allBundles[i].getHeaders(localeString)))
                 {
                     list.add(allBundles[i]);
                 }
             }
             bundles = new Bundle[list.size()];
             list.toArray(bundles);
         }
         else
         {
             bundles = allBundles;
         }
 
         Util.sortbundleslocale );
 
         final JSONWriter jw = new JSONWriterpw );
 
         try
         {
             jw.object();
 
             if (null != be)
             {
                 final StringWriter s = new StringWriter();
                 final Throwable t = be.getNestedException() != null ? be.getNestedException() : be;
                 t.printStackTracenew PrintWriter(s) );
                 jw.key"error" );
                 jw.values.toString() );
             }
 
             jw.key"status" );
             jw.valuestatusLine );
 
             // add raw status
             jw.key"s" );
             jw.array();
             for ( int i = 0; i < 5; i++ ) jw.value(status[i]);
             jw.endArray();
 
             jw.key"data" );
 
             jw.array();
 
             for ( int i = 0; i < bundles.lengthi++ )
             {
                 bundleInfojwbundles[i], fullDetails || bundle != nullpluginRootservicesRootlocale );
             }
 
             jw.endArray();
 
             jw.endObject();
 
         }
         catch ( JSONException je )
         {
             throw new IOExceptionje.toString() );
         }
 
     }
 
     private Object[] getStatusLine(final Bundle[] bundles)
     {
         Object[] ret = new Object[6];
         int active = 0, installed = 0, resolved = 0, fragments = 0;
         for ( int i = 0; i < bundles.lengthi++ )
         {
             switch ( bundles[i].getState() )
             {
                 case .:
                     active++;
                     break;
                 case .:
                     installed++;
                     break;
                 case .:
                     if ( isFragmentBundlebundles[i] ) )
                     {
                         fragments++;
                     }
                     else
                     {
                         resolved++;
                     }
                     break;
             }
         }
         final StringBuffer buffer = new StringBuffer();
         buffer.append("Bundle information: ");
         appendBundleInfoCount(buffer"in total"bundles.length);
         if ( active == bundles.length || active + fragments == bundles.length )
         {
             buffer.append(" - all ");
             appendBundleInfoCount(buffer"active."bundles.length);
         }
         else
         {
             if ( active != 0 )
             {
                 buffer.append(", ");
                 appendBundleInfoCount(buffer"active"active);
             }
             if ( fragments != 0 )
             {
                 buffer.append(", ");
                 appendBundleInfoCount(buffer"active fragments"fragments);
             }
             if ( resolved != 0 )
             {
                 buffer.append(", ");
                 appendBundleInfoCount(buffer"resolved"resolved);
             }
             if ( installed != 0 )
             {
                 buffer.append(", ");
                 appendBundleInfoCount(buffer"installed"installed);
             }
             buffer.append('.');
         }
         ret[0] = new Integer(bundles.length);
         ret[1] = new Integer(active);
         ret[2] = new Integer(fragments);
         ret[3] = new Integer(resolved);
         ret[4] = new Integer(installed);
         ret[5] = buffer.toString();
         return ret;
     }
 
     private void bundleInfoJSONWriter jwBundle bundleboolean detailsfinal String pluginRootfinal String servicesRootfinal Locale locale )
         throws JSONException
     {
         jw.object();
         jw.key"id" );
         jw.valuebundle.getBundleId() );
         jw.key"name" );
         jw.value( Util.getNamebundlelocale ) );
         jw.key"fragment" );
         jw.valueisFragmentBundle(bundle) );
         jw.key"stateRaw" );
         jw.valuebundle.getState() );
         jw.key"state" );
         jw.valuetoStateStringbundle ) );
         jw.key"version" );
         jw.value( Util.getHeaderValue(bundle.) );
         jw.key"symbolicName" );
         jw.valuebundle.getSymbolicName() );
         jw.key"category" );
         jw.value( Util.getHeaderValue(bundle.) );
 
         if ( details )
         {
             bundleDetailsjwbundlepluginRootservicesRootlocale );
         }
 
         jw.endObject();
     }
 
 
     private final Bundle[] getBundles()
     {
         return BundleContextUtil.getWorkingBundleContext(this.getBundleContext()).getBundles();
     }
 
 
     private String toStateStringfinal Bundle bundle )
     {
         switch ( bundle.getState() )
         {
             case .:
                 return "Installed";
             case .:
                 if ( isFragmentBundle(bundle) )
                 {
                     return "Fragment";
                 }
                 return "Resolved";
             case .:
                 return "Starting";
             case .:
                 return "Active";
             case .:
                 return "Stopping";
             case .:
                 return "Uninstalled";
             default:
                 return "Unknown: " + bundle.getState();
         }
     }
 
 
     private final boolean isFragmentBundleBundle bundle )
     {
         // Workaround for FELIX-3670
         if ( bundle.getState() == . )
         {
             return bundle.getHeaders().get. ) != null;
         }
 
         return getPackageAdmin().getBundleTypebundle ) == .;
     }
 
 
     private final void bundleDetailsJSONWriter jwBundle bundlefinal String pluginRootfinal String servicesRootfinal Locale locale)
         throws JSONException
     {
         Dictionary headers = bundle.getHeaderslocale == null ? null : locale.toString() );
 
         jw.key"props" );
         jw.array();
         Util.keyValjw"Symbolic Name"bundle.getSymbolicName() );
         Util.keyValjw"Version"headers.get. ) );
         Util.keyValjw"Bundle Location"bundle.getLocation() );
         Util.keyValjw"Last Modification"new Datebundle.getLastModified() ) );
 
         String docUrl = ( String ) headers.get. );
         if ( docUrl != null )
         {
             Util.keyValjw"Bundle Documentation"docUrl );
         }
 
         Util.keyValjw"Vendor"headers.get. ) );
         Util.keyValjw"Copyright"headers.get. ) );
         Util.keyValjw"Description"headers.get. ) );
 
         Util.keyValjw"Start Level"getStartLevelbundle ) );
 
         Util.keyValjw"Bundle Classpath"headers.get. ) );
 
         listFragmentInfojwbundlepluginRoot );
 
         if ( bundle.getState() == . )
         {
             listImportExportsUnresolvedjwbundlepluginRoot );
         }
         else
         {
             listImportExportjwbundlepluginRoot );
         }
 
         if ( bundle.getState() != . )
         {
             listServicesjwbundleservicesRoot );
         }
 
         listHeadersjwbundle );
         final String appRoot = ( pluginRoot == null ) ? null : pluginRoot.substring( 0, pluginRoot.lastIndexOf"/" ) );
         bundleInfoDetailsjwbundleappRootlocale );
 
         jw.endArray();
     }
 
 
     private final void bundleInfoDetailsJSONWriter jwBundle bundleString appRootfinal Locale locale)
 	        throws JSONException
     {
 	jw.object();
 	jw.key"key" );
 	jw.value"nfo" );
 	jw.key"value");
 	jw.object();
         final Object[] bundleInfoProviders = .getServices();
         for ( int i = 0; bundleInfoProviders != null && i < bundleInfoProviders.lengthi++ )
         {
             final BundleInfoProvider infoProvider = (BundleInfoProviderbundleInfoProviders[i];
             final BundleInfo[] infos = infoProvider.getBundleInfo(bundleappRootlocale);
             if ( null != infos && infos.length > 0)
             {
         	jw.keyinfoProvider.getName(locale) );
         	jw.array();
         	for ( int j = 0; j < infos.lengthj++ )
         	{
         	    bundleInfojwinfos[j] );
         	}
         	jw.endArray();
             }
         }
         jw.endObject(); // value
         jw.endObject();
     }
 
 
     private static final void bundleInfoJSONWriter jwBundleInfo info ) throws JSONException
     {
         jw.object();
         jw.key"name" );
         jw.valueinfo.getName() );
         jw.key"description" );
         jw.valueinfo.getDescription() );
         jw.key"type" );
         jw.valueinfo.getType().getName() );
         jw.key"value" );
         jw.valueinfo.getValue() );
         jw.endObject();
     }
 
 
     private final Integer getStartLevelBundle bundle )
     {
         if ( bundle.getState() != . )
         {
             StartLevel sl = getStartLevel();
             if ( sl != null )
             {
                 return new Integersl.getBundleStartLevelbundle ) );
             }
         }
 
         // bundle has been uninstalled or StartLevel service is not available
         return null;
     }
 
 
     private void listImportExportJSONWriter jwBundle bundlefinal String pluginRoot ) throws JSONException
     {
         PackageAdmin packageAdmin = getPackageAdmin();
         if ( packageAdmin == null )
         {
             return;
         }
 
         Map usingBundles = new TreeMap();
 
         ExportedPackage[] exports = packageAdmin.getExportedPackagesbundle );
         if ( exports != null && exports.length > 0 )
         {
             // do alphabetical sort
             Arrays.sortexportsnew Comparator()
             {
                 public int compareExportedPackage p1ExportedPackage p2 )
                 {
                     return p1.getName().compareTop2.getName() );
                 }
 
 
                 public int compareObject o1Object o2 )
                 {
                     return compare( ( ExportedPackage ) o1, ( ExportedPackage ) o2 );
                 }
             } );
 
             JSONArray val = new JSONArray();
             for ( int j = 0; j < exports.lengthj++ )
             {
                 ExportedPackage export = exports[j];
                 collectExportvalexport.getName(), export.getVersion() );
                 Bundle[] ubList = export.getImportingBundles();
                 if ( ubList != null )
                 {
                     for ( int i = 0; i < ubList.lengthi++ )
                     {
                         Bundle ub = ubList[i];
                         String name = ub.getSymbolicName();
                         if (name == nullname = ub.getLocation();
                         usingBundles.putnameub );
                     }
                 }
             }
             Util.keyValjw"Exported Packages"val );
         }
         else
         {
             Util.keyValjw"Exported Packages""---" );
         }
 
         exports = packageAdmin.getExportedPackages( ( Bundle ) null );
         if ( exports != null && exports.length > 0 )
         {
             // collect import packages first
             final List imports = new ArrayList();
             for ( int i = 0; i < exports.lengthi++ )
             {
                 final ExportedPackage ep = exports[i];
                 final Bundle[] importers = ep.getImportingBundles();
                 for ( int j = 0; importers != null && j < importers.lengthj++ )
                 {
                     if ( importers[j].getBundleId() == bundle.getBundleId() )
                     {
                         imports.addep );
 
                         break;
                     }
                 }
             }
             // now sort
             JSONArray val = new JSONArray();
             if ( imports.size() > 0 )
             {
                 final ExportedPackage[] packages = ( ExportedPackage[] ) imports.toArraynew ExportedPackage[imports
                     .size()] );
                 Arrays.sortpackagesnew Comparator()
                 {
                     public int compareExportedPackage p1ExportedPackage p2 )
                     {
                         return p1.getName().compareTop2.getName() );
                     }
 
 
                     public int compareObject o1Object o2 )
                     {
                         return compare( ( ExportedPackage ) o1, ( ExportedPackage ) o2 );
                     }
                 } );
                 // and finally print out
                 for ( int i = 0; i < packages.lengthi++ )
                 {
                     ExportedPackage ep = packages[i];
                     collectImportvalep.getName(), ep.getVersion(), falseeppluginRoot );
                 }
             }
             else
             {
                 // add description if there are no imports
                 val.put"None" );
             }
 
             Util.keyValjw"Imported Packages"val );
         }
 
         if ( !usingBundles.isEmpty() )
         {
            JSONArray val = new JSONArray();
            for ( Iterator ui = usingBundles.values().iterator(); ui.hasNext(); )
            {
                Bundle usingBundle = ( Bundle ) ui.next();
                val.putgetBundleDescriptorusingBundlepluginRoot ) );
            }
            Util.keyValjw"Importing Bundles"val );
        }
    }
    private void listImportExportsUnresolvedJSONWriter jwBundle bundlefinal String pluginRoot ) throws JSONException
    {
        Dictionary dict = bundle.getHeaders();
        String target = ( String ) dict.get. );
        if ( target != null )
        {
            Clause[] pkgs = Parser.parseHeadertarget );
            if ( pkgs != null && pkgs.length > 0 )
            {
                // do alphabetical sort
                Arrays.sortpkgsnew Comparator()
                {
                    public int compareClause p1Clause p2 )
                    {
                        return p1.getName().compareTop2.getName() );
                    }
                    public int compareObject o1Object o2 )
                    {
                        return compare( ( Clauseo1, ( Clause ) o2 );
                    }
                } );
                JSONArray val = new JSONArray();
                for ( int i = 0; i < pkgs.lengthi++ )
                {
                    Clause export = new Clausepkgs[i].getName(), pkgs[i].getDirectives(), pkgs[i].getAttributes() );
                    collectExportvalexport.getName(), export.getAttribute. ) );
                }
                Util.keyValjw"Exported Packages"val );
            }
            else
            {
                Util.keyValjw"Exported Packag