org.eclipse.wst.server.discovery_1.0.200.v20110518

16:49:23.450 INFO  jd.cli.Main - Decompiling org.eclipse.wst.server.discovery_1.0.200.v20110518.jar
package org.eclipse.wst.server.discovery;

import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.swt.widgets.Shell;

public class Discovery
{
  public static boolean launchExtensionWizard(Shell shell, String title, String message)
  {
    ExtensionWizard wizard = new ExtensionWizard();
    WizardDialog dialog = new WizardDialog(shell, wizard);
    if (dialog.open() != 1) {
      return true;
    }
    return false;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.server.discovery.Discovery
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.server.discovery;

import org.eclipse.jface.wizard.IWizardContainer;

class ExtensionWizard$1
  implements Runnable
{
  ExtensionWizard$1(ExtensionWizard paramExtensionWizard) {}
  
  public void run()
  {
    this$0.getContainer().updateButtons();
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.server.discovery.ExtensionWizard.1
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.server.discovery;

import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.widgets.Display;
import org.eclipse.wst.server.discovery.internal.Messages;
import org.eclipse.wst.server.discovery.internal.model.Extension;

class ExtensionWizard$2
  implements Runnable
{
  ExtensionWizard$2(Extension paramExtension, boolean[] paramArrayOfBoolean, Display paramDisplay) {}
  
  public void run()
  {
    String msg = NLS.bind(Messages.installConfirm, val$extension.getName());
    val$b[0] = MessageDialog.openConfirm(val$display.getActiveShell(), 
      Messages.dialogTitle, msg);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.server.discovery.ExtensionWizard.2
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.server.discovery;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.wst.server.discovery.internal.model.Extension;

class ExtensionWizard$3
  extends Job
{
  ExtensionWizard$3(String $anonymous0, Extension paramExtension)
  {
    super($anonymous0);
  }
  
  public IStatus run(IProgressMonitor monitor)
  {
    return val$extension.install(monitor);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.server.discovery.ExtensionWizard.3
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.server.discovery;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.equinox.internal.p2.ui.ProvisioningOperationRunner;
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
import org.eclipse.equinox.p2.ui.AcceptLicensesWizardPage;
import org.eclipse.equinox.p2.ui.ProvisioningUI;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.wizard.IWizardContainer;
import org.eclipse.jface.wizard.IWizardPage;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.wst.server.discovery.internal.ImageResource;
import org.eclipse.wst.server.discovery.internal.Messages;
import org.eclipse.wst.server.discovery.internal.model.Extension;
import org.eclipse.wst.server.discovery.internal.wizard.ErrorWizardPage;
import org.eclipse.wst.server.discovery.internal.wizard.ExtensionWizardPage;

public class ExtensionWizard
  extends Wizard
{
  protected ExtensionWizardPage extensionPage;
  protected AcceptLicensesWizardPage licensePage;
  protected ErrorWizardPage errorPage;
  protected IWizardPage nextPage;
  
  public ExtensionWizard()
  {
    setWindowTitle(Messages.wizExtensionTitle);
    setDefaultPageImageDescriptor(ImageResource.getImageDescriptor("wizard"));
    setNeedsProgressMonitor(true);
    setForcePreviousAndNextButtons(true);
  }
  
  public void addPages()
  {
    super.addPages();
    ProvisioningUI ui = ProvisioningUI.getDefaultUI();
    licensePage = new AcceptLicensesWizardPage(ui.getLicenseManager(), new IInstallableUnit[0], null);
    licensePage.setWizard(this);
    errorPage = new ErrorWizardPage();
    errorPage.setWizard(this);
    extensionPage = new ExtensionWizardPage(licensePage, errorPage);
    extensionPage.setWizard(this);
  }
  
  public int getPageCount()
  {
    if (nextPage != null) {
      return 2;
    }
    return 1;
  }
  
  public IWizardPage[] getPages()
  {
    if (nextPage != null) {
      return new IWizardPage[] { extensionPage, nextPage };
    }
    return new IWizardPage[] { extensionPage };
  }
  
  public boolean canFinish()
  {
    return (licensePage.equals(nextPage)) && (licensePage.isPageComplete());
  }
  
  public IWizardPage getStartingPage()
  {
    return extensionPage;
  }
  
  public IWizardPage getNextPage(IWizardPage page)
  {
    if (extensionPage.equals(page)) {
      return nextPage;
    }
    return null;
  }
  
  public IWizardPage getPreviousPage(IWizardPage page)
  {
    if ((nextPage != null) && (nextPage.equals(page))) {
      return extensionPage;
    }
    return null;
  }
  
  public void setSecondPage(IWizardPage page)
  {
    nextPage = page;
    getShell().getDisplay().asyncExec(new Runnable()
    {
      public void run()
      {
        getContainer().updateButtons();
      }
    });
  }
  
  public boolean performFinish()
  {
    return install(extensionPage.getExtension());
  }
  
  protected static boolean install(final Extension extension)
  {
    if (extension == null) {
      return false;
    }
    final boolean[] b = new boolean[1];
    final Display display = Display.getDefault();
    display.syncExec(new Runnable()
    {
      public void run()
      {
        String msg = NLS.bind(Messages.installConfirm, getName());
        b[0] = MessageDialog.openConfirm(display.getActiveShell(), 
          Messages.dialogTitle, msg);
      }
    });
    if (b[0] == 0) {
      return true;
    }
    String name = NLS.bind(Messages.installJobName, extension.getName());
    Job job = new Job(name)
    {
      public IStatus run(IProgressMonitor monitor)
      {
        return extension.install(monitor);
      }
    };
    ProvisioningOperationRunner por = new ProvisioningOperationRunner(ProvisioningUI.getDefaultUI());
    por.manageJob(job, 2);
    
    job.setUser(true);
    job.schedule();
    return true;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.server.discovery.ExtensionWizard
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.server.discovery.internal;

import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;

public class Activator
  extends AbstractUIPlugin
{
  public static final String PLUGIN_ID = "org.eclipse.wst.server.discovery";
  public static final String JOB_FAMILY = "org.eclipse.wst.server.discovery";
  private static Activator plugin;
  
  public void start(BundleContext context)
    throws Exception
  {
    super.start(context);
    plugin = this;
  }
  
  public void stop(BundleContext context)
    throws Exception
  {
    plugin = null;
    super.stop(context);
  }
  
  public static Activator getDefault()
  {
    return plugin;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.server.discovery.internal.Activator
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.server.discovery.internal;

import java.util.List;
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
import org.eclipse.equinox.p2.query.MatchQuery;

public class ExtensionInstallableUnitQuery
  extends MatchQuery<IInstallableUnit>
{
  private List<String> list;
  
  public ExtensionInstallableUnitQuery(List<String> list)
  {
    this.list = list;
  }
  
  public boolean isMatch(IInstallableUnit candidate)
  {
    return list.contains(candidate.getId());
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.server.discovery.internal.ExtensionInstallableUnitQuery
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.server.discovery.internal;

import java.util.List;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.wst.server.discovery.internal.model.Extension;
import org.eclipse.wst.server.discovery.internal.model.ExtensionUpdateSite;

class ExtensionUtility$1
  extends Thread
{
  ExtensionUtility$1(String $anonymous0, ExtensionUpdateSite[] paramArrayOfExtensionUpdateSite, int paramInt1, IProgressMonitor paramIProgressMonitor, int paramInt2, List paramList1, List paramList2, ExtensionUtility.ExtensionListener paramExtensionListener)
  {
    super($anonymous0);
  }
  
  public void run()
  {
    try
    {
      List<Extension> list2 = val$items[val$ii].getExtensions(ProgressUtil.getSubMonitorFor(val$monitor2, val$x));
      ExtensionUtility.addExtensions(val$list, val$existing, list2, val$listener);
    }
    catch (CoreException ce)
    {
      val$listener.siteFailure(ce.getLocalizedMessage());
      Trace.trace((byte)2, "Error downloading extension info", ce);
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.server.discovery.internal.ExtensionUtility.1
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.server.discovery.internal;

import org.eclipse.wst.server.discovery.internal.model.Extension;

public abstract interface ExtensionUtility$ExtensionListener
{
  public abstract void extensionFound(Extension paramExtension);
  
  public abstract void extensionRemoved(Extension paramExtension);
  
  public abstract void siteFailure(String paramString);
}

/* Location:
 * Qualified Name:     org.eclipse.wst.server.discovery.internal.ExtensionUtility.ExtensionListener
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.server.discovery.internal;

import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.Status;
import org.eclipse.equinox.p2.core.IProvisioningAgent;
import org.eclipse.equinox.p2.engine.IProfile;
import org.eclipse.equinox.p2.engine.IProfileRegistry;
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
import org.eclipse.equinox.p2.metadata.Version;
import org.eclipse.equinox.p2.query.IQuery;
import org.eclipse.equinox.p2.query.IQueryResult;
import org.eclipse.equinox.p2.query.QueryUtil;
import org.eclipse.osgi.util.NLS;
import org.eclipse.wst.server.discovery.internal.model.Extension;
import org.eclipse.wst.server.discovery.internal.model.ExtensionUpdateSite;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;

public class ExtensionUtility
{
  private static ExtensionUpdateSite[] getExtensionUpdateSites(URL url)
    throws CoreException
  {
    InputStream in = null;
    try
    {
      in = url.openStream();
    }
    catch (Exception localException1)
    {
      Trace.trace((byte)3, "Could not load URL " + url);
    }
    if (in == null) {
      throw new CoreException(new Status(4, "org.eclipse.wst.server.discovery", 0, "Could not load extensions", null));
    }
    try
    {
      IMemento memento = XMLMemento.loadMemento(in);
      IMemento[] children = memento.getChildren("site");
      int size = children.length;
      List<ExtensionUpdateSite> list = new ArrayList(size);
      for (int i = 0; i < size; i++)
      {
        String url2 = children[i].getString("url");
        ExtensionUpdateSite item = new ExtensionUpdateSite(url2, null, null);
        list.add(item);
      }
      ExtensionUpdateSite[] items = new ExtensionUpdateSite[list.size()];
      list.toArray(items);
      return items;
    }
    catch (Exception e)
    {
      throw new CoreException(new Status(4, "org.eclipse.wst.server.discovery", 0, e.getMessage(), e));
    }
  }
  
  private static ExtensionUpdateSite[] getExtensionUpdateSites()
  {
    URL url = Activator.getDefault().getBundle().getEntry("serverAdapterSites.xml");
    try
    {
      return getExtensionUpdateSites(url);
    }
    catch (CoreException localCoreException)
    {
      Trace.trace((byte)3, "Could not get extension items");
    }
    return new ExtensionUpdateSite[0];
  }
  
  private static boolean alreadyExists(List<Extension> existing, Extension newFeature)
  {
    if (existing.contains(newFeature)) {
      return true;
    }
    Version newV = newFeature.getVersion();
    
    Iterator<Extension> iterator = existing.iterator();
    while (iterator.hasNext())
    {
      Extension feature = (Extension)iterator.next();
      if ((feature.getId().equals(newFeature.getId())) && 
        (feature.getVersion().compareTo(newV) >= 0)) {
        return true;
      }
    }
    return false;
  }
  
  private static void addExtension(List<Extension> list, List<Extension> existing, Extension newFeature, ExtensionListener listener)
  {
    if (alreadyExists(existing, newFeature)) {
      return;
    }
    synchronized (list)
    {
      Version newV = newFeature.getVersion();
      Extension remove = null;
      
      Iterator<Extension> iterator = list.iterator();
      while (iterator.hasNext())
      {
        Extension feature = (Extension)iterator.next();
        if (feature.getId().equals(newFeature.getId())) {
          if (feature.getVersion().compareTo(newV) < 0) {
            remove = feature;
          } else {
            return;
          }
        }
      }
      if (remove != null)
      {
        list.remove(remove);
        listener.extensionRemoved(remove);
      }
      list.add(newFeature);
    }
    listener.extensionFound(newFeature);
  }
  
  protected static void addExtensions(List<Extension> list, List<Extension> existing, List<Extension> newFeatures, ExtensionListener listener)
  {
    Iterator<Extension> iterator = newFeatures.iterator();
    while (iterator.hasNext()) {
      addExtension(list, existing, (Extension)iterator.next(), listener);
    }
  }
  
  private static List<Extension> getExistingFeatures(IProgressMonitor monitor)
    throws CoreException
  {
    monitor.beginTask(Messages.discoverLocalConfiguration, 100);
    
    IProfileRegistry profileRegistry = (IProfileRegistry)getService(Activator.getDefault().getBundle().getBundleContext(), IProfileRegistry.class.getName());
    profileRegistry.getProfiles();
    IProfile profile = profileRegistry.getProfile("_SELF_");
    
    IQuery<IInstallableUnit> query = QueryUtil.createIUAnyQuery();
    
    IQueryResult<IInstallableUnit> collector = profile.query(query, monitor);
    
    List<Extension> list = new ArrayList();
    Iterator<IInstallableUnit> iter = collector.iterator();
    while (iter.hasNext())
    {
      IInstallableUnit iu = (IInstallableUnit)iter.next();
      if (!list.contains(iu)) {
        list.add(new Extension(iu, null));
      }
    }
    monitor.done();
    
    return list;
  }
  
  public static Extension[] getAllExtensions(String id, final ExtensionListener listener, IProgressMonitor monitor)
    throws CoreException
  {
    monitor = ProgressUtil.getMonitorFor(monitor);
    monitor.beginTask("", 1100);
    
    monitor.subTask(Messages.discoverLocalConfiguration);
    final List<Extension> existing = getExistingFeatures(ProgressUtil.getSubMonitorFor(monitor, 100));
    
    final ExtensionUpdateSite[] items = getExtensionUpdateSites();
    if ((items == null) || (items.length == 0)) {
      return new Extension[0];
    }
    final int x = 1000 / items.length;
    
    monitor.worked(50);
    final List<Extension> list = new ArrayList();
    int size = items.length;
    
    Thread[] threads = new Thread[size];
    for (int i = 0; i < size; i++) {
      try
      {
        if (monitor.isCanceled()) {
          return null;
        }
        monitor.subTask(NLS.bind(Messages.discoverSearching, items[i].getUrl()));
        final int ii = i;
        final IProgressMonitor monitor2 = monitor;
        threads[i = new Thread("Extension Checker for " + items[i].getUrl())
        {
          public void run()
          {
            try
            {
              List<Extension> list2 = items[ii].getExtensions(ProgressUtil.getSubMonitorFor(monitor2, x));
              ExtensionUtility.addExtensions(list, existing, list2, listener);
            }
            catch (CoreException ce)
            {
              listener.siteFailure(ce.getLocalizedMessage());
              Trace.trace((byte)2, "Error downloading extension info", ce);
            }
          }
        };
        threads[i].setDaemon(true);
        threads[i].start();
      }
      catch (Exception e)
      {
        Trace.trace((byte)2, "Error downloading extension info 2", e);
      }
    }
    for (int i = 0; i < size; i++) {
      try
      {
        if (monitor.isCanceled()) {
          return null;
        }
        if (threads[i].isAlive()) {
          threads[i].join();
        }
      }
      catch (Exception e)
      {
        Trace.trace((byte)2, "Error downloading extension info 3", e);
      }
    }
    Extension[] ef = new Extension[list.size()];
    list.toArray(ef);
    monitor.done();
    return ef;
  }
  
  public static Object getService(BundleContext context, String name)
  {
    ServiceReference reference = context.getServiceReference(IProvisioningAgent.SERVICE_NAME);
    if (reference == null) {
      return null;
    }
    IProvisioningAgent result = getAgent(context);
    if (result == null) {
      return null;
    }
    try
    {
      return result.getService(name);
    }
    finally
    {
      context.ungetService(reference);
    }
  }
  
  public static IProvisioningAgent getAgent(BundleContext context)
  {
    ServiceReference reference = context.getServiceReference(IProvisioningAgent.SERVICE_NAME);
    if (reference == null) {
      return null;
    }
    IProvisioningAgent result = (IProvisioningAgent)context.getService(reference);
    
    return result;
  }
  
  public static abstract interface ExtensionListener
  {
    public abstract void extensionFound(Extension paramExtension);
    
    public abstract void extensionRemoved(Extension paramExtension);
    
    public abstract void siteFailure(String paramString);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.server.discovery.internal.ExtensionUtility
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.server.discovery.internal;

import java.util.List;

public abstract interface IMemento
{
  public abstract IMemento createChild(String paramString);
  
  public abstract IMemento getChild(String paramString);
  
  public abstract IMemento[] getChildren(String paramString);
  
  public abstract Float getFloat(String paramString);
  
  public abstract Integer getInteger(String paramString);
  
  public abstract String getString(String paramString);
  
  public abstract Boolean getBoolean(String paramString);
  
  public abstract List<String> getNames();
  
  public abstract void putInteger(String paramString, int paramInt);
  
  public abstract void putBoolean(String paramString, boolean paramBoolean);
  
  public abstract void putString(String paramString1, String paramString2);
}

/* Location:
 * Qualified Name:     org.eclipse.wst.server.discovery.internal.IMemento
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.server.discovery.internal;

import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.resource.ImageRegistry;
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.progress.IProgressService;
import org.osgi.framework.Bundle;

public class ImageResource
{
  private static ImageRegistry imageRegistry;
  private static Map<String, ImageDescriptor> imageDescriptors;
  private static URL ICON_BASE_URL;
  private static final String URL_OBJ = "obj16/";
  private static final String URL_WIZBAN = "wizban/";
  public static final String IMG_WIZARD = "wizard";
  public static final String IMG_EXTENSION = "extension";
  
  static
  {
    try
    {
      String pathSuffix = "icons/";
      ICON_BASE_URL = Activator.getDefault().getBundle().getEntry(pathSuffix);
    }
    catch (Exception e)
    {
      Trace.trace((byte)3, "Could not set icon base URL", e);
    }
  }
  
  protected static void dispose() {}
  
  public static Image getImage(String key)
  {
    if (imageRegistry == null) {
      initializeImageRegistry();
    }
    Image image = imageRegistry.get(key);
    if (image == null)
    {
      imageRegistry.put(key, ImageDescriptor.getMissingImageDescriptor());
      image = imageRegistry.get(key);
    }
    return image;
  }
  
  public static ImageDescriptor getImageDescriptor(String key)
  {
    if (imageRegistry == null) {
      initializeImageRegistry();
    }
    ImageDescriptor id = (ImageDescriptor)imageDescriptors.get(key);
    if (id != null) {
      return id;
    }
    return ImageDescriptor.getMissingImageDescriptor();
  }
  
  protected static void initializeImageRegistry()
  {
    imageRegistry = new ImageRegistry();
    imageDescriptors = new HashMap();
    
    registerImage("wizard", "wizban/install_wiz.gif");
    registerImage("extension", "obj16/iu_obj.gif");
    
    PlatformUI.getWorkbench().getProgressService().registerIconForFamily(
      getImageDescriptor("extension"), "org.eclipse.wst.server.discovery");
  }
  
  private static void registerImage(String key, String partialURL)
  {
    try
    {
      ImageDescriptor id = ImageDescriptor.createFromURL(new URL(ICON_BASE_URL, partialURL));
      imageRegistry.put(key, id);
      imageDescriptors.put(key, id);
    }
    catch (Exception e)
    {
      Trace.trace((byte)3, "Error registering image " + key + " from " + partialURL, e);
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.server.discovery.internal.ImageResource
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.server.discovery.internal;

import org.eclipse.osgi.util.NLS;

public class Messages
  extends NLS
{
  public static String dialogTitle;
  public static String viewInitializing;
  public static String wizExtensionTitle;
  public static String wizExtensionDescription;
  public static String wizExtensionMessage;
  public static String discoverSearching;
  public static String discoverLocalConfiguration;
  public static String discoverSiteError;
  public static String installConfirm;
  public static String installJobName;
  
  static
  {
    NLS.initializeMessages("org.eclipse.wst.server.discovery.internal.Messages", Messages.class);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.server.discovery.internal.Messages
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.server.discovery.internal;

import org.eclipse.equinox.p2.metadata.IInstallableUnit;
import org.eclipse.equinox.p2.query.MatchQuery;

public class PatternInstallableUnitQuery
  extends MatchQuery<IInstallableUnit>
{
  private String categoryId;
  
  public PatternInstallableUnitQuery(String categoryId)
  {
    this.categoryId = categoryId;
  }
  
  public boolean isMatch(IInstallableUnit candidate)
  {
    if ((categoryId != null) && (candidate.getId().endsWith(categoryId))) {
      return true;
    }
    return false;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.server.discovery.internal.PatternInstallableUnitQuery
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.server.discovery.internal;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.SubProgressMonitor;

public class ProgressUtil
{
  public static IProgressMonitor getMonitorFor(IProgressMonitor monitor)
  {
    if (monitor == null) {
      return new NullProgressMonitor();
    }
    return monitor;
  }
  
  public static IProgressMonitor getSubMonitorFor(IProgressMonitor monitor, int ticks)
  {
    if (monitor == null) {
      return new NullProgressMonitor();
    }
    if ((monitor instanceof NullProgressMonitor)) {
      return monitor;
    }
    return new SubProgressMonitor(monitor, ticks);
  }
  
  public static IProgressMonitor getSubMonitorFor(IProgressMonitor monitor, int ticks, int style)
  {
    if (monitor == null) {
      return new NullProgressMonitor();
    }
    if ((monitor instanceof NullProgressMonitor)) {
      return monitor;
    }
    return new SubProgressMonitor(monitor, ticks, style);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.server.discovery.internal.ProgressUtil
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.server.discovery.internal;

import java.io.PrintStream;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import org.eclipse.core.runtime.ILog;
import org.eclipse.core.runtime.Status;

public class Trace
{
  public static final byte CONFIG = 0;
  public static final byte INFO = 1;
  public static final byte WARNING = 2;
  public static final byte SEVERE = 3;
  public static final byte FINEST = 4;
  public static final byte FINER = 5;
  public static final byte PERFORMANCE = 6;
  public static final byte EXTENSION_POINT = 7;
  private static final String[] levelNames = {
    "CONFIG ", "INFO   ", "WARNING", "SEVERE ", "FINER  ", "FINEST ", "PERF   ", "EXTENSION" };
  private static final SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yy HH:mm.ss.SSS");
  private static Set<String> logged = new HashSet();
  
  public static void trace(byte level, String s)
  {
    trace(level, s, null);
  }
  
  public static void trace(byte level, String s, Throwable t)
  {
    if (s == null) {
      return;
    }
    if ((level == 3) && 
      (!logged.contains(s)))
    {
      Activator.getDefault().getLog().log(new Status(4, "org.eclipse.wst.server.discovery", s, t));
      logged.add(s);
    }
    if (!Activator.getDefault().isDebugging()) {
      return;
    }
    StringBuffer sb = new StringBuffer("org.eclipse.wst.server.discovery");
    sb.append(" ");
    sb.append(levelNames[level]);
    sb.append(" ");
    sb.append(sdf.format(new Date()));
    sb.append(" ");
    sb.append(s);
    System.out.println(sb.toString());
    if (t != null) {
      t.printStackTrace();
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.server.discovery.internal.Trace
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.server.discovery.internal;

import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.w3c.dom.Attr;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.w3c.dom.Text;
import org.xml.sax.InputSource;

public final class XMLMemento
  implements IMemento
{
  private Document factory;
  private Element element;
  
  private XMLMemento(Document doc, Element el)
  {
    factory = doc;
    element = el;
  }
  
  public IMemento createChild(String type)
  {
    Element child = factory.createElement(type);
    element.appendChild(child);
    return new XMLMemento(factory, child);
  }
  
  protected static XMLMemento createReadRoot(InputStream in)
  {
    Document document = null;
    try
    {
      DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
      DocumentBuilder parser = factory.newDocumentBuilder();
      document = parser.parse(new InputSource(in));
      Node node = document.getFirstChild();
      if ((node instanceof Element)) {
        return new XMLMemento(document, (Element)node);
      }
    }
    catch (Exception localException2) {}finally
    {
      try
      {
        in.close();
      }
      catch (Exception localException4) {}
    }
    try
    {
      in.close();
    }
    catch (Exception localException5) {}
    return null;
  }
  
  public static XMLMemento createWriteRoot(String type)
  {
    try
    {
      Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
      Element element = document.createElement(type);
      document.appendChild(element);
      return new XMLMemento(document, element);
    }
    catch (ParserConfigurationException e)
    {
      throw new Error(e);
    }
  }
  
  public IMemento getChild(String type)
  {
    NodeList nodes = element.getChildNodes();
    int size = nodes.getLength();
    if (size == 0) {
      return null;
    }
    for (int nX = 0; nX < size; nX++)
    {
      Node node = nodes.item(nX);
      if ((node instanceof Element))
      {
        Element element2 = (Element)node;
        if (element2.getNodeName().equals(type)) {
          return new XMLMemento(factory, element2);
        }
      }
    }
    return null;
  }
  
  public IMemento[] getChildren(String type)
  {
    NodeList nodes = element.getChildNodes();
    int size = nodes.getLength();
    if (size == 0) {
      return new IMemento[0];
    }
    List<Element> list = new ArrayList(size);
    for (int nX = 0; nX < size; nX++)
    {
      Node node = nodes.item(nX);
      if ((node instanceof Element))
      {
        Element element2 = (Element)node;
        if (element2.getNodeName().equals(type)) {
          list.add(element2);
        }
      }
    }
    size = list.size();
    IMemento[] results = new IMemento[size];
    for (int x = 0; x < size; x++) {
      results[x] = new XMLMemento(factory, (Element)list.get(x));
    }
    return results;
  }
  
  public byte[] getContents()
    throws IOException
  {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    save(out);
    return out.toByteArray();
  }
  
  public InputStream getInputStream()
    throws IOException
  {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    save(out);
    return new ByteArrayInputStream(out.toByteArray());
  }
  
  public Float getFloat(String key)
  {
    Attr attr = element.getAttributeNode(key);
    if (attr == null) {
      return null;
    }
    String strValue = attr.getValue();
    try
    {
      return new Float(strValue);
    }
    catch (NumberFormatException localNumberFormatException) {}
    return null;
  }
  
  public Integer getInteger(String key)
  {
    Attr attr = element.getAttributeNode(key);
    if (attr == null) {
      return null;
    }
    String strValue = attr.getValue();
    try
    {
      return new Integer(strValue);
    }
    catch (NumberFormatException localNumberFormatException) {}
    return null;
  }
  
  public String getString(String key)
  {
    Attr attr = element.getAttributeNode(key);
    if (attr == null) {
      return null;
    }
    return attr.getValue();
  }
  
  public List<String> getNames()
  {
    NamedNodeMap map = element.getAttributes();
    int size = map.getLength();
    List<String> list = new ArrayList();
    for (int i = 0; i < size; i++)
    {
      Node node = map.item(i);
      String name = node.getNodeName();
      list.add(name);
    }
    return list;
  }
  
  public static IMemento loadMemento(InputStream in)
  {
    return createReadRoot(in);
  }
  
  public static IMemento loadMemento(String filename)
    throws IOException
  {
    InputStream in = null;
    try
    {
      in = new BufferedInputStream(new FileInputStream(filename));
      return createReadRoot(in);
    }
    finally
    {
      try
      {
        if (in != null) {
          in.close();
        }
      }
      catch (Exception localException2) {}
    }
  }
  
  public void putInteger(String key, int n)
  {
    element.setAttribute(key, String.valueOf(n));
  }
  
  public void putString(String key, String value)
  {
    if (value == null) {
      return;
    }
    element.setAttribute(key, value);
  }
  
  public void save(OutputStream os)
    throws IOException
  {
    Result result = new StreamResult(os);
    Source source = new DOMSource(factory);
    try
    {
      Transformer transformer = TransformerFactory.newInstance().newTransformer();
      transformer.setOutputProperty("indent", "yes");
      transformer.setOutputProperty("method", "xml");
      transformer.setOutputProperty("encoding", "UTF-8");
      transformer.setOutputProperty("{http://xml.apache.org/xalan}indent-amount", "2");
      transformer.transform(source, result);
    }
    catch (Exception e)
    {
      throw ((IOException)new IOException().initCause(e));
    }
  }
  
  /* Error */
  public void saveToFile(String filename)
    throws IOException
  {
    // Byte code:
    //   0: aconst_null
    //   1: astore_2
    //   2: new 154	java/io/BufferedOutputStream
    //   5: dup
    //   6: new 158	java/io/FileOutputStream
    //   9: dup
    //   10: aload_1
    //   11: invokespecial 315	java/io/FileOutputStream:<init>	(Ljava/lang/String;)V
    //   14: invokespecial 309	java/io/BufferedOutputStream:<init>	(Ljava/io/OutputStream;)V
    //   17: astore_2
    //   18: aload_0
    //   19: aload_2
    //   20: invokevirtual 341	org/eclipse/wst/server/discovery/internal/XMLMemento:save	(Ljava/io/OutputStream;)V
    //   23: goto +36 -> 59
    //   26: astore_3
    //   27: aload_3
    //   28: athrow
    //   29: astore_3
    //   30: new 159	java/io/IOException
    //   33: dup
    //   34: aload_3
    //   35: invokevirtual 322	java/lang/Exception:getLocalizedMessage	()Ljava/lang/String;
    //   38: invokespecial 317	java/io/IOException:<init>	(Ljava/lang/String;)V
    //   41: athrow
    //   42: astore 4
    //   44: aload_2
    //   45: ifnull +11 -> 56
    //   48: aload_2
    //   49: invokevirtual 308	java/io/BufferedOutputStream:close	()V
    //   52: goto +4 -> 56
    //   55: pop
    //   56: aload 4
    //   58: athrow
    //   59: aload_2
    //   60: ifnull +11 -> 71
    //   63: aload_2
    //   64: invokevirtual 308	java/io/BufferedOutputStream:close	()V
    //   67: goto +4 -> 71
    //   70: pop
    //   71: return
    // Line number table:
    //   Java source line #309	-> byte code offset #0
    //   Java source line #311	-> byte code offset #2
    //   Java source line #312	-> byte code offset #18
    //   Java source line #313	-> byte code offset #26
    //   Java source line #314	-> byte code offset #27
    //   Java source line #315	-> byte code offset #29
    //   Java source line #316	-> byte code offset #30
    //   Java source line #317	-> byte code offset #42
    //   Java source line #318	-> byte code offset #44
    //   Java source line #320	-> byte code offset #48
    //   Java source line #321	-> byte code offset #55
    //   Java source line #325	-> byte code offset #56
    //   Java source line #318	-> byte code offset #59
    //   Java source line #320	-> byte code offset #63
    //   Java source line #321	-> byte code offset #70
    //   Java source line #326	-> byte code offset #71
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	72	0	this	XMLMemento
    //   0	72	1	filename	String
    //   1	63	2	w	java.io.BufferedOutputStream
    //   26	2	3	e	IOException
    //   29	6	3	e	Exception
    //   42	15	4	localObject	Object
    //   55	1	6	localException1	Exception
    //   70	1	7	localException2	Exception
    // Exception table:
    //   from	to	target	type
    //   2	23	26	java/io/IOException
    //   2	23	29	java/lang/Exception
    //   2	42	42	finally
    //   48	52	55	java/lang/Exception
    //   63	67	70	java/lang/Exception
  }
  
  public String saveToString()
    throws IOException
  {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    save(out);
    return out.toString("UTF-8");
  }
  
  public Boolean getBoolean(String key)
  {
    Attr attr = element.getAttributeNode(key);
    if (attr == null) {
      return null;
    }
    String strValue = attr.getValue();
    if ("true".equalsIgnoreCase(strValue)) {
      return new Boolean(true);
    }
    return new Boolean(false);
  }
  
  public void putBoolean(String key, boolean value)
  {
    element.setAttribute(key, value ? "true" : "false");
  }
  
  private Text getTextNode()
  {
    NodeList nodes = element.getChildNodes();
    int size = nodes.getLength();
    if (size == 0) {
      return null;
    }
    for (int nX = 0; nX < size; nX++)
    {
      Node node = nodes.item(nX);
      if ((node instanceof Text)) {
        return (Text)node;
      }
    }
    return null;
  }
  
  public void putTextData(String data)
  {
    Text textNode = getTextNode();
    if (textNode == null)
    {
      textNode = factory.createTextNode(data);
      
      element.insertBefore(textNode, element.getFirstChild());
    }
    else
    {
      textNode.setData(data);
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.server.discovery.internal.XMLMemento
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.server.discovery.internal.model;

import java.net.URI;
import java.util.Collection;
import java.util.Iterator;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.equinox.p2.core.IProvisioningAgent;
import org.eclipse.equinox.p2.engine.IEngine;
import org.eclipse.equinox.p2.engine.IProfile;
import org.eclipse.equinox.p2.engine.IProfileRegistry;
import org.eclipse.equinox.p2.engine.IProvisioningPlan;
import org.eclipse.equinox.p2.engine.PhaseSetFactory;
import org.eclipse.equinox.p2.engine.ProvisioningContext;
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
import org.eclipse.equinox.p2.metadata.ILicense;
import org.eclipse.equinox.p2.metadata.Version;
import org.eclipse.equinox.p2.planner.IPlanner;
import org.eclipse.equinox.p2.planner.IProfileChangeRequest;
import org.eclipse.swt.graphics.Image;
import org.eclipse.wst.server.discovery.internal.Activator;
import org.eclipse.wst.server.discovery.internal.ExtensionUtility;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;

public class Extension
{
  private IInstallableUnit iu;
  private URI uri;
  private ProvisioningContext provContext;
  private IProvisioningPlan plan;
  
  public Extension(IInstallableUnit iu, URI uri)
  {
    this.iu = iu;
    this.uri = uri;
  }
  
  public String getName()
  {
    return iu.getProperty("org.eclipse.equinox.p2.name", null);
  }
  
  public String getDescription()
  {
    return iu.getProperty("org.eclipse.equinox.p2.description", null);
  }
  
  public Image getImage()
  {
    return null;
  }
  
  public String getLicense()
  {
    Collection<ILicense> licenses = iu.getLicenses(null);
    if ((licenses == null) || (licenses.isEmpty())) {
      return "";
    }
    return ((ILicense)licenses.iterator().next()).getBody();
  }
  
  public String getProvider()
  {
    return iu.getProperty("org.eclipse.equinox.p2.provider", null);
  }
  
  public String getId()
  {
    return iu.getId();
  }
  
  public Version getVersion()
  {
    return iu.getVersion();
  }
  
  public IStatus install(IProgressMonitor monitor)
  {
    Bun
1 2 3

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