New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
61 input location #62
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,7 +37,16 @@ public class Xpp3DomBuilder | |
public static Xpp3Dom build( Reader reader ) | ||
throws XmlPullParserException, IOException | ||
{ | ||
return build( reader, DEFAULT_TRIM ); | ||
return build( reader, null ); | ||
} | ||
|
||
/** | ||
* @since 3.2.0 | ||
*/ | ||
public static Xpp3Dom build( Reader reader, InputLocationBuilder locationBuilder ) | ||
throws XmlPullParserException, IOException | ||
{ | ||
return build( reader, DEFAULT_TRIM, locationBuilder ); | ||
} | ||
|
||
public static Xpp3Dom build( InputStream is, String encoding ) | ||
|
@@ -68,13 +77,22 @@ public static Xpp3Dom build( InputStream is, String encoding, boolean trim ) | |
|
||
public static Xpp3Dom build( Reader reader, boolean trim ) | ||
throws XmlPullParserException, IOException | ||
{ | ||
return build( reader, trim, null ); | ||
} | ||
|
||
/** | ||
* @since 3.2.0 | ||
*/ | ||
public static Xpp3Dom build( Reader reader, boolean trim, InputLocationBuilder locationBuilder ) | ||
throws XmlPullParserException, IOException | ||
{ | ||
try | ||
{ | ||
final XmlPullParser parser = new MXParser(); | ||
parser.setInput( reader ); | ||
|
||
final Xpp3Dom xpp3Dom = build( parser, trim ); | ||
final Xpp3Dom xpp3Dom = build( parser, trim, locationBuilder ); | ||
reader.close(); | ||
reader = null; | ||
|
||
|
@@ -94,6 +112,15 @@ public static Xpp3Dom build( XmlPullParser parser ) | |
|
||
public static Xpp3Dom build( XmlPullParser parser, boolean trim ) | ||
throws XmlPullParserException, IOException | ||
{ | ||
return build( parser, trim, null ); | ||
} | ||
|
||
/** | ||
* @since 3.2.0 | ||
*/ | ||
public static Xpp3Dom build( XmlPullParser parser, boolean trim, InputLocationBuilder locationBuilder ) | ||
throws XmlPullParserException, IOException | ||
{ | ||
List<Xpp3Dom> elements = new ArrayList<Xpp3Dom>(); | ||
|
||
|
@@ -113,6 +140,11 @@ public static Xpp3Dom build( XmlPullParser parser, boolean trim ) | |
|
||
Xpp3Dom childConfiguration = new Xpp3Dom( rawName ); | ||
|
||
if ( locationBuilder != null ) | ||
{ | ||
childConfiguration.setInputLocation( locationBuilder.toInputLocation( parser ) ); | ||
} | ||
|
||
int depth = elements.size(); | ||
|
||
if ( depth > 0 ) | ||
|
@@ -194,4 +226,14 @@ else if ( eventType == XmlPullParser.END_TAG ) | |
|
||
throw new IllegalStateException( "End of document found before returning to 0 depth" ); | ||
} | ||
|
||
/** | ||
* Input location builder interface, to be implemented to choose how to store data. | ||
* | ||
* @since 3.2.0 | ||
*/ | ||
public static interface InputLocationBuilder | ||
{ | ||
Object toInputLocation( XmlPullParser parser ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about 'getCurrentInputLocation'? Should we explicitly state the expected behavior? Is it better to return an GenericInputLocation, just as a placeholder interface? It will make code more typesafe and clearer IMHO There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'getCurrentInputLocation': since it is expected to create an object, I don't like 'get' What do you mean by "state the expected behavior"? Since the implementation is really something that will be specific to the user, and that the user will have to cast, I don't see the benefit of creating an empty interface There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
My concern is that the function takes a stateful object as parameter, so I image it will return a view of the current state of the parser.
For instance, if the method is called twice is it expected to return two equivalent objects, the same object, or what ?
should b == a, b.quals(a) or it is not important ?
Fine There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for input location, ordering is not important: really, the documentation to read is https://codehaus-plexus.github.io/modello/location-tracking.html |
||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thinking out loud: Can we add a generic to Xpp3Dom, like
Xpp3Dom<T>
, whereT
reflects the inputLocation?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose it is feasible: IMHO, gives too much visibility to input location tracking, which is really something very special, but feasible