You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@juneau.apache.org by ja...@apache.org on 2018/07/08 16:15:12 UTC

[juneau] branch master updated: Make fields in Parser private.

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 8921baf  Make fields in Parser private.
8921baf is described below

commit 8921baf10302106f278cbf08e06b2ff7d84b930b
Author: JamesBognar <ja...@apache.org>
AuthorDate: Sun Jul 8 12:14:59 2018 -0400

    Make fields in Parser private.
---
 .../main/java/org/apache/juneau/BeanContext.java   |   1 +
 .../main/java/org/apache/juneau/BeanSession.java   | 122 +++++++++++----------
 .../juneau/parser/InputStreamParserSession.java    |   5 +-
 .../main/java/org/apache/juneau/parser/Parser.java |  86 +++++++++++++--
 .../org/apache/juneau/parser/ParserSession.java    |  45 ++++----
 .../apache/juneau/parser/ReaderParserSession.java  |   5 +-
 6 files changed, 174 insertions(+), 90 deletions(-)

diff --git a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanContext.java b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanContext.java
index 682230e..8f520ba 100644
--- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanContext.java
+++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanContext.java
@@ -2923,6 +2923,7 @@ public class BeanContext extends Context {
 	 * @see #BEAN_ignoreUnknownBeanProperties
 	 * @return
 	 * 	<jk>true</jk> if trying to set a value on a non-existent bean property is silently ignored.
+	 * 	<br>Otherwise, a {@code RuntimeException} is thrown.
 	 */
 	public final boolean isIgnoreUnknownBeanProperties() {
 		return ignoreUnknownBeanProperties;
diff --git a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanSession.java b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanSession.java
index 7ce14ea..0e81a4d 100644
--- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanSession.java
+++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanSession.java
@@ -77,61 +77,6 @@ public class BeanSession extends Session {
 	}
 
 	/**
-	 * Returns the locale defined on this session.
-	 *
-	 * <p>
-	 * The locale is determined in the following order:
-	 * <ol>
-	 * 	<li><code>locale</code> parameter passed in through constructor.
-	 * 	<li>{@link BeanContext#BEAN_locale} entry in parameter passed in through constructor.
-	 * 	<li>{@link BeanContext#BEAN_locale} setting on bean context.
-	 * 	<li>Locale returned by {@link Locale#getDefault()}.
-	 * </ol>
-	 *
-	 * @return The session locale.
-	 */
-	public final Locale getLocale() {
-		return locale;
-	}
-
-	/**
-	 * Returns the timezone defined on this session.
-	 *
-	 * <p>
-	 * The timezone is determined in the following order:
-	 * <ol>
-	 * 	<li><code>timeZone</code> parameter passed in through constructor.
-	 * 	<li>{@link BeanContext#BEAN_timeZone} entry in parameter passed in through constructor.
-	 * 	<li>{@link BeanContext#BEAN_timeZone} setting on bean context.
-	 * </ol>
-	 *
-	 * @return The session timezone, or <jk>null</jk> if timezone not specified.
-	 */
-	public final TimeZone getTimeZone() {
-		return timeZone;
-	}
-
-	/**
-	 * Returns the {@link BeanContext#BEAN_debug} setting value for this session.
-	 *
-	 * @return The {@link BeanContext#BEAN_debug} setting value for this session.
-	 */
-	public final boolean isDebug() {
-		return debug;
-	}
-
-	/**
-	 * Bean property getter:  <property>ignoreUnknownBeanProperties</property>.
-	 *
-	 * <p>
-	 * See {@link BeanContext#BEAN_ignoreUnknownBeanProperties}.
-	 *
-	 * @return The value of the <property>ignoreUnknownBeanProperties</property> property on this bean.
-	 */
-	public final boolean isIgnoreUnknownBeanProperties() {
-		return ctx.isIgnoreUnknownBeanProperties();
-	}
-
 	/**
 	 * Converts the specified value to the specified class type.
 	 *
@@ -1231,12 +1176,77 @@ public class BeanSession extends Session {
 		return ctx._class();
 	}
 
+	//-----------------------------------------------------------------------------------------------------------------
+	// Properties
+	//-----------------------------------------------------------------------------------------------------------------
+
+	/**
+	 * Configuration property:  Ignore unknown properties.
+	 *
+	 * @see #BEAN_ignoreUnknownBeanProperties
+	 * @return
+	 * 	<jk>true</jk> if trying to set a value on a non-existent bean property is silently ignored.
+	 * 	<br>Otherwise, a {@code RuntimeException} is thrown.
+	 */
+	public final boolean isIgnoreUnknownBeanProperties() {
+		return ctx.isIgnoreUnknownBeanProperties();
+	}
+
+	/**
+	 * Configuration property:  Debug mode.
+	 *
+	 * @see #BEAN_debug
+	 * @return
+	 * 	<jk>true</jk> if debug mode is enabled.
+	 */
+	public final boolean isDebug() {
+		return debug;
+	}
+
+	/**
+	 * Configuration property:  Locale.
+	 *
+	 * <p>
+	 * The locale is determined in the following order:
+	 * <ol>
+	 * 	<li><code>locale</code> parameter passed in through constructor.
+	 * 	<li>{@link BeanContext#BEAN_locale} entry in parameter passed in through constructor.
+	 * 	<li>{@link BeanContext#BEAN_locale} setting on bean context.
+	 * 	<li>Locale returned by {@link Locale#getDefault()}.
+	 * </ol>
+	 *
+	 * @see #BEAN_locale
+	 * @return The session locale.
+	 */
+	public final Locale getLocale() {
+		return locale;
+	}
+
+	/**
+	 * Configuration property:  Time zone.
+	 *
+	 * <p>
+	 * The timezone is determined in the following order:
+	 * <ol>
+	 * 	<li><code>timeZone</code> parameter passed in through constructor.
+	 * 	<li>{@link BeanContext#BEAN_timeZone} entry in parameter passed in through constructor.
+	 * 	<li>{@link BeanContext#BEAN_timeZone} setting on bean context.
+	 * </ol>
+	 *
+	 * @see #BEAN_timeZone
+	 * @return The session timezone, or <jk>null</jk> if timezone not specified.
+	 */
+	public final TimeZone getTimeZone() {
+		return timeZone;
+	}
+
 	/**
-	 * Returns the media type specified for this session.
+	 * Configuration property:  Media type.
 	 *
 	 * <p>
 	 * For example, <js>"application/json"</js>.
 	 *
+	 * @see #BEAN_mediaType
 	 * @return The media type for this session, or <jk>null</jk> if not specified.
 	 */
 	public final MediaType getMediaType() {
diff --git a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/parser/InputStreamParserSession.java b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/parser/InputStreamParserSession.java
index 00a5872..d83fc31 100644
--- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/parser/InputStreamParserSession.java
+++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/parser/InputStreamParserSession.java
@@ -26,6 +26,7 @@ import org.apache.juneau.*;
  */
 public abstract class InputStreamParserSession extends ParserSession {
 
+	private final InputStreamParser ctx;
 	private final BinaryFormat binaryFormat;
 
 	/**
@@ -39,7 +40,7 @@ public abstract class InputStreamParserSession extends ParserSession {
 	 */
 	protected InputStreamParserSession(InputStreamParser ctx, ParserSessionArgs args) {
 		super(ctx, args);
-
+		this.ctx = ctx;
 		binaryFormat = getProperty(ISPARSER_binaryFormat, BinaryFormat.class, BinaryFormat.HEX);
 	}
 
@@ -79,7 +80,7 @@ public abstract class InputStreamParserSession extends ParserSession {
 	@SuppressWarnings("resource")
 	@Override /* ParserSession */
 	public final ParserPipe createPipe(Object input) {
-		return setPipe(new ParserPipe(input, isDebug(), autoCloseStreams, unbuffered, binaryFormat));
+		return setPipe(new ParserPipe(input, isDebug(), ctx.isAutoCloseStreams(), ctx.isUnbuffered(), binaryFormat));
 	}
 
 	@Override /* Session */
diff --git a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/parser/Parser.java b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/parser/Parser.java
index 517de01..9a4875b 100644
--- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/parser/Parser.java
+++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/parser/Parser.java
@@ -132,7 +132,7 @@ public abstract class Parser extends BeanContext {
 	 * 	<li><b>Name:</b>  <js>"Parser.autoCloseStreams.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 ParserBuilder#autoCloseStreams(boolean)}
@@ -284,7 +284,7 @@ public abstract class Parser extends BeanContext {
 	 * 	<li><b>Name:</b>  <js>"Parser.strict.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 ParserBuilder#strict(boolean)}
@@ -357,7 +357,7 @@ public abstract class Parser extends BeanContext {
 	 * 	<li><b>Name:</b>  <js>"Parser.trimStrings.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 ParserBuilder#trimStrings(boolean)}
@@ -400,7 +400,7 @@ public abstract class Parser extends BeanContext {
 	 * 	<li><b>Name:</b>  <js>"Parser.unbuffered.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 ParserBuilder#unbuffered(boolean)}
@@ -472,9 +472,9 @@ public abstract class Parser extends BeanContext {
 	// Instance
 	//-------------------------------------------------------------------------------------------------------------------
 
-	final boolean trimStrings, strict, autoCloseStreams, unbuffered;
-	final int debugOutputLines;
-	final Class<? extends ParserListener> listener;
+	private final boolean trimStrings, strict, autoCloseStreams, unbuffered;
+	private final int debugOutputLines;
+	private final Class<? extends ParserListener> listener;
 
 	/** General parser properties currently set on this parser. */
 	private final MediaType[] consumes;
@@ -831,4 +831,76 @@ public abstract class Parser extends BeanContext {
 					return true;
 		return false;
 	}
+
+	//-----------------------------------------------------------------------------------------------------------------
+	// Properties
+	//-----------------------------------------------------------------------------------------------------------------
+
+	/**
+	 * Configuration property:  Trim parsed strings.
+	 *
+	 * @see #PARSER_trimStrings
+	 * @return
+	 * 	<jk>true</jk> if string values will be trimmed of whitespace using {@link String#trim()} before being added to
+	 * 	the POJO.
+	 */
+	public final boolean isTrimStrings() {
+		return trimStrings;
+	}
+
+	/**
+	 * Configuration property:  Strict mode.
+	 *
+	 * @see #PARSER_strict
+	 * @return
+	 * 	<jk>true</jk> if strict mode for the parser is enabled.
+	 */
+	public final boolean isStrict() {
+		return strict;
+	}
+
+	/**
+	 * Configuration property:  Auto-close streams.
+	 *
+	 * @see #PARSER_autoCloseStreams
+	 * @return
+	 * 	<jk>true</jk> if <l>InputStreams</l> and <l>Readers</l> passed into parsers will be closed
+	 * 	after parsing is complete.
+	 */
+	public final boolean isAutoCloseStreams() {
+		return autoCloseStreams;
+	}
+
+	/**
+	 * Configuration property:  Unbuffered.
+	 *
+	 * @see #PARSER_unbuffered
+	 * @return
+	 * 	<jk>true</jk> if parsers don't use internal buffering during parsing.
+	 */
+	public final boolean isUnbuffered() {
+		return unbuffered;
+	}
+
+	/**
+	 * Configuration property:  Debug output lines.
+	 *
+	 * @see #PARSER_debugOutputLines
+	 * @return
+	 * 	The number of lines of input before and after the error location to be printed as part of the exception message.
+	 */
+	public final int isDebugOutputLines() {
+		return debugOutputLines;
+	}
+
+	/**
+	 * Configuration property:  Parser listener.
+	 *
+	 * @see #PARSER_listener
+	 * @return
+	 * 	Class used to listen for errors and warnings that occur during parsing.
+	 */
+	public final Class<? extends ParserListener> getListenerClass() {
+		return listener;
+	}
 }
diff --git a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/parser/ParserSession.java b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/parser/ParserSession.java
index 8a88f59..42765fe 100644
--- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/parser/ParserSession.java
+++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/parser/ParserSession.java
@@ -33,8 +33,7 @@ import org.apache.juneau.utils.*;
  */
 public abstract class ParserSession extends BeanSession {
 
-	final boolean trimStrings, strict, autoCloseStreams, unbuffered;
-	final int debugOutputLines;
+	private final Parser ctx;
 	private final Method javaMethod;
 	private final Object outer;
 
@@ -58,14 +57,10 @@ public abstract class ParserSession extends BeanSession {
 	 */
 	protected ParserSession(Parser ctx, ParserSessionArgs args) {
 		super(ctx, args);
-		trimStrings = getProperty(PARSER_trimStrings, boolean.class, ctx.trimStrings);
-		strict = getProperty(PARSER_strict, boolean.class, ctx.strict);
-		autoCloseStreams = getProperty(PARSER_autoCloseStreams, boolean.class, ctx.autoCloseStreams);
-		debugOutputLines = getProperty(PARSER_debugOutputLines, int.class, ctx.debugOutputLines);
-		unbuffered = getProperty(PARSER_unbuffered, boolean.class, ctx.unbuffered);
+		this.ctx = ctx;
 		javaMethod = args.javaMethod;
 		outer = args.outer;
-		listener = getInstanceProperty(PARSER_listener, ParserListener.class, ctx.listener);
+		listener = getInstanceProperty(PARSER_listener, ParserListener.class, ctx.getListenerClass());
 	}
 
 	/**
@@ -85,8 +80,6 @@ public abstract class ParserSession extends BeanSession {
 				.append("javaMethod", javaMethod)
 				.append("listener", listener)
 				.append("outer", outer)
-				.append("strict", strict)
-				.append("trimStrings", trimStrings)
 			);
 	}
 
@@ -215,7 +208,7 @@ public abstract class ParserSession extends BeanSession {
 	 * @return The {@link Parser#PARSER_trimStrings} setting value for this session.
 	 */
 	protected final boolean isTrimStrings() {
-		return trimStrings;
+		return ctx.isTrimStrings();
 	}
 
 	/**
@@ -224,7 +217,7 @@ public abstract class ParserSession extends BeanSession {
 	 * @return The {@link Parser#PARSER_strict} setting value for this session.
 	 */
 	protected final boolean isStrict() {
-		return strict;
+		return ctx.isStrict();
 	}
 
 	/**
@@ -235,7 +228,7 @@ public abstract class ParserSession extends BeanSession {
 	 */
 	@SuppressWarnings("unchecked")
 	protected final <K> K trim(K o) {
-		if (trimStrings && o instanceof String)
+		if (ctx.isTrimStrings() && o instanceof String)
 			return (K)o.toString().trim();
 		return o;
 
@@ -248,7 +241,7 @@ public abstract class ParserSession extends BeanSession {
 	 * @return The trimmed string, or <jk>null</jk> if the input was <jk>null</jk>.
 	 */
 	protected final String trim(String s) {
-		if (trimStrings && s != null)
+		if (isTrimStrings() && s != null)
 			return s.trim();
 		return s;
 	}
@@ -766,15 +759,6 @@ public abstract class ParserSession extends BeanSession {
 	}
 
 	/**
-	 * Returns the number of lines to include in exception messages before and after the error location in the input.
-	 *
-	 * @return The number of lines before and after the error.
-	 */
-	public int getDebugOutputLines() {
-		return debugOutputLines;
-	}
-
-	/**
 	 * The {@link #createPipe(Object)} method should call this method to set the pipe for debugging purposes.
 	 *
 	 * @param pipe The pipe created for this session.
@@ -834,4 +818,19 @@ public abstract class ParserSession extends BeanSession {
 	public String getInputAsString() {
 		return pipe == null ? null : pipe.getInputAsString();
 	}
+
+	//-----------------------------------------------------------------------------------------------------------------
+	// Properties
+	//-----------------------------------------------------------------------------------------------------------------
+
+	/**
+	 * Configuration property:  Debug output lines.
+	 *
+	 * @see #PARSER_debugOutputLines
+	 * @return
+	 * 	The number of lines of input before and after the error location to be printed as part of the exception message.
+	 */
+	public final int getDebugOutputLines() {
+		return ctx.isDebugOutputLines();
+	}
 }
diff --git a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/parser/ReaderParserSession.java b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/parser/ReaderParserSession.java
index d86d216..626eb10 100644
--- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/parser/ReaderParserSession.java
+++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/parser/ReaderParserSession.java
@@ -26,6 +26,7 @@ import org.apache.juneau.*;
  */
 public abstract class ReaderParserSession extends ParserSession {
 
+	private final ReaderParser ctx;
 	private final String inputStreamCharset, fileCharset;
 
 	/**
@@ -39,7 +40,7 @@ public abstract class ReaderParserSession extends ParserSession {
 	 */
 	protected ReaderParserSession(ReaderParser ctx, ParserSessionArgs args) {
 		super(ctx, args);
-
+		this.ctx = ctx;
 		inputStreamCharset = getProperty(RPARSER_inputStreamCharset, String.class, ctx.inputStreamCharset);
 		fileCharset = getProperty(RPARSER_fileCharset, String.class, ctx.fileCharset);
 	}
@@ -84,7 +85,7 @@ public abstract class ReaderParserSession extends ParserSession {
 	@SuppressWarnings("resource")
 	@Override /* ParserSesson */
 	public final ParserPipe createPipe(Object input) {
-		return setPipe(new ParserPipe(input, isDebug(), strict, autoCloseStreams, unbuffered, fileCharset, inputStreamCharset));
+		return setPipe(new ParserPipe(input, isDebug(), ctx.isStrict(), ctx.isAutoCloseStreams(), ctx.isUnbuffered(), fileCharset, inputStreamCharset));
 	}
 
 	@Override /* Session */