1 22 23 package org.gjt.sp.jedit; 24 25 import java.io.*; 27 import java.net.URL ; 28 import java.util.*; 29 30 import org.xml.sax.Attributes ; 31 import org.xml.sax.InputSource ; 32 import org.xml.sax.helpers.DefaultHandler ; 33 34 import org.gjt.sp.util.Log; 35 import org.gjt.sp.util.XMLUtilities; 36 38 43 class ServiceListHandler extends DefaultHandler 44 { 45 ServiceListHandler(PluginJAR plugin, URL uri) 47 { 48 this.plugin = plugin; 49 this.uri = uri; 50 code = new StringBuffer (); 51 stateStack = new Stack(); 52 cachedServices = new LinkedList(); 53 } 55 public InputSource resolveEntity(String publicId, String systemId) 57 { 58 return XMLUtilities.findEntity(systemId, "services.dtd", getClass()); 59 } 61 public void characters(char[] c, int off, int len) 63 { 64 String tag = peekElement(); 65 if (tag == "SERVICE") 66 code.append(c, off, len); 67 } 69 public void startElement(String uri, String localName, 71 String tag, Attributes attrs) 72 { 73 tag = pushElement(tag); 74 serviceName = attrs.getValue("NAME"); 75 serviceClass = attrs.getValue("CLASS"); 76 } 78 public void endElement(String uri, String localName, String name) 80 { 81 String tag = peekElement(); 82 83 if(name.equals(tag)) 84 { 85 if (tag.equals("SERVICE")) 86 { 87 ServiceManager.Descriptor d = 88 new ServiceManager.Descriptor( 89 serviceClass,serviceName,code.toString(),plugin); 90 ServiceManager.registerService(d); 91 cachedServices.add(d); 92 code.setLength(0); 93 } 94 95 popElement(); 96 } 97 else 98 { 99 throw new InternalError (); 101 } 102 } 104 public void startDocument() 106 { 107 try 108 { 109 pushElement(null); 110 } 111 catch (Exception e) 112 { 113 e.printStackTrace(); 114 } 115 } 117 public ServiceManager.Descriptor[] getCachedServices() 119 { 120 return (ServiceManager.Descriptor[])cachedServices.toArray( 121 new ServiceManager.Descriptor[cachedServices.size()]); 122 } 124 126 private PluginJAR plugin; 128 private URL uri; 129 130 private String serviceName; 131 private String serviceClass; 132 private StringBuffer code; 133 134 private Stack stateStack; 135 136 private List cachedServices; 137 139 private String pushElement(String name) 141 { 142 name = (name == null) ? null : name.intern(); 143 144 stateStack.push(name); 145 146 return name; 147 } 149 private String peekElement() 151 { 152 return (String ) stateStack.peek(); 153 } 155 private String popElement() 157 { 158 return (String ) stateStack.pop(); 159 } 161 } 163 | Popular Tags |