Skip to content
Browse files

Split ConfigIncludeContext from Parseable out into its own file

  • Loading branch information...
1 parent 8c6b204 commit 5e7b929b656452284bfc7b94dd81154795c7e4a4 @havocp havocp committed Apr 8, 2012
View
8 config/src/main/java/com/typesafe/config/impl/Parseable.java
@@ -65,12 +65,7 @@ private ConfigParseOptions fixupOptions(ConfigParseOptions baseOptions) {
protected void postConstruct(ConfigParseOptions baseOptions) {
this.initialOptions = fixupOptions(baseOptions);
- this.includeContext = new ConfigIncludeContext() {
- @Override
- public ConfigParseable relativeTo(String filename) {
- return Parseable.this.relativeTo(filename);
- }
- };
+ this.includeContext = new SimpleIncludeContext(this);
if (initialOptions.getOriginDescription() != null)
initialOrigin = SimpleConfigOrigin.newSimple(initialOptions.getOriginDescription());
@@ -80,6 +75,7 @@ public ConfigParseable relativeTo(String filename) {
// the general idea is that any work should be in here, not in the
// constructor,
+
// so that exceptions are thrown from the public parse() function and not
// from the creation of the Parseable. Essentially this is a lazy field.
// The parser should close the reader when it's done with it.
View
32 config/src/main/java/com/typesafe/config/impl/SimpleIncludeContext.java
@@ -0,0 +1,32 @@
+/**
+ * Copyright (C) 2011-2012 Typesafe Inc. <http://typesafe.com>
+ */
+package com.typesafe.config.impl;
+
+import com.typesafe.config.ConfigIncludeContext;
+import com.typesafe.config.ConfigParseable;
+
+class SimpleIncludeContext implements ConfigIncludeContext {
+
+ private final Parseable parseable;
+
+ SimpleIncludeContext(Parseable parseable) {
+ this.parseable = parseable;
+ }
+
+ SimpleIncludeContext() {
+ this(null);
+ }
+
+ SimpleIncludeContext withParseable(Parseable parseable) {
+ return new SimpleIncludeContext(parseable);
+ }
+
+ @Override
+ public ConfigParseable relativeTo(String filename) {
+ if (parseable != null)
+ return parseable.relativeTo(filename);
+ else
+ return null;
+ }
+}

0 comments on commit 5e7b929

Please sign in to comment.
Something went wrong with that request. Please try again.