PageRenderTime 81ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/jEdit/tags/jedit-4-3-pre5/org/gjt/sp/jedit/ServiceListHandler.java

#
Java | 161 lines | 94 code | 24 blank | 43 comment | 5 complexity | e13f04c0f9809bf37cfe80461d84e3fc MD5 | raw file
Possible License(s): BSD-3-Clause, AGPL-1.0, Apache-2.0, LGPL-2.0, LGPL-3.0, GPL-2.0, CC-BY-SA-3.0, LGPL-2.1, GPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0
  1. /*
  2. * ServiceManager.java - Handles services.xml files in plugins
  3. * :tabSize=8:indentSize=8:noTabs=false:
  4. * :folding=explicit:collapseFolds=1:
  5. *
  6. * Copyright (C) 2003 Slava Pestov
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version 2
  11. * of the License, or any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  21. */
  22. package org.gjt.sp.jedit;
  23. //{{{ Imports
  24. import java.io.*;
  25. import java.net.URL;
  26. import java.util.*;
  27. import org.xml.sax.Attributes;
  28. import org.xml.sax.InputSource;
  29. import org.xml.sax.helpers.DefaultHandler;
  30. import org.gjt.sp.util.Log;
  31. //}}}
  32. /**
  33. * @since jEdit 4.2pre1
  34. * @author Slava Pestov
  35. * @version $Id: ServiceListHandler.java 5443 2006-06-18 18:51:40Z vanza $
  36. */
  37. class ServiceListHandler extends DefaultHandler
  38. {
  39. //{{{ ServiceListHandler constructor
  40. ServiceListHandler(PluginJAR plugin, URL uri)
  41. {
  42. this.plugin = plugin;
  43. this.uri = uri;
  44. code = new StringBuffer();
  45. stateStack = new Stack();
  46. cachedServices = new LinkedList();
  47. } //}}}
  48. //{{{ resolveEntity() method
  49. public InputSource resolveEntity(String publicId, String systemId)
  50. {
  51. return MiscUtilities.findEntity(systemId, "services.dtd", getClass());
  52. } //}}}
  53. //{{{ characters() method
  54. public void characters(char[] c, int off, int len)
  55. {
  56. String tag = peekElement();
  57. if (tag == "SERVICE")
  58. code.append(c, off, len);
  59. } //}}}
  60. //{{{ startElement() method
  61. public void startElement(String uri, String localName,
  62. String tag, Attributes attrs)
  63. {
  64. tag = pushElement(tag);
  65. serviceName = attrs.getValue("NAME");
  66. serviceClass = attrs.getValue("CLASS");
  67. } //}}}
  68. //{{{ endElement() method
  69. public void endElement(String uri, String localName, String name)
  70. {
  71. String tag = peekElement();
  72. if(name.equals(tag))
  73. {
  74. if (tag.equals("SERVICE"))
  75. {
  76. ServiceManager.Descriptor d =
  77. new ServiceManager.Descriptor(
  78. serviceClass,serviceName,code.toString(),plugin);
  79. ServiceManager.registerService(d);
  80. cachedServices.add(d);
  81. code.setLength(0);
  82. }
  83. popElement();
  84. }
  85. else
  86. {
  87. // can't happen
  88. throw new InternalError();
  89. }
  90. } //}}}
  91. //{{{ startDocument() method
  92. public void startDocument()
  93. {
  94. try
  95. {
  96. pushElement(null);
  97. }
  98. catch (Exception e)
  99. {
  100. e.printStackTrace();
  101. }
  102. } //}}}
  103. //{{{ getCachedServices() method
  104. public ServiceManager.Descriptor[] getCachedServices()
  105. {
  106. return (ServiceManager.Descriptor[])cachedServices.toArray(
  107. new ServiceManager.Descriptor[cachedServices.size()]);
  108. } //}}}
  109. //{{{ Private members
  110. //{{{ Instance variables
  111. private PluginJAR plugin;
  112. private URL uri;
  113. private String serviceName;
  114. private String serviceClass;
  115. private StringBuffer code;
  116. private Stack stateStack;
  117. private List cachedServices;
  118. //}}}
  119. //{{{ pushElement() method
  120. private String pushElement(String name)
  121. {
  122. name = (name == null) ? null : name.intern();
  123. stateStack.push(name);
  124. return name;
  125. } //}}}
  126. //{{{ peekElement() method
  127. private String peekElement()
  128. {
  129. return (String) stateStack.peek();
  130. } //}}}
  131. //{{{ popElement() method
  132. private String popElement()
  133. {
  134. return (String) stateStack.pop();
  135. } //}}}
  136. //}}}
  137. }