Skip to content

Commit

Permalink
Preparing to tackle issue #2
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Feb 27, 2013
1 parent 6542b2c commit 58e70a9
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 22 deletions.
19 changes: 9 additions & 10 deletions src/main/java/org/codehaus/staxmate/in/SMFlatteningCursor.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,10 @@
public class SMFlatteningCursor
extends SMInputCursor
{

/*
////////////////////////////////////////////
// Life cycle, configuration
////////////////////////////////////////////
/**********************************************************************
/* Life cycle, configuration
/**********************************************************************
*/

public SMFlatteningCursor(SMInputContext ctxt,SMInputCursor parent, SMFilter f)
Expand All @@ -37,9 +36,9 @@ public SMFlatteningCursor(SMInputContext ctxt,SMInputCursor parent, SMFilter f)
}

/*
///////////////////////////////////////////////////
// Public API, accessing cursor state information
///////////////////////////////////////////////////
/**********************************************************************
/* Public API, accessing cursor state information
/**********************************************************************
*/

public int getParentCount()
Expand Down Expand Up @@ -71,9 +70,9 @@ public int getParentCount()
}

/*
////////////////////////////////////////////
// Public API, iterating
////////////////////////////////////////////
/**********************************************************************
/* Public API, iterating
/**********************************************************************
*/

public SMEvent getNext()
Expand Down
42 changes: 30 additions & 12 deletions src/main/java/org/codehaus/staxmate/in/SMInputCursor.java
Original file line number Diff line number Diff line change
Expand Up @@ -1354,7 +1354,7 @@ public String getElemStringValue()
* Not sure if END_ELEMENT is the best choice, but seems to work ok.
*/
String str = _streamReader.getElementText();
_currEvent = SMEvent.END_ELEMENT;
_markConsumed();
return str;
}

Expand All @@ -1378,7 +1378,7 @@ public boolean getElemBooleanValue()
{
_verifyElemAccess("getElemBooleanValue");
// need to change curr event (see comments for getElemStringValue)
_currEvent = SMEvent.END_ELEMENT;
_markConsumed();
return _streamReader.getElementAsBoolean();
}

Expand All @@ -1390,7 +1390,7 @@ public boolean getElemBooleanValue(boolean defValue)
throws XMLStreamException
{
_verifyElemAccess("getElemBooleanValue");
_currEvent = SMEvent.END_ELEMENT;
_markConsumed();
// not optimal, but should work:
try {
return _streamReader.getElementAsBoolean();
Expand Down Expand Up @@ -1419,7 +1419,7 @@ public int getElemIntValue()
throws XMLStreamException
{
_verifyElemAccess("getElemIntValue");
_currEvent = SMEvent.END_ELEMENT;
_markConsumed();
return _streamReader.getElementAsInt();
}

Expand All @@ -1431,7 +1431,7 @@ public int getElemIntValue(int defValue)
throws XMLStreamException
{
_verifyElemAccess("getElemIntValue");
_currEvent = SMEvent.END_ELEMENT;
_markConsumed();
try {
return _streamReader.getElementAsInt();
} catch (TypedXMLStreamException tse) {
Expand Down Expand Up @@ -1459,7 +1459,7 @@ public long getElemLongValue()
throws XMLStreamException
{
_verifyElemAccess("getElemLongValue");
_currEvent = SMEvent.END_ELEMENT;
_markConsumed();
return _streamReader.getElementAsLong();
}

Expand All @@ -1471,7 +1471,7 @@ public long getElemLongValue(long defValue)
throws XMLStreamException
{
_verifyElemAccess("getElemLongValue");
_currEvent = SMEvent.END_ELEMENT;
_markConsumed();
try {
return _streamReader.getElementAsLong();
} catch (TypedXMLStreamException tse) {
Expand Down Expand Up @@ -1499,7 +1499,7 @@ public double getElemDoubleValue()
throws XMLStreamException
{
_verifyElemAccess("getElemDoubleValue");
_currEvent = SMEvent.END_ELEMENT;
_markConsumed();
return _streamReader.getElementAsDouble();
}

Expand All @@ -1511,7 +1511,7 @@ public double getElemDoubleValue(double defValue)
throws XMLStreamException
{
_verifyElemAccess("getElemDoubleValue");
_currEvent = SMEvent.END_ELEMENT;
_markConsumed();
try {
return _streamReader.getElementAsDouble();
} catch (TypedXMLStreamException tse) {
Expand Down Expand Up @@ -1541,7 +1541,7 @@ public <T extends Enum<T>> T getElemEnumValue(Class<T> enumType)
throws XMLStreamException
{
_verifyElemAccess("getElemEnumValue");
_currEvent = SMEvent.END_ELEMENT;
_markConsumed();
String value = _streamReader.getElementText().trim();
if (value.length() == 0) {
return null;
Expand All @@ -1562,7 +1562,7 @@ public <T extends Enum<T>> T getElemEnumValue(Class<T> enumType)
public byte[] getElemBinaryValue(Base64Variant variant) throws XMLStreamException
{
_verifyElemAccess("getElemDoubleValue");
_currEvent = SMEvent.END_ELEMENT;
_markConsumed();
return _streamReader.getElementAsBinary();
}

Expand Down Expand Up @@ -1993,7 +1993,7 @@ protected String getCurrEventDesc() {
* valid)
*/
@Override
public String toString() {
public String toString() {
return "[Cursor that point(s/ed) to: "+getCurrEventDesc()+"]";
}

Expand Down Expand Up @@ -2049,4 +2049,22 @@ protected abstract SMInputCursor constructChildCursor(SMFilter f)
*/
protected abstract SMInputCursor constructDescendantCursor(SMFilter f)
throws XMLStreamException;

/*
/**********************************************************************
/* Helper methods for sub-classes, related objects
/**********************************************************************
*/

/**
* Method to call to notify that textual contents of this cursor have been
* read; typically when a call has been made that will traverse contents
* and make stream point to matching <code>END_ELEMENT</code>.
*
* @since 2.2
*/
protected void _markConsumed()
{
_currEvent = SMEvent.END_ELEMENT;
}
}

0 comments on commit 58e70a9

Please sign in to comment.