SASAX API - 1.5

jp.ne.dti.lares.foozy.sasax
Class DormantElement

java.lang.Object
  |
  +--jp.ne.dti.lares.foozy.sasax.AbstractElement
        |
        +--jp.ne.dti.lares.foozy.sasax.DormantElement
All Implemented Interfaces:
Element

public class DormantElement
extends AbstractElement

Pseudo element to make another dormant till occurrence of acceptable event.

This class focuses on parsing part of document under the one defined in XML Schema like as below.


 <xsd:any namespace="##any" minOccurs="1" maxOccurs="1"/>

 

For example, you are interested in the (sub)document as shown below:

 <some>
     <structured>
         <document/>
     </structured>
 </some>
 

But parse target document may be one of belows, and you can not know it beforehand.

 (1)
 <parent>
     <some>
         <structured>
             <document/>
         </structured>
     </some>
 </parent>

 (2)
 <parent>
     <upper>
         <some>
             <structured>
                 <document/>
             </structured>
         </some>
     </upper>
 </parent>

 (3)
 <parent>
     <upper>
         <some>
             <structured>
                 <document/>
             </structured>
         </some>
         <some>
             <structured>
                 <document/>
             </structured>
         </some>
     </upper>
 </parent>

 (4)
 <parent>
     <upper>
         <middle>
             <some>
                 <structured>
                     <document/>
                 </structured>
             </some>
         </middle>
     </upper>
 </parent>
 
 (5)
 <parent>
     <upper>
         <some>
             <structured>
                 <document/>
             </structured>
         </some>
         <middle>
             <some>
                 <structured>
                     <document/>
                 </structured>
             </some>
         </middle>
     </upper>
 </parent>

 .... and so on ....

 

In this case, you can catch all document fragments, in which you are interested, in the parse target document by this class with factory of "some" element.

You can get caught "fragments" by getDetermineds(boolean) after parsing.

ATTENTION:

For example, second "some" element shown below is not handled.

 <parent>
     <some>
         <structured>
             <document/>
         </structured>
     </some>
     <some>
         <structured>
             <document/>
         </structured>
     </some>
 </parent>
 

XML Schema shown below (again) tells you why:


 <xsd:any namespace="##any" minOccurs="1" maxOccurs="1"/>

 

Please combine this and ElementRepetition in this situation.

Since:
SASAX 1.5
Author:
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>(code/doc)

Constructor Summary
DormantElement(Element parent, ElementFactory factory)
           
 
Method Summary
 boolean accepts(ParseContext context, java.lang.String uri, java.lang.String lName)
          Examine whether specified name is acceptable or not.
 Element characters(ParseContext context, char[] chars, int offset, int length)
          Receive notification of character data.
 Element endElement(ParseContext context, java.lang.String uri, java.lang.String lName)
          Receive notification of the end of an element.
 java.util.Iterator getDetermineds(boolean ensure)
          Get determined elements.
 Element processingInstruction(ParseContext context, java.lang.String target, java.lang.String data)
          Receive notification of ignorable whitespace in element content.
 Element skippedEntity(ParseContext context, java.lang.String name)
          Receive notification of a processing instruction.
 Element startElement(ParseContext context, java.lang.String uri, java.lang.String lName, org.xml.sax.Attributes attrs)
          Receive notification of the beginning of an element.
 
Methods inherited from class jp.ne.dti.lares.foozy.sasax.AbstractElement
addCleanup, addNotification, clear, ensureDetermined, fireElementStarted, getAttribute, getParent, hasNotification, hasXSINil, ignorableWhitespace, isDetermined, notifyDetermined, notifyDetermined, removeNotification, setDetermined, unwatchAttribute, watchAttribute
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DormantElement

public DormantElement(Element parent,
                      ElementFactory factory)
Method Detail

getDetermineds

public final java.util.Iterator getDetermineds(boolean ensure)
Get determined elements.

Successful invocation of this method does not ensure that all elements gotten from the returned iterator are already determined. This only ensured that control is returned (by "endElement", may be) to this as same times as this encouters "startElement" which is acceptable for the factory.

But they should be determined because nobody wants to use the Element implementation which does not determine itself at the last "endElement" event for it.

Parameters:
ensure - whether determination should be ensured or not.
Returns:
iterator of elements created by factory specified to constructor.
See Also:
AbstractElement.ensureDetermined()

accepts

public boolean accepts(ParseContext context,
                       java.lang.String uri,
                       java.lang.String lName)
Examine whether specified name is acceptable or not.

This always returns "true", because this element consumes(= ignores) events till it encounters the event which is acceptable for the factory specified at construction time.

Overrides:
accepts in class AbstractElement
Following copied from class: jp.ne.dti.lares.foozy.sasax.AbstractElement
Parameters:
context - of SAX document parsing.
uri - given by "startElement" SAX event.
lName - given by "startElement" SAX event.
Returns:
whether specified name is acceptable or not.
See Also:
Element.accepts(ParseContext, String, String)

startElement

public Element startElement(ParseContext context,
                            java.lang.String uri,
                            java.lang.String lName,
                            org.xml.sax.Attributes attrs)
                     throws org.xml.sax.SAXException
Receive notification of the beginning of an element.

This returns the element(result of appling startElement on it, in fact) created by the factory specified at construction time, if start-ed element is acceptable one for the factory.

Otherwise, this returns itself.

Overrides:
startElement in class AbstractElement
Following copied from class: jp.ne.dti.lares.foozy.sasax.AbstractElement
Parameters:
context - of SAX document parsing.
uri - given by "startElement" SAX event.
lName - given by "startElement" SAX event.
attrs - given by "startElement" SAX event.
Returns:
element to handle next event.
Throws:
org.xml.sax.SAXException - if parsing should not be continued.
See Also:
Element.startElement(ParseContext, String, String, Attributes)

endElement

public Element endElement(ParseContext context,
                          java.lang.String uri,
                          java.lang.String lName)
                   throws org.xml.sax.SAXException
Receive notification of the end of an element.

This returns itself, while this encounters end-ed elements less than this does start-ed ones.

Otherwise, this returns parent .

Overrides:
endElement in class AbstractElement
Following copied from class: jp.ne.dti.lares.foozy.sasax.AbstractElement
Parameters:
context - of SAX document parsing.
uri - given by "endElement" SAX event.
lName - given by "endElement" SAX event.
Returns:
element to handle next event.
Throws:
org.xml.sax.SAXException - if parsing should not be continued.
See Also:
Element.endElement(ParseContext, String, String)

characters

public Element characters(ParseContext context,
                          char[] chars,
                          int offset,
                          int length)
                   throws org.xml.sax.SAXException
Receive notification of character data.

This always returns itself(= ignores this event), while this is not determied.

Overrides:
characters in class AbstractElement
Throws:
org.xml.sax.SAXException - if this is already determined

processingInstruction

public Element processingInstruction(ParseContext context,
                                     java.lang.String target,
                                     java.lang.String data)
                              throws org.xml.sax.SAXException
Receive notification of ignorable whitespace in element content.

This always returns itself(= ignores this event), while this is not determied.

Overrides:
processingInstruction in class AbstractElement
Throws:
org.xml.sax.SAXException - if this is already determined

skippedEntity

public Element skippedEntity(ParseContext context,
                             java.lang.String name)
                      throws org.xml.sax.SAXException
Receive notification of a processing instruction.

This always returns itself(= ignores this event), while this is not determied.

Overrides:
skippedEntity in class AbstractElement
Throws:
org.xml.sax.SAXException - if this is already determined

SASAX API - 1.5