http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/95e832e1/juneau-core/src/main/java/org/apache/juneau/urlencoding/UonParser.java ---------------------------------------------------------------------- diff --git a/juneau-core/src/main/java/org/apache/juneau/urlencoding/UonParser.java b/juneau-core/src/main/java/org/apache/juneau/urlencoding/UonParser.java deleted file mode 100644 index 948d92b..0000000 --- a/juneau-core/src/main/java/org/apache/juneau/urlencoding/UonParser.java +++ /dev/null @@ -1,1191 +0,0 @@ -// *************************************************************************************************************************** -// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * -// * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * -// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * -// * with the License. You may obtain a copy of the License at * -// * * -// * http://www.apache.org/licenses/LICENSE-2.0 * -// * * -// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * -// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * -// * specific language governing permissions and limitations under the License. * -// *************************************************************************************************************************** -package org.apache.juneau.urlencoding; - -import static org.apache.juneau.urlencoding.UonParserContext.*; - -import java.lang.reflect.*; -import java.util.*; - -import org.apache.juneau.*; -import org.apache.juneau.annotation.*; -import org.apache.juneau.internal.*; -import org.apache.juneau.parser.*; -import org.apache.juneau.transform.*; - -/** - * Parses UON (a notation for URL-encoded query parameter values) text into POJO models. - * - * <h5 class='section'>Media types:</h5> - * <p> - * Handles <code>Content-Type</code> types: <code>text/uon</code> - * - * <h5 class='section'>Description:</h5> - * <p> - * This parser uses a state machine, which makes it very fast and efficient. - * - * <h5 class='section'>Configurable properties:</h5> - * <p> - * This class has the following properties associated with it: - * <ul> - * <li>{@link UonParserContext} - * <li>{@link ParserContext} - * <li>{@link BeanContext} - * </ul> - */ -@SuppressWarnings({ "rawtypes", "unchecked" }) -@Consumes("text/uon") -public class UonParser extends ReaderParser { - - /** Reusable instance of {@link UonParser}, all default settings. */ - public static final UonParser DEFAULT = new UonParser().lock(); - - /** Reusable instance of {@link UonParser.Decoding}. */ - public static final UonParser DEFAULT_DECODING = new Decoding().lock(); - - // Characters that need to be preceeded with an escape character. - private static final AsciiSet escapedChars = new AsciiSet("~'\u0001\u0002"); - - private static final char AMP='\u0001', EQ='\u0002'; // Flags set in reader to denote & and = characters. - - /** - * Equivalent to <code><jk>new</jk> UrlEncodingParser().setProperty(UonParserContext.<jsf>UON_decodeChars</jsf>,<jk>true</jk>);</code>. - */ - public static class Decoding extends UonParser { - /** Constructor */ - public Decoding() { - setDecodeChars(true); - } - } - - /** - * Workhorse method. - * - * @param session The parser context for this parse. - * @param eType The class type being parsed, or <jk>null</jk> if unknown. - * @param r The reader being parsed. - * @param outer The outer object (for constructing nested inner classes). - * @param isUrlParamValue If <jk>true</jk>, then we're parsing a top-level URL-encoded value which is treated a bit different than the default case. - * @param pMeta The current bean property being parsed. - * @return The parsed object. - * @throws Exception - */ - protected <T> T parseAnything(UonParserSession session, ClassMeta<T> eType, ParserReader r, Object outer, boolean isUrlParamValue, BeanPropertyMeta pMeta) throws Exception { - - if (eType == null) - eType = (ClassMeta<T>)object(); - PojoSwap<T,Object> transform = (PojoSwap<T,Object>)eType.getPojoSwap(); - ClassMeta<?> sType = eType.getSerializedClassMeta(); - - Object o = null; - - int c = r.peekSkipWs(); - - if (c == -1 || c == AMP) { - // If parameter is blank and it's an array or collection, return an empty list. - if (sType.isCollectionOrArray()) - o = sType.newInstance(); - else if (sType.isString() || sType.isObject()) - o = ""; - else if (sType.isPrimitive()) - o = sType.getPrimitiveDefault(); - // Otherwise, leave null. - } else if (sType.isObject()) { - if (c == '(') { - ObjectMap m = new ObjectMap(session); - parseIntoMap(session, r, m, string(), object(), pMeta); - o = session.cast(m, pMeta, eType); - } else if (c == '@') { - Collection l = new ObjectList(session); - o = parseIntoCollection(session, r, l, sType.getElementType(), isUrlParamValue, pMeta); - } else { - String s = parseString(session, r, isUrlParamValue); - if (c != '\'') { - if ("true".equals(s) || "false".equals(s)) - o = Boolean.valueOf(s); - else if (StringUtils.isNumeric(s)) - o = StringUtils.parseNumber(s, Number.class); - else - o = s; - } else { - o = s; - } - } - } else if (sType.isBoolean()) { - o = parseBoolean(session, r); - } else if (sType.isCharSequence()) { - o = parseString(session, r, isUrlParamValue); - } else if (sType.isChar()) { - String s = parseString(session, r, isUrlParamValue); - o = s == null ? null : s.charAt(0); - } else if (sType.isNumber()) { - o = parseNumber(session, r, (Class<? extends Number>)sType.getInnerClass()); - } else if (sType.isMap()) { - Map m = (sType.canCreateNewInstance(outer) ? (Map)sType.newInstance(outer) : new ObjectMap(session)); - o = parseIntoMap(session, r, m, sType.getKeyType(), sType.getValueType(), pMeta); - } else if (sType.isCollection()) { - if (c == '(') { - ObjectMap m = new ObjectMap(session); - parseIntoMap(session, r, m, string(), object(), pMeta); - // Handle case where it's a collection, but serialized as a map with a _type or _value key. - if (m.containsKey(session.getBeanTypePropertyName())) - o = session.cast(m, pMeta, eType); - // Handle case where it's a collection, but only a single value was specified. - else { - Collection l = (sType.canCreateNewInstance(outer) ? (Collection)sType.newInstance(outer) : new ObjectList(session)); - l.add(m.cast(sType.getElementType())); - o = l; - } - } else { - Collection l = (sType.canCreateNewInstance(outer) ? (Collection)sType.newInstance(outer) : new ObjectList(session)); - o = parseIntoCollection(session, r, l, sType.getElementType(), isUrlParamValue, pMeta); - } - } else if (sType.canCreateNewBean(outer)) { - BeanMap m = session.newBeanMap(outer, sType.getInnerClass()); - m = parseIntoBeanMap(session, r, m); - o = m == null ? null : m.getBean(); - } else if (sType.canCreateNewInstanceFromString(outer)) { - String s = parseString(session, r, isUrlParamValue); - if (s != null) - o = sType.newInstanceFromString(outer, s); - } else if (sType.canCreateNewInstanceFromNumber(outer)) { - o = sType.newInstanceFromNumber(session, outer, parseNumber(session, r, sType.getNewInstanceFromNumberClass())); - } else if (sType.isArray()) { - if (c == '(') { - ObjectMap m = new ObjectMap(session); - parseIntoMap(session, r, m, string(), object(), pMeta); - // Handle case where it's an array, but serialized as a map with a _type or _value key. - if (m.containsKey(session.getBeanTypePropertyName())) - o = session.cast(m, pMeta, eType); - // Handle case where it's an array, but only a single value was specified. - else { - ArrayList l = new ArrayList(1); - l.add(m.cast(sType.getElementType())); - o = session.toArray(sType, l); - } - } else { - ArrayList l = (ArrayList)parseIntoCollection(session, r, new ArrayList(), sType.getElementType(), isUrlParamValue, pMeta); - o = session.toArray(sType, l); - } - } else if (c == '(') { - // It could be a non-bean with _type attribute. - ObjectMap m = new ObjectMap(session); - parseIntoMap(session, r, m, string(), object(), pMeta); - if (m.containsKey(session.getBeanTypePropertyName())) - o = session.cast(m, pMeta, eType); - else - throw new ParseException(session, "Class ''{0}'' could not be instantiated. Reason: ''{1}''", sType.getInnerClass().getName(), sType.getNotABeanReason()); - } else { - throw new ParseException(session, "Class ''{0}'' could not be instantiated. Reason: ''{1}''", sType.getInnerClass().getName(), sType.getNotABeanReason()); - } - - if (transform != null && o != null) - o = transform.unswap(session, o, eType); - - if (outer != null) - setParent(eType, o, outer); - - return (T)o; - } - - private <K,V> Map<K,V> parseIntoMap(UonParserSession session, ParserReader r, Map<K,V> m, ClassMeta<K> keyType, ClassMeta<V> valueType, BeanPropertyMeta pMeta) throws Exception { - - if (keyType == null) - keyType = (ClassMeta<K>)string(); - - int c = r.read(); - if (c == -1 || c == AMP) - return null; - if (c == 'n') - return (Map<K,V>)parseNull(session, r); - if (c != '(') - throw new ParseException(session, "Expected '(' at beginning of object."); - - final int S1=1; // Looking for attrName start. - final int S2=2; // Found attrName end, looking for =. - final int S3=3; // Found =, looking for valStart. - final int S4=4; // Looking for , or ) - boolean isInEscape = false; - - int state = S1; - K currAttr = null; - while (c != -1 && c != AMP) { - c = r.read(); - if (! isInEscape) { - if (state == S1) { - if (c == ')') - return m; - if (Character.isWhitespace(c)) - skipSpace(r); - else { - r.unread(); - Object attr = parseAttr(session, r, session.isDecodeChars()); - currAttr = attr == null ? null : convertAttrToType(session, m, session.trim(attr.toString()), keyType); - state = S2; - c = 0; // Avoid isInEscape if c was '\' - } - } else if (state == S2) { - if (c == EQ || c == '=') - state = S3; - else if (c == -1 || c == ',' || c == ')' || c == AMP) { - if (currAttr == null) { - // Value was '%00' - r.unread(); - return null; - } - m.put(currAttr, null); - if (c == ')' || c == -1 || c == AMP) - return m; - state = S1; - } - } else if (state == S3) { - if (c == -1 || c == ',' || c == ')' || c == AMP) { - V value = convertAttrToType(session, m, "", valueType); - m.put(currAttr, value); - if (c == -1 || c == ')' || c == AMP) - return m; - state = S1; - } else { - V value = parseAnything(session, valueType, r.unread(), m, false, pMeta); - setName(valueType, value, currAttr); - m.put(currAttr, value); - state = S4; - c = 0; // Avoid isInEscape if c was '\' - } - } else if (state == S4) { - if (c == ',') - state = S1; - else if (c == ')' || c == -1 || c == AMP) { - return m; - } - } - } - isInEscape = isInEscape(c, r, isInEscape); - } - if (state == S1) - throw new ParseException(session, "Could not find attribute name on object."); - if (state == S2) - throw new ParseException(session, "Could not find '=' following attribute name on object."); - if (state == S3) - throw new ParseException(session, "Dangling '=' found in object entry"); - if (state == S4) - throw new ParseException(session, "Could not find ')' marking end of object."); - - return null; // Unreachable. - } - - private <E> Collection<E> parseIntoCollection(UonParserSession session, ParserReader r, Collection<E> l, ClassMeta<E> elementType, boolean isUrlParamValue, BeanPropertyMeta pMeta) throws Exception { - - int c = r.readSkipWs(); - if (c == -1 || c == AMP) - return null; - if (c == 'n') - return (Collection<E>)parseNull(session, r); - - // 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") - // This is not allowed at lower levels since we use comma's as end delimiters. - boolean isInParens = (c == '@'); - if (! isInParens) { - if (isUrlParamValue) - r.unread(); - else - throw new ParseException(session, "Could not find '(' marking beginning of collection."); - } else { - r.read(); - } - - if (isInParens) { - final int S1=1; // Looking for starting of first entry. - final int S2=2; // Looking for starting of subsequent entries. - final int S3=3; // Looking for , or ) after first entry. - - int state = S1; - while (c != -1 && c != AMP) { - c = r.read(); - if (state == S1 || state == S2) { - if (c == ')') { - if (state == S2) { - l.add(parseAnything(session, elementType, r.unread(), l, false, pMeta)); - r.read(); - } - return l; - } else if (Character.isWhitespace(c)) { - skipSpace(r); - } else { - l.add(parseAnything(session, elementType, r.unread(), l, false, pMeta)); - state = S3; - } - } else if (state == S3) { - if (c == ',') { - state = S2; - } else if (c == ')') { - return l; - } - } - } - if (state == S1 || state == S2) - throw new ParseException(session, "Could not find start of entry in array."); - if (state == S3) - throw new ParseException(session, "Could not find end of entry in array."); - - } else { - final int S1=1; // Looking for starting of entry. - final int S2=2; // Looking for , or & or END after first entry. - - int state = S1; - while (c != -1 && c != AMP) { - c = r.read(); - if (state == S1) { - if (Character.isWhitespace(c)) { - skipSpace(r); - } else { - l.add(parseAnything(session, elementType, r.unread(), l, false, pMeta)); - state = S2; - } - } else if (state == S2) { - if (c == ',') { - state = S1; - } else if (Character.isWhitespace(c)) { - skipSpace(r); - } else if (c == AMP || c == -1) { - r.unread(); - return l; - } - } - } - } - - return null; // Unreachable. - } - - private <T> BeanMap<T> parseIntoBeanMap(UonParserSession session, ParserReader r, BeanMap<T> m) throws Exception { - - int c = r.readSkipWs(); - if (c == -1 || c == AMP) - return null; - if (c == 'n') - return (BeanMap<T>)parseNull(session, r); - if (c != '(') - throw new ParseException(session, "Expected '(' at beginning of object."); - - final int S1=1; // Looking for attrName start. - final int S2=2; // Found attrName end, looking for =. - final int S3=3; // Found =, looking for valStart. - final int S4=4; // Looking for , or } - boolean isInEscape = false; - - int state = S1; - String currAttr = ""; - int currAttrLine = -1, currAttrCol = -1; - while (c != -1 && c != AMP) { - c = r.read(); - if (! isInEscape) { - if (state == S1) { - if (c == ')' || c == -1 || c == AMP) { - return m; - } - if (Character.isWhitespace(c)) - skipSpace(r); - else { - r.unread(); - currAttrLine= r.getLine(); - currAttrCol = r.getColumn(); - currAttr = parseAttrName(session, r, session.isDecodeChars()); - if (currAttr == null) // Value was '%00' - return null; - state = S2; - } - } else if (state == S2) { - if (c == EQ || c == '=') - state = S3; - else if (c == -1 || c == ',' || c == ')' || c == AMP) { - m.put(currAttr, null); - if (c == ')' || c == -1 || c == AMP) - return m; - state = S1; - } - } else if (state == S3) { - if (c == -1 || c == ',' || c == ')' || c == AMP) { - if (! currAttr.equals(session.getBeanTypePropertyName())) { - BeanPropertyMeta pMeta = m.getPropertyMeta(currAttr); - if (pMeta == null) { - onUnknownProperty(session, currAttr, m, currAttrLine, currAttrCol); - } else { - Object value = session.convertToType("", pMeta.getClassMeta()); - pMeta.set(m, value); - } - } - if (c == -1 || c == ')' || c == AMP) - return m; - state = S1; - } else { - if (! currAttr.equals(session.getBeanTypePropertyName())) { - BeanPropertyMeta pMeta = m.getPropertyMeta(currAttr); - if (pMeta == null) { - onUnknownProperty(session, currAttr, m, currAttrLine, currAttrCol); - parseAnything(session, object(), r.unread(), m.getBean(false), false, null); // Read content anyway to ignore it - } else { - session.setCurrentProperty(pMeta); - ClassMeta<?> cm = pMeta.getClassMeta(); - Object value = parseAnything(session, cm, r.unread(), m.getBean(false), false, pMeta); - setName(cm, value, currAttr); - pMeta.set(m, value); - session.setCurrentProperty(null); - } - } - state = S4; - } - } else if (state == S4) { - if (c == ',') - state = S1; - else if (c == ')' || c == -1 || c == AMP) { - return m; - } - } - } - isInEscape = isInEscape(c, r, isInEscape); - } - if (state == S1) - throw new ParseException(session, "Could not find attribute name on object."); - if (state == S2) - throw new ParseException(session, "Could not find '=' following attribute name on object."); - if (state == S3) - throw new ParseException(session, "Could not find value following '=' on object."); - if (state == S4) - throw new ParseException(session, "Could not find ')' marking end of object."); - - return null; // Unreachable. - } - - Object parseNull(UonParserSession session, ParserReader r) throws Exception { - String s = parseString(session, r, false); - if ("ull".equals(s)) - return null; - throw new ParseException(session, "Unexpected character sequence: ''{0}''", s); - } - - Object parseAttr(UonParserSession session, ParserReader r, boolean encoded) throws Exception { - Object attr; - attr = parseAttrName(session, r, encoded); - return attr; - } - - String parseAttrName(UonParserSession session, ParserReader r, boolean encoded) throws Exception { - - // If string is of form 'xxx', we're looking for ' at the end. - // Otherwise, we're looking for '&' or '=' or WS or -1 denoting the end of this string. - - int c = r.peekSkipWs(); - if (c == '\'') - return parsePString(session, r); - - r.mark(); - boolean isInEscape = false; - if (encoded) { - while (c != -1) { - c = r.read(); - if (! isInEscape) { - if (c == AMP || c == EQ || c == -1 || Character.isWhitespace(c)) { - if (c != -1) - r.unread(); - String s = r.getMarked(); - return ("null".equals(s) ? null : s); - } - } - else if (c == AMP) - r.replace('&'); - else if (c == EQ) - r.replace('='); - isInEscape = isInEscape(c, r, isInEscape); - } - } else { - while (c != -1) { - c = r.read(); - if (! isInEscape) { - if (c == '=' || c == -1 || Character.isWhitespace(c)) { - if (c != -1) - r.unread(); - String s = r.getMarked(); - return ("null".equals(s) ? null : session.trim(s)); - } - } - isInEscape = isInEscape(c, r, isInEscape); - } - } - - // We should never get here. - throw new ParseException(session, "Unexpected condition."); - } - - - /** - * Returns true if the next character in the stream is preceeded by an escape '~' character. - * @param c The current character. - * @param r The reader. - * @param prevIsInEscape What the flag was last time. - */ - private static final boolean isInEscape(int c, ParserReader r, boolean prevIsInEscape) throws Exception { - if (c == '~' && ! prevIsInEscape) { - c = r.peek(); - if (escapedChars.contains(c)) { - r.delete(); - return true; - } - } - return false; - } - - String parseString(UonParserSession session, ParserReader r, boolean isUrlParamValue) throws Exception { - - // If string is of form 'xxx', we're looking for ' at the end. - // Otherwise, we're looking for ',' or ')' or -1 denoting the end of this string. - - int c = r.peekSkipWs(); - if (c == '\'') - return parsePString(session, r); - - r.mark(); - boolean isInEscape = false; - String s = null; - AsciiSet endChars = (isUrlParamValue ? endCharsParam : endCharsNormal); - while (c != -1) { - c = r.read(); - if (! isInEscape) { - // If this is a URL parameter value, we're looking for: & - // If not, we're looking for: &,) - if (endChars.contains(c)) { - r.unread(); - c = -1; - } - } - if (c == -1) - s = r.getMarked(); - else if (c == EQ) - r.replace('='); - else if (Character.isWhitespace(c) && ! isUrlParamValue) { - s = r.getMarked(0, -1); - skipSpace(r); - c = -1; - } - isInEscape = isInEscape(c, r, isInEscape); - } - - if (isUrlParamValue) - s = StringUtils.trim(s); - - return ("null".equals(s) ? null : session.trim(s)); - } - - private static final AsciiSet endCharsParam = new AsciiSet(""+AMP), endCharsNormal = new AsciiSet(",)"+AMP); - - - /** - * Parses a string of the form "'foo'" - * All whitespace within parenthesis are preserved. - */ - static String parsePString(UonParserSession session, ParserReader r) throws Exception { - - r.read(); // Skip first quote. - r.mark(); - int c = 0; - - boolean isInEscape = false; - while (c != -1) { - c = r.read(); - if (! isInEscape) { - if (c == '\'') - return session.trim(r.getMarked(0, -1)); - } - if (c == EQ) - r.replace('='); - isInEscape = isInEscape(c, r, isInEscape); - } - throw new ParseException(session, "Unmatched parenthesis"); - } - - private Boolean parseBoolean(UonParserSession session, ParserReader r) throws Exception { - String s = parseString(session, r, false); - if (s == null || s.equals("null")) - return null; - if (s.equals("true")) - return true; - if (s.equals("false")) - return false; - throw new ParseException(session, "Unrecognized syntax for boolean. ''{0}''.", s); - } - - private Number parseNumber(UonParserSession session, ParserReader r, Class<? extends Number> c) throws Exception { - String s = parseString(session, r, false); - if (s == null) - return null; - return StringUtils.parseNumber(s, c); - } - - /* - * Call this method after you've finished a parsing a string to make sure that if there's any - * remainder in the input, that it consists only of whitespace and comments. - */ - private void validateEnd(UonParserSession session, ParserReader r) throws Exception { - while (true) { - int c = r.read(); - if (c == -1) - return; - if (! Character.isWhitespace(c)) - throw new ParseException(session, "Remainder after parse: ''{0}''.", (char)c); - } - } - - private Object[] parseArgs(UonParserSession session, ParserReader r, ClassMeta<?>[] argTypes) throws Exception { - - final int S1=1; // Looking for start of entry - final int S2=2; // Looking for , or ) - - Object[] o = new Object[argTypes.length]; - int i = 0; - - int c = r.readSkipWs(); - if (c == -1 || c == AMP) - return null; - if (c != '@') - throw new ParseException(session, "Expected '@' at beginning of args array."); - c = r.read(); - - int state = S1; - while (c != -1 && c != AMP) { - c = r.read(); - if (state == S1) { - if (c == ')') - return o; - o[i] = parseAnything(session, argTypes[i], r.unread(), session.getOuter(), false, null); - i++; - state = S2; - } else if (state == S2) { - if (c == ',') { - state = S1; - } else if (c == ')') { - return o; - } - } - } - - throw new ParseException(session, "Did not find ')' at the end of args array."); - } - - private static void skipSpace(ParserReader r) throws Exception { - int c = 0; - while ((c = r.read()) != -1) { - if (c <= 2 || ! Character.isWhitespace(c)) { - r.unread(); - return; - } - } - } - - UonParserSession createParameterSession(Object input) { - return new UonParserSession(getContext(UonParserContext.class), input); - } - - - //-------------------------------------------------------------------------------- - // Entry point methods - //-------------------------------------------------------------------------------- - - @Override /* Parser */ - public UonParserSession createSession(Object input, ObjectMap op, Method javaMethod, Object outer, Locale locale, TimeZone timeZone, MediaType mediaType) { - return new UonParserSession(getContext(UonParserContext.class), op, input, javaMethod, outer, locale, timeZone, mediaType); - } - - @Override /* Parser */ - protected <T> T doParse(ParserSession session, ClassMeta<T> type) throws Exception { - UonParserSession s = (UonParserSession)session; - UonReader r = s.getReader(); - T o = parseAnything(s, type, r, s.getOuter(), true, null); - validateEnd(s, r); - return o; - } - - @Override /* ReaderParser */ - protected <K,V> Map<K,V> doParseIntoMap(ParserSession session, Map<K,V> m, Type keyType, Type valueType) throws Exception { - UonParserSession s = (UonParserSession)session; - UonReader r = s.getReader(); - m = parseIntoMap(s, r, m, (ClassMeta<K>)session.getClassMeta(keyType), (ClassMeta<V>)session.getClassMeta(valueType), null); - validateEnd(s, r); - return m; - } - - @Override /* ReaderParser */ - protected <E> Collection<E> doParseIntoCollection(ParserSession session, Collection<E> c, Type elementType) throws Exception { - UonParserSession s = (UonParserSession)session; - UonReader r = s.getReader(); - c = parseIntoCollection(s, r, c, (ClassMeta<E>)session.getClassMeta(elementType), false, null); - validateEnd(s, r); - return c; - } - - @Override /* ReaderParser */ - protected Object[] doParseArgs(ParserSession session, ClassMeta<?>[] argTypes) throws Exception { - UonParserSession s = (UonParserSession)session; - UonReader r = s.getReader(); - Object[] a = parseArgs(s, r, argTypes); - return a; - } - - - //-------------------------------------------------------------------------------- - // Properties - //-------------------------------------------------------------------------------- - - /** - * <b>Configuration property:</b> Decode <js>"%xx"</js> sequences. - * <p> - * <ul> - * <li><b>Name:</b> <js>"UonParser.decodeChars"</js> - * <li><b>Data type:</b> <code>Boolean</code> - * <li><b>Default:</b> <jk>false</jk> for {@link UonParser}, <jk>true</jk> for {@link UrlEncodingParser} - * <li><b>Session-overridable:</b> <jk>true</jk> - * </ul> - * <p> - * Specify <jk>true</jk> if URI encoded characters should be decoded, <jk>false</jk> - * if they've already been decoded before being passed to this parser. - * <p> - * <h5 class='section'>Notes:</h5> - * <ul> - * <li>This is equivalent to calling <code>setProperty(<jsf>UON_decodeChars</jsf>, value)</code>. - * </ul> - * - * @param value The new value for this property. - * @return This object (for method chaining). - * @throws LockedException If {@link #lock()} was called on this class. - * @see UonParserContext#UON_decodeChars - */ - public UonParser setDecodeChars(boolean value) throws LockedException { - return setProperty(UON_decodeChars, value); - } - - @Override /* Parser */ - public UonParser setTrimStrings(boolean value) throws LockedException { - super.setTrimStrings(value); - return this; - } - - @Override /* Parser */ - public UonParser setStrict(boolean value) throws LockedException { - super.setStrict(value); - return this; - } - - @Override /* Parser */ - public UonParser setInputStreamCharset(String value) throws LockedException { - super.setInputStreamCharset(value); - return this; - } - - @Override /* Parser */ - public UonParser setFileCharset(String value) throws LockedException { - super.setFileCharset(value); - return this; - } - - @Override /* CoreApi */ - public UonParser setBeansRequireDefaultConstructor(boolean value) throws LockedException { - super.setBeansRequireDefaultConstructor(value); - return this; - } - - @Override /* CoreApi */ - public UonParser setBeansRequireSerializable(boolean value) throws LockedException { - super.setBeansRequireSerializable(value); - return this; - } - - @Override /* CoreApi */ - public UonParser setBeansRequireSettersForGetters(boolean value) throws LockedException { - super.setBeansRequireSettersForGetters(value); - return this; - } - - @Override /* CoreApi */ - public UonParser setBeansRequireSomeProperties(boolean value) throws LockedException { - super.setBeansRequireSomeProperties(value); - return this; - } - - @Override /* CoreApi */ - public UonParser setBeanMapPutReturnsOldValue(boolean value) throws LockedException { - super.setBeanMapPutReturnsOldValue(value); - return this; - } - - @Override /* CoreApi */ - public UonParser setBeanConstructorVisibility(Visibility value) throws LockedException { - super.setBeanConstructorVisibility(value); - return this; - } - - @Override /* CoreApi */ - public UonParser setBeanClassVisibility(Visibility value) throws LockedException { - super.setBeanClassVisibility(value); - return this; - } - - @Override /* CoreApi */ - public UonParser setBeanFieldVisibility(Visibility value) throws LockedException { - super.setBeanFieldVisibility(value); - return this; - } - - @Override /* CoreApi */ - public UonParser setMethodVisibility(Visibility value) throws LockedException { - super.setMethodVisibility(value); - return this; - } - - @Override /* CoreApi */ - public UonParser setUseJavaBeanIntrospector(boolean value) throws LockedException { - super.setUseJavaBeanIntrospector(value); - return this; - } - - @Override /* CoreApi */ - public UonParser setUseInterfaceProxies(boolean value) throws LockedException { - super.setUseInterfaceProxies(value); - return this; - } - - @Override /* CoreApi */ - public UonParser setIgnoreUnknownBeanProperties(boolean value) throws LockedException { - super.setIgnoreUnknownBeanProperties(value); - return this; - } - - @Override /* CoreApi */ - public UonParser setIgnoreUnknownNullBeanProperties(boolean value) throws LockedException { - super.setIgnoreUnknownNullBeanProperties(value); - return this; - } - - @Override /* CoreApi */ - public UonParser setIgnorePropertiesWithoutSetters(boolean value) throws LockedException { - super.setIgnorePropertiesWithoutSetters(value); - return this; - } - - @Override /* CoreApi */ - public UonParser setIgnoreInvocationExceptionsOnGetters(boolean value) throws LockedException { - super.setIgnoreInvocationExceptionsOnGetters(value); - return this; - } - - @Override /* CoreApi */ - public UonParser setIgnoreInvocationExceptionsOnSetters(boolean value) throws LockedException { - super.setIgnoreInvocationExceptionsOnSetters(value); - return this; - } - - @Override /* CoreApi */ - public UonParser setSortProperties(boolean value) throws LockedException { - super.setSortProperties(value); - return this; - } - - @Override /* CoreApi */ - public UonParser setNotBeanPackages(String...values) throws LockedException { - super.setNotBeanPackages(values); - return this; - } - - @Override /* CoreApi */ - public UonParser setNotBeanPackages(Collection<String> values) throws LockedException { - super.setNotBeanPackages(values); - return this; - } - - @Override /* CoreApi */ - public UonParser addNotBeanPackages(String...values) throws LockedException { - super.addNotBeanPackages(values); - return this; - } - - @Override /* CoreApi */ - public UonParser addNotBeanPackages(Collection<String> values) throws LockedException { - super.addNotBeanPackages(values); - return this; - } - - @Override /* CoreApi */ - public UonParser removeNotBeanPackages(String...values) throws LockedException { - super.removeNotBeanPackages(values); - return this; - } - - @Override /* CoreApi */ - public UonParser removeNotBeanPackages(Collection<String> values) throws LockedException { - super.removeNotBeanPackages(values); - return this; - } - - @Override /* CoreApi */ - public UonParser setNotBeanClasses(Class<?>...values) throws LockedException { - super.setNotBeanClasses(values); - return this; - } - - @Override /* CoreApi */ - public UonParser setNotBeanClasses(Collection<Class<?>> values) throws LockedException { - super.setNotBeanClasses(values); - return this; - } - - @Override /* CoreApi */ - public UonParser addNotBeanClasses(Class<?>...values) throws LockedException { - super.addNotBeanClasses(values); - return this; - } - - @Override /* CoreApi */ - public UonParser addNotBeanClasses(Collection<Class<?>> values) throws LockedException { - super.addNotBeanClasses(values); - return this; - } - - @Override /* CoreApi */ - public UonParser removeNotBeanClasses(Class<?>...values) throws LockedException { - super.removeNotBeanClasses(values); - return this; - } - - @Override /* CoreApi */ - public UonParser removeNotBeanClasses(Collection<Class<?>> values) throws LockedException { - super.removeNotBeanClasses(values); - return this; - } - - @Override /* CoreApi */ - public UonParser setBeanFilters(Class<?>...values) throws LockedException { - super.setBeanFilters(values); - return this; - } - - @Override /* CoreApi */ - public UonParser setBeanFilters(Collection<Class<?>> values) throws LockedException { - super.setBeanFilters(values); - return this; - } - - @Override /* CoreApi */ - public UonParser addBeanFilters(Class<?>...values) throws LockedException { - super.addBeanFilters(values); - return this; - } - - @Override /* CoreApi */ - public UonParser addBeanFilters(Collection<Class<?>> values) throws LockedException { - super.addBeanFilters(values); - return this; - } - - @Override /* CoreApi */ - public UonParser removeBeanFilters(Class<?>...values) throws LockedException { - super.removeBeanFilters(values); - return this; - } - - @Override /* CoreApi */ - public UonParser removeBeanFilters(Collection<Class<?>> values) throws LockedException { - super.removeBeanFilters(values); - return this; - } - - @Override /* CoreApi */ - public UonParser setPojoSwaps(Class<?>...values) throws LockedException { - super.setPojoSwaps(values); - return this; - } - - @Override /* CoreApi */ - public UonParser setPojoSwaps(Collection<Class<?>> values) throws LockedException { - super.setPojoSwaps(values); - return this; - } - - @Override /* CoreApi */ - public UonParser addPojoSwaps(Class<?>...values) throws LockedException { - super.addPojoSwaps(values); - return this; - } - - @Override /* CoreApi */ - public UonParser addPojoSwaps(Collection<Class<?>> values) throws LockedException { - super.addPojoSwaps(values); - return this; - } - - @Override /* CoreApi */ - public UonParser removePojoSwaps(Class<?>...values) throws LockedException { - super.removePojoSwaps(values); - return this; - } - - @Override /* CoreApi */ - public UonParser removePojoSwaps(Collection<Class<?>> values) throws LockedException { - super.removePojoSwaps(values); - return this; - } - - @Override /* CoreApi */ - public UonParser setImplClasses(Map<Class<?>,Class<?>> values) throws LockedException { - super.setImplClasses(values); - return this; - } - - @Override /* CoreApi */ - public <T> CoreApi addImplClass(Class<T> interfaceClass, Class<? extends T> implClass) throws LockedException { - super.addImplClass(interfaceClass, implClass); - return this; - } - - @Override /* CoreApi */ - public UonParser setBeanDictionary(Class<?>...values) throws LockedException { - super.setBeanDictionary(values); - return this; - } - - @Override /* CoreApi */ - public UonParser setBeanDictionary(Collection<Class<?>> values) throws LockedException { - super.setBeanDictionary(values); - return this; - } - - @Override /* CoreApi */ - public UonParser addToBeanDictionary(Class<?>...values) throws LockedException { - super.addToBeanDictionary(values); - return this; - } - - @Override /* CoreApi */ - public UonParser addToBeanDictionary(Collection<Class<?>> values) throws LockedException { - super.addToBeanDictionary(values); - return this; - } - - @Override /* CoreApi */ - public UonParser removeFromBeanDictionary(Class<?>...values) throws LockedException { - super.removeFromBeanDictionary(values); - return this; - } - - @Override /* CoreApi */ - public UonParser removeFromBeanDictionary(Collection<Class<?>> values) throws LockedException { - super.removeFromBeanDictionary(values); - return this; - } - - @Override /* CoreApi */ - public UonParser setBeanTypePropertyName(String value) throws LockedException { - super.setBeanTypePropertyName(value); - return this; - } - - @Override /* CoreApi */ - public UonParser setDefaultParser(Class<?> value) throws LockedException { - super.setDefaultParser(value); - return this; - } - - @Override /* CoreApi */ - public UonParser setLocale(Locale value) throws LockedException { - super.setLocale(value); - return this; - } - - @Override /* CoreApi */ - public UonParser setTimeZone(TimeZone value) throws LockedException { - super.setTimeZone(value); - return this; - } - - @Override /* CoreApi */ - public UonParser setMediaType(MediaType value) throws LockedException { - super.setMediaType(value); - return this; - } - - @Override /* CoreApi */ - public UonParser setDebug(boolean value) throws LockedException { - super.setDebug(value); - return this; - } - - @Override /* CoreApi */ - public UonParser setProperty(String name, Object value) throws LockedException { - super.setProperty(name, value); - return this; - } - - @Override /* CoreApi */ - public UonParser setProperties(ObjectMap properties) throws LockedException { - super.setProperties(properties); - return this; - } - - @Override /* CoreApi */ - public UonParser addToProperty(String name, Object value) throws LockedException { - super.addToProperty(name, value); - return this; - } - - @Override /* CoreApi */ - public UonParser putToProperty(String name, Object key, Object value) throws LockedException { - super.putToProperty(name, key, value); - return this; - } - - @Override /* CoreApi */ - public UonParser putToProperty(String name, Object value) throws LockedException { - super.putToProperty(name, value); - return this; - } - - @Override /* CoreApi */ - public UonParser removeFromProperty(String name, Object value) throws LockedException { - super.removeFromProperty(name, value); - return this; - } - - - //-------------------------------------------------------------------------------- - // Overridden methods - //-------------------------------------------------------------------------------- - - @Override /* CoreApi */ - public UonParser setClassLoader(ClassLoader classLoader) throws LockedException { - super.setClassLoader(classLoader); - return this; - } - - @Override /* Lockable */ - public UonParser lock() { - super.lock(); - return this; - } - - @Override /* Lockable */ - public UonParser clone() { - try { - UonParser c = (UonParser)super.clone(); - return c; - } catch (CloneNotSupportedException e) { - throw new RuntimeException(e); // Shouldn't happen - } - } -}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/95e832e1/juneau-core/src/main/java/org/apache/juneau/urlencoding/UonParserContext.java ---------------------------------------------------------------------- diff --git a/juneau-core/src/main/java/org/apache/juneau/urlencoding/UonParserContext.java b/juneau-core/src/main/java/org/apache/juneau/urlencoding/UonParserContext.java deleted file mode 100644 index 2cc5745..0000000 --- a/juneau-core/src/main/java/org/apache/juneau/urlencoding/UonParserContext.java +++ /dev/null @@ -1,73 +0,0 @@ -// *************************************************************************************************************************** -// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * -// * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * -// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * -// * with the License. You may obtain a copy of the License at * -// * * -// * http://www.apache.org/licenses/LICENSE-2.0 * -// * * -// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * -// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * -// * specific language governing permissions and limitations under the License. * -// *************************************************************************************************************************** -package org.apache.juneau.urlencoding; - -import org.apache.juneau.*; -import org.apache.juneau.parser.*; - -/** - * Configurable properties on the {@link UonParser} class. - * <p> - * Context properties are set by calling {@link ContextFactory#setProperty(String, Object)} on the context factory - * returned {@link CoreApi#getContextFactory()}. - * <p> - * See {@link ContextFactory} for more information about context properties. - * - * <h5 class='section'>Inherited configurable properties:</h5> - * <ul class='javahierarchy'> - * <li class='c'><a class="doclink" href="../BeanContext.html#ConfigProperties">BeanContext</a> - Properties associated with handling beans on serializers and parsers. - * <ul> - * <li class='c'><a class="doclink" href="../parser/ParserContext.html#ConfigProperties">ParserContext</a> - Configurable properties common to all parsers. - * </ul> - * </ul> - */ -public class UonParserContext extends ParserContext { - - /** - * <b>Configuration property:</b> Decode <js>"%xx"</js> sequences. - * <p> - * <ul> - * <li><b>Name:</b> <js>"UonParser.decodeChars"</js> - * <li><b>Data type:</b> <code>Boolean</code> - * <li><b>Default:</b> <jk>false</jk> for {@link UonParser}, <jk>true</jk> for {@link UrlEncodingParser} - * <li><b>Session-overridable:</b> <jk>true</jk> - * </ul> - * <p> - * Specify <jk>true</jk> if URI encoded characters should be decoded, <jk>false</jk> - * if they've already been decoded before being passed to this parser. - */ - public static final String UON_decodeChars = "UonParser.decodeChars"; - - final boolean - decodeChars; - - /** - * Constructor. - * <p> - * Typically only called from {@link ContextFactory#getContext(Class)}. - * - * @param cf The factory that created this context. - */ - public UonParserContext(ContextFactory cf) { - super(cf); - this.decodeChars = cf.getProperty(UON_decodeChars, boolean.class, false); - } - - @Override /* Context */ - public ObjectMap asMap() { - return super.asMap() - .append("UonParserContext", new ObjectMap() - .append("decodeChars", decodeChars) - ); - } -} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/95e832e1/juneau-core/src/main/java/org/apache/juneau/urlencoding/UonParserSession.java ---------------------------------------------------------------------- diff --git a/juneau-core/src/main/java/org/apache/juneau/urlencoding/UonParserSession.java b/juneau-core/src/main/java/org/apache/juneau/urlencoding/UonParserSession.java deleted file mode 100644 index cea28dc..0000000 --- a/juneau-core/src/main/java/org/apache/juneau/urlencoding/UonParserSession.java +++ /dev/null @@ -1,118 +0,0 @@ -// *************************************************************************************************************************** -// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * -// * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * -// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * -// * with the License. You may obtain a copy of the License at * -// * * -// * http://www.apache.org/licenses/LICENSE-2.0 * -// * * -// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * -// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * -// * specific language governing permissions and limitations under the License. * -// *************************************************************************************************************************** -package org.apache.juneau.urlencoding; - -import static org.apache.juneau.urlencoding.UonParserContext.*; - -import java.io.*; -import java.lang.reflect.*; -import java.util.*; - -import org.apache.juneau.*; -import org.apache.juneau.parser.*; - -/** - * Session object that lives for the duration of a single use of {@link UonParser}. - * <p> - * This class is NOT thread safe. It is meant to be discarded after one-time use. - */ -public class UonParserSession extends ParserSession { - - private final boolean decodeChars; - private UonReader reader; - - /** - * Create a new session using properties specified in the context. - * - * @param ctx The context creating this session object. - * he context contains all the configuration settings for this object. - * @param input The input. Can be any of the following types: - * <ul> - * <li><jk>null</jk> - * <li>{@link Reader} - * <li>{@link CharSequence} - * <li>{@link InputStream} containing UTF-8 encoded text. - * <li>{@link File} containing system encoded text. - * </ul> - * @param op The override properties. - * These override any context properties defined in the context. - * @param javaMethod The java method that called this parser, usually the method in a REST servlet. - * @param outer The outer object for instantiating top-level non-static inner classes. - * @param locale The session locale. - * If <jk>null</jk>, then the locale defined on the context is used. - * @param timeZone The session timezone. - * If <jk>null</jk>, then the timezone defined on the context is used. - * @param mediaType The session media type (e.g. <js>"application/json"</js>). - */ - public UonParserSession(UonParserContext ctx, ObjectMap op, Object input, Method javaMethod, Object outer, Locale locale, TimeZone timeZone, MediaType mediaType) { - super(ctx, op, input, javaMethod, outer, locale, timeZone, mediaType); - if (op == null || op.isEmpty()) { - decodeChars = ctx.decodeChars; - } else { - decodeChars = op.getBoolean(UON_decodeChars, ctx.decodeChars); - } - } - - /** - * Create a specialized parser session for parsing URL parameters. - * <p> - * The main difference is that characters are never decoded, and the {@link UonParserContext#UON_decodeChars} property is always ignored. - * - * @param ctx The context to copy setting from. - * @param input The input. Can be any of the following types: - * <ul> - * <li><jk>null</jk> - * <li>{@link Reader} - * <li>{@link CharSequence} (e.g. {@link String}) - * <li>{@link InputStream} - Read as UTF-8 encoded character stream. - * <li>{@link File} - Read as system-default encoded stream. - * </ul> - */ - public UonParserSession(UonParserContext ctx, Object input) { - super(ctx, null, input, null, null, null, null, null); - decodeChars = false; - } - - /** - * Returns the {@link UonParserContext#UON_decodeChars} setting value for this session. - * - * @return The {@link UonParserContext#UON_decodeChars} setting value for this session. - */ - public final boolean isDecodeChars() { - return decodeChars; - } - - @Override /* ParserSession */ - public UonReader getReader() throws Exception { - if (reader == null) { - Object input = getInput(); - if (input instanceof UonReader) - reader = (UonReader)input; - else if (input instanceof CharSequence) - reader = new UonReader((CharSequence)input, decodeChars); - else - reader = new UonReader(super.getReader(), decodeChars); - } - return reader; - } - - @Override /* ParserSession */ - public Map<String,Object> getLastLocation() { - Map<String,Object> m = super.getLastLocation(); - if (reader != null) { - m.put("line", reader.getLine()); - m.put("column", reader.getColumn()); - } - return m; - } -} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/95e832e1/juneau-core/src/main/java/org/apache/juneau/urlencoding/UonReader.java ---------------------------------------------------------------------- diff --git a/juneau-core/src/main/java/org/apache/juneau/urlencoding/UonReader.java b/juneau-core/src/main/java/org/apache/juneau/urlencoding/UonReader.java deleted file mode 100644 index feb0557..0000000 --- a/juneau-core/src/main/java/org/apache/juneau/urlencoding/UonReader.java +++ /dev/null @@ -1,195 +0,0 @@ -// *************************************************************************************************************************** -// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * -// * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * -// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * -// * with the License. You may obtain a copy of the License at * -// * * -// * http://www.apache.org/licenses/LICENSE-2.0 * -// * * -// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * -// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * -// * specific language governing permissions and limitations under the License. * -// *************************************************************************************************************************** -package org.apache.juneau.urlencoding; - -import java.io.*; - -import org.apache.juneau.parser.*; - -/** - * Same functionality as {@link ParserReader} except automatically decoded <code>%xx</code> escape sequences. - * <p> - * Escape sequences are assumed to be encoded UTF-8. Extended Unicode (>\u10000) is supported. - * <p> - * If decoding is enabled, the following character replacements occur so that boundaries are not lost: - * <ul> - * <li><js>'&'</js> -> <js>'\u0001'</js> - * <li><js>'='</js> -> <js>'\u0002'</js> - * </ul> - */ -public final class UonReader extends ParserReader { - - private final boolean decodeChars; - private final char[] buff; - private int iCurrent, iEnd; - - /** - * Constructor for input from a {@link CharSequence}. - * - * @param in The character sequence being read from. - * @param decodeChars If <jk>true</jk>, decode <code>%xx</code> escape sequences. - */ - public UonReader(CharSequence in, boolean decodeChars) { - super(in); - this.decodeChars = decodeChars; - if (in == null || ! decodeChars) - this.buff = new char[0]; - else - this.buff = new char[in.length() < 1024 ? in.length() : 1024]; - } - - /** - * Constructor for input from a {@link Reader}). - * - * @param r The Reader being wrapped. - * @param decodeChars If <jk>true</jk>, decode <code>%xx</code> escape sequences. - */ - public UonReader(Reader r, boolean decodeChars) { - super(r); - this.decodeChars = decodeChars; - this.buff = new char[1024]; - } - - @Override /* Reader */ - public final int read(char[] cbuf, int off, int len) throws IOException { - - if (! decodeChars) - return super.read(cbuf, off, len); - - // Copy any remainder to the beginning of the buffer. - int remainder = iEnd - iCurrent; - if (remainder > 0) - System.arraycopy(buff, iCurrent, buff, 0, remainder); - iCurrent = 0; - - int expected = buff.length - remainder; - - int x = super.read(buff, remainder, expected); - if (x == -1 && remainder == 0) - return -1; - - iEnd = remainder + (x == -1 ? 0 : x); - - int i = 0; - while (i < len) { - if (iCurrent >= iEnd) - return i; - char c = buff[iCurrent++]; - if (c == '+') { - cbuf[off + i++] = ' '; - } else if (c == '&') { - cbuf[off + i++] = '\u0001'; - } else if (c == '=') { - cbuf[off + i++] = '\u0002'; - } else if (c != '%') { - cbuf[off + i++] = c; - } else { - int iMark = iCurrent-1; // Keep track of current position. - - // Stop if there aren't at least two more characters following '%' in the buffer, - // or there aren't at least two more positions open in cbuf to handle double-char chars. - if (iMark+2 >= iEnd || i+2 > len) { - iCurrent--; - return i; - } - - int b0 = readEncodedByte(); - int cx; - - // 0xxxxxxx - if (b0 < 128) { - cx = b0; - - // 10xxxxxx - } else if (b0 < 192) { - throw new IOException("Invalid hex value for first escape pattern in UTF-8 sequence: " + b0); - - // 110xxxxx 10xxxxxx - // 11000000(192) - 11011111(223) - } else if (b0 < 224) { - cx = readUTF8(b0-192, 1); - if (cx == -1) { - iCurrent = iMark; - return i; - } - - // 1110xxxx 10xxxxxx 10xxxxxx - // 11100000(224) - 11101111(239) - } else if (b0 < 240) { - cx = readUTF8(b0-224, 2); - if (cx == -1) { - iCurrent = iMark; - return i; - } - - // 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx - // 11110000(240) - 11110111(247) - } else if (b0 < 248) { - cx = readUTF8(b0-240, 3); - if (cx == -1) { - iCurrent = iMark; - return i; - } - - } else - throw new IOException("Invalid hex value for first escape pattern in UTF-8 sequence: " + b0); - - if (cx < 0x10000) - cbuf[off + i++] = (char)cx; - else { - cx -= 0x10000; - cbuf[off + i++] = (char)(0xd800 + (cx >> 10)); - cbuf[off + i++] = (char)(0xdc00 + (cx & 0x3ff)); - } - } - } - return i; - } - - private final int readUTF8(int n, final int numBytes) throws IOException { - if (iCurrent + numBytes*3 > iEnd) - return -1; - for (int i = 0; i < numBytes; i++) { - n <<= 6; - n += readHex()-128; - } - return n; - } - - private final int readHex() throws IOException { - int c = buff[iCurrent++]; - if (c != '%') - throw new IOException("Did not find expected '%' character in UTF-8 sequence."); - return readEncodedByte(); - } - - private final int readEncodedByte() throws IOException { - if (iEnd <= iCurrent + 1) - throw new IOException("Incomplete trailing escape pattern"); - int h = buff[iCurrent++]; - int l = buff[iCurrent++]; - h = fromHexChar(h); - l = fromHexChar(l); - return (h << 4) + l; - } - - private final int fromHexChar(int c) throws IOException { - if (c >= '0' && c <= '9') - return c - '0'; - if (c >= 'a' && c <= 'f') - return 10 + c - 'a'; - if (c >= 'A' && c <= 'F') - return 10 + c - 'A'; - throw new IOException("Invalid hex character '"+c+"' found in escape pattern."); - } -} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/95e832e1/juneau-core/src/main/java/org/apache/juneau/urlencoding/UonSerializer.java ---------------------------------------------------------------------- diff --git a/juneau-core/src/main/java/org/apache/juneau/urlencoding/UonSerializer.java b/juneau-core/src/main/java/org/apache/juneau/urlencoding/UonSerializer.java deleted file mode 100644 index d5ca9e7..0000000 --- a/juneau-core/src/main/java/org/apache/juneau/urlencoding/UonSerializer.java +++ /dev/null @@ -1,869 +0,0 @@ -// *************************************************************************************************************************** -// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * -// * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * -// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * -// * with the License. You may obtain a copy of the License at * -// * * -// * http://www.apache.org/licenses/LICENSE-2.0 * -// * * -// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * -// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * -// * specific language governing permissions and limitations under the License. * -// *************************************************************************************************************************** -package org.apache.juneau.urlencoding; - -import static org.apache.juneau.urlencoding.UonSerializerContext.*; - -import java.lang.reflect.*; -import java.util.*; - -import org.apache.juneau.*; -import org.apache.juneau.annotation.*; -import org.apache.juneau.serializer.*; -import org.apache.juneau.transform.*; - -/** - * Serializes POJO models to UON (a notation for URL-encoded query parameter values). - * - * <h5 class='section'>Media types:</h5> - * <p> - * Handles <code>Accept</code> types: <code>text/uon</code> - * <p> - * Produces <code>Content-Type</code> types: <code>text/uon</code> - * - * <h5 class='section'>Description:</h5> - * <p> - * This serializer provides several serialization options. Typically, one of the predefined DEFAULT serializers will be sufficient. - * However, custom serializers can be constructed to fine-tune behavior. - * - * <h5 class='section'>Configurable properties:</h5> - * <p> - * This class has the following properties associated with it: - * <ul> - * <li>{@link UonSerializerContext} - * <li>{@link BeanContext} - * </ul> - * <p> - * The following shows a sample object defined in Javascript: - * </p> - * <p class='bcode'> - * { - * id: 1, - * name: <js>'John Smith'</js>, - * uri: <js>'http://sample/addressBook/person/1'</js>, - * addressBookUri: <js>'http://sample/addressBook'</js>, - * birthDate: <js>'1946-08-12T00:00:00Z'</js>, - * otherIds: <jk>null</jk>, - * addresses: [ - * { - * uri: <js>'http://sample/addressBook/address/1'</js>, - * personUri: <js>'http://sample/addressBook/person/1'</js>, - * id: 1, - * street: <js>'100 Main Street'</js>, - * city: <js>'Anywhereville'</js>, - * state: <js>'NY'</js>, - * zip: 12345, - * isCurrent: <jk>true</jk>, - * } - * ] - * } - * </p> - * <p> - * Using the "strict" syntax defined in this document, the equivalent - * UON notation would be as follows: - * </p> - * <p class='bcode'> - * ( - * <ua>id</ua>=<un>1</un>, - * <ua>name</ua>=<us>'John+Smith'</us>, - * <ua>uri</ua>=<us>http://sample/addressBook/person/1</us>, - * <ua>addressBookUri</ua>=<us>http://sample/addressBook</us>, - * <ua>birthDate</ua>=<us>1946-08-12T00:00:00Z</us>, - * <ua>otherIds</ua>=<uk>null</uk>, - * <ua>addresses</ua>=@( - * ( - * <ua>uri</ua>=<us>http://sample/addressBook/address/1</us>, - * <ua>personUri</ua>=<us>http://sample/addressBook/person/1</us>, - * <ua>id</ua>=<un>1</un>, - * <ua>street</ua>=<us>'100+Main+Street'</us>, - * <ua>city</ua>=<us>Anywhereville</us>, - * <ua>state</ua>=<us>NY</us>, - * <ua>zip</ua>=<un>12345</un>, - * <ua>isCurrent</ua>=<uk>true</uk> - * ) - * ) - * ) - * </p> - * - * <h5 class='section'>Example:</h5> - * <p class='bcode'> - * <jc>// Serialize a Map</jc> - * Map m = <jk>new</jk> ObjectMap(<js>"{a:'b',c:1,d:false,e:['f',1,false],g:{h:'i'}}"</js>); - * - * <jc>// Serialize to value equivalent to JSON.</jc> - * <jc>// Produces "(a=b,c=1,d=false,e=@(f,1,false),g=(h=i))"</jc> - * String s = UonSerializer.<jsf>DEFAULT</jsf>.serialize(s); - * - * <jc>// Serialize a bean</jc> - * <jk>public class</jk> Person { - * <jk>public</jk> Person(String s); - * <jk>public</jk> String getName(); - * <jk>public int</jk> getAge(); - * <jk>public</jk> Address getAddress(); - * <jk>public boolean</jk> deceased; - * } - * - * <jk>public class</jk> Address { - * <jk>public</jk> String getStreet(); - * <jk>public</jk> String getCity(); - * <jk>public</jk> String getState(); - * <jk>public int</jk> getZip(); - * } - * - * Person p = <jk>new</jk> Person(<js>"John Doe"</js>, 23, <js>"123 Main St"</js>, <js>"Anywhere"</js>, <js>"NY"</js>, 12345, <jk>false</jk>); - * - * <jc>// Produces "(name='John Doe',age=23,address=(street='123 Main St',city=Anywhere,state=NY,zip=12345),deceased=false)"</jc> - * String s = UonSerializer.<jsf>DEFAULT</jsf>.serialize(s); - * </p> - */ -@Produces("text/uon") -public class UonSerializer extends WriterSerializer { - - /** Reusable instance of {@link UonSerializer}, all default settings. */ - public static final UonSerializer DEFAULT = new UonSerializer().lock(); - - /** Reusable instance of {@link UonSerializer.Readable}. */ - public static final UonSerializer DEFAULT_READABLE = new Readable().lock(); - - /** Reusable instance of {@link UonSerializer.Encoding}. */ - public static final UonSerializer DEFAULT_ENCODING = new Encoding().lock(); - - /** - * Equivalent to <code><jk>new</jk> UonSerializer().setUseWhitespace(<jk>true</jk>).setUseIndentation(<jk>true</jk>);</code>. - */ - public static class Readable extends UonSerializer { - /** Constructor */ - public Readable() { - setUseWhitespace(true); - } - } - - /** - * Equivalent to <code><jk>new</jk> UonSerializer().setEncodeChars(<jk>true</jk>);</code>. - */ - public static class Encoding extends UonSerializer { - /** Constructor */ - public Encoding() { - setEncodeChars(true); - } - } - - /** - * Workhorse method. Determines the type of object, and then calls the - * appropriate type-specific serialization method. - * @param session The context that exist for the duration of a serialize. - * @param out The writer to serialize to. - * @param o The object being serialized. - * @param eType The expected type of the object if this is a bean property. - * @param attrName The bean property name if this is a bean property. <jk>null</jk> if this isn't a bean property being serialized. - * @param pMeta The bean property metadata. - * - * @return The same writer passed in. - * @throws Exception - */ - @SuppressWarnings({ "rawtypes", "unchecked" }) - protected SerializerWriter serializeAnything(UonSerializerSession session, UonWriter out, Object o, ClassMeta<?> eType, - String attrName, BeanPropertyMeta pMeta) throws Exception { - - if (o == null) { - out.appendObject(null, false); - return out; - } - - if (eType == null) - eType = object(); - - ClassMeta<?> aType; // The actual type - ClassMeta<?> sType; // The serialized type - - aType = session.push(attrName, o, eType); - boolean isRecursion = aType == null; - - // Handle recursion - if (aType == null) { - o = null; - aType = object(); - } - - sType = aType.getSerializedClassMeta(); - String typeName = session.getBeanTypeName(eType, aType, pMeta); - - // Swap if necessary - PojoSwap swap = aType.getPojoSwap(); - if (swap != null) { - o = swap.swap(session, o); - - // If the getSwapClass() method returns Object, we need to figure out - // the actual type now. - if (sType.isObject()) - sType = session.getClassMetaForObject(o); - } - - // '\0' characters are considered null. - if (o == null || (sType.isChar() && ((Character)o).charValue() == 0)) - out.appendObject(null, false); - else if (sType.isBoolean()) - out.appendBoolean(o); - else if (sType.isNumber()) - out.appendNumber(o); - else if (sType.isBean()) - serializeBeanMap(session, out, session.toBeanMap(o), typeName); - else if (sType.isUri() || (pMeta != null && pMeta.isUri())) - out.appendUri(o); - else if (sType.isMap()) { - if (o instanceof BeanMap) - serializeBeanMap(session, out, (BeanMap)o, typeName); - else - serializeMap(session, out, (Map)o, eType); - } - else if (sType.isCollection()) { - serializeCollection(session, out, (Collection) o, eType); - } - else if (sType.isArray()) { - serializeCollection(session, out, toList(sType.getInnerClass(), o), eType); - } - else { - out.appendObject(o, false); - } - - if (! isRecursion) - session.pop(); - return out; - } - - @SuppressWarnings({ "rawtypes", "unchecked" }) - private SerializerWriter serializeMap(UonSerializerSession session, UonWriter out, Map m, ClassMeta<?> type) throws Exception { - - m = session.sort(m); - - ClassMeta<?> keyType = type.getKeyType(), valueType = type.getValueType(); - - int depth = session.getIndent(); - out.append('('); - - Iterator mapEntries = m.entrySet().iterator(); - - while (mapEntries.hasNext()) { - Map.Entry e = (Map.Entry) mapEntries.next(); - Object value = e.getValue(); - Object key = session.generalize(e.getKey(), keyType); - out.cr(depth).appendObject(key, false).append('='); - serializeAnything(session, out, value, valueType, (key == null ? null : session.toString(key)), null); - if (mapEntries.hasNext()) - out.append(','); - } - - if (m.size() > 0) - out.cr(depth-1); - out.append(')'); - - return out; - } - - private SerializerWriter serializeBeanMap(UonSerializerSession session, UonWriter out, BeanMap<?> m, String typeName) throws Exception { - int depth = session.getIndent(); - - out.append('('); - - boolean addComma = false; - - for (BeanPropertyValue p : m.getValues(session.isTrimNulls(), typeName != null ? session.createBeanTypeNameProperty(m, typeName) : null)) { - BeanPropertyMeta pMeta = p.getMeta(); - ClassMeta<?> cMeta = p.getClassMeta(); - - String key = p.getName(); - Object value = p.getValue(); - Throwable t = p.getThrown(); - if (t != null) - session.addBeanGetterWarning(pMeta, t); - - if (session.canIgnoreValue(cMeta, key, value)) - continue; - - if (addComma) - out.append(','); - - out.cr(depth).appendObject(key, false).append('='); - - serializeAnything(session, out, value, cMeta, key, pMeta); - - addComma = true; - } - - if (m.size() > 0) - out.cr(depth-1); - out.append(')'); - - return out; - } - - @SuppressWarnings({ "rawtypes", "unchecked" }) - private SerializerWriter serializeCollection(UonSerializerSession session, UonWriter out, Collection c, ClassMeta<?> type) throws Exception { - - ClassMeta<?> elementType = type.getElementType(); - - c = session.sort(c); - - out.append('@').append('('); - - int depth = session.getIndent(); - - for (Iterator i = c.iterator(); i.hasNext();) { - out.cr(depth); - serializeAnything(session, out, i.next(), elementType, "<iterator>", null); - if (i.hasNext()) - out.append(','); - } - - if (c.size() > 0) - out.cr(depth-1); - out.append(')'); - - return out; - } - - - //-------------------------------------------------------------------------------- - // Entry point methods - //-------------------------------------------------------------------------------- - - @Override /* Serializer */ - public UonSerializerSession createSession(Object output, ObjectMap op, Method javaMethod, Locale locale, TimeZone timeZone, MediaType mediaType) { - return new UonSerializerSession(getContext(UonSerializerContext.class), op, output, javaMethod, locale, timeZone, mediaType); - } - - @Override /* Serializer */ - protected void doSerialize(SerializerSession session, Object o) throws Exception { - UonSerializerSession s = (UonSerializerSession)session; - serializeAnything(s, s.getWriter(), o, null, "root", null); - } - - - //-------------------------------------------------------------------------------- - // Properties - //-------------------------------------------------------------------------------- - - /** - * <b>Configuration property:</b> Encode non-valid URI characters. - * <p> - * <ul> - * <li><b>Name:</b> <js>"UonSerializer.encodeChars"</js> - * <li><b>Data type:</b> <code>Boolean</code> - * <li><b>Default:</b> <jk>false</jk> for {@link UonSerializer}, <jk>true</jk> for {@link UrlEncodingSerializer} - * <li><b>Session-overridable:</b> <jk>true</jk> - * </ul> - * <p> - * Encode non-valid URI characters with <js>"%xx"</js> constructs. - * <p> - * If <jk>true</jk>, non-valid URI characters will be converted to <js>"%xx"</js> sequences. - * Set to <jk>false</jk> if parameter value is being passed to some other code that will already - * perform URL-encoding of non-valid URI characters. - * <p> - * <h5 class='section'>Notes:</h5> - * <ul> - * <li>This is equivalent to calling <code>setProperty(<jsf>UON_encodeChars</jsf>, value)</code>. - * <li>This introduces a slight performance penalty. - * </ul> - * - * @param value The new value for this property. - * @return This object (for method chaining). - * @throws LockedException If {@link #lock()} was called on this class. - * @see UonSerializerContext#UON_encodeChars - */ - public UonSerializer setEncodeChars(boolean value) throws LockedException { - return setProperty(UON_encodeChars, value); - } - - @Override /* Serializer */ - public UonSerializer setMaxDepth(int value) throws LockedException { - super.setMaxDepth(value); - return this; - } - - @Override /* Serializer */ - public UonSerializer setInitialDepth(int value) throws LockedException { - super.setInitialDepth(value); - return this; - } - - @Override /* Serializer */ - public UonSerializer setDetectRecursions(boolean value) throws LockedException { - super.setDetectRecursions(value); - return this; - } - - @Override /* Serializer */ - public UonSerializer setIgnoreRecursions(boolean value) throws LockedException { - super.setIgnoreRecursions(value); - return this; - } - - @Override /* Serializer */ - public UonSerializer setUseWhitespace(boolean value) throws LockedException { - super.setUseWhitespace(value); - return this; - } - - @Override /* Serializer */ - public UonSerializer setAddBeanTypeProperties(boolean value) throws LockedException { - super.setAddBeanTypeProperties(value); - return this; - } - - @Override /* Serializer */ - public UonSerializer setQuoteChar(char value) throws LockedException { - super.setQuoteChar(value); - return this; - } - - @Override /* Serializer */ - public UonSerializer setTrimNullProperties(boolean value) throws LockedException { - super.setTrimNullProperties(value); - return this; - } - - @Override /* Serializer */ - public UonSerializer setTrimEmptyCollections(boolean value) throws LockedException { - super.setTrimEmptyCollections(value); - return this; - } - - @Override /* Serializer */ - public UonSerializer setTrimEmptyMaps(boolean value) throws LockedException { - super.setTrimEmptyMaps(value); - return this; - } - - @Override /* Serializer */ - public UonSerializer setTrimStrings(boolean value) throws LockedException { - super.setTrimStrings(value); - return this; - } - - @Override /* Serializer */ - public UonSerializer setRelativeUriBase(String value) throws LockedException { - super.setRelativeUriBase(value); - return this; - } - - @Override /* Serializer */ - public UonSerializer setAbsolutePathUriBase(String value) throws LockedException { - super.setAbsolutePathUriBase(value); - return this; - } - - @Override /* Serializer */ - public UonSerializer setSortCollections(boolean value) throws LockedException { - super.setSortCollections(value); - return this; - } - - @Override /* Serializer */ - public UonSerializer setSortMaps(boolean value) throws LockedException { - super.setSortMaps(value); - return this; - } - - @Override /* CoreApi */ - public UonSerializer setBeansRequireDefaultConstructor(boolean value) throws LockedException { - super.setBeansRequireDefaultConstructor(value); - return this; - } - - @Override /* CoreApi */ - public UonSerializer setBeansRequireSerializable(boolean value) throws LockedException { - super.setBeansRequireSerializable(value); - return this; - } - - @Override /* CoreApi */ - public UonSerializer setBeansRequireSettersForGetters(boolean value) throws LockedException { - super.setBeansRequireSettersForGetters(value); - return this; - } - - @Override /* CoreApi */ - public UonSerializer setBeansRequireSomeProperties(boolean value) throws LockedException { - super.setBeansRequireSomeProperties(value); - return this; - } - - @Override /* CoreApi */ - public UonSerializer setBeanMapPutReturnsOldValue(boolean value) throws LockedException { - super.setBeanMapPutReturnsOldValue(value); - return this; - } - - @Override /* CoreApi */ - public UonSerializer setBeanConstructorVisibility(Visibility value) throws LockedException { - super.setBeanConstructorVisibility(value); - return this; - } - - @Override /* CoreApi */ - public UonSerializer setBeanClassVisibility(Visibility value) throws LockedException { - super.setBeanClassVisibility(value); - return this; - } - - @Override /* CoreApi */ - public UonSerializer setBeanFieldVisibility(Visibility value) throws LockedException { - super.setBeanFieldVisibility(value); - return this; - } - - @Override /* CoreApi */ - public UonSerializer setMethodVisibility(Visibility value) throws LockedException { - super.setMethodVisibility(value); - return this; - } - - @Override /* CoreApi */ - public UonSerializer setUseJavaBeanIntrospector(boolean value) throws LockedException { - super.setUseJavaBeanIntrospector(value); - return this; - } - - @Override /* CoreApi */ - public UonSerializer setUseInterfaceProxies(boolean value) throws LockedException { - super.setUseInterfaceProxies(value); - return this; - } - - @Override /* CoreApi */ - public UonSerializer setIgnoreUnknownBeanProperties(boolean value) throws LockedException { - super.setIgnoreUnknownBeanProperties(value); - return this; - } - - @Override /* CoreApi */ - public UonSerializer setIgnoreUnknownNullBeanProperties(boolean value) throws LockedException { - super.setIgnoreUnknownNullBeanProperties(value); - return this; - } - - @Override /* CoreApi */ - public UonSerializer setIgnorePropertiesWithoutSetters(boolean value) throws LockedException { - super.setIgnorePropertiesWithoutSetters(value); - return this; - } - - @Override /* CoreApi */ - public UonSerializer setIgnoreInvocationExceptionsOnGetters(boolean value) throws LockedException { - super.setIgnoreInvocationExceptionsOnGetters(value); - return this; - } - - @Override /* CoreApi */ - public UonSerializer setIgnoreInvocationExceptionsOnSetters(boolean value) throws LockedException { - super.setIgnoreInvocationExceptionsOnSetters(value); - return this; - } - - @Override /* CoreApi */ - public UonSerializer setSortProperties(boolean value) throws LockedException { - super.setSortProperties(value); - return this; - } - - @Override /* CoreApi */ - public UonSerializer setNotBeanPackages(String...values) throws LockedException { - super.setNotBeanPackages(values); - return this; - } - - @Override /* CoreApi */ - public UonSerializer setNotBeanPackages(Collection<String> values) throws LockedException { - super.setNotBeanPackages(values); - return this; - } - - @Override /* CoreApi */ - public UonSerializer addNotBeanPackages(String...values) throws LockedException { - super.addNotBeanPackages(values); - return this; - } - - @Override /* CoreApi */ - public UonSerializer addNotBeanPackages(Collection<String> values) throws LockedException { - super.addNotBeanPackages(values); - return this; - } - - @Override /* CoreApi */ - public UonSerializer removeNotBeanPackages(String...values) throws LockedException { - super.removeNotBeanPackages(values); - return this; - } - - @Override /* CoreApi */ - public UonSerializer removeNotBeanPackages(Collection<String> values) throws LockedException { - super.removeNotBeanPackages(values); - return this; - } - - @Override /* CoreApi */ - public UonSerializer setNotBeanClasses(Class<?>...values) throws LockedException { - super.setNotBeanClasses(values); - return this; - } - - @Override /* CoreApi */ - public UonSerializer setNotBeanClasses(Collection<Class<?>> values) throws LockedException { - super.setNotBeanClasses(values); - return this; - } - - @Override /* CoreApi */ - public UonSerializer addNotBeanClasses(Class<?>...values) throws LockedException { - super.addNotBeanClasses(values); - return this; - } - - @Override /* CoreApi */ - public UonSerializer addNotBeanClasses(Collection<Class<?>> values) throws LockedException { - super.addNotBeanClasses(values); - return this; - } - - @Override /* CoreApi */ - public UonSerializer removeNotBeanClasses(Class<?>...values) throws LockedException { - super.removeNotBeanClasses(values); - return this; - } - - @Override /* CoreApi */ - public UonSerializer removeNotBeanClasses(Collection<Class<?>> values) throws LockedException { - super.removeNotBeanClasses(values); - return this; - } - - @Override /* CoreApi */ - public UonSerializer setBeanFilters(Class<?>...values) throws LockedException { - super.setBeanFilters(values); - return this; - } - - @Override /* CoreApi */ - public UonSerializer setBeanFilters(Collection<Class<?>> values) throws LockedException { - super.setBeanFilters(values); - return this; - } - - @Override /* CoreApi */ - public UonSerializer addBeanFilters(Class<?>...values) throws LockedException { - super.addBeanFilters(values); - return this; - } - - @Override /* CoreApi */ - public UonSerializer addBeanFilters(Collection<Class<?>> values) throws LockedException { - super.addBeanFilters(values); - return this; - } - - @Override /* CoreApi */ - public UonSerializer removeBeanFilters(Class<?>...values) throws LockedException { - super.removeBeanFilters(values); - return this; - } - - @Override /* CoreApi */ - public UonSerializer removeBeanFilters(Collection<Class<?>> values) throws LockedException { - super.removeBeanFilters(values); - return this; - } - - @Override /* CoreApi */ - public UonSerializer setPojoSwaps(Class<?>...values) throws LockedException { - super.setPojoSwaps(values); - return this; - } - - @Override /* CoreApi */ - public UonSerializer setPojoSwaps(Collection<Class<?>> values) throws LockedException { - super.setPojoSwaps(values); - return this; - } - - @Override /* CoreApi */ - public UonSerializer addPojoSwaps(Class<?>...values) throws LockedException { - super.addPojoSwaps(values); - return this; - } - - @Override /* CoreApi */ - public UonSerializer addPojoSwaps(Collection<Class<?>> values) throws LockedException { - super.addPojoSwaps(values); - return this; - } - - @Override /* CoreApi */ - public UonSerializer removePojoSwaps(Class<?>...values) throws LockedException { - super.removePojoSwaps(values); - return this; - } - - @Override /* CoreApi */ - public UonSerializer removePojoSwaps(Collection<Class<?>> values) throws LockedException { - super.removePojoSwaps(values); - return this; - } - - @Override /* CoreApi */ - public UonSerializer setImplClasses(Map<Class<?>,Class<?>> values) throws LockedException { - super.setImplClasses(values); - return this; - } - - @Override /* CoreApi */ - public <T> CoreApi addImplClass(Class<T> interfaceClass, Class<? extends T> implClass) throws LockedException { - super.addImplClass(interfaceClass, implClass); - return this; - } - - @Override /* CoreApi */ - public UonSerializer setBeanDictionary(Class<?>...values) throws LockedException { - super.setBeanDictionary(values); - return this; - } - - @Override /* CoreApi */ - public UonSerializer setBeanDictionary(Collection<Class<?>> values) throws LockedException { - super.setBeanDictionary(values); - return this; - } - - @Override /* CoreApi */ - public UonSerializer addToBeanDictionary(Class<?>...values) throws LockedException { - super.addToBeanDictionary(values); - return this; - } - - @Override /* CoreApi */ - public UonSerializer addToBeanDictionary(Collection<Class<?>> values) throws LockedException { - super.addToBeanDictionary(values); - return this; - } - - @Override /* CoreApi */ - public UonSerializer removeFromBeanDictionary(Class<?>...values) throws LockedException { - super.removeFromBeanDictionary(values); - return this; - } - - @Override /* CoreApi */ - public UonSerializer removeFromBeanDictionary(Collection<Class<?>> values) throws LockedException { - super.removeFromBeanDictionary(values); - return this; - } - - @Override /* CoreApi */ - public UonSerializer setBeanTypePropertyName(String value) throws LockedException { - super.setBeanTypePropertyName(value); - return this; - } - - @Override /* CoreApi */ - public UonSerializer setDefaultParser(Class<?> value) throws LockedException { - super.setDefaultParser(value); - return this; - } - - @Override /* CoreApi */ - public UonSerializer setLocale(Locale value) throws LockedException { - super.setLocale(value); - return this; - } - - @Override /* CoreApi */ - public UonSerializer setTimeZone(TimeZone value) throws LockedException { - super.setTimeZone(value); - return this; - } - - @Override /* CoreApi */ - public UonSerializer setMediaType(MediaType value) throws LockedException { - super.setMediaType(value); - return this; - } - - @Override /* CoreApi */ - public UonSerializer setDebug(boolean value) throws LockedException { - super.setDebug(value); - return this; - } - - @Override /* CoreApi */ - public UonSerializer setProperty(String name, Object value) throws LockedException { - super.setProperty(name, value); - return this; - } - - @Override /* CoreApi */ - public UonSerializer setProperties(ObjectMap properties) throws LockedException { - super.setProperties(properties); - return this; - } - - @Override /* CoreApi */ - public UonSerializer addToProperty(String name, Object value) throws LockedException { - super.addToProperty(name, value); - return this; - } - - @Override /* CoreApi */ - public UonSerializer putToProperty(String name, Object key, Object value) throws LockedException { - super.putToProperty(name, key, value); - return this; - } - - @Override /* CoreApi */ - public UonSerializer putToProperty(String name, Object value) throws LockedException { - super.putToProperty(name, value); - return this; - } - - @Override /* CoreApi */ - public UonSerializer removeFromProperty(String name, Object value) throws LockedException { - super.removeFromProperty(name, value); - return this; - } - - - //-------------------------------------------------------------------------------- - // Overridden methods - //-------------------------------------------------------------------------------- - - @Override /* CoreApi */ - public UonSerializer setClassLoader(ClassLoader classLoader) throws LockedException { - super.setClassLoader(classLoader); - return this; - } - - @Override /* Lockable */ - public UonSerializer lock() { - super.lock(); - return this; - } - - @Override /* Lockable */ - public UonSerializer clone() { - try { - UonSerializer c = (UonSerializer)super.clone(); - return c; - } catch (CloneNotSupportedException e) { - throw new RuntimeException(e); // Shouldn't happen - } - } -}
