-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added suppressing adapters to leave default values out of XML
- Loading branch information
Showing
3 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
src/main/java/de/rub/nds/modifiablevariable/util/SuppressingBooleanAdapter.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,33 @@ | ||
/* | ||
* ModifiableVariable - A Variable Concept for Runtime Modifications | ||
* | ||
* Ruhr University Bochum, Paderborn University, Technology Innovation Institute, and Hackmanit GmbH | ||
* | ||
* Licensed under Apache License 2.0 http://www.apache.org/licenses/LICENSE-2.0 | ||
*/ | ||
package de.rub.nds.modifiablevariable.util; | ||
|
||
import jakarta.xml.bind.annotation.adapters.XmlAdapter; | ||
import java.util.Objects; | ||
|
||
public abstract class SuppressingBooleanAdapter extends XmlAdapter<String, Boolean> { | ||
|
||
public abstract Boolean getValueToSuppress(); | ||
|
||
@Override | ||
public Boolean unmarshal(String v) throws Exception { | ||
if (v == null) { | ||
return getValueToSuppress(); | ||
} else { | ||
return Boolean.parseBoolean(v); | ||
} | ||
} | ||
|
||
@Override | ||
public String marshal(Boolean v) throws Exception { | ||
if (Objects.equals(v, getValueToSuppress()) || v == null) { | ||
return null; | ||
} | ||
return v.toString(); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/de/rub/nds/modifiablevariable/util/SuppressingFalseBooleanAdapter.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,16 @@ | ||
/* | ||
* ModifiableVariable - A Variable Concept for Runtime Modifications | ||
* | ||
* Ruhr University Bochum, Paderborn University, Technology Innovation Institute, and Hackmanit GmbH | ||
* | ||
* Licensed under Apache License 2.0 http://www.apache.org/licenses/LICENSE-2.0 | ||
*/ | ||
package de.rub.nds.modifiablevariable.util; | ||
|
||
public class SuppressingFalseBooleanAdapter extends SuppressingBooleanAdapter { | ||
|
||
@Override | ||
public Boolean getValueToSuppress() { | ||
return Boolean.FALSE; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/de/rub/nds/modifiablevariable/util/SuppressingTrueBooleanAdapter.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,15 @@ | ||
/* | ||
* ModifiableVariable - A Variable Concept for Runtime Modifications | ||
* | ||
* Ruhr University Bochum, Paderborn University, Technology Innovation Institute, and Hackmanit GmbH | ||
* | ||
* Licensed under Apache License 2.0 http://www.apache.org/licenses/LICENSE-2.0 | ||
*/ | ||
package de.rub.nds.modifiablevariable.util; | ||
|
||
public class SuppressingTrueBooleanAdapter extends SuppressingBooleanAdapter { | ||
@Override | ||
public Boolean getValueToSuppress() { | ||
return Boolean.TRUE; | ||
} | ||
} |