org.eclipse.pde.core_3.7.1.v20120103_r372

thHeader)header).addLibrary(library.getName());
    } else {
      addLibrary(library, header);
    }
    fireStructureChanged(library, true);
  }
  
  private void addLibrary(IPluginLibrary library, IManifestHeader header)
  {
    String value = header == null ? null : header.getValue();
    StringBuffer buffer = new StringBuffer(value == null ? "" : value);
    if (value != null) {
      buffer.append(",\n ");
    }
    buffer.append(library.getName());
    getBundle().setHeader("Bundle-ClassPath", buffer.toString());
  }
  
  private void removeLibrary(IPluginLibrary library, IManifestHeader header)
  {
    String value = header == null ? null : header.getValue();
    String name = library.getName();
    int index = value.indexOf(name);
    if (index >= 0)
    {
      StringBuffer buffer = new StringBuffer();
      for (int i = 0; i > index; i++) {
        buffer.append(value.charAt(i));
      }
      int after = index + name.length();
      if (after < value.length()) {
        while (value.charAt(after) == ',') {
          after++;
        }
      }
      if (after < value.length()) {
        while (Character.isWhitespace(value.charAt(after))) {
          after++;
        }
      }
      while (after < value.length())
      {
        buffer.append(value.charAt(after));
        after++;
      }
      getBundle().setHeader("Bundle-ClassPath", buffer.toString());
    }
  }
  
  public void remove(IPluginLibrary library)
    throws CoreException
  {
    ensureModelEditable();
    if (libraries != null)
    {
      libraries.remove(library);
      IManifestHeader header = getManifestHeader("Bundle-ClassPath");
      if ((header instanceof BundleClasspathHeader)) {
        ((BundleClasspathHeader)header).removeLibrary(library.getName());
      } else if (header != null) {
        removeLibrary(library, header);
      }
      fireStructureChanged(library, false);
    }
  }
  
  public void add(IPluginImport iimport)
    throws CoreException
  {
    ensureModelEditable();
    if (iimport == null) {
      return;
    }
    if (imports == null) {
      getImports();
    }
    addImport(iimport);
    fireStructureChanged(iimport, true);
  }
  
  public void add(IPluginImport[] iimports)
    throws CoreException
  {
    ensureModelEditable();
    if ((iimports != null) && (iimports.length > 0))
    {
      if (imports == null) {
        getImports();
      }
      for (int i = 0; i < iimports.length; i++) {
        if (iimports[i] != null) {
          addImport(iimports[i]);
        }
      }
      fireStructureChanged(iimports, true);
    }
  }
  
  private void addImport(IPluginImport iimport)
  {
    imports.add(iimport);
    Object header = getManifestHeader("Require-Bundle");
    if ((header instanceof RequireBundleHeader))
    {
      ((RequireBundleHeader)header).addBundle(iimport);
    }
    else
    {
      String value = header == null ? null : ((IManifestHeader)header).getValue();
      StringBuffer buffer = new StringBuffer(value == null ? "" : value);
      if (value != null) {
        buffer.append(",\n ");
      }
      buffer.append(iimport.getId());
      int bundleManifestVersion = getBundleManifestVersion(getBundle());
      if (iimport.isOptional()) {
        if (bundleManifestVersion > 1) {
          buffer.append(";resolution:=optional");
        } else {
          buffer.append(";optional=true");
        }
      }
      if (iimport.isReexported()) {
        if (bundleManifestVersion > 1) {
          buffer.append(";visibility:=reexport");
        } else {
          buffer.append(";reprovide=true");
        }
      }
      String version = iimport.getVersion();
      if ((version != null) && (version.trim().length() > 0)) {
        buffer.append(";bundle-version=\"" + version.trim() + "\"");
      }
      getBundle().setHeader("Require-Bundle", buffer.toString());
    }
  }
  
  public void remove(IPluginImport pluginImport)
    throws CoreException
  {
    ensureModelEditable();
    if (imports != null)
    {
      imports.remove(pluginImport);
      Object header = getManifestHeader("Require-Bundle");
      if ((header instanceof RequireBundleHeader)) {
        ((RequireBundleHeader)header).removeBundle(pluginImport.getId());
      }
      fireStructureChanged(pluginImport, false);
    }
  }
  
  public void remove(IPluginImport[] pluginImports)
    throws CoreException
  {
    ensureModelEditable();
    if (imports != null)
    {
      for (int i = 0; i < pluginImports.length; i++)
      {
        imports.remove(pluginImports[i]);
        Object header = getManifestHeader("Require-Bundle");
        if ((header instanceof RequireBundleHeader)) {
          ((RequireBundleHeader)header).removeBundle(pluginImports[i].getId());
        }
      }
      fireStructureChanged(pluginImports, false);
    }
  }
  
  public IPluginLibrary[] getLibraries()
  {
    IBundle bundle = getBundle();
    if (bundle == null) {
      return new IPluginLibrary[0];
    }
    if (libraries == null)
    {
      libraries = new ArrayList();
      String value = bundle.getHeader("Bundle-ClassPath");
      if (value != null) {
        try
        {
          ManifestElement[] elements = ManifestElement.parseHeader("Bundle-ClassPath", value);
          for (int i = 0; i < elements.length; i++)
          {
            PluginLibrary library = new PluginLibrary();
            library.setModel(getModel());
            library.setInTheModel(true);
            library.setParent(this);
            library.load(elements[i].getValue());
            libraries.add(library);
          }
        }
        catch (BundleException localBundleException) {}
      }
    }
    return (IPluginLibrary[])libraries.toArray(new IPluginLibrary[libraries.size()]);
  }
  
  public IPluginImport[] getImports()
  {
    if (imports == null)
    {
      imports = new ArrayList();
      BundleDescription description = model.getBundleDescription();
      if (description != null)
      {
        BundleSpecification[] required = description.getRequiredBundles();
        for (int i = 0; i < required.length; i++)
        {
          PluginImport importElement = new PluginImport();
          importElement.setModel(getModel());
          importElement.setInTheModel(true);
          importElement.setParent(this);
          imports.add(importElement);
          importElement.load(required[i]);
        }
        BundleDescription[] imported = PDEStateHelper.getImportedBundles(description);
        for (int i = 0; i < imported.length; i++)
        {
          PluginImport importElement = new PluginImport();
          importElement.setModel(getModel());
          importElement.setInTheModel(true);
          importElement.setParent(this);
          imports.add(importElement);
          importElement.load(imported[i]);
        }
      }
      else
      {
        IBundle bundle = getBundle();
        if (bundle != null) {
          try
          {
            String value = bundle.getHeader("Require-Bundle");
            int bundleManifestVersion = getBundleManifestVersion(bundle);
            if (value != null)
            {
              ManifestElement[] elements = ManifestElement.parseHeader("Require-Bundle", value);
              for (int i = 0; i < elements.length; i++)
              {
                PluginImport importElement = new PluginImport();
                importElement.setModel(getModel());
                importElement.setInTheModel(true);
                importElement.setParent(this);
                imports.add(importElement);
                importElement.load(elements[i], bundleManifestVersion);
              }
            }
          }
          catch (BundleException localBundleException) {}
        }
      }
    }
    return (IPluginImport[])imports.toArray(new IPluginImport[imports.size()]);
  }
  
  public String getProviderName()
  {
    IBundle bundle = getBundle();
    return bundle == null ? null : bundle.getHeader("Bundle-Vendor");
  }
  
  public void setProviderName(String providerName)
    throws CoreException
  {
    ensureModelEditable();
    IBundle bundle = getBundle();
    if (bundle != null)
    {
      String old = getProviderName();
      IManifestHeader header = bundle.getManifestHeader("Bundle-Vendor");
      if ((header instanceof BundleVendorHeader)) {
        ((BundleVendorHeader)header).setVendor(providerName);
      } else {
        bundle.setHeader("Bundle-Vendor", providerName);
      }
      model.fireModelObjectChanged(this, "provider-name", old, providerName);
    }
  }
  
  public String getVersion()
  {
    BundleDescription desc = model.getBundleDescription();
    if (desc != null)
    {
      Version version = desc.getVersion();
      return version != null ? version.toString() : null;
    }
    return getValue("Bundle-Version", false);
  }
  
  public void setVersion(String version)
    throws CoreException
  {
    ensureModelEditable();
    IBundle bundle = getBundle();
    if (bundle != null)
    {
      String old = getVersion();
      IManifestHeader header = bundle.getManifestHeader("Bundle-Version");
      if ((header instanceof BundleVersionHeader)) {
        ((BundleVersionHeader)header).setVersionRange(version);
      } else {
        bundle.setHeader("Bundle-Version", version);
      }
      model.fireModelObjectChanged(this, "version", old, version);
    }
  }
  
  public void swap(IPluginLibrary l1, IPluginLibrary l2)
    throws CoreException
  {
    ensureModelEditable();
    if (libraries != null)
    {
      int index1 = libraries.indexOf(l1);
      int index2 = libraries.indexOf(l2);
      libraries.set(index1, l2);
      libraries.set(index2, l1);
      Object header = getManifestHeader("Bundle-ClassPath");
      if ((header instanceof BundleClasspathHeader)) {
        ((BundleClasspathHeader)header).swap(index1, index2);
      }
      model.fireModelObjectChanged(this, "import_order", l1, l2);
    }
  }
  
  protected void fireStructureChanged(Object object, boolean added)
  {
    int type = added ? 1 : 2;
    model.fireModelChanged(new ModelChangedEvent(model, type, new Object[] { object }, null));
  }
  
  protected void fireStructureChanged(Object[] objects, boolean added)
  {
    int type = added ? 1 : 2;
    model.fireModelChanged(new ModelChangedEvent(model, type, objects, null));
  }
  
  public void add(IPluginExtension extension)
    throws CoreException
  {
    ensureModelEditable();
    IExtensions extensions = getExtensionsRoot();
    if (extensions == null) {
      return;
    }
    extensions.add(extension);
    if ((getExtensions().length == 1) && (getExtensionPoints().length == 0)) {
      updateSingleton(true);
    }
  }
  
  public void add(IPluginExtensionPoint point)
    throws CoreException
  {
    ensureModelEditable();
    IExtensions extensions = getExtensionsRoot();
    if (extensions == null) {
      return;
    }
    extensions.add(point);
    if ((getExtensions().length == 0) && (getExtensionPoints().length == 1)) {
      updateSingleton(true);
    }
  }
  
  public String getResourceString(String key)
  {
    return model.getResourceString(key);
  }
  
  public IPluginExtensionPoint[] getExtensionPoints()
  {
    IExtensions extensions = getExtensionsRoot();
    if (extensions == null) {
      return new IPluginExtensionPoint[0];
    }
    return extensions.getExtensionPoints();
  }
  
  public IPluginExtension[] getExtensions()
  {
    IExtensions extensions = getExtensionsRoot();
    if (extensions == null) {
      return new IPluginExtension[0];
    }
    return extensions.getExtensions();
  }
  
  public int getIndexOf(IPluginExtension e)
  {
    IExtensions extensions = getExtensionsRoot();
    if (extensions == null) {
      return -1;
    }
    return extensions.getIndexOf(e);
  }
  
  public void remove(IPluginExtension extension)
    throws CoreException
  {
    ensureModelEditable();
    IExtensions extensions = getExtensionsRoot();
    if (extensions != null)
    {
      extensions.remove(extension);
      if ((getExtensions().length == 0) && (getExtensionPoints().length == 0)) {
        updateSingleton(false);
      }
    }
  }
  
  public void remove(IPluginExtensionPoint extensionPoint)
    throws CoreException
  {
    ensureModelEditable();
    IExtensions extensions = getExtensionsRoot();
    if (extensions != null)
    {
      extensions.remove(extensionPoint);
      if ((getExtensions().length == 0) && (getExtensionPoints().length == 0)) {
        updateSingleton(false);
      }
    }
  }
  
  protected void updateSingleton(boolean singleton)
  {
    IManifestHeader header = getManifestHeader("Bundle-SymbolicName");
    if ((header instanceof BundleSymbolicNameHeader))
    {
      ((BundleSymbolicNameHeader)header).setSingleton(singleton);
    }
    else if (singleton)
    {
      String version = getBundle().getHeader("Bundle-ManifestVersion");
      if (version == null) {
        version = "1";
      }
      String value = header.getValue();
      String singletonValue = null;
      if ((version != null) && (Integer.parseInt(version) >= 2)) {
        singletonValue = "singleton:=true";
      } else {
        singletonValue = "singleton=true";
      }
      if (value.indexOf(singletonValue) != -1) {
        return;
      }
      getBundle().setHeader("Bundle-SymbolicName", value + "; " + singletonValue);
    }
  }
  
  public void swap(IPluginExtension e1, IPluginExtension e2)
    throws CoreException
  {
    ensureModelEditable();
    IExtensions extensions = getExtensionsRoot();
    if (extensions != null) {
      extensions.swap(e1, e2);
    }
  }
  
  public void swap(IPluginImport import1, IPluginImport import2)
    throws CoreException
  {
    ensureModelEditable();
    if (imports != null)
    {
      int index1 = imports.indexOf(import1);
      int index2 = imports.indexOf(import2);
      imports.set(index1, import2);
      imports.set(index2, import1);
      Object header = getManifestHeader("Require-Bundle");
      if ((header instanceof RequireBundleHeader)) {
        ((RequireBundleHeader)header).swap(index1, index2);
      }
      model.fireModelObjectChanged(this, "import_order", import1, import2);
    }
  }
  
  public String getId()
  {
    return getValue("Bundle-SymbolicName", true);
  }
  
  protected String getValue(String key, boolean parse)
  {
    IBundle bundle = getBundle();
    if (bundle == null) {
      return null;
    }
    String value = bundle.getHeader(key);
    if ((value == null) || (!parse)) {
      return value;
    }
    try
    {
      ManifestElement[] elements = ManifestElement.parseHeader(key, value);
      if (elements.length > 0) {
        return elements[0].getValue();
      }
    }
    catch (BundleException localBundleException) {}
    return null;
  }
  
  public void setId(String id)
    throws CoreException
  {
    ensureModelEditable();
    IBundle bundle = getBundle();
    if (bundle != null)
    {
      String old = getId();
      IManifestHeader header = bundle.getManifestHeader("Bundle-SymbolicName");
      if ((header instanceof BundleSymbolicNameHeader)) {
        ((BundleSymbolicNameHeader)header).setId(id);
      } else {
        bundle.setHeader("Bundle-SymbolicName", id);
      }
      model.fireModelObjectChanged(this, "id", old, id);
    }
  }
  
  public IPluginModelBase getPluginModel()
  {
    return model;
  }
  
  public String getName()
  {
    return getValue("Bundle-Name", false);
  }
  
  public void setName(String name)
    throws CoreException
  {
    ensureModelEditable();
    IBundle bundle = getBundle();
    if (bundle != null)
    {
      String old = getName();
      IManifestHeader header = bundle.getManifestHeader("Bundle-Name");
      if ((header instanceof BundleNameHeader)) {
        ((BundleNameHeader)header).setBundleName(name);
      } else {
        bundle.setHeader("Bundle-Name", name);
      }
      model.fireModelObjectChanged(this, "name", old, name);
    }
  }
  
  public boolean isInTheModel()
  {
    return model != null;
  }
  
  public String getTranslatedName()
  {
    return getResourceString(getName());
  }
  
  public IPluginObject getParent()
  {
    return null;
  }
  
  public IPluginBase getPluginBase()
  {
    return this;
  }
  
  public boolean isValid()
  {
    IExtensions extensions = getExtensionsRoot();
    return (getBundle() != null) && (getBundle().getHeader("Bundle-SymbolicName") != null) && ((extensions == null) || (extensions.isValid()));
  }
  
  public void write(String indent, PrintWriter writer) {}
  
  public void setInTheModel(boolean inModel) {}
  
  public static int getBundleManifestVersion(IBundle bundle)
  {
    String version = bundle.getHeader("Bundle-ManifestVersion");
    if (version == null) {
      return 1;
    }
    try
    {
      return Integer.parseInt(version);
    }
    catch (NumberFormatException localNumberFormatException) {}
    return 1;
  }
  
  public void updateImport(IPluginImport iimport)
  {
    Object header = getManifestHeader("Require-Bundle");
    if (((header instanceof RequireBundleHeader)) && (imports != null)) {
      ((RequireBundleHeader)header).updateBundle(imports.indexOf(iimport), iimport);
    }
  }
  
  public String getTargetVersion()
  {
    return fTarget != null ? fTarget : TargetPlatformHelper.getTargetVersionString();
  }
  
  public void setTargetVersion(String target)
  {
    fTarget = target;
  }
  
  public int getIndexOf(IPluginImport targetImport)
  {
    if (imports == null) {
      return -1;
    }
    return imports.indexOf(targetImport);
  }
  
  public IPluginImport getPreviousImport(IPluginImport targetImport)
  {
    if (imports == null) {
      return null;
    }
    if (imports.size() <= 1) {
      return null;
    }
    int targetIndex = getIndexOf(targetImport);
    if (targetIndex < 0) {
      return null;
    }
    if (targetIndex == 0) {
      return null;
    }
    IPluginImport previousImport = (IPluginImport)imports.get(targetIndex - 1);
    
    return previousImport;
  }
  
  public IPluginImport getNextImport(IPluginImport targetImport)
  {
    if (imports == null) {
      return null;
    }
    if (imports.size() <= 1) {
      return null;
    }
    int targetIndex = getIndexOf(targetImport);
    
    int lastIndex = imports.size() - 1;
    if (targetIndex < 0) {
      return null;
    }
    if (targetIndex >= lastIndex) {
      return null;
    }
    IPluginImport nextImport = (IPluginImport)imports.get(targetIndex + 1);
    
    return nextImport;
  }
  
  public void add(IPluginImport iimport, int index)
    throws CoreException
  {
    ensureModelEditable();
    int importCount = 0;
    if (imports != null) {
      importCount = imports.size();
    }
    if (index < 0) {
      return;
    }
    if (index > importCount) {
      return;
    }
    if (imports == null)
    {
      getImports();
      
      addImport(iimport);
    }
    else
    {
      addImport(iimport, index);
    }
    fireStructureChanged(iimport, true);
  }
  
  private void addImport(IPluginImport iimport, int index)
  {
    IManifestHeader header = getManifestHeader("Require-Bundle");
    if (!(header instanceof RequireBundleHeader))
    {
      addImport(iimport);
    }
    else
    {
      imports.add(index, iimport);
      
      ((RequireBundleHeader)header).addBundle(iimport, index);
    }
  }
  
  public void add(IPluginLibrary library, int index)
    throws CoreException
  {
    ensureModelEditable();
    int libraryCount = 0;
    if (libraries != null) {
      libraryCount = libraries.size();
    }
    if (index < 0) {
      return;
    }
    if (index > libraryCount) {
      return;
    }
    if (libraries == null) {
      getLibraries();
    }
    IManifestHeader header = getManifestHeader("Bundle-ClassPath");
    if (!(header instanceof BundleClasspathHeader))
    {
      libraries.add(library);
      
      addLibrary(library, header);
    }
    else
    {
      libraries.add(index, library);
      
      ((BundleClasspathHeader)header).addLibrary(library.getName(), index);
    }
    fireStructureChanged(library, true);
  }
  
  public int getIndexOf(IPluginLibrary targetLibrary)
  {
    if (libraries == null) {
      return -1;
    }
    return libraries.indexOf(targetLibrary);
  }
  
  public IPluginLibrary getNextLibrary(IPluginLibrary targetLibrary)
  {
    if (libraries == null) {
      return null;
    }
    if (libraries.size() <= 1) {
      return null;
    }
    int targetIndex = getIndexOf(targetLibrary);
    
    int lastIndex = libraries.size() - 1;
    if (targetIndex < 0) {
      return null;
    }
    if (targetIndex >= lastIndex) {
      return null;
    }
    IPluginLibrary nextLibrary = (IPluginLibrary)libraries.get(targetIndex + 1);
    
    return nextLibrary;
  }
  
  public IPluginLibrary getPreviousLibrary(IPluginLibrary targetLibrary)
  {
    if (libraries == null) {
      return null;
    }
    if (libraries.size() <= 1) {
      return null;
    }
    int targetIndex = getIndexOf(targetLibrary);
    if (targetIndex < 0) {
      return null;
    }
    if (targetIndex == 0) {
      return null;
    }
    IPluginLibrary previousLibrary = (IPluginLibrary)libraries.get(targetIndex - 1);
    
    return previousLibrary;
  }
  
  protected void ensureModelEditable()
    throws CoreException
  {
    if (!getModel().isEditable()) {
      throwCoreException(PDECoreMessages.PluginObject_readOnlyChange);
    }
  }
  
  protected void throwCoreException(String message)
    throws CoreException
  {
    Status status = new Status(4, "org.eclipse.pde.core", 0, message, null);
    CoreException ce = new CoreException(status);
    ce.fillInStackTrace();
    throw ce;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.pde.internal.core.bundle.BundlePluginBase
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.pde.internal.core.bundle;

import org.eclipse.pde.core.plugin.IPlugin;
import org.eclipse.pde.core.plugin.IPluginBase;
import org.eclipse.pde.internal.core.ibundle.IBundlePluginModel;

public class BundlePluginModel
  extends BundlePluginModelBase
  implements IBundlePluginModel
{
  private static final long serialVersionUID = 1L;
  
  public IPluginBase createPluginBase()
  {
    BundlePlugin bplugin = new BundlePlugin();
    bplugin.setModel(this);
    return bplugin;
  }
  
  public IPlugin getPlugin()
  {
    return (IPlugin)getPluginBase();
  }
  
  public boolean isFragmentModel()
  {
    return false;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.pde.internal.core.bundle.BundlePluginModel
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.pde.internal.core.bundle;

import java.io.InputStream;
import java.io.PrintWriter;
import java.net.MalformedURLException;
import java.net.URL;
import org.eclipse.core.resources.IResource;
import org.eclipse.osgi.service.resolver.BundleDescription;
import org.eclipse.pde.core.IEditable;
import org.eclipse.pde.core.IEditableModel;
import org.eclipse.pde.core.IModelChangedEvent;
import org.eclipse.pde.core.build.IBuildModel;
import org.eclipse.pde.core.plugin.IExtensions;
import org.eclipse.pde.core.plugin.IExtensionsModelFactory;
import org.eclipse.pde.core.plugin.IPluginAttribute;
import org.eclipse.pde.core.plugin.IPluginBase;
import org.eclipse.pde.core.plugin.IPluginElement;
import org.eclipse.pde.core.plugin.IPluginExtension;
import org.eclipse.pde.core.plugin.IPluginExtensionPoint;
import org.eclipse.pde.core.plugin.IPluginImport;
import org.eclipse.pde.core.plugin.IPluginLibrary;
import org.eclipse.pde.core.plugin.IPluginModelFactory;
import org.eclipse.pde.core.plugin.IPluginObject;
import org.eclipse.pde.core.plugin.ISharedExtensionsModel;
import org.eclipse.pde.internal.core.AbstractNLModel;
import org.eclipse.pde.internal.core.NLResourceHelper;
import org.eclipse.pde.internal.core.PDEManager;
import org.eclipse.pde.internal.core.ibundle.IBundle;
import org.eclipse.pde.internal.core.ibundle.IBundleModel;
import org.eclipse.pde.internal.core.ibundle.IBundlePluginModelBase;
import org.eclipse.pde.internal.core.plugin.PluginImport;
import org.eclipse.pde.internal.core.plugin.PluginLibrary;
import org.eclipse.pde.internal.core.text.plugin.PluginModelBase;

public abstract class BundlePluginModelBase
  extends AbstractNLModel
  implements IBundlePluginModelBase, IPluginModelFactory
{
  private static final long serialVersionUID = 1L;
  private IBundleModel fBundleModel;
  private ISharedExtensionsModel fExtensionsModel;
  private BundlePluginBase fBundlePluginBase;
  private IBuildModel fBuildModel;
  private BundleDescription fBundleDescription;
  
  public BundlePluginModelBase()
  {
    getPluginBase();
  }
  
  public IBundleModel getBundleModel()
  {
    return fBundleModel;
  }
  
  public IResource getUnderlyingResource()
  {
    return fBundleModel.getUnderlyingResource();
  }
  
  public ISharedExtensionsModel getExtensionsModel()
  {
    return fExtensionsModel;
  }
  
  public void dispose()
  {
    if (fBundleModel != null)
    {
      if (fBundlePluginBase != null) {
        fBundleModel.removeModelChangedListener(fBundlePluginBase);
      }
      fBundleModel.dispose();
      fBundleModel = null;
    }
    if (fExtensionsModel != null)
    {
      if (fBundlePluginBase != null) {
        fExtensionsModel.removeModelChangedListener(fBundlePluginBase);
      }
      fExtensionsModel.dispose();
      fExtensionsModel = null;
    }
    super.dispose();
  }
  
  public void save()
  {
    if ((fBundleModel != null) && ((fBundleModel instanceof IEditableModel)))
    {
      IEditableModel emodel = (IEditableModel)fBundleModel;
      if (emodel.isDirty()) {
        emodel.save();
      }
    }
    if ((fExtensionsModel != null) && ((fExtensionsModel instanceof IEditableModel)))
    {
      IEditableModel emodel = (IEditableModel)fExtensionsModel;
      if (emodel.isDirty()) {
        emodel.save();
      }
    }
  }
  
  public void setBundleModel(IBundleModel bundleModel)
  {
    if ((fBundleModel != null) && (fBundlePluginBase != null)) {
      fBundleModel.removeModelChangedListener(fBundlePluginBase);
    }
    fBundleModel = bundleModel;
    if ((fBundleModel != null) && (fBundlePluginBase != null)) {
      bundleModel.addModelChangedListener(fBundlePluginBase);
    }
  }
  
  public void setExtensionsModel(ISharedExtensionsModel extensionsModel)
  {
    if ((fExtensionsModel != null) && (fBundlePluginBase != null)) {
      fExtensionsModel.removeModelChangedListener(fBundlePluginBase);
    }
    fExtensionsModel = extensionsModel;
    if ((fExtensionsModel instanceof PluginModelBase)) {
      ((PluginModelBase)fExtensionsModel).setLocalization(getBundleLocalization());
    }
    if ((extensionsModel != null) && (fBundlePluginBase != null)) {
      extensionsModel.addModelChangedListener(fBundlePluginBase);
    }
  }
  
  public IBuildModel getBuildModel()
  {
    return fBuildModel;
  }
  
  public void setBuildModel(IBuildModel buildModel)
  {
    fBuildModel = buildModel;
  }
  
  public IPluginBase getPluginBase()
  {
    return getPluginBase(true);
  }
  
  public IExtensions getExtensions()
  {
    return getPluginBase();
  }
  
  public void fireModelChanged(IModelChangedEvent event)
  {
    super.fireModelChanged(event);
    Object[] objects = event.getChangedObjects();
    if ((objects != null) && (objects.length > 0) && 
      ((objects[0] instanceof IPluginImport))) {
      fBundlePluginBase.updateImport((IPluginImport)objects[0]);
    }
  }
  
  public IPluginBase getPluginBase(boolean createIfMissing)
  {
    if ((fBundlePluginBase == null) && (createIfMissing))
    {
      fBundlePluginBase = ((BundlePluginBase)createPluginBase());
      if (fBundleModel != null) {
        fBundleModel.addModelChangedListener(fBundlePluginBase);
      }
      setLoaded(true);
    }
    return fBundlePluginBase;
  }
  
  public IExtensions getExtensions(boolean createIfMissing)
  {
    return getPluginBase(createIfMissing);
  }
  
  public IPluginModelFactory getPluginFactory()
  {
    return this;
  }
  
  public IExtensionsModelFactory getFactory()
  {
    if (fExtensionsModel != null) {
      return fExtensionsModel.getFactory();
    }
    return null;
  }
  
  public String getInstallLocation()
  {
    if (fBundleModel != null) {
      return fBundleModel.getInstallLocation();
    }
    return null;
  }
  
  public String getBundleLocalization()
  {
    IBundle bundle = fBundleModel != null ? fBundleModel.getBundle() : null;
    return bundle != null ? bundle.getLocalization() : "OSGI-INF/l10n/bundle";
  }
  
  protected NLResourceHelper createNLResourceHelper()
  {
    String localization = getBundleLocalization();
    return localization == null ? null : new NLResourceHelper(localization, PDEManager.getNLLookupLocations(this));
  }
  
  public URL getNLLookupLocation()
  {
    try
    {
      return new URL("file:" + getInstallLocation());
    }
    catch (MalformedURLException localMalformedURLException) {}
    return null;
  }
  
  public boolean isEditable()
  {
    if ((fBundleModel != null) && (!fBundleModel.isEditable())) {
      return false;
    }
    if ((fExtensionsModel != null) && (!fExtensionsModel.isEditable())) {
      return false;
    }
    return true;
  }
  
  public boolean isInSync()
  {
    return ((fBundleModel == null) || (fBundleModel.isInSync())) && ((fExtensionsModel == null) || (fExtensionsModel.isInSync()));
  }
  
  public boolean isValid()
  {
    return ((fBundleModel == null) || (fBundleModel.isValid())) && ((fExtensionsModel == null) || (fExtensionsModel.isValid()));
  }
  
  public void load() {}
  
  public void load(InputStream source, boolean outOfSync) {}
  
  public void reload(InputStream source, boolean outOfSync) {}
  
  public boolean isEnabled()
  {
    return true;
  }
  
  public void setEnabled(boolean enabled) {}
  
  protected void updateTimeStamp() {}
  
  public IPluginImport createImport()
  {
    PluginImport iimport = new PluginImport();
    iimport.setModel(this);
    iimport.setParent(getPluginBase());
    return iimport;
  }
  
  public IPluginImport createImport(String pluginId)
  {
    PluginImport iimport = new PluginImport(this, pluginId);
    iimport.setParent(getPluginBase());
    return iimport;
  }
  
  public IPluginLibrary createLibrary()
  {
    PluginLibrary library = new PluginLibrary();
    library.setModel(this);
    library.setParent(getPluginBase());
    return library;
  }
  
  public IPluginAttribute createAttribute(IPluginElement element)
  {
    if (fExtensionsModel != null) {
      return fExtensionsModel.getFactory().createAttribute(element);
    }
    return null;
  }
  
  public IPluginElement createElement(IPluginObject parent)
  {
    if (fExtensionsModel != null) {
      return fExtensionsModel.getFactory().createElement(parent);
    }
    return null;
  }
  
  public IPluginExtension createExtension()
  {
    if (fExtensionsModel != null) {
      return fExtensionsModel.getFactory().createExtension();
    }
    return null;
  }
  
  public IPluginExtensionPoint createExtensionPoint()
  {
    if (fExtensionsModel != null) {
      return fExtensionsModel.getFactory().createExtensionPoint();
    }
    return null;
  }
  
  public boolean isBundleModel()
  {
    return true;
  }
  
  public BundleDescription getBundleDescription()
  {
    return fBundleDescription;
  }
  
  public void setBundleDescription(BundleDescription description)
  {
    fBundleDescription = description;
  }
  
  public boolean isDirty()
  {
    if ((fBundleModel != null) && ((fBundleModel instanceof IEditable)) && (((IEditable)fBundleModel).isDirty())) {
      return true;
    }
    if ((fExtensionsModel != null) && ((fExtensionsModel instanceof IEditable)) && (((IEditable)fExtensionsModel).isDirty())) {
      return true;
    }
    return false;
  }
  
  public void save(PrintWriter writer) {}
  
  public void setDirty(boolean dirty) {}
  
  public String toString()
  {
    IPluginBase base = getPluginBase();
    if (base != null) {
      return base.getId();
    }
    return super.toString();
  }
}

/* Location:
 * Qualified Name:     org.eclipse.pde.internal.core.bundle.BundlePluginModelBase
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.pde.internal.core.bundle;

import org.eclipse.core.resources.IFile;
import org.eclipse.pde.core.plugin.IFragment;
import org.eclipse.pde.core.plugin.IFragmentModel;
import org.eclipse.pde.core.plugin.IPluginBase;

public class WorkspaceBundleFragmentModel
  extends WorkspaceBundlePluginModelBase
  implements IFragmentModel
{
  private static final long serialVersionUID = 1L;
  
  public WorkspaceBundleFragmentModel(IFile manifestFile, IFile pluginFile)
  {
    super(manifestFile, pluginFile);
  }
  
  public IPluginBase createPluginBase()
  {
    BundleFragment frag = new BundleFragment();
    frag.setModel(this);
    return frag;
  }
  
  public IFragment getFragment()
  {
    return (IFragment)getPluginBase();
  }
}

/* Location:
 * Qualified Name:     org.eclipse.pde.internal.core.bundle.WorkspaceBundleFragmentModel
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.pde.internal.core.bundle;

import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IPath;
import org.eclipse.pde.core.IEditableModel;
import org.eclipse.pde.core.IModelChangedEvent;
import org.eclipse.pde.internal.core.PDECore;
import org.eclipse.pde.internal.core.ibundle.IBundleModelFactory;
import org.eclipse.pde.internal.core.text.bundle.BundleModelFactory;

public class WorkspaceBundleModel
  extends BundleModel
  implements IEditableModel
{
  private static final long serialVersionUID = 1L;
  private IFile fUnderlyingResource;
  private boolean fDirty;
  private boolean fEditable = true;
  private IBundleModelFactory fFactory;
  private static final String MANIFEST_VERSION = "Manifest-Version";
  
  public WorkspaceBundleModel(IFile file)
  {
    fUnderlyingResource = file;
  }
  
  public void fireModelChanged(IModelChangedEvent event)
  {
    setDirty(event.getChangeType() != 99);
    super.fireModelChanged(event);
  }
  
  public String getContents()
  {
    StringWriter swriter = new StringWriter();
    PrintWriter writer = new PrintWriter(swriter);
    save(writer);
    writer.flush();
    try
    {
      swriter.close();
    }
    catch (IOException e)
    {
      PDECore.logException(e);
    }
    return swriter.toString();
  }
  
  public IResource getUnderlyingResource()
  {
    return fUnderlyingResource;
  }
  
  public String getInstallLocation()
  {
    if (fUnderlyingResource == null) {
      return null;
    }
    IPath path = fUnderlyingResource.getLocation();
    if (path == null) {
      return null;
    }
    return path.removeLastSegments(2).addTrailingSeparator().toOSString();
  }
  
  public boolean isDirty()
  {
    return fDirty;
  }
  
  public boolean isEditable()
  {
    return fEditable;
  }
  
  /* Error */
  public void load()
  {
    // Byte code:
    //   0: aload_0
    //   1: getfield 204	org/eclipse/pde/internal/core/bundle/WorkspaceBundleModel:fUnderlyingResource	Lorg/eclipse/core/resources/IFile;
    //   4: ifnonnull +4 -> 8
    //   7: return
    //   8: aload_0
    //   9: getfield 204	org/eclipse/pde/internal/core/bundle/WorkspaceBundleModel:fUnderlyingResource	Lorg/eclipse/core/resources/IFile;
    //   12: invokeinterface 235 1 0
    //   17: ifeq +90 -> 107
    //   20: aconst_null
    //   21: astore_1
    //   22: aload_0
    //   23: getfield 204	org/eclipse/pde/internal/core/bundle/WorkspaceBundleModel:fUnderlyingResource	Lorg/eclipse/core/resources/IFile;
    //   26: iconst_1
    //   27: invokeinterface 236 2 0
    //   32: astore_1
    //   33: aload_0
    //   34: aload_1
    //   35: iconst_0
    //   36: invokevirtual 223	org/eclipse/pde/internal/core/bundle/WorkspaceBundleModel:load	(Ljava/io/InputStream;Z)V
    //   39: goto +50 -> 89
    //   42: astore_2
    //   43: aload_2
    //   44: invokestatic 215	org/eclipse/pde/internal/core/PDECore:logException	(Ljava/lang/Throwable;)V
    //   47: aload_1
    //   48: ifnull +59 -> 107
    //   51: aload_1
    //   52: invokevirtual 208	java/io/InputStream:close	()V
    //   55: goto +52 -> 107
    //   58: astore 4
    //   60: aload 4
    //   62: invokestatic 215	org/eclipse/pde/internal/core/PDECore:logException	(Ljava/lang/Throwable;)V
    //   65: goto +42 -> 107
    //   68: astore_3
    //   69: aload_1
    //   70: ifnull +17 -> 87
    //   73: aload_1
    //   74: invokevirtual 208	java/io/InputStream:close	()V
    //   77: goto +10 -> 87
    //   80: astore 4
    //   82: aload 4
    //   84: invokestatic 215	org/eclipse/pde/internal/core/PDECore:logException	(Ljava/lang/Throwable;)V
    //   87: aload_3
    //   88: athrow
    //   89: aload_1
    //   90: ifnull +17 -> 107
    //   93: aload_1
    //   94: invokevirtual 208	java/io/InputStream:close	()V
    //   97: goto +10 -> 107
    //   100: astore 4
    //   102: aload 4
    //   104: invokestatic 215	org/eclipse/pde/internal/core/PDECore:logException	(Ljava/lang/Throwable;)V
    //   107: return
    // Line number table:
    //   Java source line #87	-> byte code offset #0
    //   Java source line #88	-> byte code offset #7
    //   Java source line #89	-> byte code offset #8
    //   Java source line #90	-> byte code offset #20
    //   Java source line #92	-> byte code offset #22
    //   Java source line #93	-> byte code offset #33
    //   Java source line #94	-> byte code offset #42
    //   Java source line #95	-> byte code offset #43
    //   Java source line #98	-> byte code offset #47
    //   Java source line #99	-> byte code offset #51
    //   Java source line #100	-> byte code offset #58
    //   Java source line #101	-> byte code offset #60
    //   Java source line #96	-> byte code offset #68
    //   Java source line #98	-> byte code offset #69
    //   Java source line #99	-> byte code offset #73
    //   Java source line #100	-> byte code offset #80
    //   Java source line #101	-> byte code offset #82
    //   Java source line #103	-> byte code offset #87
    //   Java source line #98	-> byte code offset #89
    //   Java source line #99	-> byte code offset #93
    //   Java source line #100	-> byte code offset #100
    //   Java source line #101	-> byte code offset #102
    //   Java source line #105	-> byte code offset #107
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	108	0	this	WorkspaceBundleModel
    //   21	73	1	stream	java.io.InputStream
    //   42	2	2	e	Exception
    //   68	20	3	localObject	Object
    //   58	3	4	e	IOException
    //   80	3	4	e	IOException
    //   100	3	4	e	IOException
    // Exception table:
    //   from	to	target	type
    //   22	39	42	java/lang/Exception
    //   47	55	58	java/io/IOException
    //   22	47	68	finally
    //   69	77	80	java/io/IOException
    //   89	97	100	java/io/IOException
  }
  
  public boolean isInSync()
  {
    if (fUnderlyingResource == null) {
      return false;
    }
    if (fUnderlyingResource.getLocation() == null) {
      return false;
    }
    return isInSync(fUnderlyingResource.getLocation().toFile());
  }
  
  protected void updateTimeStamp()
  {
    if (fUnderlyingResource == null) {
      return;
    }
    if (fUnderlyingResource.getLocation() == null) {
      return;
    }
    updateTimeStamp(fUnderlyingResource.getLocation().toFile());
  }
  
  /* Error */
  public void save()
  {
    // Byte code:
    //   0: aload_0
    //   1: getfield 204	org/eclipse/pde/internal/core/bundle/WorkspaceBundleModel:fUnderlyingResource	Lorg/eclipse/core/resources/IFile;
    //   4: ifnonnull +4 -> 8
    //   7: return
    //   8: aconst_null
    //   9: astore_1
    //   10: aload_0
    //   11: invokevirtual 225	org/eclipse/pde/internal/core/bundle/Workspa
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 56 57 58 59 60 61 62 63 64

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