org.eclipse.equinox.frameworkadmin_2.0.0.v20110815-1438

16:43:54.211 INFO  jd.cli.Main - Decompiling org.eclipse.equinox.frameworkadmin_2.0.0.v20110815-1438.jar
package org.eclipse.equinox.frameworkadmin;

import java.net.URI;
import org.eclipse.core.runtime.URIUtil;

public class BundleInfo
{
  public static final String EMPTY_VERSION = "0.0.0";
  public static final int NO_LEVEL = -1;
  public static final int NO_BUNDLEID = -1;
  private String symbolicName = null;
  private String version = "0.0.0";
  private URI baseLocation = null;
  private URI location = null;
  private long bundleId = -1L;
  private boolean markedAsStarted = false;
  private int startLevel = -1;
  private boolean resolved = false;
  private String manifest = null;
  private String fragmentHost = null;
  
  public BundleInfo() {}
  
  public BundleInfo(URI location)
  {
    this.location = location;
  }
  
  public BundleInfo(URI location, int startLevel, boolean started)
  {
    this.location = location;
    this.startLevel = (startLevel < 0 ? -1 : startLevel);
    markedAsStarted = started;
  }
  
  public BundleInfo(String symbolic, String version, URI location, int startLevel, boolean started)
  {
    symbolicName = symbolic;
    this.version = (version != null ? version : "0.0.0");
    this.location = location;
    markedAsStarted = started;
    this.startLevel = (startLevel < 0 ? -1 : startLevel);
  }
  
  public long getBundleId()
  {
    return bundleId;
  }
  
  public URI getBaseLocation()
  {
    return baseLocation;
  }
  
  public URI getLocation()
  {
    return location;
  }
  
  public String getManifest()
  {
    return manifest;
  }
  
  public int getStartLevel()
  {
    return startLevel;
  }
  
  public String getSymbolicName()
  {
    return symbolicName;
  }
  
  public String getVersion()
  {
    if (version == null) {
      return "0.0.0";
    }
    return version;
  }
  
  public String getFragmentHost()
  {
    return fragmentHost;
  }
  
  public boolean isMarkedAsStarted()
  {
    return markedAsStarted;
  }
  
  public boolean isResolved()
  {
    return resolved;
  }
  
  public void setBundleId(long bundleId)
  {
    this.bundleId = bundleId;
  }
  
  public void setBaseLocation(URI baseLocation)
  {
    this.baseLocation = baseLocation;
  }
  
  public void setLocation(URI location)
  {
    this.location = location;
  }
  
  public void setManifest(String manifest)
  {
    this.manifest = manifest;
  }
  
  public void setMarkedAsStarted(boolean markedAsStarted)
  {
    this.markedAsStarted = markedAsStarted;
  }
  
  public void setResolved(boolean resolved)
  {
    this.resolved = resolved;
  }
  
  public void setStartLevel(int level)
  {
    startLevel = (level < 0 ? -1 : level);
  }
  
  public void setSymbolicName(String symbolicName)
  {
    this.symbolicName = symbolicName;
  }
  
  public void setVersion(String value)
  {
    if (value == null) {
      version = "0.0.0";
    } else {
      version = value;
    }
  }
  
  public void setFragmentHost(String fragmentHost)
  {
    this.fragmentHost = fragmentHost;
  }
  
  public String toString()
  {
    StringBuffer buffer = new StringBuffer();
    buffer.append("BundleInfo(");
    if (symbolicName != null) {
      buffer.append(symbolicName);
    }
    buffer.append(", ");
    buffer.append(version);
    if (fragmentHost != null)
    {
      buffer.append(", fragmentHost=");
      buffer.append(fragmentHost);
    }
    if (baseLocation != null)
    {
      buffer.append(", baseLocation=");
      buffer.append(baseLocation);
    }
    buffer.append(", location=");
    buffer.append(location);
    buffer.append(", startLevel=");
    buffer.append(startLevel);
    buffer.append(", toBeStarted=");
    buffer.append(markedAsStarted);
    buffer.append(", resolved=");
    buffer.append(resolved);
    buffer.append(", id=");
    buffer.append(bundleId);
    buffer.append(',').append(manifest == null ? "no manifest" : "manifest available");
    buffer.append(')');
    return buffer.toString();
  }
  
  public int hashCode()
  {
    int result = 1;
    result = 31 * result + (symbolicName == null ? 0 : symbolicName.hashCode());
    result = 31 * result + version.hashCode();
    return result;
  }
  
  public boolean equals(Object obj)
  {
    if (this == obj) {
      return true;
    }
    if (obj == null) {
      return false;
    }
    if (getClass() != obj.getClass()) {
      return false;
    }
    BundleInfo other = (BundleInfo)obj;
    if (symbolicName == null)
    {
      if (symbolicName != null) {
        return false;
      }
    }
    else if (!symbolicName.equals(symbolicName)) {
      return false;
    }
    if (!version.equals(other.getVersion())) {
      return false;
    }
    if ((location == null) || (location == null)) {
      return true;
    }
    URI absoluteLocation = null;
    if ((location.isAbsolute()) || (baseLocation == null)) {
      absoluteLocation = location;
    } else {
      absoluteLocation = URIUtil.append(baseLocation, URIUtil.toUnencodedString(location));
    }
    URI otherAbsoluteLocation = null;
    if ((location.isAbsolute()) || (baseLocation == null)) {
      otherAbsoluteLocation = location;
    } else {
      otherAbsoluteLocation = URIUtil.append(baseLocation, URIUtil.toUnencodedString(location));
    }
    return URIUtil.sameURI(absoluteLocation, otherAbsoluteLocation);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.frameworkadmin.BundleInfo
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.internal.frameworkadmin.utils;

import org.eclipse.osgi.service.pluginconversion.PluginConverter;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;

public class Activator
  implements BundleActivator
{
  private static BundleContext bundleContext;
  
  public void start(BundleContext context)
    throws Exception
  {
    bundleContext = context;
  }
  
  public void stop(BundleContext context)
    throws Exception
  {
    bundleContext = null;
  }
  
  public static PluginConverter acquirePluginConverter()
  {
    if (bundleContext == null) {
      return null;
    }
    ServiceReference reference = bundleContext.getServiceReference(PluginConverter.class.getName());
    if (reference == null) {
      return null;
    }
    PluginConverter result = (PluginConverter)bundleContext.getService(reference);
    bundleContext.ungetService(reference);
    return result;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.internal.frameworkadmin.utils.Activator
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.internal.frameworkadmin.utils;

import java.io.File;
import java.net.URI;
import java.util.Dictionary;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import org.eclipse.equinox.frameworkadmin.BundleInfo;
import org.eclipse.equinox.internal.provisional.frameworkadmin.BundlesState;
import org.eclipse.equinox.internal.provisional.frameworkadmin.ConfigData;
import org.eclipse.equinox.internal.provisional.frameworkadmin.FrameworkAdmin;
import org.eclipse.equinox.internal.provisional.frameworkadmin.FrameworkAdminRuntimeException;
import org.eclipse.equinox.internal.provisional.frameworkadmin.LauncherData;
import org.eclipse.equinox.internal.provisional.frameworkadmin.Manipulator;

public class SimpleBundlesState
  implements BundlesState
{
  public static final BundleInfo[] NULL_BUNDLEINFOS = new BundleInfo[0];
  private final String systemBundleSymbolicName;
  private final String systemBundleName;
  private final String systemBundleVendor;
  
  public static void checkAvailability(FrameworkAdmin fwAdmin)
    throws FrameworkAdminRuntimeException
  {
    if (!fwAdmin.isActive()) {
      throw new FrameworkAdminRuntimeException("FrameworkAdmin creates this object is no more available.", "FrameworkAdmin service created this object is not available any more");
    }
  }
  
  static File getFwJar(LauncherData launcherData)
  {
    if (launcherData.getFwJar() != null) {
      return launcherData.getFwJar();
    }
    return null;
  }
  
  List bundleInfosList = new LinkedList();
  FrameworkAdmin fwAdmin = null;
  Manipulator manipulator = null;
  
  public SimpleBundlesState(FrameworkAdmin ManipulatorAdmin, Manipulator Manipulator, String systemBundleSymbolicName)
  {
    fwAdmin = ManipulatorAdmin;
    
    manipulator = ManipulatorAdmin.getManipulator();
    manipulator.setConfigData(Manipulator.getConfigData());
    manipulator.setLauncherData(Manipulator.getLauncherData());
    this.systemBundleSymbolicName = systemBundleSymbolicName;
    systemBundleName = null;
    systemBundleVendor = null;
    initialize();
  }
  
  public SimpleBundlesState(FrameworkAdmin ManipulatorAdmin, Manipulator Manipulator, String systemBundleName, String systemBundleVender)
  {
    fwAdmin = ManipulatorAdmin;
    
    manipulator = ManipulatorAdmin.getManipulator();
    manipulator.setConfigData(Manipulator.getConfigData());
    manipulator.setLauncherData(Manipulator.getLauncherData());
    systemBundleSymbolicName = null;
    this.systemBundleName = systemBundleName;
    systemBundleVendor = systemBundleVender;
    initialize();
  }
  
  public BundleInfo[] getExpectedState()
    throws FrameworkAdminRuntimeException
  {
    if (!fwAdmin.isActive()) {
      throw new FrameworkAdminRuntimeException("FrameworkAdmin creates this object is no more available.", "FrameworkAdmin service created this object is not available any more");
    }
    return Utils.getBundleInfosFromList(bundleInfosList);
  }
  
  public BundleInfo[] getPrerequisteBundles(BundleInfo bInfo)
  {
    URI location = bInfo.getLocation();
    String requiredBundles = Utils.getManifestMainAttributes(location, "Require-Bundle");
    if (requiredBundles == null) {
      return new BundleInfo[] { getSystemBundle() };
    }
    String[] clauses = Utils.getClauses(requiredBundles);
    List list = new LinkedList();
    for (int i = 0; i < clauses.length; i++) {
      list.add(Utils.getPathFromClause(clauses[i]));
    }
    List ret = new LinkedList();
    ret.add(getSystemBundle());
    for (Iterator ite = bundleInfosList.iterator(); ite.hasNext();)
    {
      BundleInfo currentBInfo = (BundleInfo)ite.next();
      URI currentLocation = currentBInfo.getLocation();
      String currentSymbolicName = Utils.getManifestMainAttributes(currentLocation, "Bundle-SymbolicName");
      if (currentSymbolicName != null)
      {
        currentSymbolicName = Utils.getPathFromClause(currentSymbolicName);
        for (Iterator ite2 = list.iterator(); ite2.hasNext();)
        {
          String symbolicName = (String)ite2.next();
          if (symbolicName.equals(currentSymbolicName))
          {
            ret.add(currentBInfo);
            break;
          }
        }
      }
    }
    return Utils.getBundleInfosFromList(ret);
  }
  
  public BundleInfo getSystemBundle()
  {
    if (systemBundleSymbolicName == null)
    {
      for (Iterator ite = bundleInfosList.iterator(); ite.hasNext();)
      {
        BundleInfo bInfo = (BundleInfo)ite.next();
        
        URI location = bInfo.getLocation();
        String bundleName = Utils.getManifestMainAttributes(location, "Bundle-Name");
        if (systemBundleName.equals(bundleName))
        {
          String bundleVendor = Utils.getManifestMainAttributes(location, "Bundle-Vendor");
          if (systemBundleVendor.equals(bundleVendor)) {
            return bInfo;
          }
        }
      }
      return null;
    }
    for (Iterator ite = bundleInfosList.iterator(); ite.hasNext();)
    {
      BundleInfo bInfo = (BundleInfo)ite.next();
      URI location = bInfo.getLocation();
      String symbolicName = Utils.getManifestMainAttributes(location, "Bundle-SymbolicName");
      symbolicName = Utils.getPathFromClause(symbolicName);
      if (systemBundleSymbolicName.equals(symbolicName)) {
        return bInfo;
      }
    }
    return null;
  }
  
  public BundleInfo[] getSystemFragmentedBundles()
  {
    BundleInfo systemBInfo = getSystemBundle();
    if (systemBInfo == null) {
      return NULL_BUNDLEINFOS;
    }
    List list = new LinkedList();
    for (Iterator ite = bundleInfosList.iterator(); ite.hasNext();)
    {
      BundleInfo bInfo = (BundleInfo)ite.next();
      URI location = bInfo.getLocation();
      String manifestVersion = Utils.getManifestMainAttributes(location, "Bundle-ManifestVersion");
      if (manifestVersion != null) {
        if ((!manifestVersion.equals("1")) && (!manifestVersion.equals("1.0")))
        {
          String fragmentHost = Utils.getManifestMainAttributes(location, "Fragment-Host");
          if (fragmentHost != null)
          {
            int index = fragmentHost.indexOf(";");
            if (index != -1)
            {
              String symbolicName = fragmentHost.substring(0, index).trim();
              String parameter = fragmentHost.substring(index + 1).trim();
              if ((symbolicName.equals("system.bundle")) && 
                (parameter.equals("extension:=framework")))
              {
                list.add(location);
                break;
              }
            }
          }
        }
      }
    }
    return Utils.getBundleInfosFromList(list);
  }
  
  public String[] getUnsatisfiedConstraints(BundleInfo bInfo)
    throws FrameworkAdminRuntimeException
  {
    throw new FrameworkAdminRuntimeException("getUnsatisfiedConstraints(BundleInfo bInfo) is not supported in this implementation", "This implementation doesn't support this method.");
  }
  
  private void initialize()
  {
    bundleInfosList.clear();
    LauncherData launcherData = manipulator.getLauncherData();
    ConfigData configData = manipulator.getConfigData();
    File fwJar = getFwJar(launcherData);
    if (fwJar == null) {
      throw new IllegalStateException("launcherData.getLauncherConfigFile() == null && fwJar is not set.");
    }
    BundleInfo[] bInfos = configData.getBundles();
    for (int j = 0; j < bInfos.length; j++) {
      installBundle(bInfos[j]);
    }
    if (getSystemBundle() == null)
    {
      BundleInfo sysBInfo = new BundleInfo(launcherData.getFwJar().toURI(), 0, true);
      sysBInfo.setBundleId(0L);
      installBundle(sysBInfo);
    }
  }
  
  public void installBundle(BundleInfo bInfo)
    throws FrameworkAdminRuntimeException
  {
    URI newLocation = bInfo.getLocation();
    Dictionary newManifest = Utils.getOSGiManifest(newLocation);
    if (newManifest == null) {
      return;
    }
    String newSymbolicName = (String)newManifest.get("Bundle-SymbolicName");
    String newVersion = (String)newManifest.get("Bundle-Version");
    
    boolean found = false;
    for (Iterator ite = bundleInfosList.iterator(); ite.hasNext();)
    {
      BundleInfo currentBInfo = (BundleInfo)ite.next();
      URI location = currentBInfo.getLocation();
      if (newLocation.equals(location))
      {
        found = true;
        break;
      }
      Dictionary manifest = Utils.getOSGiManifest(location);
      String symbolicName = (String)manifest.get("Bundle-SymbolicName");
      String version = (String)manifest.get("Bundle-Version");
      if ((newSymbolicName != null) && (newVersion != null) && 
        (newSymbolicName.equals(symbolicName)) && (newVersion.equals(version)))
      {
        found = true;
        break;
      }
    }
    if (!found) {
      bundleInfosList.add(bInfo);
    }
  }
  
  public boolean isFullySupported()
  {
    return false;
  }
  
  public boolean isResolved()
    throws FrameworkAdminRuntimeException
  {
    throw new FrameworkAdminRuntimeException("isResolved() is not supported in this implementation", "This implementation doesn't support this method.");
  }
  
  public boolean isResolved(BundleInfo bInfo)
    throws FrameworkAdminRuntimeException
  {
    throw new FrameworkAdminRuntimeException("isResolved(BundleInfo bInfo) is not supported in this implementation", "This implementation doesn't support this method.");
  }
  
  public void resolve(boolean increment)
    throws FrameworkAdminRuntimeException
  {
    throw new FrameworkAdminRuntimeException("resolve(boolean increment) is not supported in this implementation", "This implementation doesn't support this method.");
  }
  
  public void uninstallBundle(BundleInfo bInfo)
    throws FrameworkAdminRuntimeException
  {
    URI targetLocation = bInfo.getLocation();
    int index = -1;
    for (Iterator ite = bundleInfosList.iterator(); ite.hasNext();)
    {
      index++;
      BundleInfo currentBInfo = (BundleInfo)ite.next();
      URI location = currentBInfo.getLocation();
      if (targetLocation.equals(location)) {
        break;
      }
    }
    if (index != -1) {
      bundleInfosList.remove(index);
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.internal.frameworkadmin.utils.SimpleBundlesState
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.internal.frameworkadmin.utils;

import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import java.net.JarURLConnection;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Dictionary;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.SortedMap;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.URIUtil;
import org.eclipse.equinox.frameworkadmin.BundleInfo;
import org.eclipse.osgi.service.pluginconversion.PluginConversionException;
import org.eclipse.osgi.service.pluginconversion.PluginConverter;
import org.eclipse.osgi.util.ManifestElement;
import org.osgi.framework.BundleException;

public class Utils
{
  private static final String FEATURE_MANIFEST = "feature.xml";
  private static final String FILE_SCHEME = "file";
  private static final String FRAGMENT_MANIFEST = "fragment.xml";
  private static final String PATH_SEP = "/";
  private static final String PLUGIN_MANIFEST = "plugin.xml";
  
  public static Properties appendProperties(Properties to, Properties from)
  {
    if (from != null)
    {
      if (to == null) {
        to = new Properties();
      }
      for (Enumeration enumeration = from.keys(); enumeration.hasMoreElements();)
      {
        String key = (String)enumeration.nextElement();
        to.setProperty(key, from.getProperty(key));
      }
    }
    return to;
  }
  
  /* Error */
  private static Dictionary basicLoadManifest(File bundleLocation)
  {
    // Byte code:
    //   0: aconst_null
    //   1: astore_1
    //   2: aconst_null
    //   3: astore_2
    //   4: aload_0
    //   5: invokevirtual 505	java/io/File:isFile	()Z
    //   8: ifeq +33 -> 41
    //   11: new 313	java/util/zip/ZipFile
    //   14: dup
    //   15: aload_0
    //   16: iconst_1
    //   17: invokespecial 571	java/util/zip/ZipFile:<init>	(Ljava/io/File;I)V
    //   20: astore_2
    //   21: aload_2
    //   22: ldc 10
    //   24: invokevirtual 574	java/util/zip/ZipFile:getEntry	(Ljava/lang/String;)Ljava/util/zip/ZipEntry;
    //   27: astore_3
    //   28: aload_3
    //   29: ifnull +59 -> 88
    //   32: aload_2
    //   33: aload_3
    //   34: invokevirtual 573	java/util/zip/ZipFile:getInputStream	(Ljava/util/zip/ZipEntry;)Ljava/io/InputStream;
    //   37: astore_1
    //   38: goto +50 -> 88
    //   41: new 283	java/io/File
    //   44: dup
    //   45: aload_0
    //   46: ldc 10
    //   48: invokespecial 511	java/io/File:<init>	(Ljava/io/File;Ljava/lang/String;)V
    //   51: astore_3
    //   52: aload_3
    //   53: invokevirtual 502	java/io/File:exists	()Z
    //   56: ifeq +32 -> 88
    //   59: new 282	java/io/BufferedInputStream
    //   62: dup
    //   63: new 284	java/io/FileInputStream
    //   66: dup
    //   67: new 283	java/io/File
    //   70: dup
    //   71: aload_0
    //   72: ldc 10
    //   74: invokespecial 511	java/io/File:<init>	(Ljava/io/File;Ljava/lang/String;)V
    //   77: invokespecial 512	java/io/FileInputStream:<init>	(Ljava/io/File;)V
    //   80: invokespecial 501	java/io/BufferedInputStream:<init>	(Ljava/io/InputStream;)V
    //   83: astore_1
    //   84: goto +4 -> 88
    //   87: pop
    //   88: aload_1
    //   89: ifnonnull +37 -> 126
    //   92: aload_0
    //   93: iconst_1
    //   94: invokestatic 582	org/eclipse/equinox/internal/frameworkadmin/utils/Utils:convertPluginManifest	(Ljava/io/File;Z)Ljava/util/Dictionary;
    //   97: astore 5
    //   99: aload_1
    //   100: ifnull +11 -> 111
    //   103: aload_1
    //   104: invokevirtual 514	java/io/InputStream:close	()V
    //   107: goto +4 -> 111
    //   110: pop
    //   111: aload_2
    //   112: ifnull +11 -> 123
    //   115: aload_2
    //   116: invokevirtual 570	java/util/zip/ZipFile:close	()V
    //   119: goto +4 -> 123
    //   122: pop
    //   123: aload 5
    //   125: areturn
    //   126: aload_1
    //   127: aconst_null
    //   128: invokestatic 592	org/eclipse/osgi/util/ManifestElement:parseBundleManifest	(Ljava/io/InputStream;Ljava/util/Map;)Ljava/util/Map;
    //   131: astore_3
    //   132: aload_3
    //   133: ldc 9
    //   135: invokeinterface 602 2 0
    //   140: ifnonnull +37 -> 177
    //   143: aload_0
    //   144: iconst_1
    //   145: invokestatic 582	org/eclipse/equinox/internal/frameworkadmin/utils/Utils:convertPluginManifest	(Ljava/io/File;Z)Ljava/util/Dictionary;
    //   148: astore 5
    //   150: aload_1
    //   151: ifnull +11 -> 162
    //   154: aload_1
    //   155: invokevirtual 514	java/io/InputStream:close	()V
    //   158: goto +4 -> 162
    //   161: pop
    //   162: aload_2
    //   163: ifnull +11 -> 174
    //   166: aload_2
    //   167: invokevirtual 570	java/util/zip/ZipFile:close	()V
    //   170: goto +4 -> 174
    //   173: pop
    //   174: aload 5
    //   176: areturn
    //   177: aload_3
    //   178: invokestatic 584	org/eclipse/equinox/internal/frameworkadmin/utils/Utils:manifestToProperties	(Ljava/util/Map;)Ljava/util/Properties;
    //   181: astore 5
    //   183: aload_1
    //   184: ifnull +11 -> 195
    //   187: aload_1
    //   188: invokevirtual 514	java/io/InputStream:close	()V
    //   191: goto +4 -> 195
    //   194: pop
    //   195: aload_2
    //   196: ifnull +11 -> 207
    //   199: aload_2
    //   200: invokevirtual 570	java/util/zip/ZipFile:close	()V
    //   203: goto +4 -> 207
    //   206: pop
    //   207: aload 5
    //   209: areturn
    //   210: pop
    //   211: aload_1
    //   212: ifnull +11 -> 223
    //   215: aload_1
    //   216: invokevirtual 514	java/io/InputStream:close	()V
    //   219: goto +4 -> 223
    //   222: pop
    //   223: aload_2
    //   224: ifnull +11 -> 235
    //   227: aload_2
    //   228: invokevirtual 570	java/util/zip/ZipFile:close	()V
    //   231: goto +4 -> 235
    //   234: pop
    //   235: aconst_null
    //   236: areturn
    //   237: pop
    //   238: aload_1
    //   239: ifnull +11 -> 250
    //   242: aload_1
    //   243: invokevirtual 514	java/io/InputStream:close	()V
    //   246: goto +4 -> 250
    //   249: pop
    //   250: aload_2
    //   251: ifnull +11 -> 262
    //   254: aload_2
    //   255: invokevirtual 570	java/util/zip/ZipFile:close	()V
    //   258: goto +4 -> 262
    //   261: pop
    //   262: aconst_null
    //   263: areturn
    //   264: astore 4
    //   266: aload_1
    //   267: ifnull +11 -> 278
    //   270: aload_1
    //   271: invokevirtual 514	java/io/InputStream:close	()V
    //   274: goto +4 -> 278
    //   277: pop
    //   278: aload_2
    //   279: ifnull +11 -> 290
    //   282: aload_2
    //   283: invokevirtual 570	java/util/zip/ZipFile:close	()V
    //   286: goto +4 -> 290
    //   289: pop
    //   290: aload 4
    //   292: athrow
    // Line number table:
    //   Java source line #60	-> byte code offset #0
    //   Java source line #61	-> byte code offset #2
    //   Java source line #65	-> byte code offset #4
    //   Java source line #66	-> byte code offset #11
    //   Java source line #67	-> byte code offset #21
    //   Java source line #68	-> byte code offset #28
    //   Java source line #69	-> byte code offset #32
    //   Java source line #73	-> byte code offset #41
    //   Java source line #74	-> byte code offset #52
    //   Java source line #75	-> byte code offset #59
    //   Java source line #77	-> byte code offset #87
    //   Java source line #81	-> byte code offset #88
    //   Java source line #82	-> byte code offset #92
    //   Java source line #97	-> byte code offset #99
    //   Java source line #98	-> byte code offset #103
    //   Java source line #99	-> byte code offset #110
    //   Java source line #103	-> byte code offset #111
    //   Java source line #104	-> byte code offset #115
    //   Java source line #105	-> byte code offset #122
    //   Java source line #82	-> byte code offset #123
    //   Java source line #85	-> byte code offset #126
    //   Java source line #87	-> byte code offset #132
    //   Java source line #88	-> byte code offset #143
    //   Java source line #97	-> byte code offset #150
    //   Java source line #98	-> byte code offset #154
    //   Java source line #99	-> byte code offset #161
    //   Java source line #103	-> byte code offset #162
    //   Java source line #104	-> byte code offset #166
    //   Java source line #105	-> byte code offset #173
    //   Java source line #88	-> byte code offset #174
    //   Java source line #89	-> byte code offset #177
    //   Java source line #97	-> byte code offset #183
    //   Java source line #98	-> byte code offset #187
    //   Java source line #99	-> byte code offset #194
    //   Java source line #103	-> byte code offset #195
    //   Java source line #104	-> byte code offset #199
    //   Java source line #105	-> byte code offset #206
    //   Java source line #89	-> byte code offset #207
    //   Java source line #90	-> byte code offset #210
    //   Java source line #97	-> byte code offset #211
    //   Java source line #98	-> byte code offset #215
    //   Java source line #99	-> byte code offset #222
    //   Java source line #103	-> byte code offset #223
    //   Java source line #104	-> byte code offset #227
    //   Java source line #105	-> byte code offset #234
    //   Java source line #91	-> byte code offset #235
    //   Java source line #92	-> byte code offset #237
    //   Java source line #97	-> byte code offset #238
    //   Java source line #98	-> byte code offset #242
    //   Java source line #99	-> byte code offset #249
    //   Java source line #103	-> byte code offset #250
    //   Java source line #104	-> byte code offset #254
    //   Java source line #105	-> byte code offset #261
    //   Java source line #93	-> byte code offset #262
    //   Java source line #95	-> byte code offset #264
    //   Java source line #97	-> byte code offset #266
    //   Java source line #98	-> byte code offset #270
    //   Java source line #99	-> byte code offset #277
    //   Java source line #103	-> byte code offset #278
    //   Java source line #104	-> byte code offset #282
    //   Java source line #105	-> byte code offset #289
    //   Java source line #108	-> byte code offset #290
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	293	0	bundleLocation	File
    //   1	270	1	manifestStream	java.io.InputStream
    //   3	280	2	jarFile	ZipFile
    //   27	7	3	manifestEntry	ZipEntry
    //   51	2	3	bundleManifestFile	File
    //   131	2	3	manifest	Map
    //   177	1	3	manifest	Map
    //   264	27	4	localObject1	Object
    //   97	111	5	localObject2	Object
    //   87	1	9	localIOException1	IOException
    //   110	1	10	localIOException2	IOException
    //   122	1	11	localIOException3	IOException
    //   161	1	12	localIOException4	IOException
    //   173	1	13	localIOException5	IOException
    //   194	1	14	localIOException6	IOException
    //   206	1	15	localIOException7	IOException
    //   210	1	16	localIOException8	IOException
    //   222	1	17	localIOException9	IOException
    //   234	1	18	localIOException10	IOException
    //   237	1	19	localBundleException	BundleException
    //   249	1	20	localIOException11	IOException
    //   261	1	21	localIOException12	IOException
    //   277	1	22	localIOException13	IOException
    //   289	1	23	localIOException14	IOException
    // Exception table:
    //   from	to	target	type
    //   4	84	87	java/io/IOException
    //   99	107	110	java/io/IOException
    //   111	119	122	java/io/IOException
    //   150	158	161	java/io/IOException
    //   162	170	173	java/io/IOException
    //   183	191	194	java/io/IOException
    //   195	203	206	java/io/IOException
    //   126	150	210	java/io/IOException
    //   177	183	210	java/io/IOException
    //   211	219	222	java/io/IOException
    //   223	231	234	java/io/IOException
    //   126	150	237	org/osgi/framework/BundleException
    //   177	183	237	org/osgi/framework/BundleException
    //   238	246	249	java/io/IOException
    //   250	258	261	java/io/IOException
    //   4	99	264	finally
    //   126	150	264	finally
    //   177	183	264	finally
    //   210	211	264	finally
    //   237	238	264	finally
    //   266	274	277	java/io/IOException
    //   278	286	289	java/io/IOException
  }
  
  public static void checkAbsoluteDir(File file, String dirName)
    throws IllegalArgumentException
  {
    if (file == null) {
      throw new IllegalArgumentException(dirName + " is null");
    }
    if (!file.isAbsolute()) {
      throw new IllegalArgumentException(dirName + " is not absolute path. file=" + file.getAbsolutePath());
    }
    if (!file.isDirectory()) {
      throw new IllegalArgumentException(dirName + " is not directory. file=" + file.getAbsolutePath());
    }
  }
  
  public static void checkAbsoluteFile(File file, String dirName)
  {
    if (file == null) {
      throw new IllegalArgumentException(dirName + " is null");
    }
    if (!file.isAbsolute()) {
      throw new IllegalArgumentException(dirName + " is not absolute path. file=" + file.getAbsolutePath());
    }
    if (file.isDirectory()) {
      throw new IllegalArgumentException(dirName + " is not file but directory");
    }
  }
  
  public static URL checkFullUrl(URL url, String urlName)
    throws IllegalArgumentException
  {
    if (url == null) {
      throw new IllegalArgumentException(urlName + " is null");
    }
    if (!url.getProtocol().endsWith("file")) {
      return url;
    }
    File file = new File(url.getFile());
    if (!file.isAbsolute()) {
      throw new IllegalArgumentException(urlName + "(" + url + ") does not have absolute path");
    }
    if (file.getAbsolutePath().startsWith("/")) {
      return url;
    }
    try
    {
      return getUrl("file", null, "/" + file.getAbsolutePath());
    }
    catch (MalformedURLException localMalformedURLException)
    {
      throw new IllegalArgumentException(urlName + "(" + "file:" + "/" + file.getAbsolutePath() + ") is not fully quallified");
    }
  }
  
  private static Dictionary convertPluginManifest(File bundleLocation, boolean logConversionException)
  {
    try
    {
      PluginConverter converter = Activator.acquirePluginConverter();
      if (converter == null)
      {
        new RuntimeException("Unable to aquire PluginConverter service during generation for: " + bundleLocation).printStackTrace();
        return null;
      }
      return converter.convertManifest(bundleLocation, false, null, true, null);
    }
    catch (PluginConversionException convertException)
    {
      if (bundleLocation.getName().equals("feature.xml")) {
        return null;
      }
      if ((!new File(bundleLocation, "plugin.xml").exists()) && (!new File(bundleLocation, "fragment.xml").exists())) {
        return null;
      }
      if (logConversionException)
      {
        IStatus status = new Status(2, "org.eclipse.equinox.frameworkadmin", 0, "Error converting bundle manifest.", convertException);
        System.out.println(status);
      }
    }
    return null;
  }
  
  public static boolean createParentDir(File file)
  {
    File parent = file.getParentFile();
    if (parent == null) {
      return false;
    }
    if (parent.exists()) {
      return true;
    }
    return parent.mkdirs();
  }
  
  public static BundleInfo[] getBundleInfosFromList(List list)
  {
    if (list == null) {
      return new BundleInfo[0];
    }
    BundleInfo[] ret = new BundleInfo[list.size()];
    list.toArray(ret);
    return ret;
  }
  
  public static String[] getClauses(String header)
  {
    StringTokenizer token = new StringTokenizer(header, ",");
    List list = new LinkedList();
    while (token.hasMoreTokens()) {
      list.add(token.nextToken());
    }
    String[] ret = new String[list.size()];
    list.toArray(ret);
    return ret;
  }
  
  public static String[] getClausesManifestMainAttributes(URI location, String name)
  {
    return getClauses(getManifestMainAttributes(location, name));
  }
  
  public static String getManifestMainAttributes(URI location, String name)
  {
    Dictionary manifest = getOSGiManifest(location);
    if (manifest == null) {
      throw new RuntimeException("Unable to locate bundle manifest: " + location);
    }
    return (String)manifest.get(name);
  }
  
  public static Dictionary getOSGiManifest(URI location)
  {
    if (location == null) {
      return null;
    }
    if ("file".equals(location.getScheme())) {
      return basicLoadManifest(URIUtil.toFile(location));
    }
    try
    {
      URL url = new URL("jar:" + location.toString() + "!/");
      JarURLConnection jarConnection = (JarURLConnection)url.openConnection();
      ZipFile jar = jarConnection.getJarFile();
      try
      {
        ZipEntry entry = jar.getEntry("META-INF/MANIFEST.MF");
        if (entry == null) {
          return null;
        }
        Map manifest = ManifestElement.parseBundleManifest(jar.getInputStream(entry), null);
        Object localObject2;
        if (manifest.get("Bundle-SymbolicName") == null)
        {
          String jarName = jar.getName();
          File file = jarName != null ? new File(jarName) : null;
          if ((file != null) && (file.exists())) {
            return convertPluginManifest(file, true);
          }
          return null;
        }
        return manifestToProperties(manifest);
      }
      catch (BundleException localBundleException)
      {
        return null;
      }
      finally
      {
        jar.close();
      }
      return null;
    }
    catch (IOException e)
    {
      if (System.getProperty("osgi.debug") != null)
      {
        System.err.println("location=" + location);
        e.printStackTrace();
      }
    }
  }
  
  public static String getPathFromClause(String clause)
  {
    if (clause == null) {
      return null;
    }
    if (clause.indexOf(";") != -1) {
      clause = clause.substring(0, clause.indexOf(";"));
    }
    return clause.trim();
  }
  
  public static String getRelativePath(File target, File from)
  {
    String targetPath = replaceAll(target.getAbsolutePath(), File.separator, "/");
    String fromPath = replaceAll(from.getAbsolutePath(), File.separator, "/");
    
    String[] targetTokens = getTokens(targetPath, "/");
    String[] fromTokens = getTokens(fromPath, "/");
    int index = -1;
    for (int i = 0; i < fromTokens.length; i++)
    {
      if (!fromTokens[i].equals(targetTokens[i])) {
        break;
      }
      index = i;
    }
    StringBuffer sb = new StringBuffer();
    for (int i = index + 1; i < fromTokens.length; i++) {
      sb.append("../");
    }
    for (int i = index + 1; i < targetTokens.length; i++) {
      if (i != targetTokens.length - 1) {
        sb.append(targetTokens[i] + "/");
      } else {
        sb.append(targetTokens[i]);
      }
    }
    return sb.toString();
  }
  
  public static File getSimpleDataFormattedFile(File file)
  {
    SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
    String date = df.format(new Date());
    String filename = file.getName();
    int index = filename.lastIndexOf(".");
    if (index != -1) {
      filename = filename.substring(0, index) + "." + date + "." + filename.substring(index + 1);
    } else {
      filename = filename + "." + date;
    }
    File dest = new File(file.getParentFile(), filename);
    return dest;
  }
  
  public static String[] getTokens(String msg, String delim)
  {
    return getTokens(msg, delim, false);
  }
  
  public static String[] getTokens(String msg, String delim, boolean returnDelims)
  {
    StringTokenizer targetST = new StringTokenizer(msg, delim, returnDelims);
    String[] tokens = new String[targetST.countTokens()];
    ArrayList list = new ArrayList(targetST.countTokens());
    while (targetST.hasMoreTokens()) {
      list.add(targetST.nextToken());
    }
    list.toArray(tokens);
    return tokens;
  }
  
  public static URL getUrl(String protocol, String host, String file)
    throws MalformedURLException
  {
    file = replaceAll(file, File.separator, "/");
    return new URL(protocol, host, file);
  }
  
  public static URL getUrlInFull(String path, URL from)
    throws MalformedURLException
  {
    checkFullUrl(from, "from");
    path = replaceAll(path, File.separator, "/");
    
    String fromSt = removeLastCh(from.toExternalForm(), '/');
    if (path.startsWith("/"))
    {
      String fileSt = from.getFile();
      return new URL(fromSt.substring(0, fromSt.lastIndexOf(fileSt) - 1) + path);
    }
    return new URL(fromSt + "/" + path);
  }
  
  private static Properties manifestToProperties(Map d)
  {
    Iterator iter = d.keySet().iterator();
    Properties result = new Properties();
    while (iter.hasNext())
    {
      String key = (String)iter.next();
      result.put(key, d.get(key));
    }
    return result;
  }
  
  public static void printoutProperties(PrintStream ps, String name, Properties props)
  {
    if ((props == null) || (props.size() == 0))
    {
      ps.println("Props(" + name + ") is empty");
      return;
    }
    ps.println("Props(" + name + ")=");
    for (Enumeration enumeration = props.keys(); enumeration.hasMoreElements();)
    {
      String key = (String)enumeration.nextElement();
      ps.print("\tkey=" + key);
      ps.println("\tvalue=" + props.getProperty(key));
    }
  }
  
  public static String removeLastCh(String target, char ch)
  {
    while (target.charAt(target.length() - 1) == ch) {
      target = target.substring(0, target.length() - 1);
    }
    return target;
  }
  
  public static String replaceAll(String st, String oldSt, String newSt)
  {
    if (oldSt.equals(newSt)) {
      return st;
    }
    int index = -1;
    while ((index = st.indexOf(oldSt)) != -1) {
      st = st.substring(0, index) + newSt + st.substring(index + oldSt.length());
    }
    return st;
  }
  
  public static BundleInfo[] sortBundleInfos(BundleInfo[] bInfos, int initialBSL)
  {
    SortedMap bslToList = new TreeMap();
    for (int i = 0; i < bInfos.length; i++)
    {
      Integer sL = new Integer(bInfos[i].getStartLevel());
      if (sL.intValue() == -1) {
        sL = new Integer(initialBSL);
      }
      List list = (List)bslToList.get(sL);
      if (list == null)
      {
        list = new LinkedList();
        bslToList.put(sL, list);
      }
      list.add(bInfos[i]);
    }
    List bundleInfoList = new LinkedList();
    Iterator ite2;
    for (Iterator ite = bslToList.keySet().iterator(); ite.hasNext(); ite2.hasNext())
    {
      Integer sL = (Integer)ite.next();
      List list = (List)bslToList.get(sL);
      ite2 = list.iterator(); continue;
      BundleInfo bInfo = (
1 2

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2017. Infinite Loop Ltd