nbi.xmlsec.biocase.protocol.filter
Class ProtocolFilter

java.lang.Object
  extended byorg.xml.sax.helpers.XMLFilterImpl
      extended bynbi.xmlsec.biocase.protocol.filter.ProtocolFilter
All Implemented Interfaces:
ContentHandler, DTDHandler, EntityResolver, ErrorHandler, XMLFilter, XMLReader
Direct Known Subclasses:
ContentFilter, ContentObjectFilter, COPFilter, DiagnosticsFilter, HeaderFilter, LOPFilter, OperationTypeFilter, OperatorFilter, RBACFilter, RequestFilter, ResponseFilter

public class ProtocolFilter
extends XMLFilterImpl

Base class to parse and filter protocol treeElements of the BioCASE protocol.

The class must be initialised with the protocolURI, the root element. Furthermore, subfilters must be registered to declare the accepted subelements of the filter registerSubFilter()/ unregisterSubFilter(). Subfilters are stored in a HashMapwhere the element's local name serves as key for the registered subfilter. If the registered subfilter for a local name is null, then all incoming treeElements will be handled within the current filter. If a real subfilter is set for a local name, all events including the startElement event are redirected to the defined subfilter. Therefore, the subfilter should be configured, before it will be registered! Note, that for those subfilters, the protocol version URI is not checked, because this should be controlled individually by the subfilter! setFilterParameter(Object)allows to set special filter parameters. When the subfilter signals parse completion ( isParsingComplete()) after the processing of the corresponding endElement event, the subfilter will be unset. For all incoming SAX events, the protocolURI and the validity of the incoming treeElements according to the registered subfilters are checked. To support filtering processes in subclasses, the following callback methods may be overwritten:

All methods (except parseElement when real subfilter has completed) are offering the possibility to influence the further event processing, because they are called before the corresponding event is forwarded to the content handler or subfilter. Events may be removed from further processing if a callback method returns null. The completion of the parsing process is signaled by the method isParsingComplete().

Since:
Version:
$Revision: 1.21 $
Author:
Lutz Suhrbier

Field Summary
protected  nbi.xml.sax.FilterStack elementStack
          Stack storing all treeElements for this filter, if not redirected to subfilters
private  Map filterElements
          Map of registered subfilters
private  boolean filterInitialised
           
protected  int filterMode
          The completion state of the parsing process
static int FILTERMODE_FILTER
          Filter mode filter of this protocol filter
static int FILTERMODE_NONE
          Filter mode unspecified of this protocol filter
static int FILTERMODE_PARSER
          Filter mode parser of this protocol filter
private  Object filterParameter
          Parameter object for the current filter
protected  String filterRoot
          The local name of the element to be parsed
(package private) static Logger logger
           
private  boolean parsingComplete
          The completion state of the parsing process
static String PROT_URI_13
          ProtocolURI of the BioCASE protocol version 1.3
static String PROT_URI_20
          ProtocolURI of the BioCASE protocol version 2.0
private  String protocolURI
          Namespace URI of the BioCASE protocol version
private  ProtocolFilter subFilter
          Current active subfilter
 
Fields inherited from class org.xml.sax.helpers.XMLFilterImpl
 
Constructor Summary
ProtocolFilter(String protocolURI, String filterRoot, int trackMode, int filterMode)
          Inits the protocol filter.
ProtocolFilter(XMLReader parent, String protocolURI, String filterRoot, int trackMode, int filterMode)
          Inits the protocol filter with the specified parent.
 
Method Summary
 void characters(char[] ch, int start, int length)
          Add the characters events to the characters stack and forwards it to the subfilter or content handler.
private  void checkElementParameters(boolean checkAtts, String uri, String localName, String qName, Attributes atts)
          Checks the parameters of the start/endElement events against null parameters.
protected  void checkFilterParameter()
          Checks, if a filter parameter is set.
private  void checkProtocolURI(String uri)
          Checks the protocol URI against the protocolURI of this filter.
 void endElement(String uri, String localName, String qName)
          Completes the processesing of data collection on the stacks, controls event forwarding and callback methods.
protected  nbi.xml.sax.SAXElement filterCharacters(nbi.xml.sax.SAXElement element)
          This method is called when the characters event of any element for a registered subfilter was received, before it is forwarded to a registered subfilter or the content handler.
protected  nbi.xml.sax.SAXElement filterElement(nbi.xml.sax.SAXElement element)
          This method is called when the startElement event of any element for a registered subfilter was received, before it is forwarded to a registered subfilter or the content handler.
 int getFilterMode()
          Gets the filterMode.
 Object getFilterParameter()
          Gets the parameter object of this filter
 String getProtocolURI()
          Gets the protocol version URI.
private  void init(String protocolURI, String filterRoot, int trackMode, int filterMode)
          Inits the protocol filter.
(package private)  boolean isParsingComplete()
          Return the completion state of parsing process.
protected  nbi.xml.sax.SAXElement parseComplete(nbi.xml.sax.SAXElement element)
          This method is called when the endElement event of root element was received, before it is forwarded to the content handler
protected  nbi.xml.sax.SAXElement parseElement(nbi.xml.sax.SAXElement element)
          This method is called when the endElement event of any element for a registered element was received, before it is forwarded to the content handler.
protected  nbi.xml.sax.SAXElement parseInit(nbi.xml.sax.SAXElement element)
          This method is called when the startElement event of the root element was received, before it will be forwarded to the content handler.
protected  void registerSubFilter(String name, ProtocolFilter filter)
          Registers a subfilter.
 void setFilterParameter(Object parameter)
          Sets the parameter object of this filter
protected  void setProtocolURI(String protocolURI)
          Sets the protocol version URI.
 void startElement(String uri, String localName, String qName, Attributes atts)
          Prepares and processes the data collection on the stacks, controls event forwarding and callback methods.
protected  ProtocolFilter unregisterSubFilter(String name)
          Unregisters a subfilter.
 
Methods inherited from class org.xml.sax.helpers.XMLFilterImpl
endDocument, endPrefixMapping, error, fatalError, getContentHandler, getDTDHandler, getEntityResolver, getErrorHandler, getFeature, getParent, getProperty, ignorableWhitespace, notationDecl, parse, parse, processingInstruction, resolveEntity, setContentHandler, setDocumentLocator, setDTDHandler, setEntityResolver, setErrorHandler, setFeature, setParent, setProperty, skippedEntity, startDocument, startPrefixMapping, unparsedEntityDecl, warning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

static Logger logger

PROT_URI_13

public static final String PROT_URI_13
ProtocolURI of the BioCASE protocol version 1.3

See Also:
Constant Field Values

PROT_URI_20

public static final String PROT_URI_20
ProtocolURI of the BioCASE protocol version 2.0

See Also:
Constant Field Values

FILTERMODE_NONE

public static final int FILTERMODE_NONE
Filter mode unspecified of this protocol filter

See Also:
Constant Field Values

FILTERMODE_FILTER

public static final int FILTERMODE_FILTER
Filter mode filter of this protocol filter

See Also:
Constant Field Values

FILTERMODE_PARSER

public static final int FILTERMODE_PARSER
Filter mode parser of this protocol filter

See Also:
Constant Field Values

protocolURI

private String protocolURI
Namespace URI of the BioCASE protocol version


elementStack

protected nbi.xml.sax.FilterStack elementStack
Stack storing all treeElements for this filter, if not redirected to subfilters


filterMode

protected int filterMode
The completion state of the parsing process


parsingComplete

private boolean parsingComplete
The completion state of the parsing process


filterRoot

protected String filterRoot
The local name of the element to be parsed


filterElements

private Map filterElements
Map of registered subfilters


filterParameter

private Object filterParameter
Parameter object for the current filter


subFilter

private ProtocolFilter subFilter
Current active subfilter


filterInitialised

private boolean filterInitialised
Constructor Detail

ProtocolFilter

public ProtocolFilter(String protocolURI,
                      String filterRoot,
                      int trackMode,
                      int filterMode)
Inits the protocol filter.

Parameters:
protocolURI - URI of the protocol version.
filterRoot - Local name of the root element.
trackMode - Define track mode for the internal FilterStack.
filterMode - Define filter mode for this filter FILTERMODE_FILTER(inkl. PDPFilter) or FILTERMODE_PARSER(Parses all elements).

ProtocolFilter

public ProtocolFilter(XMLReader parent,
                      String protocolURI,
                      String filterRoot,
                      int trackMode,
                      int filterMode)
Inits the protocol filter with the specified parent.

Parameters:
parent - Parent reader.
protocolURI - URI of the protocol version.
filterRoot - Local name of the root element.
trackMode - Define track mode for the internal FilterStack.
filterMode - Define filter mode for this filter FILTERMODE_FILTER(inkl. PDPFilter) or FILTERMODE_PARSER(Parses all elements).
Method Detail

init

private void init(String protocolURI,
                  String filterRoot,
                  int trackMode,
                  int filterMode)
Inits the protocol filter.

Parameters:
protocolURI - URI of the protocol version.
filterRoot - Local name of the root element.
trackMode - Define track mode for the internal FilterStack.
filterMode - Define filter mode for this filter FILTERMODE_FILTER(inkl. PDPFilter) or FILTERMODE_PARSER(Parses all elements).

checkElementParameters

private void checkElementParameters(boolean checkAtts,
                                    String uri,
                                    String localName,
                                    String qName,
                                    Attributes atts)
                             throws SAXException
Checks the parameters of the start/endElement events against null parameters.

Parameters:
checkAtts - Signals, if attributes have to be checked or not.
Throws:
SAXException - if null parameter occurs.

checkProtocolURI

private void checkProtocolURI(String uri)
                       throws SAXException
Checks the protocol URI against the protocolURI of this filter. TODO: Provider muss wieder namespaceURI senden !

Throws:
SAXException - if incorrect protocol URI occurs.

startElement

public void startElement(String uri,
                         String localName,
                         String qName,
                         Attributes atts)
                  throws SAXException
Prepares and processes the data collection on the stacks, controls event forwarding and callback methods.

Throws:
SAXException
See Also:
ContentHandler.startElement(String,String,String,Attributes)

endElement

public void endElement(String uri,
                       String localName,
                       String qName)
                throws SAXException
Completes the processesing of data collection on the stacks, controls event forwarding and callback methods.

Throws:
SAXException
See Also:
ContentHandler.endElement(String,String,String)

characters

public void characters(char[] ch,
                       int start,
                       int length)
                throws SAXException
Add the characters events to the characters stack and forwards it to the subfilter or content handler.

Throws:
SAXException
See Also:
ContentHandler.characters(char[], int, int)

getProtocolURI

public String getProtocolURI()
Gets the protocol version URI.

Returns:
Returns the protocol URI.

setProtocolURI

protected void setProtocolURI(String protocolURI)
Sets the protocol version URI.

Parameters:
protocolURI - The protocol URI.

isParsingComplete

boolean isParsingComplete()
Return the completion state of parsing process.

Returns:
true , when the header is parsed completely, false otherwise.

parseInit

protected nbi.xml.sax.SAXElement parseInit(nbi.xml.sax.SAXElement element)
                                    throws SAXException
This method is called when the startElement event of the root element was received, before it will be forwarded to the content handler.

Parameters:
element - The element of the startElement event (contains no value).
Returns:
The (modified) element or null when the event shall be removed.
Throws:
SAXException - If any parsing error occurs.

filterElement

protected nbi.xml.sax.SAXElement filterElement(nbi.xml.sax.SAXElement element)
                                        throws SAXException
This method is called when the startElement event of any element for a registered subfilter was received, before it is forwarded to a registered subfilter or the content handler.

Parameters:
element - The element corresponding to the startElement event.
Returns:
The (modified) element or null when element shall be removed.
Throws:
SAXException - If any parsing error occurs.

filterCharacters

protected nbi.xml.sax.SAXElement filterCharacters(nbi.xml.sax.SAXElement element)
                                           throws SAXException
This method is called when the characters event of any element for a registered subfilter was received, before it is forwarded to a registered subfilter or the content handler.

Parameters:
element - The element corresponding to the startElement event.
Returns:
The (modified) element or null when element shall be removed.
Throws:
SAXException - If any parsing error occurs.

parseElement

protected nbi.xml.sax.SAXElement parseElement(nbi.xml.sax.SAXElement element)
                                       throws SAXException
This method is called when the endElement event of any element for a registered element was received, before it is forwarded to the content handler. This method is also called, when a registered subfilter signals isParsingComplete(). But, the returned element will not influence the event processing, because this has to be done by the subfilter.

Parameters:
element - The element corresponding to the endElement event.
Returns:
The (modified) element or null when element shall be removed.
Throws:
SAXException - If any parsing error occurs.

parseComplete

protected nbi.xml.sax.SAXElement parseComplete(nbi.xml.sax.SAXElement element)
                                        throws SAXException
This method is called when the endElement event of root element was received, before it is forwarded to the content handler

Parameters:
element - The complete root element (including the value).
Returns:
The (modified) element or null when element shall be removed.
Throws:
SAXException - If any parsing error occurs.

registerSubFilter

protected void registerSubFilter(String name,
                                 ProtocolFilter filter)
Registers a subfilter. Registering overwrites already registered subfilters for the same element.

Parameters:
name - local name for the subfilter to register.
filter - subfilter for this element or null.

unregisterSubFilter

protected ProtocolFilter unregisterSubFilter(String name)
Unregisters a subfilter.

Parameters:
name - local name for the subfilter to unregister.
Returns:
The removed subfilter.

getFilterParameter

public Object getFilterParameter()
Gets the parameter object of this filter

Returns:
Returns the filter parameter.

setFilterParameter

public void setFilterParameter(Object parameter)
Sets the parameter object of this filter

Parameters:
parameter - Returns the filter parameter.

checkFilterParameter

protected void checkFilterParameter()
                             throws SAXException
Checks, if a filter parameter is set.

Throws:
SAXException - If no parameter is set (null)

getFilterMode

public int getFilterMode()
Gets the filterMode. May be on of these:
  • FILTERMODE_FILTER(inkl. PDPFilter)
  • FILTERMODE_PARSER(Parses all elements)
  • .

    Returns:
    Returns the filterMode.


    Copyright © 2006 Lutz Suhrbier, Freie Universitšt Berlin. All Rights Reserved.