Class FeatureHandler

  • All Implemented Interfaces:
    StAXContentHandler
    Direct Known Subclasses:
    StrandedFeatureHandler

    public class FeatureHandler
    extends StAXContentHandlerBase
    StAX handler for the basic feature type of XFF. This class can also be subclassed to handle other XFF types.

    In general, to handle a feature subclass, you will with to:

    • If necessary, override createFeatureTemplate to build the appropriate BioJava Feature.Template
    • Add your own startElement and endElement methods which handle extra extra elements in your feature type. These should normally pass on all the standard elements to super.startElement and super.endElement.

    Note that, since FeatureHandler does some basic housekeeping, if you `consume' a startElement notification (i.e. don't pass it on to the superclass) you must also consume the matching endElement. Since FeatureHandler silently ignores all unrecognized elements, it is usually safe to pass on all startElement and endElement notifications -- even those which are specific to your feature type.

    Since:
    1.2
    Author:
    Thomas Down
    • Constructor Detail

      • FeatureHandler

        public FeatureHandler​(XFFFeatureSetHandler xffenv)
        Construct a new Feature handler, passing in an XFF-parsing environment.
    • Method Detail

      • getXFFEnvironment

        public XFFFeatureSetHandler getXFFEnvironment()
        Return the XFF processing environment passed in when this handler was created.
      • getFeatureTemplate

        protected Feature.Template getFeatureTemplate()
        Get the template for the feature being constructed. This should usually not be overridden. Delegates to createFeatureTemplate for template construction.
      • createFeatureTemplate

        protected Feature.Template createFeatureTemplate()
        Create a new template of the appropriate type. Override this method if you wish to use a template type other than Feature.Template.
      • fireStartFeature

        protected void fireStartFeature()
                                 throws ParseException
        Fire the startFeature event. You should wrap this method if you want to perform any validation on the Feature.Template before the startFeature is fired.
        Throws:
        ParseException - if the startFeature notification fails, or if it has already been made.
      • setFeatureProperty

        protected void setFeatureProperty​(java.lang.Object key,
                                          java.lang.Object value)
                                   throws ChangeVetoException,
                                          ParseException
        Set a property. If the startFeature notification has not yet been fired, the property is added directly to the annotation bundle in the feature template, otherwise an addFeatureProperty event is generated.
        Throws:
        ChangeVetoException
        ParseException
      • startElement

        public void startElement​(java.lang.String nsURI,
                                 java.lang.String localName,
                                 java.lang.String qName,
                                 org.xml.sax.Attributes attrs,
                                 DelegationManager dm)
                          throws org.xml.sax.SAXException
        StAX callback for element starts. Wrap this method to handle extra elements within your own feature types.
        Specified by:
        startElement in interface StAXContentHandler
        Overrides:
        startElement in class StAXContentHandlerBase
        Throws:
        org.xml.sax.SAXException
      • endElement

        public void endElement​(java.lang.String nsURI,
                               java.lang.String localName,
                               java.lang.String qName,
                               StAXContentHandler handler)
                        throws org.xml.sax.SAXException
        StAX callback for element ends. Wrap this method to handle extra elements within your own feature types.
        Specified by:
        endElement in interface StAXContentHandler
        Overrides:
        endElement in class StAXContentHandlerBase
        Throws:
        org.xml.sax.SAXException