org.eclipse.pde.api.tools_1.0.301.v20111129-2053

Container$ArchiveApiTypeRoot(ArchiveApiTypeContainer container, String entryName)
  {
    super(container, entryName);
  }
  
  public String getTypeName()
  {
    if (fTypeName == null) {
      fTypeName = getName().replace('/', '.').substring(0, getName().length() - ".class".length());
    }
    return fTypeName;
  }
  
  public int compareTo(Object o)
  {
    return getTypeName().compareTo(((ArchiveApiTypeRoot)o).getTypeName());
  }
  
  public boolean equals(Object obj)
  {
    if ((obj instanceof ArchiveApiTypeRoot))
    {
      ArchiveApiTypeRoot classFile = (ArchiveApiTypeRoot)obj;
      return getName().equals(classFile.getName());
    }
    return false;
  }
  
  public int hashCode()
  {
    return getName().hashCode();
  }
  
  public byte[] getContents()
    throws CoreException
  {
    ArchiveApiTypeContainer archive = (ArchiveApiTypeContainer)getParent();
    try
    {
      zipFile = new ZipFile(fLocation);
    }
    catch (IOException e)
    {
      ZipFile zipFile;
      abort("Failed to open archive: " + fLocation, e);
      return null;
    }
    ZipFile zipFile;
    try
    {
      ZipEntry entry = zipFile.getEntry(getName());
      InputStream stream = null;
      if (entry != null)
      {
        try
        {
          stream = zipFile.getInputStream(entry);
        }
        catch (IOException e)
        {
          abort("Failed to open class file: " + getTypeName() + " in archive: " + fLocation, e);
          return null;
        }
        try
        {
          InputStream stream;
          ZipEntry entry;
          byte[] arrayOfByte = Util.getInputStreamAsByteArray(stream, -1);
          try
          {
            stream.close();
          }
          catch (IOException e)
          {
            ApiPlugin.log(e);
          }
          return arrayOfByte;
        }
        catch (IOException ioe)
        {
          InputStream stream;
          ZipEntry entry;
          abort("Unable to read class file: " + getTypeName(), ioe);
          try
          {
            stream.close();
          }
          catch (IOException e)
          {
            ApiPlugin.log(e);
          }
          return null;
        }
        finally
        {
          try
          {
            InputStream stream;
            ZipEntry entry;
            stream.close();
          }
          catch (IOException e)
          {
            ApiPlugin.log(e);
          }
        }
      }
    }
    finally
    {
      try
      {
        zipFile.close();
      }
      catch (IOException e)
      {
        abort("Failed to close class file archive", e);
      }
    }
    abort("Class file not found: " + getTypeName() + " in archive: " + fLocation, null);
    return null;
  }
  
  public String toString()
  {
    return getTypeName();
  }
}

/* Location:
 * Qualified Name:     org.eclipse.pde.api.tools.internal.model.ArchiveApiTypeContainer.ArchiveApiTypeRoot
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.pde.api.tools.internal.model;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.pde.api.tools.internal.provisional.ApiPlugin;
import org.eclipse.pde.api.tools.internal.provisional.model.ApiTypeContainerVisitor;
import org.eclipse.pde.api.tools.internal.provisional.model.IApiElement;
import org.eclipse.pde.api.tools.internal.provisional.model.IApiTypeContainer;
import org.eclipse.pde.api.tools.internal.provisional.model.IApiTypeRoot;
import org.eclipse.pde.api.tools.internal.util.Util;

public class ArchiveApiTypeContainer
  extends ApiElement
  implements IApiTypeContainer
{
  String fLocation;
  private Map fPackages;
  private String[] fPackageNames;
  
  static class ArchiveApiTypeRoot
    extends AbstractApiTypeRoot
    implements Comparable
  {
    private String fTypeName;
    
    public ArchiveApiTypeRoot(ArchiveApiTypeContainer container, String entryName)
    {
      super(entryName);
    }
    
    public String getTypeName()
    {
      if (fTypeName == null) {
        fTypeName = getName().replace('/', '.').substring(0, getName().length() - ".class".length());
      }
      return fTypeName;
    }
    
    public int compareTo(Object o)
    {
      return getTypeName().compareTo(((ArchiveApiTypeRoot)o).getTypeName());
    }
    
    public boolean equals(Object obj)
    {
      if ((obj instanceof ArchiveApiTypeRoot))
      {
        ArchiveApiTypeRoot classFile = (ArchiveApiTypeRoot)obj;
        return getName().equals(classFile.getName());
      }
      return false;
    }
    
    public int hashCode()
    {
      return getName().hashCode();
    }
    
    public byte[] getContents()
      throws CoreException
    {
      ArchiveApiTypeContainer archive = (ArchiveApiTypeContainer)getParent();
      try
      {
        zipFile = new ZipFile(fLocation);
      }
      catch (IOException e)
      {
        ZipFile zipFile;
        abort("Failed to open archive: " + fLocation, e);
        return null;
      }
      ZipFile zipFile;
      try
      {
        ZipEntry entry = zipFile.getEntry(getName());
        InputStream stream = null;
        if (entry != null)
        {
          try
          {
            stream = zipFile.getInputStream(entry);
          }
          catch (IOException e)
          {
            abort("Failed to open class file: " + getTypeName() + " in archive: " + fLocation, e);
            return null;
          }
          try
          {
            InputStream stream;
            ZipEntry entry;
            byte[] arrayOfByte = Util.getInputStreamAsByteArray(stream, -1);
            try
            {
              stream.close();
            }
            catch (IOException e)
            {
              ApiPlugin.log(e);
            }
            return arrayOfByte;
          }
          catch (IOException ioe)
          {
            InputStream stream;
            ZipEntry entry;
            abort("Unable to read class file: " + getTypeName(), ioe);
            try
            {
              stream.close();
            }
            catch (IOException e)
            {
              ApiPlugin.log(e);
            }
            return null;
          }
          finally
          {
            try
            {
              InputStream stream;
              ZipEntry entry;
              stream.close();
            }
            catch (IOException e)
            {
              ApiPlugin.log(e);
            }
          }
        }
      }
      finally
      {
        try
        {
          zipFile.close();
        }
        catch (IOException e)
        {
          abort("Failed to close class file archive", e);
        }
      }
      abort("Class file not found: " + getTypeName() + " in archive: " + fLocation, null);
      return null;
    }
    
    public String toString()
    {
      return getTypeName();
    }
  }
  
  public ArchiveApiTypeContainer(IApiElement parent, String path)
  {
    super(parent, 3, path);
    fLocation = path;
  }
  
  public void accept(ApiTypeContainerVisitor visitor)
    throws CoreException
  {
    if (visitor.visit(this))
    {
      init();
      List packages = new ArrayList(fPackages.keySet());
      Collections.sort(packages);
      Iterator iterator = packages.iterator();
      while (iterator.hasNext())
      {
        String pkg = (String)iterator.next();
        if (visitor.visitPackage(pkg))
        {
          List types = new ArrayList((Set)fPackages.get(pkg));
          Iterator cfIterator = types.iterator();
          List classFiles = new ArrayList(types.size());
          while (cfIterator.hasNext())
          {
            String entryName = (String)cfIterator.next();
            classFiles.add(new ArchiveApiTypeRoot(this, entryName));
          }
          Collections.sort(classFiles);
          cfIterator = classFiles.iterator();
          while (cfIterator.hasNext())
          {
            ArchiveApiTypeRoot classFile = (ArchiveApiTypeRoot)cfIterator.next();
            visitor.visit(pkg, classFile);
            visitor.end(pkg, classFile);
          }
        }
        visitor.endVisitPackage(pkg);
      }
    }
    visitor.end(this);
  }
  
  public String toString()
  {
    StringBuffer buff = new StringBuffer();
    buff.append("Archive Class File Container: " + getName());
    return buff.toString();
  }
  
  public synchronized void close()
    throws CoreException
  {}
  
  public IApiTypeRoot findTypeRoot(String qualifiedName)
    throws CoreException
  {
    init();
    int index = qualifiedName.lastIndexOf('.');
    String packageName = "";
    if (index >= 0) {
      packageName = qualifiedName.substring(0, index);
    }
    Set classFileNames = (Set)fPackages.get(packageName);
    if (classFileNames != null)
    {
      String fileName = qualifiedName.replace('.', '/') + ".class";
      if (classFileNames.contains(fileName)) {
        return new ArchiveApiTypeRoot(this, fileName);
      }
    }
    return null;
  }
  
  public String[] getPackageNames()
    throws CoreException
  {
    init();
    synchronized (this)
    {
      if (fPackageNames == null)
      {
        Set names = fPackages.keySet();
        String[] result = new String[names.size()];
        names.toArray(result);
        Arrays.sort(result);
        fPackageNames = result;
      }
      return fPackageNames;
    }
  }
  
  /* Error */
  private synchronized void init()
    throws CoreException
  {
    // Byte code:
    //   0: aload_0
    //   1: getfield 215	org/eclipse/pde/api/tools/internal/model/ArchiveApiTypeContainer:fPackages	Ljava/util/Map;
    //   4: ifnonnull +229 -> 233
    //   7: aload_0
    //   8: new 111	java/util/HashMap
    //   11: dup
    //   12: invokespecial 231	java/util/HashMap:<init>	()V
    //   15: putfield 215	org/eclipse/pde/api/tools/internal/model/ArchiveApiTypeContainer:fPackages	Ljava/util/Map;
    //   18: new 118	java/util/zip/ZipFile
    //   21: dup
    //   22: aload_0
    //   23: getfield 213	org/eclipse/pde/api/tools/internal/model/ArchiveApiTypeContainer:fLocation	Ljava/lang/String;
    //   26: invokespecial 235	java/util/zip/ZipFile:<init>	(Ljava/lang/String;)V
    //   29: astore_1
    //   30: goto +29 -> 59
    //   33: astore_2
    //   34: aload_0
    //   35: new 106	java/lang/StringBuffer
    //   38: dup
    //   39: ldc 5
    //   41: invokespecial 225	java/lang/StringBuffer:<init>	(Ljava/lang/String;)V
    //   44: aload_0
    //   45: getfield 213	org/eclipse/pde/api/tools/internal/model/ArchiveApiTypeContainer:fLocation	Ljava/lang/String;
    //   48: invokevirtual 226	java/lang/StringBuffer:append	(Ljava/lang/String;)Ljava/lang/StringBuffer;
    //   51: invokevirtual 224	java/lang/StringBuffer:toString	()Ljava/lang/String;
    //   54: aload_2
    //   55: invokevirtual 240	org/eclipse/pde/api/tools/internal/model/ArchiveApiTypeContainer:abort	(Ljava/lang/String;Ljava/lang/Throwable;)V
    //   58: return
    //   59: aload_1
    //   60: invokevirtual 236	java/util/zip/ZipFile:entries	()Ljava/util/Enumeration;
    //   63: astore_2
    //   64: goto +118 -> 182
    //   67: aload_2
    //   68: invokeinterface 250 1 0
    //   73: checkcast 117	java/util/zip/ZipEntry
    //   76: astore_3
    //   77: aload_3
    //   78: invokevirtual 233	java/util/zip/ZipEntry:getName	()Ljava/lang/String;
    //   81: astore 4
    //   83: aload 4
    //   85: ldc 2
    //   87: invokevirtual 221	java/lang/String:endsWith	(Ljava/lang/String;)Z
    //   90: ifeq +92 -> 182
    //   93: ldc 1
    //   95: astore 5
    //   97: aload 4
    //   99: bipush 47
    //   101: invokevirtual 217	java/lang/String:lastIndexOf	(I)I
    //   104: istore 6
    //   106: iload 6
    //   108: iflt +20 -> 128
    //   111: aload 4
    //   113: iconst_0
    //   114: iload 6
    //   116: invokevirtual 220	java/lang/String:substring	(II)Ljava/lang/String;
    //   119: bipush 47
    //   121: bipush 46
    //   123: invokevirtual 219	java/lang/String:replace	(CC)Ljava/lang/String;
    //   126: astore 5
    //   128: aload_0
    //   129: getfield 215	org/eclipse/pde/api/tools/internal/model/ArchiveApiTypeContainer:fPackages	Ljava/util/Map;
    //   132: aload 5
    //   134: invokeinterface 257 2 0
    //   139: checkcast 116	java/util/Set
    //   142: astore 7
    //   144: aload 7
    //   146: ifnonnull +26 -> 172
    //   149: new 112	java/util/HashSet
    //   152: dup
    //   153: invokespecial 232	java/util/HashSet:<init>	()V
    //   156: astore 7
    //   158: aload_0
    //   159: getfield 215	org/eclipse/pde/api/tools/internal/model/ArchiveApiTypeContainer:fPackages	Ljava/util/Map;
    //   162: aload 5
    //   164: aload 7
    //   166: invokeinterface 258 3 0
    //   171: pop
    //   172: aload 7
    //   174: aload 4
    //   176: invokeinterface 260 2 0
    //   181: pop
    //   182: aload_2
    //   183: invokeinterface 249 1 0
    //   188: ifne -121 -> 67
    //   191: goto +25 -> 216
    //   194: astore 8
    //   196: aload_1
    //   197: invokevirtual 234	java/util/zip/ZipFile:close	()V
    //   200: goto +13 -> 213
    //   203: astore 9
    //   205: aload_0
    //   206: ldc 4
    //   208: aload 9
    //   210: invokevirtual 240	org/eclipse/pde/api/tools/internal/model/ArchiveApiTypeContainer:abort	(Ljava/lang/String;Ljava/lang/Throwable;)V
    //   213: aload 8
    //   215: athrow
    //   216: aload_1
    //   217: invokevirtual 234	java/util/zip/ZipFile:close	()V
    //   220: goto +13 -> 233
    //   223: astore 9
    //   225: aload_0
    //   226: ldc 4
    //   228: aload 9
    //   230: invokevirtual 240	org/eclipse/pde/api/tools/internal/model/ArchiveApiTypeContainer:abort	(Ljava/lang/String;Ljava/lang/Throwable;)V
    //   233: return
    // Line number table:
    //   Java source line #272	-> byte code offset #0
    //   Java source line #273	-> byte code offset #7
    //   Java source line #276	-> byte code offset #18
    //   Java source line #277	-> byte code offset #33
    //   Java source line #278	-> byte code offset #34
    //   Java source line #279	-> byte code offset #58
    //   Java source line #282	-> byte code offset #59
    //   Java source line #283	-> byte code offset #64
    //   Java source line #284	-> byte code offset #67
    //   Java source line #285	-> byte code offset #77
    //   Java source line #286	-> byte code offset #83
    //   Java source line #287	-> byte code offset #93
    //   Java source line #288	-> byte code offset #97
    //   Java source line #289	-> byte code offset #106
    //   Java source line #290	-> byte code offset #111
    //   Java source line #292	-> byte code offset #128
    //   Java source line #293	-> byte code offset #144
    //   Java source line #294	-> byte code offset #149
    //   Java source line #295	-> byte code offset #158
    //   Java source line #297	-> byte code offset #172
    //   Java source line #283	-> byte code offset #182
    //   Java source line #300	-> byte code offset #194
    //   Java source line #302	-> byte code offset #196
    //   Java source line #303	-> byte code offset #203
    //   Java source line #304	-> byte code offset #205
    //   Java source line #306	-> byte code offset #213
    //   Java source line #302	-> byte code offset #216
    //   Java source line #303	-> byte code offset #223
    //   Java source line #304	-> byte code offset #225
    //   Java source line #308	-> byte code offset #233
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	234	0	this	ArchiveApiTypeContainer
    //   29	2	1	zipFile	ZipFile
    //   59	158	1	zipFile	ZipFile
    //   33	22	2	e	IOException
    //   63	120	2	entries	java.util.Enumeration
    //   76	2	3	entry	ZipEntry
    //   81	94	4	name	String
    //   95	68	5	pkg	String
    //   104	11	6	index	int
    //   142	31	7	fileNames	Set
    //   194	20	8	localObject	Object
    //   203	6	9	e	IOException
    //   223	6	9	e	IOException
    // Exception table:
    //   from	to	target	type
    //   18	30	33	java/io/IOException
    //   59	194	194	finally
    //   196	200	203	java/io/IOException
    //   216	220	223	java/io/IOException
  }
  
  public boolean equals(Object obj)
  {
    if ((obj instanceof ArchiveApiTypeContainer)) {
      return fLocation.equals(fLocation);
    }
    return false;
  }
  
  public int hashCode()
  {
    return fLocation.hashCode();
  }
  
  public IApiTypeRoot findTypeRoot(String qualifiedName, String id)
    throws CoreException
  {
    return findTypeRoot(qualifiedName);
  }
  
  public int getContainerType()
  {
    return 1;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.pde.api.tools.internal.model.ArchiveApiTypeContainer
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.pde.api.tools.internal.model;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Dictionary;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.jar.Manifest;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import javax.xml.parsers.FactoryConfigurationError;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
import org.eclipse.osgi.service.resolver.BundleDescription;
import org.eclipse.osgi.service.resolver.BundleSpecification;
import org.eclipse.osgi.service.resolver.ExportPackageDescription;
import org.eclipse.osgi.service.resolver.HostSpecification;
import org.eclipse.osgi.service.resolver.ResolverError;
import org.eclipse.osgi.service.resolver.State;
import org.eclipse.osgi.service.resolver.StateObjectFactory;
import org.eclipse.osgi.util.ManifestElement;
import org.eclipse.osgi.util.NLS;
import org.eclipse.pde.api.tools.internal.ApiDescription;
import org.eclipse.pde.api.tools.internal.ApiDescriptionProcessor;
import org.eclipse.pde.api.tools.internal.BundleVersionRange;
import org.eclipse.pde.api.tools.internal.CompositeApiDescription;
import org.eclipse.pde.api.tools.internal.RequiredComponentDescription;
import org.eclipse.pde.api.tools.internal.provisional.ApiPlugin;
import org.eclipse.pde.api.tools.internal.provisional.Factory;
import org.eclipse.pde.api.tools.internal.provisional.IApiDescription;
import org.eclipse.pde.api.tools.internal.provisional.IApiFilterStore;
import org.eclipse.pde.api.tools.internal.provisional.IRequiredComponentDescription;
import org.eclipse.pde.api.tools.internal.provisional.ProfileModifiers;
import org.eclipse.pde.api.tools.internal.provisional.descriptors.IPackageDescriptor;
import org.eclipse.pde.api.tools.internal.provisional.model.IApiBaseline;
import org.eclipse.pde.api.tools.internal.provisional.model.IApiComponent;
import org.eclipse.pde.api.tools.internal.provisional.model.IApiTypeContainer;
import org.eclipse.pde.api.tools.internal.util.FileManager;
import org.eclipse.pde.api.tools.internal.util.SourceDefaultHandler;
import org.eclipse.pde.api.tools.internal.util.Util;
import org.eclipse.pde.internal.core.TargetWeaver;
import org.osgi.framework.BundleException;
import org.osgi.framework.Version;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

public class BundleComponent
  extends Component
{
  static final String TMP_API_FILE_PREFIX = "api";
  static final String TMP_API_FILE_POSTFIX = "tmp";
  private Dictionary fManifest;
  private static final String[] MANIFEST_HEADERS = {
    "Eclipse-SourceBundle", 
    "Bundle-ClassPath", 
    "Bundle-Name", 
    "Bundle-Version" };
  private boolean fHasApiDescription = false;
  private String fLocation;
  private BundleDescription fBundleDescription;
  private String fSymbolicName = null;
  private Version fVersion = null;
  private String[] lowestEEs;
  private boolean fWorkspaceBinary = false;
  private long fBundleId = 0L;
  
  public BundleComponent(IApiBaseline baseline, String location, long bundleid)
    throws CoreException
  {
    super(baseline);
    fLocation = location;
    fBundleId = bundleid;
    fWorkspaceBinary = ((isBinary()) && ("workspace".equals(baseline.getName())));
  }
  
  /* Error */
  public void dispose()
  {
    // Byte code:
    //   0: aload_0
    //   1: invokespecial 939	org/eclipse/pde/api/tools/internal/model/Component:dispose	()V
    //   4: goto +28 -> 32
    //   7: astore_1
    //   8: aload_0
    //   9: dup
    //   10: astore_2
    //   11: monitorenter
    //   12: aload_0
    //   13: aconst_null
    //   14: putfield 817	org/eclipse/pde/api/tools/internal/model/BundleComponent:fManifest	Ljava/util/Dictionary;
    //   17: aload_0
    //   18: aconst_null
    //   19: putfield 818	org/eclipse/pde/api/tools/internal/model/BundleComponent:fBundleDescription	Lorg/eclipse/osgi/service/resolver/BundleDescription;
    //   22: aload_2
    //   23: monitorexit
    //   24: goto +6 -> 30
    //   27: aload_2
    //   28: monitorexit
    //   29: athrow
    //   30: aload_1
    //   31: athrow
    //   32: aload_0
    //   33: dup
    //   34: astore_2
    //   35: monitorenter
    //   36: aload_0
    //   37: aconst_null
    //   38: putfield 817	org/eclipse/pde/api/tools/internal/model/BundleComponent:fManifest	Ljava/util/Dictionary;
    //   41: aload_0
    //   42: aconst_null
    //   43: putfield 818	org/eclipse/pde/api/tools/internal/model/BundleComponent:fBundleDescription	Lorg/eclipse/osgi/service/resolver/BundleDescription;
    //   46: aload_2
    //   47: monitorexit
    //   48: goto +6 -> 54
    //   51: aload_2
    //   52: monitorexit
    //   53: athrow
    //   54: return
    // Line number table:
    //   Java source line #172	-> byte code offset #0
    //   Java source line #173	-> byte code offset #7
    //   Java source line #174	-> byte code offset #8
    //   Java source line #175	-> byte code offset #12
    //   Java source line #176	-> byte code offset #17
    //   Java source line #174	-> byte code offset #22
    //   Java source line #178	-> byte code offset #30
    //   Java source line #174	-> byte code offset #32
    //   Java source line #175	-> byte code offset #36
    //   Java source line #176	-> byte code offset #41
    //   Java source line #174	-> byte code offset #46
    //   Java source line #179	-> byte code offset #54
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	55	0	this	BundleComponent
    //   7	24	1	localObject1	Object
    // Exception table:
    //   from	to	target	type
    //   0	7	7	finally
    //   12	24	27	finally
    //   27	29	27	finally
    //   36	48	51	finally
    //   51	53	51	finally
  }
  
  protected synchronized Dictionary getManifest()
    throws CoreException
  {
    if (fManifest == null) {
      try
      {
        fManifest = ((Dictionary)loadManifest(new File(fLocation)));
      }
      catch (IOException e)
      {
        abort("Unable to load manifest due to IO error", e);
      }
    }
    return fManifest;
  }
  
  protected synchronized void doManifestCompaction()
  {
    Dictionary temp = fManifest;
    fManifest = new Hashtable(MANIFEST_HEADERS.length, 1.0F);
    for (int i = 0; i < MANIFEST_HEADERS.length; i++)
    {
      String header = MANIFEST_HEADERS[i];
      Object value = temp.get(header);
      if (value != null) {
        fManifest.put(header, value);
      }
    }
  }
  
  public boolean isValidBundle()
    throws CoreException
  {
    Dictionary manifest = getManifest();
    return (manifest != null) && (manifest.get("Bundle-Name") != null) && (manifest.get("Bundle-Version") != null);
  }
  
  public boolean equals(Object obj)
  {
    if ((obj instanceof BundleComponent))
    {
      BundleComponent comp = (BundleComponent)obj;
      
      return (getName().equals(comp.getName())) && (getSymbolicName().equals(comp.getSymbolicName())) && (getVersion().equals(comp.getVersion()));
    }
    return false;
  }
  
  protected synchronized void init()
  {
    if (fBundleDescription != null) {
      return;
    }
    try
    {
      Dictionary manifest = getManifest();
      if (isWorkspaceBinary()) {
        TargetWeaver.weaveManifest(manifest);
      }
      fBundleDescription = getBundleDescription(manifest, fLocation, fBundleId);
      if (fBundleDescription == null) {
        ApiPlugin.log(new Status(
          4, 
          "org.eclipse.pde.api.tools", 
          "Unable to resolve the BundleDescription for the component from: " + fLocation, 
          null));
      }
      fSymbolicName = fBundleDescription.getSymbolicName();
      fVersion = fBundleDescription.getVersion();
      setName((String)manifest.get("Bundle-Name"));
    }
    catch (BundleException e)
    {
      ApiPlugin.log(new Status(
        4, 
        "org.eclipse.pde.api.tools", 
        "Unable to create API component from specified location: " + fLocation, 
        e));
    }
    catch (CoreException ce)
    {
      ApiPlugin.log(ce);
    }
    doManifestCompaction();
  }
  
  public boolean isWorkspaceBinary()
  {
    return fWorkspaceBinary;
  }
  
  protected State getState()
  {
    return ((ApiBaseline)getBaseline()).getState();
  }
  
  protected BundleDescription getBundleDescription(Dictionary manifest, String location, long id)
    throws BundleException
  {
    State state = getState();
    BundleDescription bundle = lookupBundle(state, manifest);
    if (bundle != null) {
      return bundle;
    }
    StateObjectFactory factory = StateObjectFactory.defaultFactory;
    bundle = factory.createBundleDescription(state, manifest, fLocation, id);
    state.addBundle(bundle);
    return bundle;
  }
  
  protected BundleDescription lookupBundle(State state, Dictionary manifest)
    throws BundleException
  {
    Version version = null;
    try
    {
      String ver = (String)manifest.get("Bundle-Version");
      version = ver != null ? new Version(ver) : null;
    }
    catch (NumberFormatException localNumberFormatException) {}
    ManifestElement[] name = ManifestElement.parseHeader("Bundle-SymbolicName", (String)manifest.get("Bundle-SymbolicName"));
    if (name.length < 1) {
      return null;
    }
    return state.getBundle(name[0].getValue(), version);
  }
  
  protected boolean isBinary()
  {
    return true;
  }
  
  protected IApiDescription createApiDescription()
    throws CoreException
  {
    BundleDescription[] fragments = getBundleDescription().getFragments();
    if (fragments.length == 0) {
      return createLocalApiDescription();
    }
    ArrayList descriptions = new ArrayList(fragments.length);
    descriptions.add(createLocalApiDescription());
    IApiComponent component = null;
    for (int i = 0; i < fragments.length; i++) {
      if (fragments[i].isResolved())
      {
        component = getBaseline().getApiComponent(fragments[i].getSymbolicName());
        if (component != null) {
          descriptions.add(component.getApiDescription());
        } else {
          ApiPlugin.log(new Status(
            2, 
            "org.eclipse.pde.api.tools", 
            NLS.bind(Messages.BundleComponent_failed_to_lookup_fragment, fragments[i].getSymbolicName())));
        }
      }
    }
    return new CompositeApiDescription((IApiDescription[])descriptions.toArray(new IApiDescription[descriptions.size()]));
  }
  
  protected IApiDescription createLocalApiDescription()
    throws CoreException
  {
    IApiDescription apiDesc = new ApiDescription(getSymbolicName());
    
    initializeApiDescription(apiDesc, getBundleDescription(), getLocalPackageNames());
    try
    {
      String xml = loadApiDescription(new File(fLocation));
      setHasApiDescription(xml != null);
      if (xml != null) {
        ApiDescriptionProcessor.annotateApiSettings(null, apiDesc, xml);
      }
    }
    catch (IOException e)
    {
      abort("Unable to load .api_description file ", e);
    }
    return apiDesc;
  }
  
  protected Set getLocalPackageNames()
    throws CoreException
  {
    Set names = new HashSet();
    IApiTypeContainer[] containers = getApiTypeContainers();
    IApiComponent comp = null;
    for (int i = 0; i < containers.length; i++)
    {
      comp = (IApiComponent)containers[i].getAncestor(1);
      if ((comp != null) && (comp.getSymbolicName().equals(getSymbolicName())))
      {
        String[] packageNames = containers[i].getPackageNames();
        for (int j = 0; j < packageNames.length; j++) {
          names.add(packageNames[j]);
        }
      }
    }
    return names;
  }
  
  public static void initializeApiDescription(IApiDescription apiDesc, BundleDescription bundle, Set packages)
    throws CoreException
  {
    Iterator iterator = packages.iterator();
    while (iterator.hasNext())
    {
      String name = (String)iterator.next();
      apiDesc.setVisibility(Factory.packageDescriptor(name), 2);
    }
    List supplied = new ArrayList();
    ExportPackageDescription[] exportPackages = bundle.getExportPackages();
    addSuppliedPackages(packages, supplied, exportPackages);
    HostSpecification host = bundle.getHost();
    if (host != null)
    {
      BundleDescription[] hosts = host.getHosts();
      for (int i = 0; i < hosts.length; i++) {
        addSuppliedPackages(packages, supplied, hosts[i].getExportPackages());
      }
    }
    BundleDescription[] fragments = bundle.getFragments();
    for (int i = 0; i < fragments.length; i++) {
      if (fragments[i].isResolved()) {
        addSuppliedPackages(packages, supplied, fragments[i].getExportPackages());
      }
    }
    annotateExportedPackages(apiDesc, (ExportPackageDescription[])supplied.toArray(new ExportPackageDescription[supplied.size()]));
  }
  
  protected static void addSuppliedPackages(Set packages, List supplied, ExportPackageDescription[] exportPackages)
  {
    for (int i = 0; i < exportPackages.length; i++)
    {
      ExportPackageDescription pkg = exportPackages[i];
      String name = pkg.getName();
      if (name.equals(".")) {
        name = "";
      }
      if (packages.contains(name)) {
        supplied.add(pkg);
      }
    }
  }
  
  protected static void annotateExportedPackages(IApiDescription apiDesc, ExportPackageDescription[] exportedPackages)
  {
    for (int i = 0; i < exportedPackages.length; i++)
    {
      ExportPackageDescription pkg = exportedPackages[i];
      boolean internal = ((Boolean)pkg.getDirective("x-internal")).booleanValue();
      String[] friends = (String[])pkg.getDirective("x-friends");
      String pkgName = pkg.getName();
      if (pkgName.equals(".")) {
        pkgName = "";
      }
      IPackageDescriptor pkgDesc = Factory.packageDescriptor(pkgName);
      if (internal) {
        apiDesc.setVisibility(pkgDesc, 2);
      }
      if (friends != null)
      {
        apiDesc.setVisibility(pkgDesc, 2);
        for (int j = 0; j < friends.length; j++) {
          apiDesc.setAccessLevel(
            Factory.componentDescriptor(friends[j]), 
            Factory.packageDescriptor(pkgName), 
            1);
        }
      }
      if ((!internal) && (friends == null)) {
        apiDesc.setVisibility(pkgDesc, 1);
      }
    }
  }
  
  protected IApiFilterStore createApiFilterStore()
    throws CoreException
  {
    return null;
  }
  
  protected synchronized List createApiTypeContainers()
    throws CoreException
  {
    List containers = new ArrayList(5);
    try
    {
      List all = new ArrayList();
      
      all.add(this);
      boolean considerFragments = true;
      if ("org.eclipse.swt".equals(getSymbolicName())) {
        considerFragments = !isApiEnabled();
      }
      if (considerFragments)
      {
        BundleDescription[] fragments = getBundleDescription().getFragments();
        IApiComponent component = null;
        for (int i = 0; i < fragments.length; i++) {
          if (fragments[i].isResolved())
          {
            component = getBaseline().getApiComponent(fragments[i].getSymbolicName());
            if (component != null)
            {
              component.getApiTypeContainers();
              all.add(component);
            }
          }
        }
      }
      Iterator iterator = all.iterator();
      Set entryNames = new HashSet(5);
      BundleComponent other = null;
      String[] paths;
      int i;
      for (; iterator.hasNext(); i < paths.length)
      {
        BundleComponent component = (BundleComponent)iterator.next();
        paths = getClasspathEntries(component.getManifest());
        i = 0; continue;
        String path = paths[i];
        if ((".".equals(path)) || 
          (!entryNames.contains(path)))
        {
          IApiTypeContainer container = component.createApiTypeContainer(path);
          if (container == null) {
            for (Iterator iter = all.iterator(); iter.hasNext();)
            {
              other = (BundleComponent)iter.next();
              if (other != component) {
                container = other.createApiTypeContainer(path);
              }
            }
          }
          if (container != null)
          {
            containers.add(container);
            if (!".".equals(path)) {
              entryNames.add(path);
            }
          }
        }
        i++;
      }
    }
    catch (BundleException e)
    {
      abort("Unable to parse bundle classpath", e);
    }
    catch (IOException e)
    {
      abort("Unable to initialize class file containers", e);
    }
    return containers;
  }
  
  protected boolean isApiEnabled()
  {
    return false;
  }
  
  protected String[] getClasspathEntries(Dictionary manifest)
    throws BundleException
  {
    ManifestElement[] classpath = ManifestElement.parseHeader("Bundle-ClassPath", (String)manifest.get("Bundle-ClassPath"));
    String[] elements = (String[])null;
    if (classpath == null)
    {
      elements = new String[] { "." };
    }
    else
    {
      elements = new String[classpath.length];
      for (int i = 0; i < classpath.length; i++) {
        elements[i] = classpath[i].getValue();
      }
    }
    return elements;
  }
  
  protected IApiTypeContainer createApiTypeContainer(String path)
    throws IOException, CoreException
  {
    File bundle = new File(fLocation);
    if (bundle.isDirectory())
    {
      File entry = new File(bundle, path);
      if (entry.exists())
      {
        if (entry.isFile()) {
          return new ArchiveApiTypeContainer(this, entry.getCanonicalPath());
        }
        return new DirectoryApiTypeContainer(this, entry.getCanonicalPath());
      }
    }
    else
    {
      ZipFile zip = null;
      try
      {
        Object localObject2;
        if (path.equals(".")) {
          return new ArchiveApiTypeContainer(this, fLocation);
        }
        zip = new ZipFile(fLocation);
        ZipEntry entry = zip.getEntry(path);
        if (entry != null)
        {
          File tmpfolder = new File(System.getProperty("java.io.tmpdir"));
          if (entry.isDirectory())
          {
            File dir = Util.createTempFile("api", "tmp");
            if (dir.delete())
            {
              dir.mkdir();
              FileManager.getManager().recordTempFileRoot(dir.getCanonicalPath());
            }
            extractDirectory(zip, entry.getName(), dir);
            if ((dir.isDirectory()) && (dir.exists())) {
              return new DirectoryApiTypeContainer(this, dir.getCanonicalPath());
            }
          }
          else
          {
            File tmpfolder;
            ZipEntry entry;
            File file = extractEntry(zip, entry, tmpfolder);
            if (Util.isArchive(file.getName()))
            {
              File parent = file.getParentFile();
              if (!parent.equals(tmpfolder)) {
                FileManager.getManager().recordTempFileRoot(parent.getCanonicalPath());
              } else {
                FileManager.getManager().recordTempFileRoot(file.getCanonicalPath());
              }
              return new ArchiveApiTypeContainer(this, file.getCanonicalPath());
            }
          }
        }
      }
      finally
      {
        if (zip != null) {
          zip.close();
        }
      }
      if (zip != null) {
        zip.close();
      }
    }
    return null;
  }
  
  void extractDirectory(ZipFile zip, String pathprefix, File parent)
    throws IOException
  {
    Enumeration entries = zip.entries();
    String prefix = pathprefix == null ? "" : pathprefix;
    ZipEntry entry = null;
    File file = null;
    while (entries.hasMoreElements())
    {
      entry = (ZipEntry)entries.nextElement();
      if (entry.getName().startsWith(prefix))
      {
        file = new File(parent, entry.getName());
        if (entry.isDirectory()) {
          file.mkdir();
        } else {
          extractEntry(zip, entry, parent);
        }
      }
    }
  }
  
  /* Error */
  File extractEntry(ZipFile zip, ZipEntry entry, File parent)
    throws IOException
  {
    // Byte code:
    //   0: aconst_null
    //   1: astore 4
    //   3: aconst_null
    //   4: astore 6
    //   6: aload_1
    //   7: aload_2
    //   8: invokevirtual 878	java/util/zip/ZipFile:getInputStream	(Ljava/util/zip/ZipEntry;)Ljava/io/InputStream;
    //   11: astore 4
    //   13: new 443	java/io/File
    //   16: dup
    //   17: aload_3
    //   18: aload_2
    //   19: invokevirtual 873	java/util/zip/ZipEntry:getName	()Ljava/lang/String;
    //   22: invokespecial 835	java/io/File:<init>	(Ljava/io/File;Ljava/lang/String;)V
    //   25: astore 5
    //   27: aload 5
    //   29: invokevirtual 829	java/io/File:getParentFile	()Ljava/io/File;
    //   32: astore 7
    //   34: aload 7
    //   36: invokevirtual 824	java/io/File:exists	()Z
    //   39: ifne +9 -> 48
    //   42: aload 7
    //   44: invokevirtual 828	java/io/File:mkdirs	()Z
    //   47: pop
    //   48: new 445	java/io/FileOutputStream
    //   51: dup
    //   52: aload 5
    //   54: invokespecial 839	java/io/FileOutputStream:<init>	(Ljava/io/File;)V
    //   57: astore 6
    //   59: sipush 8096
    //   62: newarray <illegal type>
    //   64: astore 8
    //   66: goto +27 -> 93
    //   69: aload 4
    //   71: aload 8
    //   73: invokevirtual 842	java/io/InputStream:read	([B)I
    //   76: istore 9
    //   78: iload 9
    //   80: ifle +13 -> 93
    //   83: aload 6
    //   85: aload 8
    //   87: iconst_0
    //   88: iload 9
    //   90: invokevirtual 838	java/io/FileOutputStream:write	([BII)V
    //   93: aload 4
    //   95: invokevirtual 840	java/io/InputStream:available	()I
    //   98: ifgt -29 -> 69
    //   101: goto +48 -> 149
    //   104: astore 10
    //   106: aload 4
    //   108: ifnull +18 -> 126
    //   111: aload 4
    //   113: invokevirtual 841	java/io/InputStream:close	()V
    //   116: goto +10 -> 126
    //   119: astore 11
    //   121: aload 11
    //   123: invokestatic 942	org/eclipse/pde/api/tools/internal/provisional/ApiPlugin:log	(Ljava/lang/Throwable;)V
    //   126: aload 6
    //   128: ifnull +18 -> 146
    //   131: aload 6
    //   133: invokevirtual 837	java/io/FileOutputStream:close	()V
    //   136: goto +10 -> 146
    //   139: astore 11
    //   141: aload 11
    //   143: invokestatic 942	org/eclipse/pde/api/tools/internal/provisional/ApiPlugin:log	(Ljava/lang/Throwable;)V
    //   146: aload 10
    //   148: athrow
    //   149: aload 4
    //   151: ifnull +18 -> 169
    //   154: aload 4
    //   156: invokevirtual 841	java/io/InputStream:close	()V
 
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55

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-2019. Infinite Loop Ltd