juneau-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jamesbog...@apache.org
Subject [juneau] branch master updated: Make Parser fields private.
Date Sun, 08 Jul 2018 21:01:00 GMT
This is an automated email from the ASF dual-hosted git repository.

jamesbognar pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/juneau.git


The following commit(s) were added to refs/heads/master by this push:
     new 719a58c  Make Parser fields private.
719a58c is described below

commit 719a58cba2ab28affb39c3e2f8675234fad771a4
Author: JamesBognar <jamesbognar@apache.org>
AuthorDate: Sun Jul 8 17:00:47 2018 -0400

    Make Parser fields private.
---
 .../apache/juneau/httppart/OpenApiPartParser.java  |  4 +-
 .../main/java/org/apache/juneau/uon/UonParser.java | 34 +++++++++-
 .../org/apache/juneau/uon/UonParserSession.java    | 13 ++--
 .../juneau/urlencoding/UrlEncodingParser.java      | 21 +++++-
 .../urlencoding/UrlEncodingParserSession.java      |  9 +--
 .../main/java/org/apache/juneau/xml/XmlParser.java | 76 +++++++++++++++++++---
 .../org/apache/juneau/xml/XmlParserSession.java    | 22 ++-----
 7 files changed, 132 insertions(+), 47 deletions(-)

diff --git a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/httppart/OpenApiPartParser.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/httppart/OpenApiPartParser.java
index 1ca2ee3..cfeaec9 100644
--- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/httppart/OpenApiPartParser.java
+++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/httppart/OpenApiPartParser.java
@@ -178,8 +178,8 @@ public class OpenApiPartParser extends UonPartParser {
 	// Instance
 	//-------------------------------------------------------------------------------------------------------------------
 
-	final HttpPartSchema schema;
-	final BeanSession bs;
+	private final HttpPartSchema schema;
+	private final BeanSession bs;
 
 	/**
 	 * Constructor.
diff --git a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/uon/UonParser.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/uon/UonParser.java
index 9b73b71..6462371 100644
--- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/uon/UonParser.java
+++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/uon/UonParser.java
@@ -43,7 +43,7 @@ public class UonParser extends ReaderParser {
 	 * 	<li><b>Name:</b>  <js>"UonParser.decoding.b"</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>
+	 * 	<li><b>Session-overridable:</b>  <jk>false</jk>
 	 * 	<li><b>Methods:</b>
 	 * 		<ul>
 	 * 			<li class='jm'>{@link UonParserBuilder#decoding(boolean)}
@@ -84,7 +84,7 @@ public class UonParser extends ReaderParser {
 	 * 	<li><b>Name:</b>  <js>"UonParser.validateEnd.b"</js>
 	 * 	<li><b>Data type:</b>  <code>Boolean</code>
 	 * 	<li><b>Default:</b>  <jk>false</jk>
-	 * 	<li><b>Session-overridable:</b>  <jk>true</jk>
+	 * 	<li><b>Session-overridable:</b>  <jk>false</jk>
 	 * 	<li><b>Methods:</b>
 	 * 		<ul>
 	 * 			<li class='jm'>{@link UonParserBuilder#validateEnd(boolean)}
@@ -151,7 +151,7 @@ public class UonParser extends ReaderParser {
 	// Instance
 	//-------------------------------------------------------------------------------------------------------------------
 
-	final boolean
+	private final boolean
 		decodeChars, validateEnd;
 
 	/**
@@ -213,6 +213,34 @@ public class UonParser extends ReaderParser {
 		return new UonParserSession(this, args);
 	}
 
+	//-----------------------------------------------------------------------------------------------------------------
+	// Properties
+	//-----------------------------------------------------------------------------------------------------------------
+
+	/**
+	 * Configuration property: Decode <js>"%xx"</js> sequences.
+	 *
+	 * @see #UON_decoding
+	 * @return
+	 * 	<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 final boolean isDecodeChars() {
+		return decodeChars;
+	}
+
+	/**
+	 * Configuration property:  Validate end.
+	 *
+	 * @see #UON_validateEnd
+	 * @return
+	 * 	<jk>true</jk> if after parsing a POJO from the input, verifies that the
remaining input in
+	 * 	the stream consists of only comments or whitespace.
+	 */
+	public final boolean isValidateEnd() {
+		return validateEnd;
+	}
+
 	@Override /* Context */
 	public ObjectMap asMap() {
 		return super.asMap()
diff --git a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/uon/UonParserSession.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/uon/UonParserSession.java
index 6915c06..37041e6 100644
--- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/uon/UonParserSession.java
+++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/uon/UonParserSession.java
@@ -39,8 +39,8 @@ public class UonParserSession extends ReaderParserSession {
 
 	private static final char AMP='\u0001', EQ='\u0002';  // Flags set in reader to denote &
and = characters.
 
-
-	private final boolean decodeChars, validateEnd;
+	private final UonParser ctx;
+	private final boolean decodeChars;
 
 	/**
 	 * Create a new session using properties specified in the context.
@@ -53,8 +53,8 @@ public class UonParserSession extends ReaderParserSession {
 	 */
 	protected UonParserSession(UonParser ctx, ParserSessionArgs args) {
 		super(ctx, args);
-		decodeChars = getProperty(UON_decoding, boolean.class, ctx.decodeChars);
-		validateEnd = getProperty(UON_validateEnd, boolean.class, ctx.validateEnd);
+		this.ctx = ctx;
+		decodeChars = getProperty(UON_decoding, boolean.class, ctx.isDecodeChars());
 	}
 
 	@Override /* Session */
@@ -82,8 +82,8 @@ public class UonParserSession extends ReaderParserSession {
 	 */
 	protected UonParserSession(UonParser ctx, ParserSessionArgs args, boolean decodeChars) {
 		super(ctx, args);
+		this.ctx = ctx;
 		this.decodeChars = decodeChars;
-		this.validateEnd = true;
 	}
 
 	@Override /* ParserSession */
@@ -750,7 +750,7 @@ public class UonParserSession extends ReaderParserSession {
 	 * remainder in the input, that it consists only of whitespace and comments.
 	 */
 	private void validateEnd(UonReader r) throws Exception {
-		if (! validateEnd)
+		if (! ctx.isValidateEnd())
 			return;
 		while (true) {
 			int c = r.read();
@@ -779,7 +779,6 @@ public class UonParserSession extends ReaderParserSession {
 	 * @return A new {@link UonReader} object.
 	 * @throws Exception
 	 */
-	@SuppressWarnings({ })
 	public final UonReader getUonReader(ParserPipe pipe, boolean decodeChars) throws Exception
{
 		Reader r = pipe.getReader();
 		if (r instanceof UonReader)
diff --git a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/urlencoding/UrlEncodingParser.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/urlencoding/UrlEncodingParser.java
index 42338b5..d33845d 100644
--- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/urlencoding/UrlEncodingParser.java
+++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/urlencoding/UrlEncodingParser.java
@@ -50,7 +50,7 @@ public class UrlEncodingParser extends UonParser {
 	 * 	<li><b>Name:</b>  <js>"UrlEncodingParser.expandedParams.b"</js>
 	 * 	<li><b>Data type:</b>  <code>Boolean</code>
 	 * 	<li><b>Default:</b>  <jk>false</jk>
-	 * 	<li><b>Session-overridable:</b>  <jk>true</jk>
+	 * 	<li><b>Session-overridable:</b>  <jk>false</jk>
 	 * 	<li><b>Methods:</b>
 	 * 		<ul>
 	 * 			<li class='jm'>{@link UrlEncodingParserBuilder#expandedParams(boolean)}
@@ -108,8 +108,7 @@ public class UrlEncodingParser extends UonParser {
 	// Instance
 	//-------------------------------------------------------------------------------------------------------------------
 
-	final boolean
-		expandedParams;
+	private final boolean expandedParams;
 
 	/**
 	 * Constructor.
@@ -157,6 +156,22 @@ public class UrlEncodingParser extends UonParser {
 		return new UrlEncodingParserSession(this, args);
 	}
 
+	//--------------------------------------------------------------------------------
+	// Properties
+	//--------------------------------------------------------------------------------
+
+	/**
+	 * Configuration property:  Parser bean property collections/arrays as separate key/value
pairs.
+	 *
+	 * @see #URLENC_expandedParams
+	 * @return
+	 * <jk>false</jk> if serializing the array <code>[1,2,3]</code>
results in <code>?key=$a(1,2,3)</code>.
+	 * <br><jk>true</jk> if serializing the same array results in <code>?key=1&amp;key=2&amp;key=3</code>.
+	 */
+	public final boolean isExpandedParams() {
+		return expandedParams;
+	}
+
 	@Override /* Context */
 	public ObjectMap asMap() {
 		return super.asMap()
diff --git a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/urlencoding/UrlEncodingParserSession.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/urlencoding/UrlEncodingParserSession.java
index 611a5c8..d1af782 100644
--- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/urlencoding/UrlEncodingParserSession.java
+++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/urlencoding/UrlEncodingParserSession.java
@@ -12,8 +12,6 @@
 // ***************************************************************************************************************************
 package org.apache.juneau.urlencoding;
 
-import static org.apache.juneau.urlencoding.UrlEncodingParser.*;
-
 import java.lang.reflect.*;
 import java.util.*;
 
@@ -33,7 +31,7 @@ import org.apache.juneau.uon.*;
 @SuppressWarnings({ "unchecked", "rawtypes" })
 public class UrlEncodingParserSession extends UonParserSession {
 
-	private final boolean expandedParams;
+	private final UrlEncodingParser ctx;
 
 	/**
 	 * Create a new session using properties specified in the context.
@@ -46,14 +44,13 @@ public class UrlEncodingParserSession extends UonParserSession {
 	 */
 	protected UrlEncodingParserSession(UrlEncodingParser ctx, ParserSessionArgs args) {
 		super(ctx, args);
-		expandedParams = getProperty(URLENC_expandedParams, boolean.class, ctx.expandedParams);
+		this.ctx = ctx;
 	}
 
 	@Override /* Session */
 	public ObjectMap asMap() {
 		return super.asMap()
 			.append("UrlEncodingParser", new ObjectMap()
-				.append("expandedParams", expandedParams)
 			);
 	}
 
@@ -66,7 +63,7 @@ public class UrlEncodingParserSession extends UonParserSession {
 	public final boolean shouldUseExpandedParams(BeanPropertyMeta pMeta) {
 		ClassMeta<?> cm = pMeta.getClassMeta().getSerializedClassMeta(this);
 		if (cm.isCollectionOrArray()) {
-			if (expandedParams)
+			if (ctx.isExpandedParams())
 				return true;
 			if (pMeta.getBeanMeta().getClassMeta().getExtendedMeta(UrlEncodingClassMeta.class).isExpandedParams())
 				return true;
diff --git a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/xml/XmlParser.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/xml/XmlParser.java
index 928ae9c..a8effec 100644
--- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/xml/XmlParser.java
+++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/xml/XmlParser.java
@@ -66,7 +66,7 @@ public class XmlParser extends ReaderParser {
 	 * 	<li><b>Name:</b>  <js>"XmlParser.preserveRootElement.b"</js>
 	 * 	<li><b>Data type:</b>  <code>Boolean</code>
 	 * 	<li><b>Default:</b>  <jk>false</jk>
-	 * 	<li><b>Session-overridable:</b>  <jk>true</jk>
+	 * 	<li><b>Session-overridable:</b>  <jk>false</jk>
 	 * 	<li><b>Methods:</b>
 	 * 		<ul>
 	 * 			<li class='jm'>{@link XmlParserBuilder#preserveRootElement(boolean)}
@@ -112,7 +112,7 @@ public class XmlParser extends ReaderParser {
 	 * 	<li><b>Name:</b>  <js>"XmlParser.reporter.c"</js>
 	 * 	<li><b>Data type:</b>  <code>Class&lt;? <jk>extends</jk>
{@link XMLReporter}&gt;</code>
 	 * 	<li><b>Default:</b>  <jk>null</jk>
-	 * 	<li><b>Session-overridable:</b>  <jk>true</jk>
+	 * 	<li><b>Session-overridable:</b>  <jk>false</jk>
 	 * 	<li><b>Methods:</b>
 	 * 		<ul>
 	 * 			<li class='jm'>{@link XmlParserBuilder#reporter(XMLReporter)}
@@ -139,7 +139,7 @@ public class XmlParser extends ReaderParser {
 	 * 	<li><b>Name:</b>  <js>"XmlParser.resolver.c"</js>
 	 * 	<li><b>Data type:</b>  <code>Class&lt;? <jk>extends</jk>
{@link XMLResolver}&gt;</code>
 	 * 	<li><b>Default:</b>  <jk>null</jk>
-	 * 	<li><b>Session-overridable:</b>  <jk>true</jk>
+	 * 	<li><b>Session-overridable:</b>  <jk>false</jk>
 	 * 	<li><b>Methods:</b>
 	 * 		<ul>
 	 * 			<li class='jm'>{@link XmlParserBuilder#resolver(XMLResolver)}
@@ -160,7 +160,7 @@ public class XmlParser extends ReaderParser {
 	 * 	<li><b>Name:</b>  <js>"XmlParser.validating.b"</js>
 	 * 	<li><b>Data type:</b>  <code>Boolean</code>
 	 * 	<li><b>Default:</b>  <jk>false</jk>
-	 * 	<li><b>Session-overridable:</b>  <jk>true</jk>
+	 * 	<li><b>Session-overridable:</b>  <jk>false</jk>
 	 * 	<li><b>Methods:</b>
 	 * 		<ul>
 	 * 			<li class='jm'>{@link XmlParserBuilder#validating(boolean)}
@@ -190,12 +190,12 @@ public class XmlParser extends ReaderParser {
 	// Instance
 	//-------------------------------------------------------------------------------------------------------------------
 
-	final boolean
+	private final boolean
 		validating,
 		preserveRootElement;
-	final XMLReporter reporter;
-	final XMLResolver resolver;
-	final XMLEventAllocator eventAllocator;
+	private final XMLReporter reporter;
+	private final XMLResolver resolver;
+	private final XMLEventAllocator eventAllocator;
 
 	/**
 	 * Constructor.
@@ -250,6 +250,66 @@ public class XmlParser extends ReaderParser {
 		return new XmlParserSession(this, args);
 	}
 
+	//-----------------------------------------------------------------------------------------------------------------
+	// Properties
+	//-----------------------------------------------------------------------------------------------------------------
+
+	/**
+	 * Configuration property:  Enable validation.
+	 *
+	 * @see #XML_validating
+	 * @return
+	 * 	<jk>true</jk> if XML document will be validated.
+	 */
+	public final boolean isValidating() {
+		return validating;
+	}
+
+	/**
+	 * Configuration property:  Preserve root element during generalized parsing.
+	 *
+	 * @see #XML_preserveRootElement
+	 * @return
+	 * 	<jk>true</jk> if when parsing into a generic {@link ObjectMap}, the map
will contain a single entry whose key
+	 * 	is the root element name.
+	 */
+	public final boolean isPreserveRootElement() {
+		return preserveRootElement;
+	}
+
+	/**
+	 * Configuration property:  XML reporter.
+	 *
+	 * @see #XML_reporter
+	 * @return
+	 * 	The {@link XMLReporter} associated with this parser, or <jk>null</jk> if
there isn't one.
+	 */
+	public final XMLReporter getReporter() {
+		return reporter;
+	}
+
+	/**
+	 * Configuration property:  XML resolver.
+	 *
+	 * @see #XML_resolver
+	 * @return
+	 * 	The {@link XMLResolver} associated with this parser, or <jk>null</jk> if
there isn't one.
+	 */
+	public final XMLResolver getResolver() {
+		return resolver;
+	}
+
+	/**
+	 * Configuration property:  XML event allocator.
+	 *
+	 * @see #XML_eventAllocator
+	 * @return
+	 * 	The {@link XMLEventAllocator} associated with this parser, or <jk>null</jk>
if there isn't one.
+	 */
+	public final XMLEventAllocator getEventAllocator() {
+		return eventAllocator;
+	}
+
 	@Override /* Context */
 	public ObjectMap asMap() {
 		return super.asMap()
diff --git a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/xml/XmlParserSession.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/xml/XmlParserSession.java
index 37a3b8d..4f112a6 100644
--- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/xml/XmlParserSession.java
+++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/xml/XmlParserSession.java
@@ -40,12 +40,7 @@ public class XmlParserSession extends ReaderParserSession {
 
 	private static final int UNKNOWN=0, OBJECT=1, ARRAY=2, STRING=3, NUMBER=4, BOOLEAN=5, NULL=6;
 
-	private final boolean
-		validating,
-		preserveRootElement;
-	private final XMLReporter reporter;
-	private final XMLResolver resolver;
-	private final XMLEventAllocator eventAllocator;
+	private final XmlParser ctx;
 	private final StringBuilder rsb = new StringBuilder();  // Reusable string builder used
in this class.
 
 	/**
@@ -59,22 +54,13 @@ public class XmlParserSession extends ReaderParserSession {
 	 */
 	protected XmlParserSession(XmlParser ctx, ParserSessionArgs args) {
 		super(ctx, args);
-		validating = getProperty(XML_validating, boolean.class, ctx.validating);
-		reporter = getInstanceProperty(XML_reporter, XMLReporter.class, ctx.reporter);
-		resolver = getInstanceProperty(XML_resolver, XMLResolver.class, ctx.resolver);
-		eventAllocator = getInstanceProperty(XML_eventAllocator, XMLEventAllocator.class, ctx.eventAllocator);
-		preserveRootElement = getProperty(XML_preserveRootElement, boolean.class, ctx.preserveRootElement);
+		this.ctx = ctx;
 	}
 
 	@Override /* Session */
 	public ObjectMap asMap() {
 		return super.asMap()
 			.append("XmlParser", new ObjectMap()
-				.append("eventAllocator", eventAllocator)
-				.append("preserveRootElement", preserveRootElement)
-				.append("reporter", reporter)
-				.append("resolver", resolver)
-				.append("validating", validating)
 			);
 	}
 
@@ -86,7 +72,7 @@ public class XmlParserSession extends ReaderParserSession {
 	 * @throws Exception If problem occurred trying to create reader.
 	 */
 	protected final XmlReader getXmlReader(ParserPipe pipe) throws Exception {
-		return new XmlReader(pipe, validating, reporter, resolver, eventAllocator);
+		return new XmlReader(pipe, ctx.isValidating(), ctx.getReporter(), ctx.getResolver(), ctx.getEventAllocator());
 	}
 
 	/**
@@ -296,7 +282,7 @@ public class XmlParserSession extends ReaderParserSession {
 			sType = eType;
 		setCurrentClass(sType);
 
-		String wrapperAttr = (isRoot && preserveRootElement) ? r.getName().getLocalPart()
: null;
+		String wrapperAttr = (isRoot && ctx.isPreserveRootElement()) ? r.getName().getLocalPart()
: null;
 		String typeAttr = r.getAttributeValue(null, getBeanTypePropertyName(eType));
 		int jsonType = getJsonType(typeAttr);
 		String elementName = getElementName(r);


Mime
View raw message