Package javax.jnlp

Examples of javax.jnlp.DownloadService


public class SweetHome3DJavaWebStartBootstrap {
  public static void main(String [] args) throws ClassNotFoundException,
        NoSuchMethodException, IllegalAccessException, InvocationTargetException {
    try {
      // Lookup the javax.jnlp.DownloadService object
      DownloadService service = (DownloadService)ServiceManager.lookup("javax.jnlp.DownloadService");
      DownloadServiceListener progressWindow = service.getDefaultProgressWindow();
      // Search jars lazily downloaded
      String lazyParts = System.getProperty("com.eteks.sweethome3d.lazyParts", "");
      List<String> lazyPartsToDownload = new ArrayList<String>();
      for (String lazyPart : lazyParts.split("\\s")) {
        if (!service.isPartCached(lazyPart)) {
          lazyPartsToDownload.add(lazyPart);
        }
      }     
      try {
        if (lazyPartsToDownload.size() > 0) {
          service.loadPart(lazyPartsToDownload.toArray(new String [lazyPartsToDownload.size()]), progressWindow);
        }
      } catch (IOException ex) {
        ex.printStackTrace();
        System.exit(1);
      }       
View Full Code Here


  return true;
    }
   
    /** Remove data component data JAR from cache */
    static public void removeInstallerComponent() {
  DownloadService downloadService = Config.getDownloadService();
  if (downloadService != null) {
      String component = Config.getInstallerLocation();
      String version   = Config.getInstallerVersion();
      try {
    URL codebase = Config.getBasicService().getCodeBase();
    URL url = new URL(codebase, component);
    component = url.toString();
    Config.trace("Removing: " + component + "/" + version);
    downloadService.removeResource(url, version);
      } catch(IOException ioe) {
    Config.trace("Unable to remove " + component + "/" + version);
      }
  } else {
      Config.trace("No download service found");
View Full Code Here

   * @throws ApplicationException if the download service is not available.
   */
  private void startDownload(boolean forceDownload)
      throws IOException, ApplicationException
  {
    DownloadService ds;
    try
    {
      ds =
          (DownloadService) ServiceManager.lookup(Utils.JNLP_SERVICE_NAME);
    } catch (UnavailableServiceException e)
    {
      LOG.log(Level.SEVERE, "Could not find service: "+
          Utils.JNLP_SERVICE_NAME, e);
      String setupFile;
      if (Utils.isWindows())
      {
        setupFile = Installation.WINDOWS_SETUP_FILE_NAME;
      }
      else
      {
        setupFile = Installation.UNIX_SETUP_FILE_NAME;
      }
      throw new ApplicationException(
        ReturnCode.DOWNLOAD_ERROR,
        getThrowableMsg(INFO_DOWNLOADING_ERROR_NO_SERVICE_FOUND.get(
            Utils.JNLP_SERVICE_NAME, setupFile),
            e), e);
    }

    String[] urls = getJarUrls();
    String[] versions = getJarVersions();

    /*
     * Calculate the percentages that correspond to each file.
     * TODO ideally this should be done dynamically, but as this is just
     * to provide progress, updating this information from time to time can
     * be enough and does not complexify the build process.
     */
    int[] percentageMax = new int[urls.length];
    int[] ratios = new int[urls.length];
    int totalRatios = 0;
    for (int i=0; i<percentageMax.length; i++)
    {
      int ratio;
      if (urls[i].endsWith("NasuTekDS.jar"))
      {
        ratio =  23;
      }
      else if (urls[i].endsWith("je.jar"))
      {
        ratio = 11;
      }
      else if (urls[i].endsWith("zipped.jar"))
      {
        ratio = 110;
      }
      else if (urls[i].endsWith("aspectjrt.jar"))
      {
        ratio = 10;
      }
      else
      {
        ratio = (100 / urls.length);
      }
      ratios[i] = ratio;
      totalRatios += ratio;
    }

    for (int i=0; i<percentageMax.length; i++)
    {
      int r = 0;
      for (int j=0; j<=i; j++)
      {
        r += ratios[j];
      }
      percentageMax[i] = (100 * r)/totalRatios;
    }


    for (int i = 0; i < urls.length && (getException() == null); i++)
    {
      if (i == 0)
      {
        currentPercMin = 0;
      }
      else {
        currentPercMin = percentageMax[i-1];
      }
      currentPercMax = percentageMax[i];

      // determine if a particular resource is cached
      String sUrl = urls[i];
      String version = versions[i];

      URL url = new URL(sUrl);
      boolean cached = ds.isResourceCached(url, version);

      if (cached && forceDownload)
      {
        try
        {
          ds.removeResource(url, version);
        } catch (IOException ioe)
        {
        }
        cached = false;
      }

      if (!cached)
      {
        // if not in the cache load the resource into the cache
        ds.loadResource(url, version, this);
      }
      downloadPercentage = currentPercMax;
    }
    isFinished = true;
  }
View Full Code Here

TOP

Related Classes of javax.jnlp.DownloadService

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.