protected internal TokenFilterContext(int type, com.fasterxml.jackson.core.filter.TokenFilterContext parent, com.fasterxml.jackson.core.filter.TokenFilter filter, bool startHandled ) : base() { /* /********************************************************** /* Simple instance reuse slots; speed up things /* a bit (10-15%) for docs with lots of small /* arrays/objects /********************************************************** */ /* /********************************************************** /* Location/state information /********************************************************** */ /* /********************************************************** /* Life-cycle /********************************************************** */ _type = type; _parent = parent; _filter = filter; _index = -1; _startHandled = startHandled; _needToHandleName = false; }
/// <summary>Method called when a new potentially included context is found.</summary> /// <exception cref="System.IO.IOException"/> protected internal com.fasterxml.jackson.core.JsonToken _nextTokenWithBuffering(com.fasterxml.jackson.core.filter.TokenFilterContext buffRoot) { while (true) { com.fasterxml.jackson.core.JsonToken t = delegate_.nextToken(); if (t == null) { // is this even legal? return t; } com.fasterxml.jackson.core.filter.TokenFilter f; switch (t.id()) { case JsonTokenIdConstants.ID_START_ARRAY: { // One simplification here: we know for a fact that the item filter is // neither null nor 'include all', for most cases; the only exception // being FIELD_NAME handling f = _headContext.checkValue(_itemFilter); if (f == null) { delegate_.skipChildren(); goto main_loop_continue; } if (f != com.fasterxml.jackson.core.filter.TokenFilter.INCLUDE_ALL) { f = f.filterStartArray(); } _itemFilter = f; if (f == com.fasterxml.jackson.core.filter.TokenFilter.INCLUDE_ALL) { _headContext = _headContext.createChildArrayContext(f, true); return _nextBuffered(buffRoot); } _headContext = _headContext.createChildArrayContext(f, false); goto main_loop_continue; } case JsonTokenIdConstants.ID_START_OBJECT: { f = _itemFilter; if (f == com.fasterxml.jackson.core.filter.TokenFilter.INCLUDE_ALL) { _headContext = _headContext.createChildObjectContext(f, true); return t; } if (f == null) { // does this occur? delegate_.skipChildren(); goto main_loop_continue; } // Otherwise still iffy, need to check f = _headContext.checkValue(f); if (f == null) { delegate_.skipChildren(); goto main_loop_continue; } if (f != com.fasterxml.jackson.core.filter.TokenFilter.INCLUDE_ALL) { f = f.filterStartObject(); } _itemFilter = f; if (f == com.fasterxml.jackson.core.filter.TokenFilter.INCLUDE_ALL) { _headContext = _headContext.createChildObjectContext(f, true); return _nextBuffered(buffRoot); } _headContext = _headContext.createChildObjectContext(f, false); goto main_loop_continue; } case JsonTokenIdConstants.ID_END_ARRAY: case JsonTokenIdConstants.ID_END_OBJECT: { // Unlike with other loops, here we know that content was NOT // included (won't get this far otherwise) f = _headContext.getFilter(); if ((f != null) && (f != com.fasterxml.jackson.core.filter.TokenFilter.INCLUDE_ALL )) { f.filterFinishArray(); } bool gotEnd = (_headContext == buffRoot); bool returnEnd = gotEnd && _headContext.isStartHandled(); _headContext = ((com.fasterxml.jackson.core.filter.TokenFilterContext)_headContext .getParent()); _itemFilter = _headContext.getFilter(); if (returnEnd) { return t; } // Hmmh. Do we need both checks, or should above suffice? if (gotEnd || (_headContext == buffRoot)) { return null; } goto main_loop_continue; } case JsonTokenIdConstants.ID_FIELD_NAME: { string name = delegate_.getCurrentName(); f = _headContext.setFieldName(name); if (f == com.fasterxml.jackson.core.filter.TokenFilter.INCLUDE_ALL) { _itemFilter = f; return _nextBuffered(buffRoot); } if (f == null) { // filter out the value delegate_.nextToken(); delegate_.skipChildren(); goto main_loop_continue; } f = f.includeProperty(name); if (f == null) { // filter out the value delegate_.nextToken(); delegate_.skipChildren(); goto main_loop_continue; } _itemFilter = f; if (f == com.fasterxml.jackson.core.filter.TokenFilter.INCLUDE_ALL) { return _nextBuffered(buffRoot); } goto main_loop_continue; } default: { // scalar value f = _itemFilter; if (f == com.fasterxml.jackson.core.filter.TokenFilter.INCLUDE_ALL) { return _nextBuffered(buffRoot); } if (f != null) { f = _headContext.checkValue(f); if ((f == com.fasterxml.jackson.core.filter.TokenFilter.INCLUDE_ALL) || ((f != null ) && f.includeValue(delegate_))) { return _nextBuffered(buffRoot); } } // Otherwise not included (leaves must be explicitly included) goto main_loop_continue; } } main_loop_continue: ; } main_loop_break: ; }
/// <summary> /// Offlined handling for cases where there was no buffered token to /// return, and the token read next could not be returned as-is, /// at least not yet, but where we have not yet established that /// buffering is needed. /// </summary> /// <exception cref="System.IO.IOException"/> protected internal com.fasterxml.jackson.core.JsonToken _nextToken2() { while (true) { com.fasterxml.jackson.core.JsonToken t = delegate_.nextToken(); if (t == null) { // is this even legal? return (_currToken = t); } com.fasterxml.jackson.core.filter.TokenFilter f; switch (t.id()) { case JsonTokenIdConstants.ID_START_ARRAY: { f = _itemFilter; if (f == com.fasterxml.jackson.core.filter.TokenFilter.INCLUDE_ALL) { _headContext = _headContext.createChildArrayContext(f, true); return (_currToken = t); } if (f == null) { // does this occur? delegate_.skipChildren(); goto main_loop_continue; } // Otherwise still iffy, need to check f = _headContext.checkValue(f); if (f == null) { delegate_.skipChildren(); goto main_loop_continue; } if (f != com.fasterxml.jackson.core.filter.TokenFilter.INCLUDE_ALL) { f = f.filterStartArray(); } _itemFilter = f; if (f == com.fasterxml.jackson.core.filter.TokenFilter.INCLUDE_ALL) { _headContext = _headContext.createChildArrayContext(f, true); return (_currToken = t); } _headContext = _headContext.createChildArrayContext(f, false); // but if we didn't figure it out yet, need to buffer possible events if (_includePath) { t = _nextTokenWithBuffering(_headContext); if (t != null) { _currToken = t; return t; } } goto main_loop_continue; } case JsonTokenIdConstants.ID_START_OBJECT: { f = _itemFilter; if (f == com.fasterxml.jackson.core.filter.TokenFilter.INCLUDE_ALL) { _headContext = _headContext.createChildObjectContext(f, true); return (_currToken = t); } if (f == null) { // does this occur? delegate_.skipChildren(); goto main_loop_continue; } // Otherwise still iffy, need to check f = _headContext.checkValue(f); if (f == null) { delegate_.skipChildren(); goto main_loop_continue; } if (f != com.fasterxml.jackson.core.filter.TokenFilter.INCLUDE_ALL) { f = f.filterStartObject(); } _itemFilter = f; if (f == com.fasterxml.jackson.core.filter.TokenFilter.INCLUDE_ALL) { _headContext = _headContext.createChildObjectContext(f, true); return (_currToken = t); } _headContext = _headContext.createChildObjectContext(f, false); if (_includePath) { t = _nextTokenWithBuffering(_headContext); if (t != null) { _currToken = t; return t; } } goto main_loop_continue; } case JsonTokenIdConstants.ID_END_ARRAY: case JsonTokenIdConstants.ID_END_OBJECT: { bool returnEnd = _headContext.isStartHandled(); f = _headContext.getFilter(); if ((f != null) && (f != com.fasterxml.jackson.core.filter.TokenFilter.INCLUDE_ALL )) { f.filterFinishArray(); } _headContext = ((com.fasterxml.jackson.core.filter.TokenFilterContext)_headContext .getParent()); _itemFilter = _headContext.getFilter(); if (returnEnd) { return (_currToken = t); } goto main_loop_continue; } case JsonTokenIdConstants.ID_FIELD_NAME: { string name = delegate_.getCurrentName(); f = _headContext.setFieldName(name); if (f == com.fasterxml.jackson.core.filter.TokenFilter.INCLUDE_ALL) { _itemFilter = f; return (_currToken = t); } if (f == null) { // filter out the value delegate_.nextToken(); delegate_.skipChildren(); goto main_loop_continue; } f = f.includeProperty(name); if (f == null) { // filter out the value delegate_.nextToken(); delegate_.skipChildren(); goto main_loop_continue; } _itemFilter = f; if (f == com.fasterxml.jackson.core.filter.TokenFilter.INCLUDE_ALL) { if (_includePath) { return (_currToken = t); } // if (_includeImmediateParent) { ... goto main_loop_continue; } if (_includePath) { t = _nextTokenWithBuffering(_headContext); if (t != null) { _currToken = t; return t; } } goto main_loop_continue; } default: { // scalar value f = _itemFilter; if (f == com.fasterxml.jackson.core.filter.TokenFilter.INCLUDE_ALL) { return (_currToken = t); } if (f != null) { f = _headContext.checkValue(f); if ((f == com.fasterxml.jackson.core.filter.TokenFilter.INCLUDE_ALL) || ((f != null ) && f.includeValue(delegate_))) { return (_currToken = t); } } // Otherwise not included (leaves must be explicitly included) break; } } main_loop_continue: ; } main_loop_break: ; }
/* /********************************************************** /* Public API, traversal /********************************************************** */ /// <exception cref="System.IO.IOException"/> public override com.fasterxml.jackson.core.JsonToken nextToken() { // Anything buffered? com.fasterxml.jackson.core.filter.TokenFilterContext ctxt = _exposedContext; if (ctxt != null) { while (true) { com.fasterxml.jackson.core.JsonToken t = ctxt.nextTokenToRead(); if (t != null) { _currToken = t; return t; } // all done with buffered stuff? if (ctxt == _headContext) { _exposedContext = null; if (ctxt.inArray()) { t = delegate_.getCurrentToken(); // Is this guaranteed to work without further checks? // if (t != JsonToken.START_ARRAY) { _currToken = t; return t; } // Almost! Most likely still have the current token; // with the sole exception of /* t = delegate.getCurrentToken(); if (t != JsonToken.FIELD_NAME) { _currToken = t; return t; } */ break; } // If not, traverse down the context chain ctxt = _headContext.findChildOf(ctxt); _exposedContext = ctxt; if (ctxt == null) { // should never occur throw _constructError("Unexpected problem: chain of filtered context broken"); } } } // If not, need to read more. If we got any: com.fasterxml.jackson.core.JsonToken t_1 = delegate_.nextToken(); if (t_1 == null) { // no strict need to close, since we have no state here return (_currToken = t_1); } // otherwise... to include or not? com.fasterxml.jackson.core.filter.TokenFilter f; switch (t_1.id()) { case JsonTokenIdConstants.ID_START_ARRAY: { f = _itemFilter; if (f == com.fasterxml.jackson.core.filter.TokenFilter.INCLUDE_ALL) { _headContext = _headContext.createChildArrayContext(f, true); return (_currToken = t_1); } if (f == null) { // does this occur? delegate_.skipChildren(); break; } // Otherwise still iffy, need to check f = _headContext.checkValue(f); if (f == null) { delegate_.skipChildren(); break; } if (f != com.fasterxml.jackson.core.filter.TokenFilter.INCLUDE_ALL) { f = f.filterStartArray(); } _itemFilter = f; if (f == com.fasterxml.jackson.core.filter.TokenFilter.INCLUDE_ALL) { _headContext = _headContext.createChildArrayContext(f, true); return (_currToken = t_1); } _headContext = _headContext.createChildArrayContext(f, false); // Also: only need buffering if parent path to be included if (_includePath) { t_1 = _nextTokenWithBuffering(_headContext); if (t_1 != null) { _currToken = t_1; return t_1; } } break; } case JsonTokenIdConstants.ID_START_OBJECT: { f = _itemFilter; if (f == com.fasterxml.jackson.core.filter.TokenFilter.INCLUDE_ALL) { _headContext = _headContext.createChildObjectContext(f, true); return (_currToken = t_1); } if (f == null) { // does this occur? delegate_.skipChildren(); break; } // Otherwise still iffy, need to check f = _headContext.checkValue(f); if (f == null) { delegate_.skipChildren(); break; } if (f != com.fasterxml.jackson.core.filter.TokenFilter.INCLUDE_ALL) { f = f.filterStartObject(); } _itemFilter = f; if (f == com.fasterxml.jackson.core.filter.TokenFilter.INCLUDE_ALL) { _headContext = _headContext.createChildObjectContext(f, true); return (_currToken = t_1); } _headContext = _headContext.createChildObjectContext(f, false); // Also: only need buffering if parent path to be included if (_includePath) { t_1 = _nextTokenWithBuffering(_headContext); if (t_1 != null) { _currToken = t_1; return t_1; } } // note: inclusion of surrounding Object handled separately via // FIELD_NAME break; } case JsonTokenIdConstants.ID_END_ARRAY: case JsonTokenIdConstants.ID_END_OBJECT: { bool returnEnd = _headContext.isStartHandled(); f = _headContext.getFilter(); if ((f != null) && (f != com.fasterxml.jackson.core.filter.TokenFilter.INCLUDE_ALL )) { f.filterFinishArray(); } _headContext = ((com.fasterxml.jackson.core.filter.TokenFilterContext)_headContext .getParent()); _itemFilter = _headContext.getFilter(); if (returnEnd) { return (_currToken = t_1); } break; } case JsonTokenIdConstants.ID_FIELD_NAME: { string name = delegate_.getCurrentName(); // note: this will also set 'needToHandleName' f = _headContext.setFieldName(name); if (f == com.fasterxml.jackson.core.filter.TokenFilter.INCLUDE_ALL) { _itemFilter = f; if (!_includePath) { // Minor twist here: if parent NOT included, may need to induce output of // surrounding START_OBJECT/END_OBJECT if (_includeImmediateParent && !_headContext.isStartHandled()) { t_1 = _headContext.nextTokenToRead(); // returns START_OBJECT but also marks it handled _exposedContext = _headContext; } } return (_currToken = t_1); } if (f == null) { delegate_.nextToken(); delegate_.skipChildren(); break; } f = f.includeProperty(name); if (f == null) { delegate_.nextToken(); delegate_.skipChildren(); break; } _itemFilter = f; if (f == com.fasterxml.jackson.core.filter.TokenFilter.INCLUDE_ALL) { if (_includePath) { return (_currToken = t_1); } } if (_includePath) { t_1 = _nextTokenWithBuffering(_headContext); if (t_1 != null) { _currToken = t_1; return t_1; } } break; } default: { // scalar value f = _itemFilter; if (f == com.fasterxml.jackson.core.filter.TokenFilter.INCLUDE_ALL) { return (_currToken = t_1); } if (f != null) { f = _headContext.checkValue(f); if ((f == com.fasterxml.jackson.core.filter.TokenFilter.INCLUDE_ALL) || ((f != null ) && f.includeValue(delegate_))) { return (_currToken = t_1); } } // Otherwise not included (leaves must be explicitly included) break; } } // We get here if token was not yet found; offlined handling return _nextToken2(); }
public FilteringParserDelegate(com.fasterxml.jackson.core.JsonParser p, com.fasterxml.jackson.core.filter.TokenFilter f, bool includePath, bool allowMultipleMatches) : base(p) { /* /********************************************************** /* Configuration /********************************************************** */ /* NOTE: this feature is included in the first version (2.6), but * there is no public API to enable it, yet, since there isn't an * actual use case. But it seemed possible need could arise, which * is feature has not yet been removed. If no use is found within * first version or two, just remove. * * Marked as deprecated since its status is uncertain. */ /* /********************************************************** /* State /********************************************************** */ /* /********************************************************** /* Construction, initialization /********************************************************** */ rootFilter = f; // and this is the currently active filter for root values _itemFilter = f; _headContext = com.fasterxml.jackson.core.filter.TokenFilterContext.createRootContext (f); _includePath = includePath; _allowMultipleMatches = allowMultipleMatches; }
protected internal virtual com.fasterxml.jackson.core.filter.TokenFilterContext reset(int type, com.fasterxml.jackson.core.filter.TokenFilter filter, bool startWritten ) { _type = type; _filter = filter; _index = -1; _currentName = null; _startHandled = startWritten; _needToHandleName = false; return this; }
public virtual void skipParentChecks() { _filter = null; for (com.fasterxml.jackson.core.filter.TokenFilterContext ctxt = _parent; ctxt != null; ctxt = ctxt._parent) { _parent._filter = null; } }
/// <exception cref="System.IO.IOException"/> public override void writeStartArray(int size) { if (_itemFilter == null) { _filterContext = _filterContext.createChildArrayContext(null, false); return; } if (_itemFilter == com.fasterxml.jackson.core.filter.TokenFilter.INCLUDE_ALL) { _filterContext = _filterContext.createChildArrayContext(_itemFilter, true); delegate_.writeStartArray(size); return; } _itemFilter = _filterContext.checkValue(_itemFilter); if (_itemFilter == null) { _filterContext = _filterContext.createChildArrayContext(null, false); return; } if (_itemFilter != com.fasterxml.jackson.core.filter.TokenFilter.INCLUDE_ALL) { _itemFilter = _itemFilter.filterStartArray(); } if (_itemFilter == com.fasterxml.jackson.core.filter.TokenFilter.INCLUDE_ALL) { _checkParentPath(); _filterContext = _filterContext.createChildArrayContext(_itemFilter, true); delegate_.writeStartArray(size); } else { _filterContext = _filterContext.createChildArrayContext(_itemFilter, false); } }
/* /********************************************************** /* Public API, write methods, structural /********************************************************** */ /// <exception cref="System.IO.IOException"/> public override void writeStartArray() { // First things first: whole-sale skipping easy if (_itemFilter == null) { _filterContext = _filterContext.createChildArrayContext(null, false); return; } if (_itemFilter == com.fasterxml.jackson.core.filter.TokenFilter.INCLUDE_ALL) { // include the whole sub-tree? _filterContext = _filterContext.createChildArrayContext(_itemFilter, true); delegate_.writeStartArray(); return; } // Ok; regular checking state then _itemFilter = _filterContext.checkValue(_itemFilter); if (_itemFilter == null) { _filterContext = _filterContext.createChildArrayContext(null, false); return; } if (_itemFilter != com.fasterxml.jackson.core.filter.TokenFilter.INCLUDE_ALL) { _itemFilter = _itemFilter.filterStartArray(); } if (_itemFilter == com.fasterxml.jackson.core.filter.TokenFilter.INCLUDE_ALL) { _checkParentPath(); _filterContext = _filterContext.createChildArrayContext(_itemFilter, true); delegate_.writeStartArray(); } else { _filterContext = _filterContext.createChildArrayContext(_itemFilter, false); } }
/// <exception cref="System.IO.IOException"/> public override void writeFieldName(com.fasterxml.jackson.core.SerializableString name) { com.fasterxml.jackson.core.filter.TokenFilter state = _filterContext.setFieldName (name.getValue()); if (state == null) { _itemFilter = null; return; } if (state == com.fasterxml.jackson.core.filter.TokenFilter.INCLUDE_ALL) { _itemFilter = state; delegate_.writeFieldName(name); return; } state = state.includeProperty(name.getValue()); _itemFilter = state; if (state == com.fasterxml.jackson.core.filter.TokenFilter.INCLUDE_ALL) { _checkPropertyParentPath(); } }
/// <exception cref="System.IO.IOException"/> public override void writeEndObject() { _filterContext = _filterContext.closeObject(delegate_); if (_filterContext != null) { _itemFilter = _filterContext.getFilter(); } }