Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 81689200D04 for ; Mon, 28 Aug 2017 00:20:10 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 7FE48163B13; Sun, 27 Aug 2017 22:20:10 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 2B446163941 for ; Mon, 28 Aug 2017 00:20:08 +0200 (CEST) Received: (qmail 76577 invoked by uid 500); 27 Aug 2017 22:20:06 -0000 Mailing-List: contact commits-help@juneau.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@juneau.incubator.apache.org Delivered-To: mailing list commits@juneau.incubator.apache.org Received: (qmail 76531 invoked by uid 99); 27 Aug 2017 22:20:06 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 27 Aug 2017 22:20:06 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id 8765218430F for ; Sun, 27 Aug 2017 22:20:05 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -5.022 X-Spam-Level: X-Spam-Status: No, score=-5.022 tagged_above=-999 required=6.31 tests=[RCVD_IN_DNSWL_HI=-5, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RP_MATCHES_RCVD=-0.001, SPF_PASS=-0.001] autolearn=disabled Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id oGVGRHplvhwk for ; Sun, 27 Aug 2017 22:19:48 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with SMTP id D09A0611C3 for ; Sun, 27 Aug 2017 22:19:36 +0000 (UTC) Received: (qmail 72774 invoked by uid 99); 27 Aug 2017 22:19:36 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 27 Aug 2017 22:19:36 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id C7256F5F4F; Sun, 27 Aug 2017 22:19:34 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: jamesbognar@apache.org To: commits@juneau.incubator.apache.org Date: Sun, 27 Aug 2017 22:19:49 -0000 Message-Id: In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [16/51] [partial] incubator-juneau-website git commit: Update javadocs. archived-at: Sun, 27 Aug 2017 22:20:10 -0000 http://git-wip-us.apache.org/repos/asf/incubator-juneau-website/blob/2ead32d5/content/site/apidocs/src-html/org/apache/juneau/uon/UonParserSession.html ---------------------------------------------------------------------- diff --git a/content/site/apidocs/src-html/org/apache/juneau/uon/UonParserSession.html b/content/site/apidocs/src-html/org/apache/juneau/uon/UonParserSession.html index def4de6..eb343d0 100644 --- a/content/site/apidocs/src-html/org/apache/juneau/uon/UonParserSession.html +++ b/content/site/apidocs/src-html/org/apache/juneau/uon/UonParserSession.html @@ -76,699 +76,705 @@ 068 * The main difference is that characters are never decoded, and the {@link UonParserContext#UON_decodeChars} 069 * property is always ignored. 070 * -071 * @param ctx The context to copy setting from. -072 */ -073 protected UonParserSession(UonParserContext ctx) { -074 super(ctx, null); -075 decodeChars = false; -076 } -077 -078 @Override /* ParserSession */ -079 protected <T> T doParse(ParserPipe pipe, ClassMeta<T> type) throws Exception { -080 UonReader r = getUonReader(pipe, decodeChars); -081 T o = parseAnything(type, r, getOuter(), true, null); -082 validateEnd(r); -083 return o; -084 } -085 -086 @Override /* ReaderParserSession */ -087 protected <K,V> Map<K,V> doParseIntoMap(ParserPipe pipe, Map<K,V> m, Type keyType, Type valueType) throws Exception { -088 UonReader r = getUonReader(pipe, decodeChars); -089 m = parseIntoMap(r, m, (ClassMeta<K>)getClassMeta(keyType), (ClassMeta<V>)getClassMeta(valueType), null); -090 validateEnd(r); -091 return m; -092 } -093 -094 @Override /* ReaderParserSession */ -095 protected <E> Collection<E> doParseIntoCollection(ParserPipe pipe, Collection<E> c, Type elementType) throws Exception { -096 UonReader r = getUonReader(pipe, decodeChars); -097 c = parseIntoCollection(r, c, (ClassMeta<E>)getClassMeta(elementType), false, null); -098 validateEnd(r); -099 return c; -100 } -101 -102 /** -103 * Workhorse method. -104 * -105 * @param eType The class type being parsed, or <jk>null</jk> if unknown. -106 * @param r The reader being parsed. -107 * @param outer The outer object (for constructing nested inner classes). -108 * @param isUrlParamValue -109 * If <jk>true</jk>, then we're parsing a top-level URL-encoded value which is treated a bit different than the -110 * default case. -111 * @param pMeta The current bean property being parsed. -112 * @return The parsed object. -113 * @throws Exception -114 */ -115 public <T> T parseAnything(ClassMeta<T> eType, UonReader r, Object outer, boolean isUrlParamValue, BeanPropertyMeta pMeta) throws Exception { -116 -117 if (eType == null) -118 eType = (ClassMeta<T>)object(); -119 PojoSwap<T,Object> transform = (PojoSwap<T,Object>)eType.getPojoSwap(); -120 ClassMeta<?> sType = eType.getSerializedClassMeta(); -121 -122 Object o = null; -123 -124 int c = r.peekSkipWs(); -125 -126 if (c == -1 || c == AMP) { -127 // If parameter is blank and it's an array or collection, return an empty list. -128 if (sType.isCollectionOrArray()) -129 o = sType.newInstance(); -130 else if (sType.isString() || sType.isObject()) -131 o = ""; -132 else if (sType.isPrimitive()) -133 o = sType.getPrimitiveDefault(); -134 // Otherwise, leave null. -135 } else if (sType.isVoid()) { -136 String s = parseString(r, isUrlParamValue); -137 if (s != null) -138 throw new ParseException(loc(r), "Expected ''null'' for void value, but was ''{0}''.", s); -139 } else if (sType.isObject()) { -140 if (c == '(') { -141 ObjectMap m = new ObjectMap(this); -142 parseIntoMap(r, m, string(), object(), pMeta); -143 o = cast(m, pMeta, eType); -144 } else if (c == '@') { -145 Collection l = new ObjectList(this); -146 o = parseIntoCollection(r, l, sType, isUrlParamValue, pMeta); -147 } else { -148 String s = parseString(r, isUrlParamValue); -149 if (c != '\'') { -150 if ("true".equals(s) || "false".equals(s)) -151 o = Boolean.valueOf(s); -152 else if (! "null".equals(s)) { -153 if (isNumeric(s)) -154 o = StringUtils.parseNumber(s, Number.class); -155 else -156 o = s; -157 } -158 } else { -159 o = s; -160 } -161 } -162 } else if (sType.isBoolean()) { -163 o = parseBoolean(r); -164 } else if (sType.isCharSequence()) { -165 o = parseString(r, isUrlParamValue); -166 } else if (sType.isChar()) { -167 String s = parseString(r, isUrlParamValue); -168 o = s == null ? null : s.charAt(0); -169 } else if (sType.isNumber()) { -170 o = parseNumber(r, (Class<? extends Number>)sType.getInnerClass()); -171 } else if (sType.isMap()) { -172 Map m = (sType.canCreateNewInstance(outer) ? (Map)sType.newInstance(outer) : new ObjectMap(this)); -173 o = parseIntoMap(r, m, sType.getKeyType(), sType.getValueType(), pMeta); -174 } else if (sType.isCollection()) { -175 if (c == '(') { -176 ObjectMap m = new ObjectMap(this); -177 parseIntoMap(r, m, string(), object(), pMeta); -178 // Handle case where it's a collection, but serialized as a map with a _type or _value key. -179 if (m.containsKey(getBeanTypePropertyName(sType))) -180 o = cast(m, pMeta, eType); -181 // Handle case where it's a collection, but only a single value was specified. -182 else { -183 Collection l = ( -184 sType.canCreateNewInstance(outer) -185 ? (Collection)sType.newInstance(outer) -186 : new ObjectList(this) -187 ); -188 l.add(m.cast(sType.getElementType())); -189 o = l; -190 } -191 } else { -192 Collection l = ( -193 sType.canCreateNewInstance(outer) -194 ? (Collection)sType.newInstance(outer) -195 : new ObjectList(this) -196 ); -197 o = parseIntoCollection(r, l, sType, isUrlParamValue, pMeta); -198 } -199 } else if (sType.canCreateNewBean(outer)) { -200 BeanMap m = newBeanMap(outer, sType.getInnerClass()); -201 m = parseIntoBeanMap(r, m); -202 o = m == null ? null : m.getBean(); -203 } else if (sType.canCreateNewInstanceFromString(outer)) { -204 String s = parseString(r, isUrlParamValue); -205 if (s != null) -206 o = sType.newInstanceFromString(outer, s); -207 } else if (sType.canCreateNewInstanceFromNumber(outer)) { -208 o = sType.newInstanceFromNumber(this, outer, parseNumber(r, sType.getNewInstanceFromNumberClass())); -209 } else if (sType.isArray() || sType.isArgs()) { -210 if (c == '(') { -211 ObjectMap m = new ObjectMap(this); -212 parseIntoMap(r, m, string(), object(), pMeta); -213 // Handle case where it's an array, but serialized as a map with a _type or _value key. -214 if (m.containsKey(getBeanTypePropertyName(sType))) -215 o = cast(m, pMeta, eType); -216 // Handle case where it's an array, but only a single value was specified. -217 else { -218 ArrayList l = new ArrayList(1); -219 l.add(m.cast(sType.getElementType())); -220 o = toArray(sType, l); -221 } -222 } else { -223 ArrayList l = (ArrayList)parseIntoCollection(r, new ArrayList(), sType, isUrlParamValue, pMeta); -224 o = toArray(sType, l); -225 } -226 } else if (c == '(') { -227 // It could be a non-bean with _type attribute. -228 ObjectMap m = new ObjectMap(this); -229 parseIntoMap(r, m, string(), object(), pMeta); -230 if (m.containsKey(getBeanTypePropertyName(sType))) -231 o = cast(m, pMeta, eType); -232 else -233 throw new ParseException(loc(r), "Class ''{0}'' could not be instantiated. Reason: ''{1}''", -234 sType.getInnerClass().getName(), sType.getNotABeanReason()); -235 } else if (c == 'n') { -236 r.read(); -237 parseNull(r); -238 } else { -239 throw new ParseException(loc(r), "Class ''{0}'' could not be instantiated. Reason: ''{1}''", -240 sType.getInnerClass().getName(), sType.getNotABeanReason()); -241 } -242 -243 if (o == null && sType.isPrimitive()) -244 o = sType.getPrimitiveDefault(); -245 if (transform != null && o != null) -246 o = transform.unswap(this, o, eType); -247 -248 if (outer != null) -249 setParent(eType, o, outer); -250 -251 return (T)o; -252 } +071 * @param ctx +072 * The context creating this session object. +073 * The context contains all the configuration settings for this object. +074 * @param args +075 * Runtime session arguments. +076 * @param decodeChars +077 * Whether to decode characters. +078 */ +079 protected UonParserSession(UonParserContext ctx, ParserSessionArgs args, boolean decodeChars) { +080 super(ctx, args); +081 this.decodeChars = decodeChars; +082 } +083 +084 @Override /* ParserSession */ +085 protected <T> T doParse(ParserPipe pipe, ClassMeta<T> type) throws Exception { +086 UonReader r = getUonReader(pipe, decodeChars); +087 T o = parseAnything(type, r, getOuter(), true, null); +088 validateEnd(r); +089 return o; +090 } +091 +092 @Override /* ReaderParserSession */ +093 protected <K,V> Map<K,V> doParseIntoMap(ParserPipe pipe, Map<K,V> m, Type keyType, Type valueType) throws Exception { +094 UonReader r = getUonReader(pipe, decodeChars); +095 m = parseIntoMap(r, m, (ClassMeta<K>)getClassMeta(keyType), (ClassMeta<V>)getClassMeta(valueType), null); +096 validateEnd(r); +097 return m; +098 } +099 +100 @Override /* ReaderParserSession */ +101 protected <E> Collection<E> doParseIntoCollection(ParserPipe pipe, Collection<E> c, Type elementType) throws Exception { +102 UonReader r = getUonReader(pipe, decodeChars); +103 c = parseIntoCollection(r, c, (ClassMeta<E>)getClassMeta(elementType), false, null); +104 validateEnd(r); +105 return c; +106 } +107 +108 /** +109 * Workhorse method. +110 * +111 * @param eType The class type being parsed, or <jk>null</jk> if unknown. +112 * @param r The reader being parsed. +113 * @param outer The outer object (for constructing nested inner classes). +114 * @param isUrlParamValue +115 * If <jk>true</jk>, then we're parsing a top-level URL-encoded value which is treated a bit different than the +116 * default case. +117 * @param pMeta The current bean property being parsed. +118 * @return The parsed object. +119 * @throws Exception +120 */ +121 public <T> T parseAnything(ClassMeta<T> eType, UonReader r, Object outer, boolean isUrlParamValue, BeanPropertyMeta pMeta) throws Exception { +122 +123 if (eType == null) +124 eType = (ClassMeta<T>)object(); +125 PojoSwap<T,Object> transform = (PojoSwap<T,Object>)eType.getPojoSwap(); +126 ClassMeta<?> sType = eType.getSerializedClassMeta(); +127 +128 Object o = null; +129 +130 int c = r.peekSkipWs(); +131 +132 if (c == -1 || c == AMP) { +133 // If parameter is blank and it's an array or collection, return an empty list. +134 if (sType.isCollectionOrArray()) +135 o = sType.newInstance(); +136 else if (sType.isString() || sType.isObject()) +137 o = ""; +138 else if (sType.isPrimitive()) +139 o = sType.getPrimitiveDefault(); +140 // Otherwise, leave null. +141 } else if (sType.isVoid()) { +142 String s = parseString(r, isUrlParamValue); +143 if (s != null) +144 throw new ParseException(loc(r), "Expected ''null'' for void value, but was ''{0}''.", s); +145 } else if (sType.isObject()) { +146 if (c == '(') { +147 ObjectMap m = new ObjectMap(this); +148 parseIntoMap(r, m, string(), object(), pMeta); +149 o = cast(m, pMeta, eType); +150 } else if (c == '@') { +151 Collection l = new ObjectList(this); +152 o = parseIntoCollection(r, l, sType, isUrlParamValue, pMeta); +153 } else { +154 String s = parseString(r, isUrlParamValue); +155 if (c != '\'') { +156 if ("true".equals(s) || "false".equals(s)) +157 o = Boolean.valueOf(s); +158 else if (! "null".equals(s)) { +159 if (isNumeric(s)) +160 o = StringUtils.parseNumber(s, Number.class); +161 else +162 o = s; +163 } +164 } else { +165 o = s; +166 } +167 } +168 } else if (sType.isBoolean()) { +169 o = parseBoolean(r); +170 } else if (sType.isCharSequence()) { +171 o = parseString(r, isUrlParamValue); +172 } else if (sType.isChar()) { +173 String s = parseString(r, isUrlParamValue); +174 o = s == null ? null : s.charAt(0); +175 } else if (sType.isNumber()) { +176 o = parseNumber(r, (Class<? extends Number>)sType.getInnerClass()); +177 } else if (sType.isMap()) { +178 Map m = (sType.canCreateNewInstance(outer) ? (Map)sType.newInstance(outer) : new ObjectMap(this)); +179 o = parseIntoMap(r, m, sType.getKeyType(), sType.getValueType(), pMeta); +180 } else if (sType.isCollection()) { +181 if (c == '(') { +182 ObjectMap m = new ObjectMap(this); +183 parseIntoMap(r, m, string(), object(), pMeta); +184 // Handle case where it's a collection, but serialized as a map with a _type or _value key. +185 if (m.containsKey(getBeanTypePropertyName(sType))) +186 o = cast(m, pMeta, eType); +187 // Handle case where it's a collection, but only a single value was specified. +188 else { +189 Collection l = ( +190 sType.canCreateNewInstance(outer) +191 ? (Collection)sType.newInstance(outer) +192 : new ObjectList(this) +193 ); +194 l.add(m.cast(sType.getElementType())); +195 o = l; +196 } +197 } else { +198 Collection l = ( +199 sType.canCreateNewInstance(outer) +200 ? (Collection)sType.newInstance(outer) +201 : new ObjectList(this) +202 ); +203 o = parseIntoCollection(r, l, sType, isUrlParamValue, pMeta); +204 } +205 } else if (sType.canCreateNewBean(outer)) { +206 BeanMap m = newBeanMap(outer, sType.getInnerClass()); +207 m = parseIntoBeanMap(r, m); +208 o = m == null ? null : m.getBean(); +209 } else if (sType.canCreateNewInstanceFromString(outer)) { +210 String s = parseString(r, isUrlParamValue); +211 if (s != null) +212 o = sType.newInstanceFromString(outer, s); +213 } else if (sType.canCreateNewInstanceFromNumber(outer)) { +214 o = sType.newInstanceFromNumber(this, outer, parseNumber(r, sType.getNewInstanceFromNumberClass())); +215 } else if (sType.isArray() || sType.isArgs()) { +216 if (c == '(') { +217 ObjectMap m = new ObjectMap(this); +218 parseIntoMap(r, m, string(), object(), pMeta); +219 // Handle case where it's an array, but serialized as a map with a _type or _value key. +220 if (m.containsKey(getBeanTypePropertyName(sType))) +221 o = cast(m, pMeta, eType); +222 // Handle case where it's an array, but only a single value was specified. +223 else { +224 ArrayList l = new ArrayList(1); +225 l.add(m.cast(sType.getElementType())); +226 o = toArray(sType, l); +227 } +228 } else { +229 ArrayList l = (ArrayList)parseIntoCollection(r, new ArrayList(), sType, isUrlParamValue, pMeta); +230 o = toArray(sType, l); +231 } +232 } else if (c == '(') { +233 // It could be a non-bean with _type attribute. +234 ObjectMap m = new ObjectMap(this); +235 parseIntoMap(r, m, string(), object(), pMeta); +236 if (m.containsKey(getBeanTypePropertyName(sType))) +237 o = cast(m, pMeta, eType); +238 else +239 throw new ParseException(loc(r), "Class ''{0}'' could not be instantiated. Reason: ''{1}''", +240 sType.getInnerClass().getName(), sType.getNotABeanReason()); +241 } else if (c == 'n') { +242 r.read(); +243 parseNull(r); +244 } else { +245 throw new ParseException(loc(r), "Class ''{0}'' could not be instantiated. Reason: ''{1}''", +246 sType.getInnerClass().getName(), sType.getNotABeanReason()); +247 } +248 +249 if (o == null && sType.isPrimitive()) +250 o = sType.getPrimitiveDefault(); +251 if (transform != null && o != null) +252 o = transform.unswap(this, o, eType); 253 -254 private <K,V> Map<K,V> parseIntoMap(UonReader r, Map<K,V> m, ClassMeta<K> keyType, ClassMeta<V> valueType, -255 BeanPropertyMeta pMeta) throws Exception { +254 if (outer != null) +255 setParent(eType, o, outer); 256 -257 if (keyType == null) -258 keyType = (ClassMeta<K>)string(); +257 return (T)o; +258 } 259 -260 int c = r.read(); -261 if (c == -1 || c == AMP) -262 return null; -263 if (c == 'n') -264 return (Map<K,V>)parseNull(r); -265 if (c != '(') -266 throw new ParseException(loc(r), "Expected '(' at beginning of object."); -267 -268 final int S1=1; // Looking for attrName start. -269 final int S2=2; // Found attrName end, looking for =. -270 final int S3=3; // Found =, looking for valStart. -271 final int S4=4; // Looking for , or ) -272 boolean isInEscape = false; +260 private <K,V> Map<K,V> parseIntoMap(UonReader r, Map<K,V> m, ClassMeta<K> keyType, ClassMeta<V> valueType, +261 BeanPropertyMeta pMeta) throws Exception { +262 +263 if (keyType == null) +264 keyType = (ClassMeta<K>)string(); +265 +266 int c = r.read(); +267 if (c == -1 || c == AMP) +268 return null; +269 if (c == 'n') +270 return (Map<K,V>)parseNull(r); +271 if (c != '(') +272 throw new ParseException(loc(r), "Expected '(' at beginning of object."); 273 -274 int state = S1; -275 K currAttr = null; -276 while (c != -1 && c != AMP) { -277 c = r.read(); -278 if (! isInEscape) { -279 if (state == S1) { -280 if (c == ')') -281 return m; -282 if (Character.isWhitespace(c)) -283 skipSpace(r); -284 else { -285 r.unread(); -286 Object attr = parseAttr(r, decodeChars); -287 currAttr = attr == null ? null : convertAttrToType(m, trim(attr.toString()), keyType); -288 state = S2; -289 c = 0; // Avoid isInEscape if c was '\' -290 } -291 } else if (state == S2) { -292 if (c == EQ || c == '=') -293 state = S3; -294 else if (c == -1 || c == ',' || c == ')' || c == AMP) { -295 if (currAttr == null) { -296 // Value was '%00' -297 r.unread(); -298 return null; -299 } -300 m.put(currAttr, null); -301 if (c == ')' || c == -1 || c == AMP) -302 return m; -303 state = S1; -304 } -305 } else if (state == S3) { -306 if (c == -1 || c == ',' || c == ')' || c == AMP) { -307 V value = convertAttrToType(m, "", valueType); -308 m.put(currAttr, value); -309 if (c == -1 || c == ')' || c == AMP) -310 return m; -311 state = S1; -312 } else { -313 V value = parseAnything(valueType, r.unread(), m, false, pMeta); -314 setName(valueType, value, currAttr); -315 m.put(currAttr, value); -316 state = S4; -317 c = 0; // Avoid isInEscape if c was '\' -318 } -319 } else if (state == S4) { -320 if (c == ',') -321 state = S1; -322 else if (c == ')' || c == -1 || c == AMP) { -323 return m; +274 final int S1=1; // Looking for attrName start. +275 final int S2=2; // Found attrName end, looking for =. +276 final int S3=3; // Found =, looking for valStart. +277 final int S4=4; // Looking for , or ) +278 boolean isInEscape = false; +279 +280 int state = S1; +281 K currAttr = null; +282 while (c != -1 && c != AMP) { +283 c = r.read(); +284 if (! isInEscape) { +285 if (state == S1) { +286 if (c == ')') +287 return m; +288 if (Character.isWhitespace(c)) +289 skipSpace(r); +290 else { +291 r.unread(); +292 Object attr = parseAttr(r, decodeChars); +293 currAttr = attr == null ? null : convertAttrToType(m, trim(attr.toString()), keyType); +294 state = S2; +295 c = 0; // Avoid isInEscape if c was '\' +296 } +297 } else if (state == S2) { +298 if (c == EQ || c == '=') +299 state = S3; +300 else if (c == -1 || c == ',' || c == ')' || c == AMP) { +301 if (currAttr == null) { +302 // Value was '%00' +303 r.unread(); +304 return null; +305 } +306 m.put(currAttr, null); +307 if (c == ')' || c == -1 || c == AMP) +308 return m; +309 state = S1; +310 } +311 } else if (state == S3) { +312 if (c == -1 || c == ',' || c == ')' || c == AMP) { +313 V value = convertAttrToType(m, "", valueType); +314 m.put(currAttr, value); +315 if (c == -1 || c == ')' || c == AMP) +316 return m; +317 state = S1; +318 } else { +319 V value = parseAnything(valueType, r.unread(), m, false, pMeta); +320 setName(valueType, value, currAttr); +321 m.put(currAttr, value); +322 state = S4; +323 c = 0; // Avoid isInEscape if c was '\' 324 } -325 } -326 } -327 isInEscape = isInEscape(c, r, isInEscape); -328 } -329 if (state == S1) -330 throw new ParseException(loc(r), "Could not find attribute name on object."); -331 if (state == S2) -332 throw new ParseException(loc(r), "Could not find '=' following attribute name on object."); -333 if (state == S3) -334 throw new ParseException(loc(r), "Dangling '=' found in object entry"); -335 if (state == S4) -336 throw new ParseException(loc(r), "Could not find ')' marking end of object."); -337 -338 return null; // Unreachable. -339 } -340 -341 private <E> Collection<E> parseIntoCollection(UonReader r, Collection<E> l, ClassMeta<E> type, boolean isUrlParamValue, BeanPropertyMeta pMeta) throws Exception { -342 -343 int c = r.readSkipWs(); -344 if (c == -1 || c == AMP) -345 return null; -346 if (c == 'n') -347 return (Collection<E>)parseNull(r); +325 } else if (state == S4) { +326 if (c == ',') +327 state = S1; +328 else if (c == ')' || c == -1 || c == AMP) { +329 return m; +330 } +331 } +332 } +333 isInEscape = isInEscape(c, r, isInEscape); +334 } +335 if (state == S1) +336 throw new ParseException(loc(r), "Could not find attribute name on object."); +337 if (state == S2) +338 throw new ParseException(loc(r), "Could not find '=' following attribute name on object."); +339 if (state == S3) +340 throw new ParseException(loc(r), "Dangling '=' found in object entry"); +341 if (state == S4) +342 throw new ParseException(loc(r), "Could not find ')' marking end of object."); +343 +344 return null; // Unreachable. +345 } +346 +347 private <E> Collection<E> parseIntoCollection(UonReader r, Collection<E> l, ClassMeta<E> type, boolean isUrlParamValue, BeanPropertyMeta pMeta) throws Exception { 348 -349 int argIndex = 0; -350 -351 // If we're parsing a top-level parameter, we're allowed to have comma-delimited lists outside parenthesis (e.g. "&foo=1,2,3&bar=a,b,c") -352 // This is not allowed at lower levels since we use comma's as end delimiters. -353 boolean isInParens = (c == '@'); -354 if (! isInParens) { -355 if (isUrlParamValue) -356 r.unread(); -357 else -358 throw new ParseException(loc(r), "Could not find '(' marking beginning of collection."); -359 } else { -360 r.read(); -361 } -362 -363 if (isInParens) { -364 final int S1=1; // Looking for starting of first entry. -365 final int S2=2; // Looking for starting of subsequent entries. -366 final int S3=3; // Looking for , or ) after first entry. -367 -368 int state = S1; -369 while (c != -1 && c != AMP) { -370 c = r.read(); -371 if (state == S1 || state == S2) { -372 if (c == ')') { -373 if (state == S2) { -374 l.add((E)parseAnything(type.isArgs() ? type.getArg(argIndex++) : type.getElementType(), -375 r.unread(), l, false, pMeta)); -376 r.read(); -377 } -378 return l; -379 } else if (Character.isWhitespace(c)) { -380 skipSpace(r); -381 } else { -382 l.add((E)parseAnything(type.isArgs() ? type.getArg(argIndex++) : type.getElementType(), -383 r.unread(), l, false, pMeta)); -384 state = S3; -385 } -386 } else if (state == S3) { -387 if (c == ',') { -388 state = S2; -389 } else if (c == ')') { -390 return l; +349 int c = r.readSkipWs(); +350 if (c == -1 || c == AMP) +351 return null; +352 if (c == 'n') +353 return (Collection<E>)parseNull(r); +354 +355 int argIndex = 0; +356 +357 // If we're parsing a top-level parameter, we're allowed to have comma-delimited lists outside parenthesis (e.g. "&foo=1,2,3&bar=a,b,c") +358 // This is not allowed at lower levels since we use comma's as end delimiters. +359 boolean isInParens = (c == '@'); +360 if (! isInParens) { +361 if (isUrlParamValue) +362 r.unread(); +363 else +364 throw new ParseException(loc(r), "Could not find '(' marking beginning of collection."); +365 } else { +366 r.read(); +367 } +368 +369 if (isInParens) { +370 final int S1=1; // Looking for starting of first entry. +371 final int S2=2; // Looking for starting of subsequent entries. +372 final int S3=3; // Looking for , or ) after first entry. +373 +374 int state = S1; +375 while (c != -1 && c != AMP) { +376 c = r.read(); +377 if (state == S1 || state == S2) { +378 if (c == ')') { +379 if (state == S2) { +380 l.add((E)parseAnything(type.isArgs() ? type.getArg(argIndex++) : type.getElementType(), +381 r.unread(), l, false, pMeta)); +382 r.read(); +383 } +384 return l; +385 } else if (Character.isWhitespace(c)) { +386 skipSpace(r); +387 } else { +388 l.add((E)parseAnything(type.isArgs() ? type.getArg(argIndex++) : type.getElementType(), +389 r.unread(), l, false, pMeta)); +390 state = S3; 391 } -392 } -393 } -394 if (state == S1 || state == S2) -395 throw new ParseException(loc(r), "Could not find start of entry in array."); -396 if (state == S3) -397 throw new ParseException(loc(r), "Could not find end of entry in array."); -398 -399 } else { -400 final int S1=1; // Looking for starting of entry. -401 final int S2=2; // Looking for , or & or END after first entry. -402 -403 int state = S1; -404 while (c != -1 && c != AMP) { -405 c = r.read(); -406 if (state == S1) { -407 if (Character.isWhitespace(c)) { -408 skipSpace(r); -409 } else { -410 l.add((E)parseAnything(type.isArgs() ? type.getArg(argIndex++) : type.getElementType(), -411 r.unread(), l, false, pMeta)); -412 state = S2; -413 } -414 } else if (state == S2) { -415 if (c == ',') { -416 state = S1; -417 } else if (Character.isWhitespace(c)) { -418 skipSpace(r); -419 } else if (c == AMP || c == -1) { -420 r.unread(); -421 return l; -422 } -423 } -424 } -425 } -426 -427 return null; // Unreachable. -428 } -429 -430 private <T> BeanMap<T> parseIntoBeanMap(UonReader r, BeanMap<T> m) throws Exception { -431 -432 int c = r.readSkipWs(); -433 if (c == -1 || c == AMP) -434 return null; -435 if (c == 'n') -436 return (BeanMap<T>)parseNull(r); -437 if (c != '(') -438 throw new ParseException(loc(r), "Expected '(' at beginning of object."); -439 -440 final int S1=1; // Looking for attrName start. -441 final int S2=2; // Found attrName end, looking for =. -442 final int S3=3; // Found =, looking for valStart. -443 final int S4=4; // Looking for , or } -444 boolean isInEscape = false; +392 } else if (state == S3) { +393 if (c == ',') { +394 state = S2; +395 } else if (c == ')') { +396 return l; +397 } +398 } +399 } +400 if (state == S1 || state == S2) +401 throw new ParseException(loc(r), "Could not find start of entry in array."); +402 if (state == S3) +403 throw new ParseException(loc(r), "Could not find end of entry in array."); +404 +405 } else { +406 final int S1=1; // Looking for starting of entry. +407 final int S2=2; // Looking for , or & or END after first entry. +408 +409 int state = S1; +410 while (c != -1 && c != AMP) { +411 c = r.read(); +412 if (state == S1) { +413 if (Character.isWhitespace(c)) { +414 skipSpace(r); +415 } else { +416 l.add((E)parseAnything(type.isArgs() ? type.getArg(argIndex++) : type.getElementType(), +417 r.unread(), l, false, pMeta)); +418 state = S2; +419 } +420 } else if (state == S2) { +421 if (c == ',') { +422 state = S1; +423 } else if (Character.isWhitespace(c)) { +424 skipSpace(r); +425 } else if (c == AMP || c == -1) { +426 r.unread(); +427 return l; +428 } +429 } +430 } +431 } +432 +433 return null; // Unreachable. +434 } +435 +436 private <T> BeanMap<T> parseIntoBeanMap(UonReader r, BeanMap<T> m) throws Exception { +437 +438 int c = r.readSkipWs(); +439 if (c == -1 || c == AMP) +440 return null; +441 if (c == 'n') +442 return (BeanMap<T>)parseNull(r); +443 if (c != '(') +444 throw new ParseException(loc(r), "Expected '(' at beginning of object."); 445 -446 int state = S1; -447 String currAttr = ""; -448 int currAttrLine = -1, currAttrCol = -1; -449 while (c != -1 && c != AMP) { -450 c = r.read(); -451 if (! isInEscape) { -452 if (state == S1) { -453 if (c == ')' || c == -1 || c == AMP) { -454 return m; -455 } -456 if (Character.isWhitespace(c)) -457 skipSpace(r); -458 else { -459 r.unread(); -460 currAttrLine= r.getLine(); -461 currAttrCol = r.getColumn(); -462 currAttr = parseAttrName(r, decodeChars); -463 if (currAttr == null) // Value was '%00' -464 return null; -465 state = S2; -466 } -467 } else if (state == S2) { -468 if (c == EQ || c == '=') -469 state = S3; -470 else if (c == -1 || c == ',' || c == ')' || c == AMP) { -471 m.put(currAttr, null); -472 if (c == ')' || c == -1 || c == AMP) -473 return m; -474 state = S1; -475 } -476 } else if (state == S3) { -477 if (c == -1 || c == ',' || c == ')' || c == AMP) { -478 if (! currAttr.equals(getBeanTypePropertyName(m.getClassMeta()))) { -479 BeanPropertyMeta pMeta = m.getPropertyMeta(currAttr); -480 if (pMeta == null) { -481 onUnknownProperty(r.getPipe(), currAttr, m, currAttrLine, currAttrCol); -482 } else { -483 Object value = convertToType("", pMeta.getClassMeta()); -484 pMeta.set(m, currAttr, value); -485 } -486 } -487 if (c == -1 || c == ')' || c == AMP) -488 return m; -489 state = S1; -490 } else { -491 if (! currAttr.equals(getBeanTypePropertyName(m.getClassMeta()))) { -492 BeanPropertyMeta pMeta = m.getPropertyMeta(currAttr); -493 if (pMeta == null) { -494 onUnknownProperty(r.getPipe(), currAttr, m, currAttrLine, currAttrCol); -495 parseAnything(object(), r.unread(), m.getBean(false), false, null); // Read content anyway to ignore it -496 } else { -497 setCurrentProperty(pMeta); -498 ClassMeta<?> cm = pMeta.getClassMeta(); -499 Object value = parseAnything(cm, r.unread(), m.getBean(false), false, pMeta); -500 setName(cm, value, currAttr); -501 pMeta.set(m, currAttr, value); -502 setCurrentProperty(null); -503 } -504 } -505 state = S4; -506 } -507 } else if (state == S4) { -508 if (c == ',') -509 state = S1; -510 else if (c == ')' || c == -1 || c == AMP) { -511 return m; +446 final int S1=1; // Looking for attrName start. +447 final int S2=2; // Found attrName end, looking for =. +448 final int S3=3; // Found =, looking for valStart. +449 final int S4=4; // Looking for , or } +450 boolean isInEscape = false; +451 +452 int state = S1; +453 String currAttr = ""; +454 int currAttrLine = -1, currAttrCol = -1; +455 while (c != -1 && c != AMP) { +456 c = r.read(); +457 if (! isInEscape) { +458 if (state == S1) { +459 if (c == ')' || c == -1 || c == AMP) { +460 return m; +461 } +462 if (Character.isWhitespace(c)) +463 skipSpace(r); +464 else { +465 r.unread(); +466 currAttrLine= r.getLine(); +467 currAttrCol = r.getColumn(); +468 currAttr = parseAttrName(r, decodeChars); +469 if (currAttr == null) // Value was '%00' +470 return null; +471 state = S2; +472 } +473 } else if (state == S2) { +474 if (c == EQ || c == '=') +475 state = S3; +476 else if (c == -1 || c == ',' || c == ')' || c == AMP) { +477 m.put(currAttr, null); +478 if (c == ')' || c == -1 || c == AMP) +479 return m; +480 state = S1; +481 } +482 } else if (state == S3) { +483 if (c == -1 || c == ',' || c == ')' || c == AMP) { +484 if (! currAttr.equals(getBeanTypePropertyName(m.getClassMeta()))) { +485 BeanPropertyMeta pMeta = m.getPropertyMeta(currAttr); +486 if (pMeta == null) { +487 onUnknownProperty(r.getPipe(), currAttr, m, currAttrLine, currAttrCol); +488 } else { +489 Object value = convertToType("", pMeta.getClassMeta()); +490 pMeta.set(m, currAttr, value); +491 } +492 } +493 if (c == -1 || c == ')' || c == AMP) +494 return m; +495 state = S1; +496 } else { +497 if (! currAttr.equals(getBeanTypePropertyName(m.getClassMeta()))) { +498 BeanPropertyMeta pMeta = m.getPropertyMeta(currAttr); +499 if (pMeta == null) { +500 onUnknownProperty(r.getPipe(), currAttr, m, currAttrLine, currAttrCol); +501 parseAnything(object(), r.unread(), m.getBean(false), false, null); // Read content anyway to ignore it +502 } else { +503 setCurrentProperty(pMeta); +504 ClassMeta<?> cm = pMeta.getClassMeta();