⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 desktop.java

📁 OSGI这是一个中间件,与UPNP齐名,是用于移植到嵌入式平台之上
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
        divloc = pane.getDividerLocation();      }      target.setVisible(!b);      if(!b) {        pane.setDividerLocation(divloc);      }      pane.getParent().invalidate();    }  }  public void stopFramework() {    Object[] options = {Strings.get("yes"),                        Strings.get("cancel")};    int n =JOptionPane      .showOptionDialog(frame,                        Strings.get("q_stopframework"),                        Strings.get("msg_stopframework"),                        JOptionPane.YES_NO_OPTION,                        JOptionPane.QUESTION_MESSAGE,                        null,                        options,                        options[1]);    if(n == 0) {      try {        Bundle sysBundle = Activator.getBC().getBundle((long)0);        sysBundle.stop();      } catch (Exception e) {        e.printStackTrace();      }    }  }  String lastBundleLocation = "http://";  void addBundleURL() {    try {      lastBundleLocation = (String)        JOptionPane.showInputDialog(frame,                                    Strings.get("dialog_addbundleurl_msg"),                                    Strings.get("dialog_addbundleurl_title"),                                    JOptionPane.QUESTION_MESSAGE,                                    null,                                    null,                                    lastBundleLocation);      if(lastBundleLocation != null && !"".equals(lastBundleLocation)) {        Bundle b = Activator.getTargetBC().installBundle(lastBundleLocation);        Dictionary headers = b.getHeaders();        if(Util.canBeStarted(b)) {          startBundle(b);        }      }    } catch (Exception e) {      showErr(null, e);    }  }  JFileChooser openFC = null;  /**   * Open a file dialog and ask for jar files to install as bundles.   */  void addBundle() {    if(openFC == null) {      openFC = new JFileChooser();      openFC.setCurrentDirectory(new File("."));      openFC.setMultiSelectionEnabled(true);      FileFilterImpl filter = new FileFilterImpl();      filter.addExtension("jar");      filter.setDescription("Jar files");      openFC.setFileFilter(filter);      openFC.setDialogTitle("Open bundle jar file");      openFC.setApproveButtonText("Open");    }    int returnVal = openFC.showOpenDialog(frame);    if(returnVal == JFileChooser.APPROVE_OPTION) {      File[] files = openFC.getSelectedFiles();      for(int i = 0; i < files.length; i++) {        addFile(files[i]);      }    }  }  void doConnect() {    String[] options = new String[Activator.remoteHosts.size()];    Activator.remoteHosts.copyInto(options);    // The selection comp I want in the dialog    JComboBox combo = new JComboBox(options);    combo.setEditable(true);    // Mindboggling complicate way of creating an option dialog    // without the auto-generated input field    JLabel msg    = new JLabel(Strings.get("remote_connect_msg"));    JPanel panel  = new JPanel(new BorderLayout());    panel.add(combo, BorderLayout.SOUTH);    panel.add(msg,   BorderLayout.NORTH);    JOptionPane optionPane = new JOptionPane(panel,                                             JOptionPane.QUESTION_MESSAGE);    optionPane.setIcon(connectIconLarge);    optionPane.setRootFrame(frame);    optionPane.setOptionType(JOptionPane.OK_CANCEL_OPTION);    optionPane.setWantsInput(false);    optionPane.setOptions(new String[]      {        Strings.get("ok"),        Strings.get("cancel"),        Strings.get("local"),      });    optionPane.selectInitialValue();    JDialog dialog =      optionPane.createDialog(frame,                              Strings.get("remote_connect_title"));    dialog.show();    dialog.dispose();    String value = (String)optionPane.getValue();    if (Strings.get("cancel").equals(value)) {      return;    }    String s = (String)combo.getSelectedItem();    if (Strings.get("local").equals(value)) {      s = "";    }    if(!Activator.remoteHosts.contains(s)) {      Activator.remoteHosts.addElement(s);    }    if ((s != null)) {      Activator.openRemote(s);    }  }  JFileChooser saveFC = null;  void save() {    if(saveFC == null) {      saveFC = new JFileChooser();      saveFC.setCurrentDirectory(new File("."));      saveFC.setMultiSelectionEnabled(false);      FileFilterImpl filter = new FileFilterImpl();      filter.addExtension("jar");      filter.addExtension("zip");      filter.setDescription("Deploy archives");      saveFC.setFileFilter(filter);      saveFC.setDialogTitle("Save deploy archive");      saveFC.setApproveButtonText("Save");    }    Bundle[] targets    = getSelectedBundles();    StringBuffer title = new StringBuffer();    title.append("Save deploy archive of: ");    for(int i = 0; i < targets.length; i++) {      title.append(Util.getBundleName(targets[i]));      if(i < targets.length - 1) {        title.append(", ");      }    }    saveFC.setDialogTitle(title.toString());    int returnVal = saveFC.showSaveDialog(frame);    if(returnVal == JFileChooser.APPROVE_OPTION) {      File file = saveFC.getSelectedFile();      doSave(file, targets);    }  }  void doSave(File file, Bundle[] targets) {    byte[] buf = new byte[1024 * 5];    if(file.getName().endsWith(".jar") ||       file.getName().endsWith(".zip")) {      // OK    } else {      file = new File(file.getAbsolutePath() + ".jar");    }    if(file.exists()) {      Object[] options = { Strings.get("yes"),                           Strings.get("cancel")};      int n = JOptionPane.showOptionDialog(frame,                                           file.getAbsolutePath() + "\n" +                                           "already exist.\n\n" +                                           "Overwrite file?",                                           "File exists",                                           JOptionPane.YES_NO_OPTION,                                           JOptionPane.QUESTION_MESSAGE,                                           null,                                           options,                                           options[1]);      if(n == 1) {        return;      }    }    String base = file.getName();    int ix = base.lastIndexOf(".");    if(ix != -1) {      base = base.substring(0, ix);    }    PackageAdmin pkgAdmin = (PackageAdmin)pkgTracker.getService();    if(pkgAdmin == null) {      Activator.log.error("No pkg admin available for save");      return;    }    Bundle[] allBundles = Activator.getTargetBC().getBundles();    Set pkgClosure = new TreeSet(Util.bundleIdComparator);    for(int i = 0; i < targets.length; i++) {      pkgClosure.addAll(Util.getPackageClosure(pkgAdmin,                                               allBundles,                                               targets[i],                                               null));    }    Set serviceClosure = new TreeSet(Util.bundleIdComparator);    for(int i = 0; i < targets.length; i++) {      serviceClosure.addAll(Util.getServiceClosure(targets[i], null));    }    Set all = new TreeSet(Util.bundleIdComparator);    all.addAll(pkgClosure);    all.addAll(serviceClosure);    for(int i = 0; i < targets.length; i++) {      all.add(targets[i]);    }    // remove system bundle.    all.remove(Activator.getTargetBC().getBundle(0));    ZipOutputStream out = null;    StartLevel sl = (StartLevel)slTracker.getService();    File jarunpackerFile = new File("../tools/jarunpacker/out/jarunpacker/jarunpacker.jar");    URL jarunpackerURL = null;    try {      jarunpackerURL = getClass().getResource("/jarunpacker.jar");    } catch (Exception ignored) {    }    InputStream jarunpacker_in = null;    try {      if(file.getName().endsWith(".jar")) {        if(jarunpackerURL != null) {          jarunpacker_in = jarunpackerURL.openStream();          //          System.out.println("using local jarunpacker");        } else if(jarunpackerFile.exists()) {          jarunpacker_in = new FileInputStream(jarunpackerFile);          //          System.out.println("using file jarunpacker");        }        if(jarunpacker_in != null) {          // Construct a string version of a manifest          StringBuffer sb = new StringBuffer();          sb.append("Manifest-Version: 1.0\n");          sb.append("Main-class: org.knopflerfish.tools.jarunpacker.Main\n");          sb.append("jarunpacker-optbutton: base\n");          sb.append("jarunpacker-destdir: .\n");          sb.append("knopflerfish-version: " + base + "\n");          sb.append("jarunpacker-opendir: " + base + "\n");          // Convert the string to a input stream          InputStream is = new ByteArrayInputStream(sb.toString().getBytes("UTF-8"));          Manifest mf = new Manifest(is);          out = new JarOutputStream(new FileOutputStream(file), mf);        } else {          out = new JarOutputStream(new FileOutputStream(file));        }      } else if(file.getName().endsWith(".zip")) {        out = new ZipOutputStream(new FileOutputStream(file));      }      StringBuffer xargs = new StringBuffer();      int levelMax = -1;      int bid = 0;      int lastLevel = -1;      for(Iterator it = all.iterator(); it.hasNext(); ) {        Bundle b   = (Bundle)it.next();        String loc = b.getLocation();        bid++;        URL srcURL = new URL(loc);        String name = Util.shortLocation(loc);        ZipEntry entry = new ZipEntry(base + "/" + name);        int level     = -1;        try {          level = sl.getBundleStartLevel(b);        } catch (Exception ignored) {        }        levelMax = Math.max(level, levelMax);        if(level != -1 && level != lastLevel) {          xargs.append("-initlevel " + level + "\n");          lastLevel = level;        }        xargs.append("-install file:" + name + "\n");        out.putNextEntry(entry);        InputStream in = null;        try {          in = srcURL.openStream();          int n = 0;          while ((n = in.read(buf)) != -1) {            out.write(buf, 0, n);          }        } finally {          try {            in.close();          } catch (Exception ignored) { }        }      }      bid = 0;      for(Iterator it = all.iterator(); it.hasNext(); ) {        Bundle b   = (Bundle)it.next();        bid++;        if(b.getState() == Bundle.ACTIVE) {          xargs.append("-start " + bid + "\n");        }      }      if(levelMax != -1) {        xargs.append("-startlevel " + levelMax + "\n");      }      ZipEntry entry = new ZipEntry(base + "/" + "init.xargs");      out.putNextEntry(entry);      out.write(xargs.toString().getBytes());      entry = new ZipEntry(base + "/" + "framework.jar");      out.putNextEntry(entry);      InputStream in = null;      File fwFile = new File("framework.jar");      if(fwFile.exists()) {        try {          in = new FileInputStream(fwFile);          int n = 0;          while ((n = in.read(buf)) != -1) {            out.write(buf, 0, n);          }        } finally {          try {            in.close();          } catch (Exception ignored) { }        }      } else {        Activator.log.warn("No framework.jar file found");      }      // Copy jarunpacker files, if availbale      if(jarunpacker_in != null) {        JarInputStream jar_in = null;        try {          jar_in = new JarInputStream(new BufferedInputStream(jarunpacker_in));          ZipEntry srcEntry;          while(null != (srcEntry = jar_in.getNextEntry())) {            // Skip unused files from jarunpacker            if(srcEntry.getName().startsWith("META-INF") ||               srcEntry.getName().startsWith("OSGI-OPT")) {              continue;            }            ZipEntry destEntry = new ZipEntry(srcEntry.getName());            out.putNextEntry(destEntry);            long nTotal = 0;            int n = 0;            while (-1 != (n = jar_in.read(buf, 0, buf.length))) {              out.write(buf, 0, n);              nTotal += n;            }          }        } finally {          try { jar_in.close();  } catch (Exception ignored) {  }        }      } else {        System.out.println("No jarunpacker available");      }      // end of jarunpacker copy    } catch (Exception e) {      e.printStackTrace();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -