1 11 12 package org.eclipse.core.internal.registry.osgi; 13 14 import org.eclipse.core.runtime.*; 15 import org.eclipse.osgi.framework.console.CommandInterpreter; 16 import org.eclipse.osgi.framework.console.CommandProvider; 17 18 public class RegistryCommandProvider implements CommandProvider { 19 20 private final static String helpText = "---Extension Registry Commands---\n" + "\tns [-v] [name] - display extension points in the namespace; add -v to display extensions\n" + "\tpt [-v] uniqueExtensionPointId - display the extension point and extensions; add -v to display config elements"; 24 private static final String indent = " "; 26 private boolean verbose = false; 28 public String getHelp() { 29 return helpText; 30 } 31 32 public void _ns(CommandInterpreter ci) throws Exception { 33 String namespace = getArgument(ci); 34 if (namespace == null) { 35 String [] namespaces = RegistryFactory.getRegistry().getNamespaces(); 36 ci.println("Namespace(s):"); ci.println("-------------------"); for (int i = 0; i < namespaces.length; i++) 39 ci.println(namespaces[i]); 40 return; 41 } 42 43 IExtensionRegistry registry = RegistryFactory.getRegistry(); 44 IExtensionPoint[] extpts = registry.getExtensionPoints(namespace); 45 ci.println("Extension point(s):"); ci.println("-------------------"); for (int i = 0; i < extpts.length; i++) 48 displayExtensionPoint(extpts[i], ci); 49 50 if (verbose) { 51 ci.println("\nExtension(s):"); ci.println("-------------------"); IExtension[] exts = RegistryFactory.getRegistry().getExtensions(namespace); 54 for (int j = 0; j < exts.length; j++) 55 displayExtension(exts[j], ci, true ); 56 } 57 } 58 59 public void _pt(CommandInterpreter ci) throws Exception { 60 String extensionPointId = getArgument(ci); 61 if (extensionPointId == null) 62 return; 63 IExtensionPoint extpt = RegistryFactory.getRegistry().getExtensionPoint(extensionPointId); 64 if (extpt == null) 65 return; 66 ci.print("Extension point: "); displayExtensionPoint(extpt, ci); 68 IExtension[] exts = extpt.getExtensions(); 69 ci.println("\nExtension(s):"); ci.println("-------------------"); for (int i = 0; i < exts.length; i++) { 72 displayExtension(exts[i], ci, false ); 73 if (verbose) { 74 IConfigurationElement[] ce = exts[i].getConfigurationElements(); 75 for (int j = 0; j < ce.length; j++) 76 displayConfigElement(ci, ce[j], 1); 77 ci.println(); 78 } 79 } 80 } 81 82 private String getArgument(CommandInterpreter ci) { 84 String firstParm = ci.nextArgument(); 85 if ("-v".equals(firstParm)) { verbose = true; 87 return ci.nextArgument(); 88 } 89 90 verbose = false; 91 return firstParm; 92 } 93 94 private void displayExtensionPoint(IExtensionPoint extentionPoint, CommandInterpreter ci) { 95 if (extentionPoint == null) 96 return; 97 ci.println(extentionPoint.getUniqueIdentifier() + " [from " + extentionPoint.getContributor().getName() + ']'); } 99 100 private void displayExtension(IExtension extention, CommandInterpreter ci, boolean full) { 101 if (extention == null) 102 return; 103 if (full) { 104 ci.print("Id: " + extention.getUniqueIdentifier()); ci.print(" PointId: " + extention.getExtensionPointUniqueIdentifier()); ci.println(" [from " + extention.getContributor().getName() + "]"); } else { 108 ci.println(extention.getUniqueIdentifier() + " [from " + extention.getContributor().getName() + "]"); } 110 } 111 112 private void displayConfigElement(CommandInterpreter ci, IConfigurationElement ce, int level) throws Exception { 113 String spacing = spacing(ci, level); 114 ci.println(spacing + '<' + ce.getName() + '>'); 115 String [] attrs = ce.getAttributeNames(); 116 for (int k = 0; k < attrs.length; k++) 117 ci.println(indent + spacing + attrs[k] + " = " + ce.getAttribute(attrs[k])); String value = ce.getValue(); 119 if (value != null) 120 ci.println(indent + spacing + value); 121 IConfigurationElement[] children = ce.getChildren(); 122 for (int z = 0; z < children.length; z++) 123 displayConfigElement(ci, children[z], level + 1); 124 ci.println(spacing + "</" + ce.getName() + '>'); } 126 127 private String spacing(CommandInterpreter ci, int level) { 128 StringBuffer b = new StringBuffer (); 129 for (int i = 0; i < level; i++) 130 b.append(indent); 131 return b.toString(); 132 } 133 } 134 | Popular Tags |