-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into dependabot/maven/impl/snakeyaml/org.yaml-s…
…nakeyaml-2.0
- Loading branch information
Showing
28 changed files
with
449 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
core/src/main/java/io/github/mmm/marshall/AbstractStructuredProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* Copyright (c) The m-m-m Team, Licensed under the Apache License, Version 2.0 | ||
* http://www.apache.org/licenses/LICENSE-2.0 */ | ||
package io.github.mmm.marshall; | ||
|
||
/** | ||
* Abstract base implementation of {@link StructuredReader}. | ||
*/ | ||
public abstract class AbstractStructuredProcessor implements StructuredProcessor { | ||
|
||
private final StructuredFormat format; | ||
|
||
/** The {@link MarshallingConfig}. */ | ||
protected final MarshallingConfig config; | ||
|
||
/** @see MarshallingConfig#OPT_ENUM_FORMAT */ | ||
protected final EnumFormat enumFormat; | ||
|
||
/** | ||
* The constructor. | ||
* | ||
* @param format the {@link #getFormat() format}. | ||
*/ | ||
public AbstractStructuredProcessor(StructuredFormat format) { | ||
|
||
super(); | ||
this.format = format; | ||
this.config = format.getConfig(); | ||
this.enumFormat = this.config.get(MarshallingConfig.OPT_ENUM_FORMAT); | ||
} | ||
|
||
@Override | ||
public StructuredFormat getFormat() { | ||
|
||
return this.format; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
core/src/main/java/io/github/mmm/marshall/AbstractStructuredScannerReader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* Copyright (c) The m-m-m Team, Licensed under the Apache License, Version 2.0 | ||
* http://www.apache.org/licenses/LICENSE-2.0 */ | ||
package io.github.mmm.marshall; | ||
|
||
import io.github.mmm.scanner.CharStreamScanner; | ||
|
||
/** | ||
* {@link AbstractStructuredReader} that {@link #readValue() reads values} as {@link Object}. | ||
*/ | ||
@SuppressWarnings("exports") | ||
public abstract class AbstractStructuredScannerReader extends AbstractStructuredValueReader { | ||
|
||
/** The {@link CharStreamScanner} to read from. */ | ||
protected final CharStreamScanner reader; | ||
|
||
/** | ||
* The constructor. | ||
* | ||
* @param scanner the {@link CharStreamScanner} to read from. | ||
* @param format the {@link #getFormat() format}. | ||
*/ | ||
public AbstractStructuredScannerReader(CharStreamScanner scanner, StructuredFormat format) { | ||
|
||
super(format); | ||
this.reader = scanner; | ||
} | ||
|
||
@Override | ||
protected String appendContextDetails(String message) { | ||
|
||
StringBuilder sb = new StringBuilder(message); | ||
sb.append('('); | ||
if (this.name != null) { | ||
sb.append("at property '"); | ||
sb.append(this.name); | ||
sb.append("' "); | ||
} | ||
sb.append("in line "); | ||
sb.append(this.reader.getLine()); | ||
sb.append(" and column "); | ||
sb.append(this.reader.getColumn()); | ||
sb.append(')'); | ||
return sb.toString(); | ||
} | ||
|
||
@Override | ||
public void close() { | ||
|
||
this.reader.close(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* Copyright (c) The m-m-m Team, Licensed under the Apache License, Version 2.0 | ||
* http://www.apache.org/licenses/LICENSE-2.0 */ | ||
package io.github.mmm.marshall; | ||
|
||
import io.github.mmm.base.text.CaseHelper; | ||
import io.github.mmm.base.text.CaseSyntax; | ||
|
||
/** | ||
* {@link Enum} with the available formats how to serialize an {@link Enum}. | ||
*/ | ||
public enum EnumFormat { | ||
|
||
/** Write {@link Enum} as {@link Enum#ordinal() ordinal}. */ | ||
ORDINAL, | ||
|
||
/** Write {@link Enum} as {@link Enum#name() name}. */ | ||
NAME, | ||
|
||
/** Write {@link Enum} as {@link Enum#toString() toString representation}. */ | ||
TO_STRING, | ||
|
||
/** Like {@link #TO_STRING} but in {@link CaseHelper#toLowerCase(String) lowercase}. */ | ||
TO_STRING_LOWER_CASE, | ||
|
||
/** Like {@link #TO_STRING} but in {@link CaseSyntax#TRAIN_CASE train-case}. */ | ||
TO_STRING_TRAIN_CASE; | ||
|
||
/** | ||
* @param e the {@link Enum} value. | ||
* @return the corresponding {@link String} representation according to this format. | ||
*/ | ||
public String toString(Enum<?> e) { | ||
|
||
if (e == null) { | ||
return null; | ||
} | ||
switch (this) { | ||
case ORDINAL: | ||
return null; | ||
case NAME: | ||
return e.name(); | ||
case TO_STRING: | ||
return e.toString(); | ||
case TO_STRING_LOWER_CASE: | ||
return CaseHelper.toLowerCase(e.toString()); | ||
case TO_STRING_TRAIN_CASE: | ||
return CaseSyntax.TRAIN_CASE.convert(e.toString()); | ||
} | ||
return null; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
core/src/main/java/io/github/mmm/marshall/StructuredProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* Copyright (c) The m-m-m Team, Licensed under the Apache License, Version 2.0 | ||
* http://www.apache.org/licenses/LICENSE-2.0 */ | ||
package io.github.mmm.marshall; | ||
|
||
/** | ||
* Base interface for {@link StructuredReader} and {@link StructuredWriter}. | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
public abstract interface StructuredProcessor extends AutoCloseable { | ||
|
||
@Override | ||
void close(); | ||
|
||
/** | ||
* @return the owning {@link StructuredFormat} that {@link StructuredFormat#reader(java.io.InputStream) created} this | ||
* writer. | ||
*/ | ||
StructuredFormat getFormat(); | ||
|
||
} |
Oops, something went wrong.