Refactored simple SAX ElementHandler to be an interface.
[debian/openrocket] / core / src / net / sf / openrocket / file / simplesax / ElementHandler.java
index ae678f80bb43915398ad72f377a9b8a649ee55f4..cdbbe1d6187dadef53638464274d6dd00e9d1e31 100644 (file)
@@ -2,7 +2,6 @@ package net.sf.openrocket.file.simplesax;
 
 import java.util.HashMap;
 
-import net.sf.openrocket.aerodynamics.Warning;
 import net.sf.openrocket.aerodynamics.WarningSet;
 
 import org.xml.sax.SAXException;
@@ -18,30 +17,23 @@ import org.xml.sax.SAXException;
  * 
  * and the initial handler is initHandler, then the following methods will be called:
  * 
- * 1. initHandler.{@link #openElement(String, HashMap, WarningSet)} is called for
- *       the opening element <bar>, which returns fooHandler
- * 2. fooHandler.{@link #openElement(String, HashMap, WarningSet)} is called for
- *       the opening element <bar>, which returns barHandler
- * 3. barHandler.{@link #endHandler(String, HashMap, String, WarningSet)} is called for
- *       the closing element </bar>
- * 4. fooHandler.{@link #closeElement(String, HashMap, String, WarningSet)} is called for
- *       the closing element </bar>
- * 5. fooHandler.{@link #endHandler(String, HashMap, String, WarningSet)} is called for
- *       the closing element </foo>
- * 6. initHandler.{@link #closeElement(String, HashMap, String, WarningSet)} is called for
- *       the closing element </foo>
+ * 1. initHandler.openElement(String, HashMap, WarningSet) is called for the opening element <foo>, which returns fooHandler
+ * 2. fooHandler.openElement(String, HashMap, WarningSet) is called for the opening element <bar>, which returns barHandler
+ * 3. barHandler.endHandler(String, HashMap, String, WarningSet) is called for the closing element </bar>
+ * 4. fooHandler.closeElement(String, HashMap, String, WarningSet) is called for the closing element </bar>
+ * 5. fooHandler.endHandler(String, HashMap, String, WarningSet) is called for the closing element </foo>
+ * 6. initHandler.closeElement(String, HashMap, String, WarningSet) is called for the closing element </foo>
  * 
- * Note that {@link #endHandler(String, HashMap, String, WarningSet)} is not called for
- * the initial handler.
+ * Note that endHandler(String, HashMap, String, WarningSet) is not called for the initial handler.
  * 
  * @author Sampo Niskanen <sampo.niskanen@iki.fi>
  */
-public abstract class ElementHandler {
-
+public interface ElementHandler {
+       
        /**
-        * Called when an opening element is encountered.  Returns the handler that will handle
-        * the elements within that element, or <code>null</code> if the element and all of
-        * its contents is to be ignored.
+        * Called when an opening tag of a contained element is encountered.  Returns the handler
+        * that will handle the elements within that element, or <code>null</code> if the element
+        * and all of its contents is to be ignored.
         * <p>
         * Note that this method may also return <code>this</code>, in which case this
         * handler will also handle the subelement.
@@ -52,43 +44,29 @@ public abstract class ElementHandler {
         * @return                              the handler that handles elements encountered within this element,
         *                                              or <code>null</code> if the element is to be ignored.
         */
-       public abstract ElementHandler openElement(String element,
-                       HashMap<String, String> attributes, WarningSet warnings) throws SAXException;
-
+       public ElementHandler openElement(String element, HashMap<String, String> attributes,
+                       WarningSet warnings) throws SAXException;
+       
        /**
-        * Called when an element is closed.  The default implementation checks whether there is
-        * any non-space text within the element and if there exists any attributes, and adds
-        * a warning of both.  This can be used at the and of the method to check for 
-        * spurious data.
+        * Called when a closing tag of a contained element is encountered.
+        * <p>
+        * This method can be used to handle the textual content of the element for simple text
+        * elements, which is passed in as the "content" parameter.
         * 
         * @param element               the element name.
         * @param attributes    attributes of the element.
         * @param content               the textual content of the element.
         * @param warnings              the warning set to store warnings in.
         */
-       public void closeElement(String element, HashMap<String, String> attributes,
-                       String content, WarningSet warnings) throws SAXException {
-
-               if (!content.trim().equals("")) {
-                       warnings.add(Warning.fromString("Unknown text in element '" + element
-                                       + "', ignoring."));
-               }
-               if (!attributes.isEmpty()) {
-                       warnings.add(Warning.fromString("Unknown attributes in element '" + element
-                                       + "', ignoring."));
-               }
-       }
-       
+       public abstract void closeElement(String element, HashMap<String, String> attributes,
+                       String content, WarningSet warnings) throws SAXException;
        
        /**
-        * Called when the element block that this handler is handling ends.
-        * The default implementation is a no-op.
+        * Called when the current element that this handler is handling is closed.
         * 
         * @param warnings              the warning set to store warnings in.
         */
-       public void endHandler(String element, HashMap<String, String> attributes,
-                       String content, WarningSet warnings) throws SAXException {
-               // No-op
-       }
+       public abstract void endHandler(String element, HashMap<String, String> attributes,
+                       String content, WarningSet warnings) throws SAXException;
        
-}
+}
\ No newline at end of file