Changeset 13231 in josm for trunk/src/org/glassfish/json/JsonStructureParser.java
- Timestamp:
- 2017-12-23T02:40:43+01:00 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/glassfish/json/JsonStructureParser.java
r6756 r13231 2 2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 3 * 4 * Copyright (c) 2012-201 3Oracle and/or its affiliates. All rights reserved.4 * Copyright (c) 2012-2017 Oracle and/or its affiliates. All rights reserved. 5 5 * 6 6 * The contents of this file are subject to the terms of either the GNU … … 9 9 * may not use this file except in compliance with the License. You can 10 10 * obtain a copy of the License at 11 * https:// glassfish.dev.java.net/public/CDDL+GPL_1_1.html12 * or packager/legal/LICENSE.txt. See the License for the specific11 * https://oss.oracle.com/licenses/CDDL+GPL-1.1 12 * or LICENSE.txt. See the License for the specific 13 13 * language governing permissions and limitations under the License. 14 14 * 15 15 * 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. 17 17 * 18 18 * GPL Classpath Exception: … … 45 45 import javax.json.stream.JsonParser; 46 46 import java.math.BigDecimal; 47 import java.util.*; 47 import java.util.ArrayDeque; 48 import java.util.Deque; 49 import java.util.Iterator; 50 import java.util.Map; 51 import java.util.NoSuchElementException; 48 52 49 53 /** … … 56 60 private Scope current; 57 61 private Event state; 58 private final Deque<Scope> scopeStack = new ArrayDeque< Scope>();62 private final Deque<Scope> scopeStack = new ArrayDeque<>(); 59 63 60 64 JsonStructureParser(JsonArray array) { … … 68 72 @Override 69 73 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 } 76 84 } 77 85 … … 168 176 public void close() { 169 177 // 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 } 170 234 } 171 235 … … 187 251 return Event.VALUE_NULL; 188 252 default: 189 throw new JsonException( "Unknown value type="+value.getValueType());253 throw new JsonException(JsonMessages.PARSER_STATE_ERR(value.getValueType())); 190 254 } 191 255 } … … 200 264 return new ObjectScope((JsonObject)value); 201 265 } 202 throw new JsonException( "Cannot be called for value="+value);266 throw new JsonException(JsonMessages.PARSER_SCOPE_ERR(value)); 203 267 } 204 268 }
Note:
See TracChangeset
for help on using the changeset viewer.