📄 frameworkcommandgroup.java
字号:
+ showBundle(ib[j])); } } out.println(); } else { out.println(" exported by " + showBundle(b)); } } else { if (verbose) { out.println("Package not found: " + selection[i]); out.println(); } } } return 0; } // // Permissions command // public final static String USAGE_PERMISSIONS = "[-d] [<selection>] ..."; public final static String[] HELP_PERMISSIONS = new String[] { "Show permission information", "If no parameters is given show all entries", "-d Show default permissions", "<selection> Name or id of bundle or an unknown location" }; public int cmdPermissions(Dictionary opts, Reader in, PrintWriter out, Session session) { if (permissionAdmin == null) { out.println("Permission Admin service is not available"); return 1; } String[] loclist = permissionAdmin.getLocations(); String[] selection = (String[]) opts.get("selection"); if (loclist != null && selection != null) { Bundle[] b = bc.getBundles(); Util.selectBundles(b, selection); lloop: for (int i = 0; i < loclist.length; i++) { for (int j = 0; j < selection.length; j++) { if (loclist[i].equals(selection[j])) { continue lloop; } } for (int j = 0; j < b.length; j++) { if (b[j] != null && loclist[i].equals(b[j].getLocation())) { continue lloop; } } loclist[i] = null; } } if (opts.get("-d") != null) { out.println("Default permissions"); showPerms(out, permissionAdmin.getDefaultPermissions()); } if (loclist != null) { Bundle[] b = bc.getBundles(); for (int i = 0; i < loclist.length; i++) { if (loclist[i] != null) { int j = b.length; while (--j >= 0) { if (loclist[i].equals(b[j].getLocation())) { break; } } out.println("Location: " + loclist[i] + (j >= 0 ? " (Bundle #" + b[j].getBundleId() + ")" : "")); showPerms(out, permissionAdmin.getPermissions(loclist[i])); } } } return 0; } // // Refresh command // public final static String USAGE_REFRESH = "[<bundle>] ..."; public final static String[] HELP_REFRESH = new String[] { "Refresh all exported java packages belong to specified bundle", "If no bundle is specified refresh all bundles", "<bundle> Name or id of bundle" }; public int cmdRefresh(Dictionary opts, Reader in, PrintWriter out, Session session) { if (packageAdmin == null) { out.println("Package Admin service is not available"); return 1; } String[] bs = (String[]) opts.get("bundle"); if (bs != null) { Bundle[] b = getBundles(bs, true); for (int i = 0; i < b.length; i++) { if (b[i] == null) { Bundle[] nb = new Bundle[i]; System.arraycopy(b, 0, nb, 0, nb.length); b = nb; break; } } if (b.length == 0) { out.println("ERROR! No matching bundle"); return 1; } packageAdmin.refreshPackages(b); } else { packageAdmin.refreshPackages(null); } return 0; } // // Services command // public final static String USAGE_SERVICES = "[-i] [-l] [-r] [-u] [<bundle>] ..."; public final static String[] HELP_SERVICES = new String[] { "List registered services", "-i Sort on bundle id", "-l Verbose output", "-r Show services registered by named bundles (default)", "-u Show services used by named bundles", "<bundle> Name or id of bundle" }; public int cmdServices(final Dictionary opts, Reader in, final PrintWriter out, Session session) { final Bundle[] b = getBundles((String[]) opts.get("bundle"), opts .get("-i") != null); AccessController.doPrivileged(new PrivilegedAction() { public Object run() { for (int i = 0; i < b.length; i++) { if (b[i] != null) { out.println("Bundle: " + showBundle(b[i])); if (opts.get("-r") != null || opts.get("-u") == null) { ServiceReference[] s = b[i].getRegisteredServices(); if (s.length > 0) { out.print(" registered:"); for (int j = 0; j < s.length; j++) { if (opts.get("-l") != null) { out.print("\n "); showLongService(s[j], " ", out); } else { out .print(" " + Util .showServiceClasses(s[j])); } } out.println(""); } } if (opts.get("-u") != null) { ServiceReference[] s = b[i].getServicesInUse(); if (s.length > 0) { out.print(" uses:"); for (int j = 0; j < s.length; j++) { if (opts.get("-l") != null) { out.print("\n "); showLongService(s[j], " ", out); } else { out .print(" " + Util .showServiceClasses(s[j])); } } } out.println(""); } } } return null; } }); return 0; } void showLongService(ServiceReference s, String pad, PrintWriter out) { out.print(Util.showServiceClasses(s)); String[] k = s.getPropertyKeys(); for (int i = 0; i < k.length; i++) { out.print("\n " + pad + k[i] + " = " + Util.showObject(s.getProperty(k[i]))); } } // // Start command // public final static String USAGE_START = "<bundle> ..."; public final static String[] HELP_START = new String[] { "Start one or more bundles", "<bundle> Name or id of bundle" }; public int cmdStart(Dictionary opts, Reader in, PrintWriter out, Session session) { Bundle[] b = getBundles((String[]) opts.get("bundle"), true); boolean found = false; for (int i = 0; i < b.length; i++) { if (b[i] != null) { try { b[i].start(); out.println("Started: " + showBundle(b[i])); } catch (BundleException e) { Throwable t = e; while (t instanceof BundleException && ((BundleException) t).getNestedException() != null) t = ((BundleException) t).getNestedException(); out.println("Couldn't start bundle: " + showBundle(b[i]) + " (due to: " + t + ")"); t.printStackTrace(out); } found = true; } } if (!found) { out.println("ERROR! No matching bundle"); return 1; } return 0; } // // Stop command // public final static String USAGE_STOP = "<bundle> ..."; public final static String[] HELP_STOP = new String[] { "Stop one or more bundles", "<bundle> Name or id of bundle" }; public int cmdStop(Dictionary opts, Reader in, PrintWriter out, Session session) { Bundle[] b = getBundles((String[]) opts.get("bundle"), true); boolean found = false; for (int i = b.length - 1; i >= 0; i--) { if (b[i] != null) { try { b[i].stop(); out.println("Stopped: " + showBundle(b[i])); } catch (BundleException e) { Throwable t = e; while (t instanceof BundleException && ((BundleException) t).getNestedException() != null) t = ((BundleException) t).getNestedException(); out.println("Couldn't stop bundle: " + showBundle(b[i]) + " (due to: " + t + ")"); } found = true; } } if (!found) { out.println("ERROR! No matching bundle"); return 1; } return 0; } // // Showstate command // public final static String USAGE_SHOWSTATE = "[<pid>] ..."; public final static String[] HELP_SHOWSTATE = new String[] { "Show the state of a service, if the service provides state information", "<pid> The service pid(s) of interest" }; public int cmdShowstate(Dictionary opts, Reader in, PrintWriter out, Session session) { String[] pids = (String[]) opts.get("pid"); try { if (pids != null && pids.length > 0) { for (int i = 0; i < pids.length; i++) { showstate(out, bc.getServiceReferences(null, "(service.id=" + pids[i] + ")")); } } else showstate(out, bc.getServiceReferences(null, "(state=*)")); } catch (Exception e) { out.println("Error: " + e); } return 0; } // // Shutdown command // public final static String USAGE_SHUTDOWN = "[<exit code>]"; public final static String[] HELP_SHUTDOWN = new String[] { "Shutdown framework", "<exit code> Exit code for JVM" }; public int cmdShutdown(Dictionary opts, Reader in, PrintWriter out, Session session) { /* * String c = (String) opts.get("exit code"); int ec = 0; if (c != null) { * try { ec = Integer.parseInt(c); } catch (NumberFormatException e) { * out.println("Illegal exit code must be an integer."); return 1; } } */ try { Bundle sysBundle = bc.getBundle(0); sysBundle.stop(); } catch (Exception e) { out.println("Failed to stop using system bundle"); try { System.exit(0); } catch (Exception e2) { out.println("Failed to exit using system exit " + e2); } } return 0; } // // Uninstall command // public final static String USAGE_UNINSTALL = "<bundle> ..."; public final static String[] HELP_UNINSTALL = new String[] { "Uninstall one or more bundles", "<bundle> Name or id of bundle" }; public int cmdUninstall(Dictionary opts, Reader in, PrintWriter out, Session session) { Bundle[] b = getBundles((String[]) opts.get("bundle"), true); boolean found = false; for (int i = 0; i < b.length; i++) { if (b[i] != null) { try { b[i].uninstall(); out.println("Uninstalled: " + showBundle(b[i])); } catch (BundleException e) { Throwable t = e; while (t instanceof BundleException && ((BundleException) t).getNestedException() != null) t = ((BundleException) t).getNestedException(); out.println("Couldn't uninstall: " + showBundle(b[i]) + " (due to: " + t + ")"); } found = true; } } if (!found) { out.println("ERROR! No matching bundle"); return 1; } return 0; } // // Update command
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -