Ignore:
Timestamp:
2017-12-23T02:40:43+01:00 (7 years ago)
Author:
Don-vip
Message:

see #15682 - upgrade to JSR 374 (JSON Processing) API 1.1.2

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/glassfish/json/JsonStructureParser.java

    r6756 r13231  
    22 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    33 *
    4  * Copyright (c) 2012-2013 Oracle and/or its affiliates. All rights reserved.
     4 * Copyright (c) 2012-2017 Oracle and/or its affiliates. All rights reserved.
    55 *
    66 * The contents of this file are subject to the terms of either the GNU
     
    99 * may not use this file except in compliance with the License.  You can
    1010 * obtain a copy of the License at
    11  * https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
    12  * or packager/legal/LICENSE.txt.  See the License for the specific
     11 * https://oss.oracle.com/licenses/CDDL+GPL-1.1
     12 * or LICENSE.txt.  See the License for the specific
    1313 * language governing permissions and limitations under the License.
    1414 *
    1515 * When distributing the software, include this License Header Notice in each
    16  * file and include the License file at packager/legal/LICENSE.txt.
     16 * file and include the License file at LICENSE.txt.
    1717 *
    1818 * GPL Classpath Exception:
     
    4545import javax.json.stream.JsonParser;
    4646import java.math.BigDecimal;
    47 import java.util.*;
     47import java.util.ArrayDeque;
     48import java.util.Deque;
     49import java.util.Iterator;
     50import java.util.Map;
     51import java.util.NoSuchElementException;
    4852
    4953/**
     
    5660    private Scope current;
    5761    private Event state;
    58     private final Deque<Scope> scopeStack = new ArrayDeque<Scope>();
     62    private final Deque<Scope> scopeStack = new ArrayDeque<>();
    5963
    6064    JsonStructureParser(JsonArray array) {
     
    6872    @Override
    6973    public String getString() {
    70         if (state == Event.KEY_NAME) {
    71             return ((ObjectScope)current).key;
    72         } else if (state == Event.VALUE_STRING) {
    73             return ((JsonString)current.getJsonValue()).getString();
    74         }
    75         throw new IllegalStateException(JsonMessages.PARSER_GETSTRING_ERR(state));
     74        switch (state) {
     75            case KEY_NAME:
     76                return ((ObjectScope)current).key;
     77            case VALUE_STRING:
     78                return ((JsonString)current.getJsonValue()).getString();
     79            case VALUE_NUMBER:
     80                return ((JsonNumber)current.getJsonValue()).toString();
     81            default:
     82                throw new IllegalStateException(JsonMessages.PARSER_GETSTRING_ERR(state));
     83        }
    7684    }
    7785
     
    168176    public void close() {
    169177        // no-op
     178    }
     179
     180    @Override
     181    public void skipObject() {
     182        if (current instanceof ObjectScope) {
     183            int depth = 1;
     184            do {
     185                if (state == Event.KEY_NAME) {
     186                    state = getState(current.getJsonValue());
     187                    switch (state) {
     188                        case START_OBJECT:
     189                            depth++;
     190                            break;
     191                        case END_OBJECT:
     192                            depth--;
     193                            break;
     194                        default:
     195                            //no-op
     196                    }
     197                } else {
     198                    if (current.hasNext()) {
     199                        current.next();
     200                        state = Event.KEY_NAME;
     201                    } else {
     202                        state = Event.END_OBJECT;
     203                        depth--;
     204                    }
     205                }
     206            } while (state != Event.END_OBJECT && depth > 0);
     207        }
     208    }
     209
     210    @Override
     211    public void skipArray() {
     212        if (current instanceof ArrayScope) {
     213            int depth = 1;
     214            do {
     215                if (current.hasNext()) {
     216                    current.next();
     217                    state = getState(current.getJsonValue());
     218                    switch (state) {
     219                        case START_ARRAY:
     220                            depth++;
     221                            break;
     222                        case END_ARRAY:
     223                            depth--;
     224                            break;
     225                        default:
     226                            //no-op
     227                    }
     228                } else {
     229                    state = Event.END_ARRAY;
     230                    depth--;
     231                }
     232            } while (!(state == Event.END_ARRAY && depth == 0));
     233        }
    170234    }
    171235
     
    187251                return Event.VALUE_NULL;
    188252            default:
    189                 throw new JsonException("Unknown value type="+value.getValueType());
     253                throw new JsonException(JsonMessages.PARSER_STATE_ERR(value.getValueType()));
    190254        }
    191255    }
     
    200264                return new ObjectScope((JsonObject)value);
    201265            }
    202             throw new JsonException("Cannot be called for value="+value);
     266            throw new JsonException(JsonMessages.PARSER_SCOPE_ERR(value));
    203267        }
    204268    }
Note: See TracChangeset for help on using the changeset viewer.