Fix code style for code generated by velocity templates (#1146)
diff --git a/src/mdo/merger.vm b/src/mdo/merger.vm
index 1126d21..3723878 100644
--- a/src/mdo/merger.vm
+++ b/src/mdo/merger.vm
@@ -51,8 +51,7 @@
#end
@Generated
-public class ${className}
-{
+public class ${className} {
private final boolean deepMerge;
@@ -76,19 +75,16 @@
* @param hints A set of key-value pairs that customized merger implementations can use to carry domain-specific
* information along, may be <code>null</code>.
*/
- public ${root.name} merge( ${root.name} target, ${root.name} source, boolean sourceDominant, Map<?, ?> hints )
- {
- Objects.requireNonNull( target, "target cannot be null" );
- if ( source == null )
- {
+ public ${root.name} merge(${root.name} target, ${root.name} source, boolean sourceDominant, Map<?, ?> hints) {
+ Objects.requireNonNull(target, "target cannot be null");
+ if (source == null) {
return target;
}
Map<Object, Object> context = new HashMap<>();
- if ( hints != null )
- {
- context.putAll( hints );
+ if (hints != null) {
+ context.putAll(hints);
}
- return merge${root.name}( target, source, sourceDominant, context );
+ return merge${root.name}(target, source, sourceDominant, context);
}
#foreach ( $class in $model.allClasses )
@@ -98,121 +94,101 @@
#foreach ( $cl in $ancestors )
#set ( $dummy = $allFields.addAll( $cl.getFields($version) ) )
#end
- protected ${class.name} merge${class.name}( ${class.name} target, ${class.name} source, boolean sourceDominant, Map<Object, Object> context )
- {
- ${class.name}.Builder builder = ${class.name}.newBuilder( target );
- merge${class.name}( builder, target, source, sourceDominant, context );
+ protected ${class.name} merge${class.name}(${class.name} target, ${class.name} source, boolean sourceDominant, Map<Object, Object> context) {
+ ${class.name}.Builder builder = ${class.name}.newBuilder(target);
+ merge${class.name}(builder, target, source, sourceDominant, context);
return builder.build();
}
- protected void merge${class.name}( ${class.name}.Builder builder, ${class.name} target, ${class.name} source, boolean sourceDominant, Map<Object, Object> context )
- {
+ protected void merge${class.name}(${class.name}.Builder builder, ${class.name} target, ${class.name} source, boolean sourceDominant, Map<Object, Object> context) {
#if ( $class.superClass )
- merge${class.superClass}( builder, target ,source, sourceDominant, context );
+ merge${class.superClass}(builder, target ,source, sourceDominant, context);
#end
#foreach ( $field in $class.getFields($version) )
- merge${field.modelClass.name}_${Helper.capitalise($field.name)}( builder, target, source, sourceDominant, context );
+ merge${field.modelClass.name}_${Helper.capitalise($field.name)}(builder, target, source, sourceDominant, context);
#end
}
#foreach ( $field in $allFields )
#set ( $capField = ${Helper.capitalise($field.name)} )
- protected void merge${class.name}_${capField}( ${class.name}.Builder builder, ${class.name} target, ${class.name} source, boolean sourceDominant, Map<Object, Object> context )
+ protected void merge${class.name}_${capField}(${class.name}.Builder builder, ${class.name} target, ${class.name} source, boolean sourceDominant, Map<Object, Object> context)
{
#if ( $field.type == "String" )
String src = source.get${capField}();
String tgt = target.get${capField}();
- if ( src != null && ( sourceDominant || tgt == null ) )
- {
- builder.${field.name}( src );
+ if (src != null && (sourceDominant || tgt == null)) {
+ builder.${field.name}(src);
#if ( $locationTracking )
- builder.location( "${field.name}", source.getLocation( "${field.name}" ) );
+ builder.location("${field.name}", source.getLocation("${field.name}"));
#end
}
#elseif ( $field.type == "java.util.List" && $field.to == "String" && $field.multiplicity == "*" )
- builder.${field.name}( merge( target.get${capField}(), source.get${capField}(), sourceDominant, e -> e ) );
+ builder.${field.name}(merge(target.get${capField}(), source.get${capField}(), sourceDominant, e -> e));
#elseif ( $field.type == "java.util.Properties" && $field.to == "String" && $field.multiplicity == "*" )
Map<String, String> src = source.get${capField}();
- if ( !src.isEmpty() )
- {
+ if (!src.isEmpty()) {
Map<String, String> tgt = target.get${capField}();
- if ( tgt.isEmpty() )
- {
- builder.${field.name}( src );
+ if (tgt.isEmpty()) {
+ builder.${field.name}(src);
#if ( $locationTracking )
- builder.location( "${field.name}", source.getLocation( "${field.name}" ) );
+ builder.location("${field.name}", source.getLocation("${field.name}"));
#end
- }
- else
- {
+ } else {
Map<String, String> merged = new HashMap<>();
- merged.putAll( sourceDominant ? target.get${capField}() : source.get${capField}() );
- merged.putAll( sourceDominant ? source.get${capField}() : target.get${capField}() );
- builder.${field.name}( merged );
+ merged.putAll(sourceDominant ? target.get${capField}() : source.get${capField}());
+ merged.putAll(sourceDominant ? source.get${capField}() : target.get${capField}());
+ builder.${field.name}(merged);
#if ( $locationTracking )
- builder.location( "${field.name}", InputLocation.merge( target.getLocation( "${field.name}" ), source.getLocation( "${field.name}" ), sourceDominant ) );
+ builder.location("${field.name}", InputLocation.merge(target.getLocation("${field.name}"), source.getLocation("${field.name}"), sourceDominant));
#end
}
}
#elseif ( $field.to && $field.multiplicity == "1" )
${field.to} src = source.get${capField}();
- if ( src != null )
- {
+ if (src != null) {
${field.to} tgt = target.get${capField}();
- if ( tgt == null )
- {
- tgt = ${field.to}.newInstance( false );
+ if (tgt == null) {
+ tgt = ${field.to}.newInstance(false);
}
- ${field.to} merged = merge${field.to}( tgt, src, sourceDominant, context );
- if ( merged == src )
- {
- builder.${field.name}( merged );
+ ${field.to} merged = merge${field.to}(tgt, src, sourceDominant, context);
+ if (merged == src) {
+ builder.${field.name}(merged);
#if ( $locationTracking )
- builder.location( "${field.name}", source.getLocation( "${field.name}" ) );
+ builder.location("${field.name}", source.getLocation("${field.name}"));
#end
- }
- else if ( merged != tgt )
- {
- builder.${field.name}( merged );
+ } else if (merged != tgt) {
+ builder.${field.name}(merged);
#if ( $locationTracking )
- builder.location( "${field.name}", InputLocation.merge( target.getLocation( "${field.name}" ), source.getLocation( "${field.name}" ), sourceDominant ) );
+ builder.location("${field.name}", InputLocation.merge(target.getLocation("${field.name}"), source.getLocation("${field.name}"), sourceDominant));
#end
}
}
#elseif ( $field.to && $field.multiplicity == "*" )
if (deepMerge) {
- builder.${field.name}( merge( target.get${capField}(), source.get${capField}(), get${field.to}Key(),
- ( t, s ) -> merge${field.to}( t, s, sourceDominant, context ) ) );
+ builder.${field.name}(merge(target.get${capField}(), source.get${capField}(), get${field.to}Key(),
+ (t, s) -> merge${field.to}(t, s, sourceDominant, context)));
} else {
- builder.${field.name}( merge( target.get${capField}(), source.get${capField}(), sourceDominant, get${field.to}Key() ) );
+ builder.${field.name}(merge(target.get${capField}(), source.get${capField}(), sourceDominant, get${field.to}Key()));
}
#elseif ( $field.type == "DOM" )
XmlNode src = source.getConfiguration();
- if ( src != null )
- {
+ if (src != null) {
XmlNode tgt = target.getConfiguration();
- if ( tgt == null )
- {
- builder.configuration( src );
- }
- else if ( sourceDominant )
- {
- builder.configuration( src.merge( tgt ) );
- }
- else
- {
- builder.configuration( tgt.merge( src ) );
+ if (tgt == null) {
+ builder.configuration(src);
+ } else if (sourceDominant) {
+ builder.configuration(src.merge(tgt));
+ } else {
+ builder.configuration(tgt.merge(src));
}
}
- #elseif ( $field.type == "boolean" )
- if ( sourceDominant )
- {
- builder.${field.name}( source.is${capField}() );
+ #elseif ($field.type == "boolean")
+ if (sourceDominant) {
+ builder.${field.name}(source.is${capField}());
}
- #elseif ( $field.type == "int" || $field.type == "java.nio.file.Path" )
- if ( sourceDominant )
- {
- builder.${field.name}( source.get${capField}() );
+ #elseif ($field.type == "int" || $field.type == "java.nio.file.Path")
+ if (sourceDominant) {
+ builder.${field.name}(source.get${capField}());
}
#else
// TODO: type=${field.type} to=${field.to} multiplicity=${field.multiplicity}
@@ -225,8 +201,7 @@
#foreach ( $class in $model.allClasses )
#if ( $class.name != "InputSource" && $class.name != "InputLocation" )
- protected KeyComputer<${class.name}> get${class.name}Key()
- {
+ protected KeyComputer<${class.name}> get${class.name}Key() {
return v -> v;
}
#end
@@ -237,37 +212,30 @@
* @param <T> the data structure type
*/
@FunctionalInterface
- public interface KeyComputer<T> extends Function<T, Object>
- {
+ public interface KeyComputer<T> extends Function<T, Object> {
}
/**
* Merge two lists
*/
- public static <T> List<T> merge( List<T> tgt, List<T> src, boolean sourceDominant, KeyComputer<T> computer )
- {
- return merge( tgt, src, computer, ( t, s ) -> sourceDominant ? s : t );
+ public static <T> List<T> merge(List<T> tgt, List<T> src, boolean sourceDominant, KeyComputer<T> computer) {
+ return merge(tgt, src, computer, (t, s) -> sourceDominant ? s : t);
}
- public static <T> List<T> merge( List<T> tgt, List<T> src, KeyComputer<T> computer, BinaryOperator<T> remapping )
- {
- if ( src.isEmpty() )
- {
+ public static <T> List<T> merge(List<T> tgt, List<T> src, KeyComputer<T> computer, BinaryOperator<T> remapping) {
+ if (src.isEmpty()) {
return tgt;
}
MergingList<T> list;
- if ( tgt instanceof MergingList )
- {
+ if (tgt instanceof MergingList) {
list = (MergingList<T>) tgt;
- }
- else
- {
- list = new MergingList<>( computer, src.size() + tgt.size() );
- list.mergeAll( tgt, ( t, s ) -> s );
+ } else {
+ list = new MergingList<>(computer, src.size() + tgt.size());
+ list.mergeAll(tgt, (t, s) -> s);
}
- list.mergeAll( src, remapping );
+ list.mergeAll(src, remapping);
return list;
}
@@ -275,119 +243,90 @@
* Merging list
* @param <V>
*/
- private static class MergingList<V> extends AbstractList<V> implements java.io.Serializable
- {
+ private static class MergingList<V> extends AbstractList<V> implements java.io.Serializable {
private final KeyComputer<V> keyComputer;
private Map<Object, V> map;
private List<V> list;
- MergingList( KeyComputer<V> keyComputer, int initialCapacity )
- {
- this.map = new LinkedHashMap<>( initialCapacity );
+ MergingList(KeyComputer<V> keyComputer, int initialCapacity) {
+ this.map = new LinkedHashMap<>(initialCapacity);
this.keyComputer = keyComputer;
}
- Object writeReplace() throws ObjectStreamException
- {
- return new ArrayList<>( this );
+ Object writeReplace() throws ObjectStreamException {
+ return new ArrayList<>(this);
}
@Override
- public Iterator<V> iterator()
- {
- if ( map != null )
- {
+ public Iterator<V> iterator() {
+ if (map != null) {
return map.values().iterator();
- }
- else
- {
+ } else {
return list.iterator();
}
}
- void mergeAll( Collection<V> vs, BinaryOperator<V> remapping )
- {
- if ( map == null )
- {
- map = list.stream().collect( Collectors.toMap( keyComputer,
- Function.identity(),
- null,
- LinkedHashMap::new ) );
-
+ void mergeAll(Collection<V> vs, BinaryOperator<V> remapping) {
+ if (map == null) {
+ map = list.stream().collect(Collectors.toMap(keyComputer,
+ Function.identity(),
+ null,
+ LinkedHashMap::new));
list = null;
}
- if ( vs instanceof MergingList && ( (MergingList<V>) vs ).map != null )
- {
- for ( Map.Entry<Object, V> e : ( (MergingList<V>) vs ).map.entrySet() )
- {
+ if (vs instanceof MergingList && ((MergingList<V>) vs).map != null) {
+ for (Map.Entry<Object, V> e : ((MergingList<V>) vs).map.entrySet()) {
Object key = e.getKey();
V v = e.getValue();
- map.merge( key, v, remapping );
+ map.merge(key, v, remapping);
}
- }
- else
- {
- for ( V v : vs )
- {
- Object key = keyComputer.apply( v );
-
- map.merge( key, v, remapping );
+ } else {
+ for (V v : vs) {
+ Object key = keyComputer.apply(v);
+ map.merge(key, v, remapping);
}
}
}
@Override
- public boolean contains( Object o )
- {
- if ( map != null )
- {
- return map.containsValue( o );
- }
- else
- {
- return list.contains( o );
+ public boolean contains(Object o) {
+ if (map != null) {
+ return map.containsValue(o);
+ } else {
+ return list.contains(o);
}
}
- private List<V> asList()
- {
- if ( list == null )
- {
- list = new ArrayList<>( map.values() );
+ private List<V> asList() {
+ if (list == null) {
+ list = new ArrayList<>(map.values());
map = null;
}
return list;
}
@Override
- public void add( int index, V element )
- {
- asList().add( index, element );
+ public void add(int index, V element) {
+ asList().add(index, element);
}
@Override
- public V remove( int index )
- {
- return asList().remove( index );
+ public V remove(int index) {
+ return asList().remove(index);
}
@Override
- public V get( int index )
- {
- return asList().get( index );
+ public V get(int index) {
+ return asList().get(index);
}
@Override
- public int size()
- {
- if ( map != null )
- {
+ public int size() {
+ if (map != null) {
return map.size();
- }
- else
- {
+ } else {
return list.size();
}
}
diff --git a/src/mdo/model-v3.vm b/src/mdo/model-v3.vm
index 5fd6ddc..afa0d49 100644
--- a/src/mdo/model-v3.vm
+++ b/src/mdo/model-v3.vm
@@ -106,58 +106,48 @@
#end
{
- public ${class.name}()
- {
- this( ${packageModelV4}.${class.name}.newInstance() );
+ public ${class.name}() {
+ this(${packageModelV4}.${class.name}.newInstance());
}
- public ${class.name}( ${packageModelV4}.${class.name} delegate )
- {
- this( delegate, null );
+ public ${class.name}(${packageModelV4}.${class.name} delegate) {
+ this(delegate, null);
}
- public ${class.name}( ${packageModelV4}.${class.name} delegate, BaseObject parent )
- {
- super( delegate, parent );
+ public ${class.name}(${packageModelV4}.${class.name} delegate, BaseObject parent) {
+ super(delegate, parent);
}
- public ${class.name} clone()
- {
- return new ${class.name}( getDelegate() );
+ public ${class.name} clone(){
+ return new ${class.name}(getDelegate());
}
#if ( $class.superClass )
@Override
#end
- public ${packageModelV4}.${class.name} getDelegate()
- {
- return ( ${packageModelV4}.${class.name} ) super.getDelegate();
+ public ${packageModelV4}.${class.name} getDelegate() {
+ return (${packageModelV4}.${class.name}) super.getDelegate();
}
@Override
- public boolean equals( Object o )
- {
- if ( this == o )
- {
+ public boolean equals(Object o) {
+ if (this == o) {
return true;
}
- if ( o == null || !( o instanceof ${class.name} ) )
- {
+ if (o == null || !(o instanceof ${class.name})) {
return false;
}
- ${class.name} that = ( ${class.name} ) o;
- return Objects.equals( this.delegate, that.delegate );
+ ${class.name} that = (${class.name}) o;
+ return Objects.equals(this.delegate, that.delegate);
}
@Override
- public int hashCode()
- {
+ public int hashCode() {
return getDelegate().hashCode();
}
#if ( $class == $root )
- public String getModelEncoding()
- {
+ public String getModelEncoding() {
return getDelegate().getModelEncoding();
}
@@ -173,52 +163,47 @@
#if ( $field.type == "java.util.List" || $field.type == "java.util.Properties" )
@Nonnull
#end
- public ${type} ${pfx}${cap}()
- {
+ public ${type} ${pfx}${cap}() {
#if ( $field.to != "String" && $field.type == "java.util.List" && $field.multiplicity == "*" )
return new WrapperList<${field.to}, ${packageModelV4}.${field.to}>(
- () -> getDelegate().get${cap}(), l -> update( getDelegate().with${cap}( l ) ),
- d -> new ${field.to}( d, this ), ${field.to}::getDelegate );
+ () -> getDelegate().get${cap}(), l -> update(getDelegate().with${cap}(l)),
+ d -> new ${field.to}(d, this), ${field.to}::getDelegate);
#elseif ( $field.to == "String" && $field.type == "java.util.Properties" && $field.multiplicity == "*" )
- return new WrapperProperties( () -> getDelegate().get${cap}(), this::set${cap} );
+ return new WrapperProperties(() -> getDelegate().get${cap}(), this::set${cap});
#elseif ( $field.to == "String" && $field.type == "java.util.List" && $field.multiplicity == "*" )
- return new WrapperList<String, ${field.to}>( () -> getDelegate().get${cap}(), this::set${cap}, s -> s, s -> s );
+ return new WrapperList<String, ${field.to}>(() -> getDelegate().get${cap}(), this::set${cap}, s -> s, s -> s);
#elseif ( $field.to )
- return getDelegate().${pfx}${cap}() != null ? new ${field.to}( getDelegate().${pfx}${cap}(), this ) : null;
+ return getDelegate().${pfx}${cap}() != null ? new ${field.to}(getDelegate().${pfx}${cap}(), this) : null;
#elseif ( $field.type == "DOM" )
- return getDelegate().${pfx}${cap}() != null ? new Xpp3Dom( getDelegate().${pfx}${cap}(), this::replace ) : null;
+ return getDelegate().${pfx}${cap}() != null ? new Xpp3Dom(getDelegate().${pfx}${cap}(), this::replace) : null;
#else
return getDelegate().${pfx}${cap}();
#end
}
- public void set${cap}( ${type} ${field.name} )
- {
- #if ( $field.type == "DOM" )
- if ( ! Objects.equals( ( ( Xpp3Dom ) ${field.name} ).getDom(), getDelegate().${pfx}${cap}() ) )
- {
- update( getDelegate().with${cap}( ( ( Xpp3Dom ) ${field.name} ).getDom() ) );
- ( ( Xpp3Dom ) ${field.name} ).setChildrenTracking( this::replace );
+ public void set${cap}(${type} ${field.name}) {
+ #if ($field.type == "DOM")
+ if (!Objects.equals(((Xpp3Dom) ${field.name}).getDom(), getDelegate().${pfx}${cap}())) {
+ update(getDelegate().with${cap}(((Xpp3Dom) ${field.name}).getDom()));
+ ((Xpp3Dom) ${field.name}).setChildrenTracking(this::replace);
}
#elseif( $field.type == "java.util.Properties" )
Map<String, String> map = ${field.name}.entrySet().stream()
- .collect( Collectors.toMap( e -> e.getKey().toString(), e -> e.getValue().toString() ) );
- if ( !Objects.equals( map, getDelegate().get${cap}() ) )
- {
- update( getDelegate().with${cap}( map ) );
+ .collect(Collectors.toMap(e -> e.getKey().toString(), e -> e.getValue().toString()));
+ if (!Objects.equals(map, getDelegate().get${cap}())) {
+ update(getDelegate().with${cap}(map));
}
#else
- if ( !Objects.equals( ${field.name}, getDelegate().${pfx}${cap}() ) )
- {
+ if (!Objects.equals(${field.name}, getDelegate().${pfx}${cap}())) {
#if ( $field.to != "String" && $field.type == "java.util.List" && $field.multiplicity == "*" )
- update( getDelegate().with${cap}(
- ${field.name}.stream().map( c -> c.getDelegate() ).collect( Collectors.toList() ) ) );
- ${field.name}.forEach( e -> e.childrenTracking = this::replace );
+ update(getDelegate().with${cap}(
+ ${field.name}.stream().map(c -> c.getDelegate()).collect(Collectors.toList())));
+ ${field.name}.forEach(e -> e.childrenTracking = this::replace);
#elseif ( $field.to && $field.to != "String" )
- update( getDelegate().with${cap}( ${field.name}.getDelegate() ) );
+ update(getDelegate().with${cap}(${field.name}.getDelegate()));
${field.name}.childrenTracking = this::replace;
#else
- update( getDelegate().with${cap}( ${field.name} ) );
+ update(getDelegate().with${cap}(${field.name}));
#end
}
#end
@@ -227,32 +212,30 @@
#if ( $field.type == "java.util.List" && $field.multiplicity == "*" )
#set ( $v = $Helper.singular( ${field.name} ) )
#set ( $scap = $Helper.capitalise( $v ) )
- public void add${scap}( ${field.to} ${v} )
- {
+ public void add${scap}(${field.to} ${v}) {
#if ( $field.to == "String" )
- update( getDelegate().with${cap}(
- Stream.concat( getDelegate().get${cap}().stream(), Stream.of( ${v} ) )
- .collect( Collectors.toList() ) ) );
+ update(getDelegate().with${cap}(
+ Stream.concat(getDelegate().get${cap}().stream(), Stream.of(${v}))
+ .collect(Collectors.toList())));
#else
- update( getDelegate().with${cap}(
- Stream.concat( getDelegate().get${cap}().stream(), Stream.of( ${v}.getDelegate() ) )
- .collect( Collectors.toList() ) ) );
+ update(getDelegate().with${cap}(
+ Stream.concat(getDelegate().get${cap}().stream(), Stream.of(${v}.getDelegate()))
+ .collect(Collectors.toList())));
${v}.childrenTracking = this::replace;
#end
}
- public void remove${scap}( ${field.to} ${v} )
- {
+ public void remove${scap}(${field.to} ${v}) {
#if ( $field.to == "String" )
- update( getDelegate().with${cap}(
- getDelegate().get${cap}().stream()
- .filter( e -> !Objects.equals( e, ${v} ) )
- .collect( Collectors.toList() ) ) );
+ update(getDelegate().with${cap}(
+ getDelegate().get${cap}().stream()
+ .filter(e -> !Objects.equals(e, ${v}))
+ .collect(Collectors.toList())));
#else
- update( getDelegate().with${cap}(
- getDelegate().get${cap}().stream()
- .filter( e -> !Objects.equals( e, ${v} ) )
- .collect( Collectors.toList() ) ) );
+ update(getDelegate().with${cap}(
+ getDelegate().get${cap}().stream()
+ .filter(e -> !Objects.equals(e, ${v}))
+ .collect(Collectors.toList())));
${v}.childrenTracking = null;
#end
}
@@ -260,68 +243,58 @@
#elseif ( $field.type == "java.util.Properties" && $field.multiplicity == "*" )
#set ( $v = $Helper.singular( ${field.name} ) )
#set ( $scap = $Helper.capitalise( $v ) )
- public void add${scap}( String key, String value )
- {
- get${cap}().put( key, value );
+ public void add${scap}(String key, String value) {
+ get${cap}().put(key, value);
}
#end
#end
#if ( $locationTracking )
- public InputLocation getLocation( Object key )
- {
- ${packageModelV4}.InputLocation loc = getDelegate().getLocation( key );
- return loc != null ? new InputLocation( loc ) : null;
+ public InputLocation getLocation(Object key) {
+ ${packageModelV4}.InputLocation loc = getDelegate().getLocation(key);
+ return loc != null ? new InputLocation(loc) : null;
}
- public void setLocation( Object key, InputLocation location )
- {
- update( ${packageModelV4}.${class.name}.newBuilder( getDelegate(), true )
- .location( key, location.toApiLocation() ).build() );
+ public void setLocation(Object key, InputLocation location) {
+ update(${packageModelV4}.${class.name}.newBuilder(getDelegate(), true)
+ .location(key, location.toApiLocation()).build());
}
#end
- protected boolean replace( Object oldDelegate, Object newDelegate )
- {
- if ( super.replace( oldDelegate, newDelegate ) )
- {
+ protected boolean replace(Object oldDelegate, Object newDelegate) {
+ if (super.replace(oldDelegate, newDelegate)) {
return true;
}
#foreach ( $field in $class.getFields($version) )
#set ( $cap = $Helper.capitalise( $field.name ) )
#set ( $type = ${types.getOrDefault($field,${types.getOrDefault($field.type,$field.type)})} )
#if ( $field.to && $field.multiplicity != "*" )
- if ( oldDelegate == getDelegate().get${cap}() )
- {
- update( getDelegate().with${cap}( ( ${packageModelV4}.${field.to} ) newDelegate ) );
+ if (oldDelegate == getDelegate().get${cap}()) {
+ update(getDelegate().with${cap}((${packageModelV4}.${field.to}) newDelegate));
return true;
}
- #elseif ( $field.type == "java.util.List" && $field.to != "String" )
- if ( getDelegate().get${cap}().contains( oldDelegate ) )
- {
- List<${packageModelV4}.${field.to}> list = new ArrayList<>( getDelegate().get${cap}() );
- list.replaceAll( d -> d == oldDelegate ? ( ${packageModelV4}.${field.to} ) newDelegate : d );
- update( getDelegate().with${cap}( list ) );
+ #elseif ($field.type == "java.util.List" && $field.to != "String")
+ if (getDelegate().get${cap}().contains(oldDelegate)) {
+ List<${packageModelV4}.${field.to}> list = new ArrayList<>(getDelegate().get${cap}());
+ list.replaceAll(d -> d == oldDelegate ? (${packageModelV4}.${field.to}) newDelegate : d);
+ update(getDelegate().with${cap}(list));
return true;
}
#elseif ( $field.type == "DOM" )
- if ( getDelegate().get${cap}() == oldDelegate )
- {
- update( getDelegate().with${cap}( ( org.apache.maven.api.xml.XmlNode ) newDelegate ) );
+ if (getDelegate().get${cap}() == oldDelegate) {
+ update(getDelegate().with${cap}((org.apache.maven.api.xml.XmlNode) newDelegate));
}
#end
#end
return false;
}
- public static List<${packageModelV4}.${class.name}> ${Helper.uncapitalise(${class.name})}ToApiV4( List<${class.name}> list )
- {
- return list != null ? new WrapperList<>( list, ${class.name}::getDelegate, ${class.name}::new ) : null;
+ public static List<${packageModelV4}.${class.name}> ${Helper.uncapitalise(${class.name})}ToApiV4(List<${class.name}> list) {
+ return list != null ? new WrapperList<>(list, ${class.name}::getDelegate, ${class.name}::new) : null;
}
- public static List<${class.name}> ${Helper.uncapitalise(${class.name})}ToApiV3( List<${packageModelV4}.${class.name}> list )
- {
- return list != null ? new WrapperList<>( list, ${class.name}::new, ${class.name}::getDelegate ) : null;
+ public static List<${class.name}> ${Helper.uncapitalise(${class.name})}ToApiV3(List<${packageModelV4}.${class.name}> list) {
+ return list != null ? new WrapperList<>(list, ${class.name}::new, ${class.name}::getDelegate) : null;
}
#foreach ( $cs in $class.getCodeSegments($version) )
diff --git a/src/mdo/model.vm b/src/mdo/model.vm
index d3f21a0..fa66957 100644
--- a/src/mdo/model.vm
+++ b/src/mdo/model.vm
@@ -151,8 +151,7 @@
#if ( $locationTracking )
Map<Object, InputLocation> locations
#end
- )
- {
+ ) {
#if ( $class.superClass )
super(
#foreach ( $field in $inheritedFields )
@@ -169,44 +168,39 @@
#end
#foreach ( $field in $class.getFields($version) )
#if ( $field.type == "java.util.List" || $field.type == "java.util.Properties" || $field.type == "java.util.Map" )
- this.${field.name} = ImmutableCollections.copy( ${field.name} );
+ this.${field.name} = ImmutableCollections.copy(${field.name});
#else
this.${field.name} = ${field.name};
#end
#end
#if ( $locationTracking )
#if ( ! $class.superClass )
- this.locations = ImmutableCollections.copy( locations );
+ this.locations = ImmutableCollections.copy(locations);
#end
#end
}
#if ( ! $eq.empty )
@Override
- public boolean equals( Object o )
- {
- if ( this == o )
- {
+ public boolean equals(Object o) {
+ if (this == o) {
return true;
}
- if ( o == null || !( o instanceof ${class.name} ) )
- {
+ if (o == null || !(o instanceof ${class.name})) {
return false;
}
- ${class.name} that = ( ${class.name} ) o;
+ ${class.name} that = (${class.name}) o;
return ${eq};
}
@Override
- public int hashCode()
- {
- return Objects.hash( ${hc} );
+ public int hashCode() {
+ return Objects.hash(${hc});
}
#end
#if ( $class == $root )
- public String getModelEncoding()
- {
+ public String getModelEncoding() {
return modelEncoding;
}
@@ -230,8 +224,7 @@
#if ( $field.type == "java.util.List" || $field.type == "java.util.Properties" )
@Nonnull
#end
- public ${type} ${pfx}${cap}()
- {
+ public ${type} ${pfx}${cap}() {
return this.${field.name};
}
@@ -240,9 +233,8 @@
/**
* Gets the location of the specified field in the input source.
*/
- public InputLocation getLocation( Object key )
- {
- return locations != null ? locations.get( key ) : null;
+ public InputLocation getLocation(Object key) {
+ return locations != null ? locations.get(key) : null;
}
#end
@@ -252,9 +244,8 @@
* @return a {@code Builder}
*/
@Nonnull
- public Builder with()
- {
- return newBuilder( this );
+ public Builder with() {
+ return newBuilder(this);
}
#foreach ( $field in $allFields )
#set ( $cap = $Helper.capitalise( $field.name ) )
@@ -269,49 +260,45 @@
* @return a {@code ${class.name}} with the specified ${field.name}
*/
@Nonnull
- public ${class.name} with${cap}( $type $field.name )
- {
- return newBuilder(this, true).${field.name}( $field.name ).build();
+ public ${class.name} with${cap}($type $field.name) {
+ return newBuilder(this, true).${field.name}($field.name).build();
}
#end
/**
* Creates a new {@code ${class.name}} instance.
- * Equivalent to {@code newInstance( true )}.
+ * Equivalent to {@code newInstance(true)}.
* @see #newInstance(boolean)
*
* @return a new {@code ${class.name}}
*/
@Nonnull
- public static ${class.name} newInstance()
- {
- return newInstance( true );
+ public static ${class.name} newInstance() {
+ return newInstance(true);
}
/**
* Creates a new {@code ${class.name}} instance using default values or not.
- * Equivalent to {@code newBuilder( withDefaults ).build()}.
+ * Equivalent to {@code newBuilder(withDefaults).build()}.
*
* @param withDefaults the boolean indicating whether default values should be used
* @return a new {@code ${class.name}}
*/
@Nonnull
- public static ${class.name} newInstance( boolean withDefaults )
- {
- return newBuilder( withDefaults ).build();
+ public static ${class.name} newInstance(boolean withDefaults) {
+ return newBuilder(withDefaults).build();
}
/**
* Creates a new {@code ${class.name}} builder instance.
- * Equivalent to {@code newBuilder( true )}.
+ * Equivalent to {@code newBuilder(true)}.
* @see #newBuilder(boolean)
*
* @return a new {@code Builder}
*/
@Nonnull
- public static Builder newBuilder()
- {
- return newBuilder( true );
+ public static Builder newBuilder() {
+ return newBuilder(true);
}
/**
@@ -321,22 +308,20 @@
* @return a new {@code Builder}
*/
@Nonnull
- public static Builder newBuilder( boolean withDefaults )
- {
- return new Builder( withDefaults );
+ public static Builder newBuilder(boolean withDefaults) {
+ return new Builder(withDefaults);
}
/**
* Creates a new {@code ${class.name}} builder instance using the specified object as a basis.
- * Equivalent to {@code newBuilder( from, false )}.
+ * Equivalent to {@code newBuilder(from, false)}.
*
* @param from the {@code ${class.name}} instance to use as a basis
* @return a new {@code Builder}
*/
@Nonnull
- public static Builder newBuilder( ${class.name} from )
- {
- return newBuilder( from, false );
+ public static Builder newBuilder(${class.name} from) {
+ return newBuilder(from, false);
}
/**
@@ -347,9 +332,8 @@
* @return a new {@code Builder}
*/
@Nonnull
- public static Builder newBuilder( ${class.name} from, boolean forceCopy )
- {
- return new Builder( from, forceCopy );
+ public static Builder newBuilder(${class.name} from, boolean forceCopy) {
+ return new Builder(from, forceCopy);
}
/**
@@ -384,13 +368,11 @@
Map<Object, InputLocation> locations;
#end
- Builder( boolean withDefaults )
- {
+ Builder(boolean withDefaults) {
#if ( $class.superClass )
- super( withDefaults );
+ super(withDefaults);
#end
- if ( withDefaults )
- {
+ if (withDefaults) {
#foreach ( $field in $class.getFields($version) )
#if ( $field.defaultValue )
#set ( $type = ${types.getOrDefault($field,${types.getOrDefault($field.type,$field.type)})} )
@@ -404,30 +386,25 @@
}
}
- Builder( ${class.name} base, boolean forceCopy )
- {
+ Builder(${class.name} base, boolean forceCopy) {
#if ( $class.superClass )
- super( base, forceCopy );
+ super(base, forceCopy);
#end
- if ( forceCopy )
- {
+ if (forceCopy) {
#foreach ( $field in $class.getFields($version) )
this.${field.name} = base.${field.name};
#end
#if ( $locationTracking )
this.locations = base.locations;
#end
- }
- else
- {
+ } else {
this.base = base;
}
}
#if ( $class == $root )
@Nonnull
- public Builder modelEncoding( String modelEncoding )
- {
+ public Builder modelEncoding(String modelEncoding) {
this.modelEncoding = modelEncoding;
return this;
}
@@ -439,8 +416,7 @@
#set ( $type = ${type.replace('List<','Collection<')} )
#end
@Nonnull
- public Builder ${field.name}( ${type} ${field.name} )
- {
+ public Builder ${field.name}(${type} ${field.name}) {
this.${field.name} = ${field.name};
return this;
}
@@ -449,29 +425,24 @@
#if ( $locationTracking )
@Nonnull
- public Builder location( Object key, InputLocation location )
- {
- if ( location != null )
- {
- if ( !(this.locations instanceof HashMap) )
- {
- this.locations = this.locations != null ? new HashMap<>( this.locations ) : new HashMap<>();
+ public Builder location(Object key, InputLocation location) {
+ if (location != null) {
+ if (!(this.locations instanceof HashMap)) {
+ this.locations = this.locations != null ? new HashMap<>(this.locations) : new HashMap<>();
}
- this.locations.put( key, location );
+ this.locations.put(key, location);
}
return this;
}
#end
@Nonnull
- public ${class.name} build()
- {
- if ( base != null
+ public ${class.name} build() {
+ if (base != null
#foreach ( $field in $allFields )
- && ( ${field.name} == null || ${field.name} == base.${field.name} )
+ && (${field.name} == null || ${field.name} == base.${field.name})
#end
- )
- {
+ ) {
return base;
}
#if ( $locationTracking )
@@ -480,25 +451,24 @@
#foreach ( $field in $allFields )
InputLocation ${field.name}Location = null;
#end
- if ( this.locations != null )
- {
+ if (this.locations != null) {
locations = this.locations;
}
#end
return new ${class.name}(
#if ( $class == $root )
- modelEncoding != null ? modelEncoding : ( base != null ? base.modelEncoding : "UTF-8" ),
+ modelEncoding != null ? modelEncoding : (base != null ? base.modelEncoding : "UTF-8"),
#end
#foreach ( $field in $allFields )
#set ( $sep = "#if(${locationTracking}||$field!=${allFields[${allFields.size()} - 1]}),#end" )
#if ( $field.type == "boolean" || $field.type == "int" )
- ${field.name} != null ? ${field.name} : ( base != null ? base.${field.name} : ${field.defaultValue} )${sep}
+ ${field.name} != null ? ${field.name} : (base != null ? base.${field.name} : ${field.defaultValue})${sep}
#else
- ${field.name} != null ? ${field.name} : ( base != null ? base.${field.name} : null )${sep}
+ ${field.name} != null ? ${field.name} : (base != null ? base.${field.name} : null)${sep}
#end
#end
#if ( $locationTracking )
- locations != null ? locations : ( base != null ? base.locations : null )
+ locations != null ? locations : (base != null ? base.locations : null)
#end
);
}
diff --git a/src/mdo/reader-ex.vm b/src/mdo/reader-ex.vm
index a061e1b..3ee8119 100644
--- a/src/mdo/reader-ex.vm
+++ b/src/mdo/reader-ex.vm
@@ -60,19 +60,17 @@
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
@Generated
-public class ${className}
-{
+public class ${className} {
+
private boolean addDefaultEntities = true;
private final ContentTransformer contentTransformer;
- public ${className}()
- {
- this( ( s, f ) -> s );
+ public ${className}() {
+ this((s, f) -> s);
}
- public ${className}( ContentTransformer contentTransformer )
- {
+ public ${className}(ContentTransformer contentTransformer) {
this.contentTransformer = contentTransformer;
}
@@ -81,8 +79,7 @@
*
* @return boolean
*/
- public boolean getAddDefaultEntities()
- {
+ public boolean getAddDefaultEntities() {
return addDefaultEntities;
} //-- boolean getAddDefaultEntities()
@@ -91,10 +88,9 @@
*
* @param addDefaultEntities a addDefaultEntities object.
*/
- public void setAddDefaultEntities( boolean addDefaultEntities )
- {
+ public void setAddDefaultEntities(boolean addDefaultEntities) {
this.addDefaultEntities = addDefaultEntities;
- } //-- void setAddDefaultEntities( boolean )
+ } //-- void setAddDefaultEntities(boolean)
/**
* @see ReaderFactory#newXmlReader
@@ -106,13 +102,11 @@
* any.
* @return ${root.name}
*/
- public ${root.name} read( Reader reader, boolean strict, InputSource source )
- throws IOException, XmlPullParserException
- {
- XmlPullParser parser = addDefaultEntities ? new MXParser(EntityReplacementMap.defaultEntityReplacementMap) : new MXParser( );
- parser.setInput( reader );
- return read( parser, strict, source );
- } //-- ${root.name} read( Reader, boolean )
+ public ${root.name} read(Reader reader, boolean strict, InputSource source) throws IOException, XmlPullParserException {
+ XmlPullParser parser = addDefaultEntities ? new MXParser(EntityReplacementMap.defaultEntityReplacementMap) : new MXParser();
+ parser.setInput(reader);
+ return read(parser, strict, source);
+ } //-- ${root.name} read(Reader, boolean)
/**
* Method read.
@@ -124,11 +118,9 @@
* any.
* @return ${root.name}
*/
- public ${root.name} read( InputStream in, boolean strict, InputSource source )
- throws IOException, XmlPullParserException
- {
- return read( ReaderFactory.newXmlReader( in ), strict, source );
- } //-- ${root.name} read( InputStream, boolean )
+ public ${root.name} read(InputStream in, boolean strict, InputSource source) throws IOException, XmlPullParserException {
+ return read(ReaderFactory.newXmlReader(in), strict, source);
+ } //-- ${root.name} read(InputStream, boolean)
/**
* Method read.
@@ -140,36 +132,28 @@
* any.
* @return ${root.name}
*/
- public ${root.name} read( XmlPullParser parser, boolean strict, InputSource source )
- throws IOException, XmlPullParserException
- {
+ public ${root.name} read(XmlPullParser parser, boolean strict, InputSource source) throws IOException, XmlPullParserException {
$rootUcapName $rootLcapName = null;
int eventType = parser.getEventType();
boolean parsed = false;
- while ( eventType != XmlPullParser.END_DOCUMENT )
- {
- if ( eventType == XmlPullParser.START_TAG )
- {
- if ( strict && ! "${rootTag}".equals( parser.getName() ) )
- {
- throw new XmlPullParserException( "Expected root element '${rootTag}' but found '" + parser.getName() + "'", parser, null );
- }
- else if ( parsed )
- {
+ while (eventType != XmlPullParser.END_DOCUMENT) {
+ if (eventType == XmlPullParser.START_TAG) {
+ if (strict && ! "${rootTag}".equals(parser.getName())) {
+ throw new XmlPullParserException("Expected root element '${rootTag}' but found '" + parser.getName() + "'", parser, null);
+ } else if (parsed) {
// fallback, already expected a XmlPullParserException due to invalid XML
- throw new XmlPullParserException( "Duplicated tag: '${rootTag}'", parser, null );
+ throw new XmlPullParserException("Duplicated tag: '${rootTag}'", parser, null);
}
- $rootLcapName = parse${rootUcapName}( parser, strict, source );
+ $rootLcapName = parse${rootUcapName}(parser, strict, source);
parsed = true;
}
eventType = parser.next();
}
- if ( parsed )
- {
+ if (parsed) {
return $rootLcapName;
}
- throw new XmlPullParserException( "Expected root element '${rootTag}' but found no element at all: invalid XML document", parser, null );
- } //-- ${root.name} read( XmlPullParser, boolean )
+ throw new XmlPullParserException("Expected root element '${rootTag}' but found no element at all: invalid XML document", parser, null);
+ } //-- ${root.name} read(XmlPullParser, boolean)
#foreach ( $class in $model.allClasses )
#if ( $class.name != "InputSource" && $class.name != "InputLocation" )
@@ -177,61 +161,48 @@
#set ( $classLcapName = $Helper.uncapitalise( $class.name ) )
#set ( $ancestors = $Helper.ancestors( $class ) )
#set ( $allFields = $Helper.xmlFields( $class ) )
- private ${classUcapName} parse${classUcapName}( XmlPullParser parser, boolean strict, InputSource source )
- throws IOException, XmlPullParserException
- {
+ private ${classUcapName} parse${classUcapName}(XmlPullParser parser, boolean strict, InputSource source) throws IOException, XmlPullParserException {
String tagName = parser.getName();
- ${classUcapName}.Builder ${classLcapName} = ${classUcapName}.newBuilder( true );
- ${classLcapName}.location( "", new InputLocation( parser.getLineNumber(), parser.getColumnNumber(), source ) );
- for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
- {
- String name = parser.getAttributeName( i );
- String value = parser.getAttributeValue( i );
- if ( name.indexOf( ':' ) >= 0 )
- {
+ ${classUcapName}.Builder ${classLcapName} = ${classUcapName}.newBuilder(true);
+ ${classLcapName}.location("", new InputLocation(parser.getLineNumber(), parser.getColumnNumber(), source));
+ for (int i = parser.getAttributeCount() - 1; i >= 0; i--) {
+ String name = parser.getAttributeName(i);
+ String value = parser.getAttributeValue(i);
+ if (name.indexOf(':') >= 0) {
// just ignore attributes with non-default namespace (for example: xmlns:xsi)
- }
#if ( $class == $root )
- else if ( "xmlns".equals( name ) )
- {
+ } else if ("xmlns".equals(name)) {
// ignore xmlns attribute in root class, which is a reserved attribute name
- }
#end
#foreach ( $field in $allFields )
#if ( $Helper.xmlFieldMetadata( $field ).attribute )
#set ( $fieldTagName = $Helper.xmlFieldMetadata( $field ).tagName )
#set ( $fieldCapName = $Helper.capitalise( $field.name ) )
- else if ( "$fieldTagName".equals( name ) )
- {
- ${classLcapName}.location( name, new InputLocation( parser.getLineNumber(), parser.getColumnNumber(), source ) );
+ } else if ("$fieldTagName".equals(name)) {
+ ${classLcapName}.location(name, new InputLocation(parser.getLineNumber(), parser.getColumnNumber(), source));
#if ( $field.type == "String" )
- ${classLcapName}.${field.name}( interpolatedTrimmed( value, "$fieldTagName" ) );
+ ${classLcapName}.${field.name}(interpolatedTrimmed(value, "$fieldTagName"));
#elseif ( $field.type == "boolean" || $field.type == "Boolean" )
- ${classLcapName}.${field.name}( getBooleanValue( interpolatedTrimmed( value, "$fieldTagName" ), "$fieldTagName", parser, ${field.defaultValue} ) );
+ ${classLcapName}.${field.name}(getBooleanValue(interpolatedTrimmed(value, "$fieldTagName"), "$fieldTagName", parser, ${field.defaultValue}));
#else
// TODO: type=${field.type} to=${field.to} multiplicity=${field.multiplicity}
#end
- }
#end
#end
- else
- {
- checkUnknownAttribute( parser, name, tagName, strict );
+ } else {
+ checkUnknownAttribute(parser, name, tagName, strict);
}
}
Set<String> parsed = new HashSet<>();
- while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
- {
- String childName = unalias( parser.getName() );
- if ( !parsed.add( childName ) )
- {
- throw new XmlPullParserException( "Duplicated tag: '" + childName + "'", parser, null );
+ while ((strict ? parser.nextTag() : nextTag(parser)) == XmlPullParser.START_TAG) {
+ String childName = unalias(parser.getName());
+ if (!parsed.add(childName)) {
+ throw new XmlPullParserException("Duplicated tag: '" + childName + "'", parser, null);
}
int line = parser.getLineNumber();
int column = parser.getColumnNumber();
Map<Object, InputLocation> locations = null;
- switch ( childName )
- {
+ switch (childName) {
#set( $ift = "if" )
#foreach ( $field in $allFields )
#if ( ! $Helper.xmlFieldMetadata( $field ).attribute && ! $Helper.xmlFieldMetadata( $field ).transient )
@@ -239,67 +210,57 @@
#if ( ! $fieldTagName )
#set ( $fieldTagName = $field.name )
#end
- #set ( $fieldCapName = $Helper.capitalise( $field.name ) )
- case "${fieldTagName}":
- {
+ #set ( $fieldCapName = $Helper.capitalise($field.name))
+ case "${fieldTagName}": {
#if ( $field.type == "String" )
- ${classLcapName}.${field.name}( interpolatedTrimmed( parser.nextText(), "${fieldTagName}" ) );
+ ${classLcapName}.${field.name}(interpolatedTrimmed(parser.nextText(), "${fieldTagName}"));
break;
#elseif ( $field.type == "boolean" || $field.type == "Boolean" )
- ${classLcapName}.${field.name}( getBooleanValue( interpolatedTrimmed( parser.nextText(), "${fieldTagName}" ), "${fieldTagName}", parser, ${field.defaultValue} ) );
+ ${classLcapName}.${field.name}(getBooleanValue(interpolatedTrimmed(parser.nextText(), "${fieldTagName}"), "${fieldTagName}", parser, ${field.defaultValue}));
break;
#elseif ( $field.type == "int" )
- ${classLcapName}.${field.name}( getIntegerValue( interpolatedTrimmed( parser.nextText(), "${fieldTagName}" ), "${fieldTagName}", parser, strict, ${field.defaultValue} ) );
+ ${classLcapName}.${field.name}(getIntegerValue(interpolatedTrimmed(parser.nextText(), "${fieldTagName}"), "${fieldTagName}", parser, strict, ${field.defaultValue}));
break;
#elseif ( $field.type == "DOM" )
- ${classLcapName}.${field.name}( XmlNodeBuilder.build( parser, true ) );
+ ${classLcapName}.${field.name}(XmlNodeBuilder.build(parser, true));
break;
#elseif ( $field.type == "java.util.List" && $field.to == "String" && $field.multiplicity == "*" )
List<String> ${field.name} = new ArrayList<>();
locations = new HashMap<>();
- while ( parser.nextTag() == XmlPullParser.START_TAG )
- {
- if ( "${Helper.singular($fieldTagName)}".equals( parser.getName() ) )
- {
- locations.put( Integer.valueOf( locations.size() ), new InputLocation( parser.getLineNumber(), parser.getColumnNumber(), source ) );
- ${field.name}.add( interpolatedTrimmed( parser.nextText(), "${fieldTagName}" ) );
- }
- else
- {
- checkUnknownElement( parser, strict );
+ while (parser.nextTag() == XmlPullParser.START_TAG) {
+ if ("${Helper.singular($fieldTagName)}".equals(parser.getName())) {
+ locations.put(Integer.valueOf(locations.size()), new InputLocation(parser.getLineNumber(), parser.getColumnNumber(), source));
+ ${field.name}.add(interpolatedTrimmed(parser.nextText(), "${fieldTagName}"));
+ } else {
+ checkUnknownElement(parser, strict);
}
}
- ${classLcapName}.${field.name}( ${field.name} );
+ ${classLcapName}.${field.name}(${field.name});
break;
#elseif ( $field.type == "java.util.Properties" && $field.to == "String" && $field.multiplicity == "*" )
Map<String, String> ${field.name} = new LinkedHashMap<>();
locations = new HashMap<>();
- while ( parser.nextTag() == XmlPullParser.START_TAG )
- {
+ while (parser.nextTag() == XmlPullParser.START_TAG) {
String key = parser.getName();
String value = parser.nextText().trim();
- locations.put( key, new InputLocation( parser.getLineNumber(), parser.getColumnNumber(), source ) );
- ${field.name}.put( key, value );
+ locations.put(key, new InputLocation(parser.getLineNumber(), parser.getColumnNumber(), source));
+ ${field.name}.put(key, value);
}
- ${classLcapName}.${field.name}( ${field.name} );
+ ${classLcapName}.${field.name}(${field.name});
break;
#elseif ( $field.to && $field.multiplicity == "1" )
- ${classLcapName}.${field.name}( parse${field.toClass.name}( parser, strict, source ) );
+ ${classLcapName}.${field.name}(parse${field.toClass.name}(parser, strict, source ));
break;
#elseif ( $field.to && $field.multiplicity == "*" )
List<$field.to> ${field.name} = new ArrayList<>();
- while ( parser.nextTag() == XmlPullParser.START_TAG )
- {
- if ( "${Helper.singular($fieldTagName)}".equals( parser.getName() ) )
- {
- ${field.name}.add( parse${field.toClass.name}( parser, strict, source ) );
- }
- else
- {
- checkUnknownElement( parser, strict );
+ while (parser.nextTag() == XmlPullParser.START_TAG) {
+ if ("${Helper.singular($fieldTagName)}".equals(parser.getName())) {
+ ${field.name}.add(parse${field.toClass.name}(parser, strict, source));
+ } else {
+ checkUnknownElement(parser, strict);
}
}
- ${classLcapName}.${field.name}( ${field.name} );
+ ${classLcapName}.${field.name}(${field.name});
break;
#else
// TODO: type=${field.type} to=${field.to} multiplicity=${field.multiplicity}
@@ -309,16 +270,15 @@
#set( $ift = "else if" )
#end
#end
- default:
- {
- checkUnknownElement( parser, strict );
+ default: {
+ checkUnknownElement(parser, strict);
break;
}
}
- ${classLcapName}.location( childName, new InputLocation( line, column, source, locations ) );
+ ${classLcapName}.location(childName, new InputLocation(line, column, source, locations));
}
#if ( $class == $root )
- ${classLcapName}.modelEncoding( parser.getInputEncoding() );
+ ${classLcapName}.modelEncoding(parser.getInputEncoding());
#end
return ${classLcapName}.build();
}
@@ -326,10 +286,8 @@
#end
#end
- private String unalias( String tagName )
- {
- switch ( tagName )
- {
+ private String unalias(String tagName) {
+ switch (tagName) {
#set( $aliases = { } )
#foreach( $class in $model.allClasses )
#foreach ( $field in $class.allFields )
@@ -358,15 +316,12 @@
* any.
* @throws IOException IOException if any.
*/
- private void checkUnknownAttribute( XmlPullParser parser, String attribute, String tagName, boolean strict )
- throws XmlPullParserException, IOException
- {
+ private void checkUnknownAttribute(XmlPullParser parser, String attribute, String tagName, boolean strict) throws XmlPullParserException, IOException {
// strictXmlAttributes = true for model: if strict == true, not only elements are checked but attributes too
- if ( strict )
- {
- throw new XmlPullParserException( "Unknown attribute '" + attribute + "' for tag '" + tagName + "'", parser, null );
+ if (strict) {
+ throw new XmlPullParserException("Unknown attribute '" + attribute + "' for tag '" + tagName + "'", parser, null);
}
- } //-- void checkUnknownAttribute( XmlPullParser, String, String, boolean )
+ } //-- void checkUnknownAttribute(XmlPullParser, String, String, boolean)
/**
* Method checkUnknownElement.
@@ -377,27 +332,20 @@
* any.
* @throws IOException IOException if any.
*/
- private void checkUnknownElement( XmlPullParser parser, boolean strict )
- throws XmlPullParserException, IOException
- {
- if ( strict )
- {
- throw new XmlPullParserException( "Unrecognised tag: '" + parser.getName() + "'", parser, null );
+ private void checkUnknownElement(XmlPullParser parser, boolean strict) throws XmlPullParserException, IOException {
+ if (strict) {
+ throw new XmlPullParserException("Unrecognised tag: '" + parser.getName() + "'", parser, null);
}
- for ( int unrecognizedTagCount = 1; unrecognizedTagCount > 0; )
- {
+ for (int unrecognizedTagCount = 1; unrecognizedTagCount > 0;) {
int eventType = parser.next();
- if ( eventType == XmlPullParser.START_TAG )
- {
+ if (eventType == XmlPullParser.START_TAG) {
unrecognizedTagCount++;
- }
- else if ( eventType == XmlPullParser.END_TAG )
- {
+ } else if (eventType == XmlPullParser.END_TAG) {
unrecognizedTagCount--;
}
}
- } //-- void checkUnknownElement( XmlPullParser, boolean )
+ } //-- void checkUnknownElement(XmlPullParser, boolean)
/**
* Method getTrimmedValue.
@@ -405,14 +353,12 @@
* @param s a s object.
* @return String
*/
- private String getTrimmedValue( String s )
- {
- if ( s != null )
- {
+ private String getTrimmedValue(String s) {
+ if (s != null) {
s = s.trim();
}
return s;
- } //-- String getTrimmedValue( String )
+ } //-- String getTrimmedValue(String)
/**
* Method interpolatedTrimmed.
@@ -421,10 +367,9 @@
* @param context a context object.
* @return String
*/
- private String interpolatedTrimmed( String value, String context )
- {
- return getTrimmedValue( contentTransformer.transform( value, context ) );
- } //-- String interpolatedTrimmed( String, String )
+ private String interpolatedTrimmed(String value, String context) {
+ return getTrimmedValue(contentTransformer.transform(value, context));
+ } //-- String interpolatedTrimmed(String, String)
/**
* Method nextTag.
@@ -435,20 +380,16 @@
* any.
* @return int
*/
- private int nextTag( XmlPullParser parser )
- throws IOException, XmlPullParserException
- {
+ private int nextTag(XmlPullParser parser) throws IOException, XmlPullParserException {
int eventType = parser.next();
- if ( eventType == XmlPullParser.TEXT )
- {
+ if (eventType == XmlPullParser.TEXT) {
eventType = parser.next();
}
- if ( eventType != XmlPullParser.START_TAG && eventType != XmlPullParser.END_TAG )
- {
- throw new XmlPullParserException( "expected START_TAG or END_TAG not " + XmlPullParser.TYPES[eventType], parser, null );
+ if (eventType != XmlPullParser.START_TAG && eventType != XmlPullParser.END_TAG) {
+ throw new XmlPullParserException("expected START_TAG or END_TAG not " + XmlPullParser.TYPES[eventType], parser, null);
}
return eventType;
- } //-- int nextTag( XmlPullParser )
+ } //-- int nextTag(XmlPullParser)
#foreach ( $class in $model.allClasses )
#foreach ( $field in $class.getFields($version) )
@@ -471,15 +412,12 @@
* any.
* @return boolean
*/
- private boolean getBooleanValue( String s, String attribute, XmlPullParser parser, boolean defaultValue )
- throws XmlPullParserException
- {
- if ( s != null && s.length() != 0 )
- {
- return Boolean.valueOf( s ).booleanValue();
+ private boolean getBooleanValue(String s, String attribute, XmlPullParser parser, boolean defaultValue) throws XmlPullParserException {
+ if (s != null && s.length() != 0) {
+ return Boolean.valueOf(s).booleanValue();
}
return defaultValue;
- } //-- boolean getBooleanValue( String, String, XmlPullParser, String )
+ } //-- boolean getBooleanValue(String, String, XmlPullParser, String)
#end
#if ( $hasIntegerField )
@@ -494,29 +432,21 @@
* any.
* @return int
*/
- private int getIntegerValue( String s, String attribute, XmlPullParser parser, boolean strict, int defaultValue )
- throws XmlPullParserException
- {
- if ( s != null )
- {
- try
- {
- return Integer.valueOf( s ).intValue();
- }
- catch ( NumberFormatException nfe )
- {
- if ( strict )
- {
- throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be an integer", parser, nfe );
+ private int getIntegerValue(String s, String attribute, XmlPullParser parser, boolean strict, int defaultValue) throws XmlPullParserException {
+ if (s != null) {
+ try {
+ return Integer.valueOf(s).intValue();
+ } catch (NumberFormatException nfe) {
+ if (strict) {
+ throw new XmlPullParserException("Unable to parse element '" + attribute + "', must be an integer", parser, nfe);
}
}
}
return defaultValue;
- } //-- int getIntegerValue( String, String, XmlPullParser, boolean )
+ } //-- int getIntegerValue(String, String, XmlPullParser, boolean)
#end
- public static interface ContentTransformer
- {
+ public static interface ContentTransformer {
/**
* Interpolate the value read from the xpp3 document
* @param source The source value
@@ -524,7 +454,7 @@
* log stuff.
* @return The interpolated value.
*/
- String transform( String source, String fieldName );
+ String transform(String source, String fieldName);
}
}
diff --git a/src/mdo/reader-modified.vm b/src/mdo/reader-modified.vm
index be4f495..48d088b 100644
--- a/src/mdo/reader-modified.vm
+++ b/src/mdo/reader-modified.vm
@@ -58,19 +58,17 @@
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
@Generated
-public class ${className}
-{
+public class ${className} {
+
private boolean addDefaultEntities = true;
private final ContentTransformer contentTransformer;
- public ${className}()
- {
- this( ( s, f ) -> s );
+ public ${className}() {
+ this((s, f) -> s);
}
- public ${className}( ContentTransformer contentTransformer )
- {
+ public ${className}(ContentTransformer contentTransformer) {
this.contentTransformer = contentTransformer;
}
@@ -79,8 +77,7 @@
*
* @return boolean
*/
- public boolean getAddDefaultEntities()
- {
+ public boolean getAddDefaultEntities() {
return addDefaultEntities;
} //-- boolean getAddDefaultEntities()
@@ -89,10 +86,9 @@
*
* @param addDefaultEntities a addDefaultEntities object.
*/
- public void setAddDefaultEntities( boolean addDefaultEntities )
- {
+ public void setAddDefaultEntities(boolean addDefaultEntities) {
this.addDefaultEntities = addDefaultEntities;
- } //-- void setAddDefaultEntities( boolean )
+ } //-- void setAddDefaultEntities(boolean)
/**
* @see ReaderFactory#newXmlReader
@@ -104,16 +100,11 @@
* any.
* @return ${root.name}
*/
- public ${root.name} read( Reader reader, boolean strict )
- throws IOException, XmlPullParserException
- {
- XmlPullParser parser = addDefaultEntities ? new MXParser(EntityReplacementMap.defaultEntityReplacementMap) : new MXParser( );
-
- parser.setInput( reader );
-
-
- return read( parser, strict );
- } //-- ${root.name} read( Reader, boolean )
+ public ${root.name} read(Reader reader, boolean strict) throws IOException, XmlPullParserException {
+ XmlPullParser parser = addDefaultEntities ? new MXParser(EntityReplacementMap.defaultEntityReplacementMap) : new MXParser();
+ parser.setInput(reader);
+ return read(parser, strict);
+ } //-- ${root.name} read(Reader, boolean)
/**
* @see ReaderFactory#newXmlReader
@@ -124,11 +115,9 @@
* any.
* @return ${root.name}
*/
- public ${root.name} read( Reader reader )
- throws IOException, XmlPullParserException
- {
- return read( reader, true );
- } //-- ${root.name} read( Reader )
+ public ${root.name} read(Reader reader) throws IOException, XmlPullParserException {
+ return read(reader, true);
+ } //-- ${root.name} read(Reader)
/**
* Method read.
@@ -140,11 +129,9 @@
* any.
* @return ${root.name}
*/
- public ${root.name} read( InputStream in, boolean strict )
- throws IOException, XmlPullParserException
- {
- return read( ReaderFactory.newXmlReader( in ), strict );
- } //-- ${root.name} read( InputStream, boolean )
+ public ${root.name} read(InputStream in, boolean strict) throws IOException, XmlPullParserException {
+ return read(ReaderFactory.newXmlReader(in), strict);
+ } //-- ${root.name} read(InputStream, boolean)
/**
* Method read.
@@ -155,11 +142,9 @@
* any.
* @return ${root.name}
*/
- public ${root.name} read( InputStream in )
- throws IOException, XmlPullParserException
- {
- return read( ReaderFactory.newXmlReader( in ) );
- } //-- ${root.name} read( InputStream )
+ public ${root.name} read(InputStream in) throws IOException, XmlPullParserException {
+ return read(ReaderFactory.newXmlReader(in));
+ } //-- ${root.name} read(InputStream)
/**
* Method read.
@@ -171,36 +156,29 @@
* any.
* @return ${root.name}
*/
- public ${root.name} read( XmlPullParser parser, boolean strict )
- throws IOException, XmlPullParserException
- {
+ public ${root.name} read(XmlPullParser parser, boolean strict) throws IOException, XmlPullParserException {
$rootUcapName $rootLcapName = null;
int eventType = parser.getEventType();
boolean parsed = false;
- while ( eventType != XmlPullParser.END_DOCUMENT )
- {
- if ( eventType == XmlPullParser.START_TAG )
- {
- if ( strict && ! "${rootTag}".equals( parser.getName() ) )
- {
- throw new XmlPullParserException( "Expected root element '${rootTag}' but found '" + parser.getName() + "'", parser, null );
+ while (eventType != XmlPullParser.END_DOCUMENT) {
+ if (eventType == XmlPullParser.START_TAG) {
+ if (strict && ! "${rootTag}".equals(parser.getName())) {
+ throw new XmlPullParserException("Expected root element '${rootTag}' but found '" + parser.getName() + "'", parser, null);
}
- else if ( parsed )
- {
+ else if (parsed) {
// fallback, already expected a XmlPullParserException due to invalid XML
- throw new XmlPullParserException( "Duplicated tag: '${rootTag}'", parser, null );
+ throw new XmlPullParserException("Duplicated tag: '${rootTag}'", parser, null);
}
- $rootLcapName = parse${rootUcapName}( parser, strict );
+ $rootLcapName = parse${rootUcapName}(parser, strict);
parsed = true;
}
eventType = parser.next();
}
- if ( parsed )
- {
+ if (parsed) {
return $rootLcapName;
}
- throw new XmlPullParserException( "Expected root element '${rootTag}' but found no element at all: invalid XML document", parser, null );
- } //-- ${root.name} read( XmlPullParser, boolean )
+ throw new XmlPullParserException("Expected root element '${rootTag}' but found no element at all: invalid XML document", parser, null);
+ } //-- ${root.name} read(XmlPullParser, boolean)
#foreach ( $class in $model.allClasses )
#if ( $class.name != "InputSource" && $class.name != "InputLocation" )
@@ -208,22 +186,17 @@
#set ( $classLcapName = $Helper.uncapitalise( $class.name ) )
#set ( $ancestors = $Helper.ancestors( $class ) )
#set ( $allFields = $Helper.xmlFields( $class ) )
- private ${classUcapName} parse${classUcapName}( XmlPullParser parser, boolean strict )
- throws IOException, XmlPullParserException
- {
+ private ${classUcapName} parse${classUcapName}(XmlPullParser parser, boolean strict) throws IOException, XmlPullParserException {
String tagName = parser.getName();
- ${classUcapName}.Builder ${classLcapName} = ${classUcapName}.newBuilder( true );
- for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
- {
- String name = parser.getAttributeName( i );
- String value = parser.getAttributeValue( i );
- if ( name.indexOf( ':' ) >= 0 )
- {
+ ${classUcapName}.Builder ${classLcapName} = ${classUcapName}.newBuilder(true);
+ for (int i = parser.getAttributeCount() - 1; i >= 0; i--) {
+ String name = parser.getAttributeName(i);
+ String value = parser.getAttributeValue(i);
+ if (name.indexOf(':') >= 0) {
// just ignore attributes with non-default namespace (for example: xmlns:xsi)
}
#if ( $class == $root )
- else if ( "xmlns".equals( name ) )
- {
+ else if ("xmlns".equals(name)) {
// ignore xmlns attribute in root class, which is a reserved attribute name
}
#end
@@ -231,33 +204,28 @@
#if ( $Helper.xmlFieldMetadata( $field ).attribute )
#set ( $fieldTagName = $Helper.xmlFieldMetadata( $field ).tagName )
#set ( $fieldCapName = $Helper.capitalise( $field.name ) )
- else if ( "$fieldTagName".equals( name ) )
- {
+ else if ("$fieldTagName".equals(name)) {
#if ( $field.type == "String" )
- ${classLcapName}.${field.name}( interpolatedTrimmed( value, "$fieldTagName" ) );
+ ${classLcapName}.${field.name}(interpolatedTrimmed(value, "$fieldTagName"));
#elseif ( $field.type == "boolean" || $field.type == "Boolean" )
- ${classLcapName}.${field.name}( getBooleanValue( interpolatedTrimmed( value, "$fieldTagName" ), "$fieldTagName", parser, ${field.defaultValue} ) );
+ ${classLcapName}.${field.name}(getBooleanValue(interpolatedTrimmed(value, "$fieldTagName"), "$fieldTagName", parser, ${field.defaultValue}));
#else
// TODO: type=${field.type} to=${field.to} multiplicity=${field.multiplicity}
#end
}
#end
#end
- else
- {
- checkUnknownAttribute( parser, name, tagName, strict );
+ else {
+ checkUnknownAttribute(parser, name, tagName, strict);
}
}
Set<String> parsed = new HashSet<>();
- while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
- {
- String childName = unalias( parser.getName() );
- if ( !parsed.add( childName ) )
- {
- throw new XmlPullParserException( "Duplicated tag: '" + childName + "'", parser, null );
+ while ((strict ? parser.nextTag() : nextTag(parser)) == XmlPullParser.START_TAG) {
+ String childName = unalias(parser.getName());
+ if (!parsed.add(childName)) {
+ throw new XmlPullParserException("Duplicated tag: '" + childName + "'", parser, null);
}
- switch ( childName )
- {
+ switch (childName) {
#set( $ift = "if" )
#foreach ( $field in $allFields )
#if ( ! $Helper.xmlFieldMetadata( $field ).attribute && ! $Helper.xmlFieldMetadata( $field ).transient )
@@ -266,62 +234,54 @@
#set ( $fieldTagName = $field.name )
#end
#set ( $fieldCapName = $Helper.capitalise( $field.name ) )
- case "${fieldTagName}":
- {
+ case "${fieldTagName}": {
#if ( $field.type == "String" )
- ${classLcapName}.${field.name}( interpolatedTrimmed( parser.nextText(), "${fieldTagName}" ) );
+ ${classLcapName}.${field.name}(interpolatedTrimmed(parser.nextText(), "${fieldTagName}"));
break;
#elseif ( $field.type == "boolean" || $field.type == "Boolean" )
- ${classLcapName}.${field.name}( getBooleanValue( interpolatedTrimmed( parser.nextText(), "${fieldTagName}" ), "${fieldTagName}", parser, ${field.defaultValue} ) );
+ ${classLcapName}.${field.name}(getBooleanValue(interpolatedTrimmed(parser.nextText(), "${fieldTagName}"), "${fieldTagName}", parser, ${field.defaultValue}));
break;
#elseif ( $field.type == "int" )
- ${classLcapName}.${field.name}( getIntegerValue( interpolatedTrimmed( parser.nextText(), "${fieldTagName}" ), "${fieldTagName}", parser, strict, ${field.defaultValue} ) );
+ ${classLcapName}.${field.name}(getIntegerValue(interpolatedTrimmed(parser.nextText(), "${fieldTagName}"), "${fieldTagName}", parser, strict, ${field.defaultValue}));
break;
#elseif ( $field.type == "DOM" )
- ${classLcapName}.${field.name}( XmlNodeBuilder.build( parser, true ) );
+ ${classLcapName}.${field.name}(XmlNodeBuilder.build(parser, true));
break;
#elseif ( $field.type == "java.util.List" && $field.to == "String" && $field.multiplicity == "*" )
List<String> ${field.name} = new ArrayList<>();
- while ( parser.nextTag() == XmlPullParser.START_TAG )
- {
- if ( "${Helper.singular($fieldTagName)}".equals( parser.getName() ) )
- {
- ${field.name}.add( interpolatedTrimmed( parser.nextText(), "${fieldTagName}" ) );
+ while (parser.nextTag() == XmlPullParser.START_TAG) {
+ if ("${Helper.singular($fieldTagName)}".equals(parser.getName())) {
+ ${field.name}.add(interpolatedTrimmed(parser.nextText(), "${fieldTagName}"));
}
- else
- {
- checkUnknownElement( parser, strict );
+ else {
+ checkUnknownElement(parser, strict);
}
}
- ${classLcapName}.${field.name}( ${field.name} );
+ ${classLcapName}.${field.name}(${field.name});
break;
#elseif ( $field.type == "java.util.Properties" && $field.to == "String" && $field.multiplicity == "*" )
Map<String, String> ${field.name} = new LinkedHashMap<>();
- while ( parser.nextTag() == XmlPullParser.START_TAG )
- {
+ while (parser.nextTag() == XmlPullParser.START_TAG) {
String key = parser.getName();
String value = parser.nextText().trim();
- ${field.name}.put( key, value );
+ ${field.name}.put(key, value);
}
- ${classLcapName}.${field.name}( ${field.name} );
+ ${classLcapName}.${field.name}(${field.name});
break;
#elseif ( $field.to && $field.multiplicity == "1" )
- ${classLcapName}.${field.name}( parse${field.toClass.name}( parser, strict ) );
+ ${classLcapName}.${field.name}(parse${field.toClass.name}(parser, strict));
break;
#elseif ( $field.to && $field.multiplicity == "*" )
List<$field.to> ${field.name} = new ArrayList<>();
- while ( parser.nextTag() == XmlPullParser.START_TAG )
- {
- if ( "${Helper.singular($fieldTagName)}".equals( parser.getName() ) )
- {
- ${field.name}.add( parse${field.toClass.name}( parser, strict ) );
+ while (parser.nextTag() == XmlPullParser.START_TAG) {
+ if ("${Helper.singular($fieldTagName)}".equals(parser.getName())) {
+ ${field.name}.add(parse${field.toClass.name}(parser, strict));
}
- else
- {
- checkUnknownElement( parser, strict );
+ else {
+ checkUnknownElement(parser, strict);
}
}
- ${classLcapName}.${field.name}( ${field.name} );
+ ${classLcapName}.${field.name}(${field.name});
break;
#else
// TODO: type=${field.type} to=${field.to} multiplicity=${field.multiplicity}
@@ -331,15 +291,14 @@
#set( $ift = "else if" )
#end
#end
- default:
- {
- checkUnknownElement( parser, strict );
+ default: {
+ checkUnknownElement(parser, strict);
break;
}
}
}
#if ( $class == $root )
- ${classLcapName}.modelEncoding( parser.getInputEncoding() );
+ ${classLcapName}.modelEncoding(parser.getInputEncoding());
#end
return ${classLcapName}.build();
}
@@ -347,10 +306,8 @@
#end
#end
- private String unalias( String tagName )
- {
- switch ( tagName )
- {
+ private String unalias(String tagName) {
+ switch (tagName) {
#set( $aliases = { } )
#foreach( $class in $model.allClasses )
#foreach ( $field in $class.allFields )
@@ -379,15 +336,12 @@
* any.
* @throws IOException IOException if any.
*/
- private void checkUnknownAttribute( XmlPullParser parser, String attribute, String tagName, boolean strict )
- throws XmlPullParserException, IOException
- {
+ private void checkUnknownAttribute(XmlPullParser parser, String attribute, String tagName, boolean strict) throws XmlPullParserException, IOException {
// strictXmlAttributes = true for model: if strict == true, not only elements are checked but attributes too
- if ( strict )
- {
- throw new XmlPullParserException( "Unknown attribute '" + attribute + "' for tag '" + tagName + "'", parser, null );
+ if (strict) {
+ throw new XmlPullParserException("Unknown attribute '" + attribute + "' for tag '" + tagName + "'", parser, null);
}
- } //-- void checkUnknownAttribute( XmlPullParser, String, String, boolean )
+ } //-- void checkUnknownAttribute(XmlPullParser, String, String, boolean)
/**
* Method checkUnknownElement.
@@ -398,27 +352,21 @@
* any.
* @throws IOException IOException if any.
*/
- private void checkUnknownElement( XmlPullParser parser, boolean strict )
- throws XmlPullParserException, IOException
- {
- if ( strict )
- {
- throw new XmlPullParserException( "Unrecognised tag: '" + parser.getName() + "'", parser, null );
+ private void checkUnknownElement(XmlPullParser parser, boolean strict) throws XmlPullParserException, IOException {
+ if (strict) {
+ throw new XmlPullParserException("Unrecognised tag: '" + parser.getName() + "'", parser, null);
}
- for ( int unrecognizedTagCount = 1; unrecognizedTagCount > 0; )
- {
+ for (int unrecognizedTagCount = 1; unrecognizedTagCount > 0;) {
int eventType = parser.next();
- if ( eventType == XmlPullParser.START_TAG )
- {
+ if (eventType == XmlPullParser.START_TAG) {
unrecognizedTagCount++;
}
- else if ( eventType == XmlPullParser.END_TAG )
- {
+ else if (eventType == XmlPullParser.END_TAG) {
unrecognizedTagCount--;
}
}
- } //-- void checkUnknownElement( XmlPullParser, boolean )
+ } //-- void checkUnknownElement(XmlPullParser, boolean)
/**
* Method getTrimmedValue.
@@ -426,14 +374,12 @@
* @param s a s object.
* @return String
*/
- private String getTrimmedValue( String s )
- {
- if ( s != null )
- {
+ private String getTrimmedValue(String s) {
+ if (s != null) {
s = s.trim();
}
return s;
- } //-- String getTrimmedValue( String )
+ } //-- String getTrimmedValue(String)
/**
* Method interpolatedTrimmed.
@@ -442,10 +388,9 @@
* @param context a context object.
* @return String
*/
- private String interpolatedTrimmed( String value, String context )
- {
- return getTrimmedValue( contentTransformer.transform( value, context ) );
- } //-- String interpolatedTrimmed( String, String )
+ private String interpolatedTrimmed(String value, String context) {
+ return getTrimmedValue(contentTransformer.transform(value, context));
+ } //-- String interpolatedTrimmed(String, String)
/**
* Method nextTag.
@@ -456,20 +401,16 @@
* any.
* @return int
*/
- private int nextTag( XmlPullParser parser )
- throws IOException, XmlPullParserException
- {
+ private int nextTag(XmlPullParser parser) throws IOException, XmlPullParserException {
int eventType = parser.next();
- if ( eventType == XmlPullParser.TEXT )
- {
+ if (eventType == XmlPullParser.TEXT) {
eventType = parser.next();
}
- if ( eventType != XmlPullParser.START_TAG && eventType != XmlPullParser.END_TAG )
- {
- throw new XmlPullParserException( "expected START_TAG or END_TAG not " + XmlPullParser.TYPES[eventType], parser, null );
+ if (eventType != XmlPullParser.START_TAG && eventType != XmlPullParser.END_TAG) {
+ throw new XmlPullParserException("expected START_TAG or END_TAG not " + XmlPullParser.TYPES[eventType], parser, null);
}
return eventType;
- } //-- int nextTag( XmlPullParser )
+ } //-- int nextTag(XmlPullParser)
#foreach ( $class in $model.allClasses )
#foreach ( $field in $class.getFields($version) )
@@ -492,15 +433,12 @@
* any.
* @return boolean
*/
- private boolean getBooleanValue( String s, String attribute, XmlPullParser parser, boolean defaultValue )
- throws XmlPullParserException
- {
- if ( s != null && s.length() != 0 )
- {
- return Boolean.valueOf( s ).booleanValue();
+ private boolean getBooleanValue(String s, String attribute, XmlPullParser parser, boolean defaultValue) throws XmlPullParserException {
+ if (s != null && s.length() != 0) {
+ return Boolean.valueOf(s).booleanValue();
}
return defaultValue;
- } //-- boolean getBooleanValue( String, String, XmlPullParser, String )
+ } //-- boolean getBooleanValue(String, String, XmlPullParser, String)
#end
#if ( $hasIntegerField )
@@ -515,29 +453,22 @@
* any.
* @return int
*/
- private int getIntegerValue( String s, String attribute, XmlPullParser parser, boolean strict, int defaultValue )
- throws XmlPullParserException
- {
- if ( s != null )
- {
- try
- {
- return Integer.valueOf( s ).intValue();
+ private int getIntegerValue(String s, String attribute, XmlPullParser parser, boolean strict, int defaultValue) throws XmlPullParserException {
+ if (s != null) {
+ try {
+ return Integer.valueOf(s).intValue();
}
- catch ( NumberFormatException nfe )
- {
- if ( strict )
- {
- throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be an integer", parser, nfe );
+ catch (NumberFormatException nfe) {
+ if (strict) {
+ throw new XmlPullParserException("Unable to parse element '" + attribute + "', must be an integer", parser, nfe);
}
}
}
return defaultValue;
- } //-- int getIntegerValue( String, String, XmlPullParser, boolean )
+ } //-- int getIntegerValue(String, String, XmlPullParser, boolean)
#end
- public static interface ContentTransformer
- {
+ public static interface ContentTransformer {
/**
* Interpolate the value read from the xpp3 document
* @param source The source value
@@ -545,7 +476,7 @@
* log stuff.
* @return The interpolated value.
*/
- String transform( String source, String fieldName );
+ String transform(String source, String fieldName);
}
}
diff --git a/src/mdo/reader.vm b/src/mdo/reader.vm
index 8f04323..b95ea61 100644
--- a/src/mdo/reader.vm
+++ b/src/mdo/reader.vm
@@ -59,19 +59,17 @@
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
@Generated
-public class ${className}
-{
+public class ${className} {
+
private boolean addDefaultEntities = true;
private final ContentTransformer contentTransformer;
- public ${className}()
- {
- this( ( s, f ) -> s );
+ public ${className}() {
+ this((s, f) -> s);
}
- public ${className}( ContentTransformer contentTransformer )
- {
+ public ${className}(ContentTransformer contentTransformer) {
this.contentTransformer = contentTransformer;
}
@@ -86,19 +84,16 @@
* any.
* @return boolean
*/
- private boolean checkFieldWithDuplicate( XmlPullParser parser, String tagName, String alias, Set<String> parsed )
- throws XmlPullParserException
- {
- if ( !( parser.getName().equals( tagName ) || parser.getName().equals( alias ) ) )
- {
+ private boolean checkFieldWithDuplicate(XmlPullParser parser, String tagName, String alias, Set<String> parsed)
+ throws XmlPullParserException {
+ if (!(parser.getName().equals(tagName) || parser.getName().equals(alias))) {
return false;
}
- if ( !parsed.add( tagName ) )
- {
- throw new XmlPullParserException( "Duplicated tag: '" + tagName + "'", parser, null );
+ if (!parsed.add(tagName)) {
+ throw new XmlPullParserException("Duplicated tag: '" + tagName + "'", parser, null);
}
return true;
- } //-- boolean checkFieldWithDuplicate( XmlPullParser, String, String, Set<String> )
+ } //-- boolean checkFieldWithDuplicate(XmlPullParser, String, String, Set<String>)
/**
* Method checkUnknownAttribute.
@@ -111,15 +106,13 @@
* any.
* @throws IOException IOException if any.
*/
- private void checkUnknownAttribute( XmlPullParser parser, String attribute, String tagName, boolean strict )
- throws XmlPullParserException, IOException
- {
+ private void checkUnknownAttribute(XmlPullParser parser, String attribute, String tagName, boolean strict)
+ throws XmlPullParserException, IOException {
// strictXmlAttributes = true for model: if strict == true, not only elements are checked but attributes too
- if ( strict )
- {
- throw new XmlPullParserException( "Unknown attribute '" + attribute + "' for tag '" + tagName + "'", parser, null );
+ if (strict) {
+ throw new XmlPullParserException("Unknown attribute '" + attribute + "' for tag '" + tagName + "'", parser, null);
}
- } //-- void checkUnknownAttribute( XmlPullParser, String, String, boolean )
+ } //-- void checkUnknownAttribute(XmlPullParser, String, String, boolean)
/**
* Method checkUnknownElement.
@@ -130,35 +123,28 @@
* any.
* @throws IOException IOException if any.
*/
- private void checkUnknownElement( XmlPullParser parser, boolean strict )
- throws XmlPullParserException, IOException
- {
- if ( strict )
- {
- throw new XmlPullParserException( "Unrecognised tag: '" + parser.getName() + "'", parser, null );
+ private void checkUnknownElement(XmlPullParser parser, boolean strict)
+ throws XmlPullParserException, IOException {
+ if (strict) {
+ throw new XmlPullParserException("Unrecognised tag: '" + parser.getName() + "'", parser, null);
}
- for ( int unrecognizedTagCount = 1; unrecognizedTagCount > 0; )
- {
+ for (int unrecognizedTagCount = 1; unrecognizedTagCount > 0;) {
int eventType = parser.next();
- if ( eventType == XmlPullParser.START_TAG )
- {
+ if (eventType == XmlPullParser.START_TAG) {
unrecognizedTagCount++;
- }
- else if ( eventType == XmlPullParser.END_TAG )
- {
+ } else if (eventType == XmlPullParser.END_TAG) {
unrecognizedTagCount--;
}
}
- } //-- void checkUnknownElement( XmlPullParser, boolean )
+ } //-- void checkUnknownElement(XmlPullParser, boolean)
/**
* Returns the state of the "add default entities" flag.
*
* @return boolean
*/
- public boolean getAddDefaultEntities()
- {
+ public boolean getAddDefaultEntities() {
return addDefaultEntities;
} //-- boolean getAddDefaultEntities()
@@ -172,11 +158,10 @@
* any.
* @return boolean
*/
- private boolean getBooleanValue( String s, String attribute, XmlPullParser parser )
- throws XmlPullParserException
- {
- return getBooleanValue( s, attribute, parser, false );
- } //-- boolean getBooleanValue( String, String, XmlPullParser )
+ private boolean getBooleanValue(String s, String attribute, XmlPullParser parser)
+ throws XmlPullParserException {
+ return getBooleanValue(s, attribute, parser, false);
+ } //-- boolean getBooleanValue(String, String, XmlPullParser)
/**
* Method getBooleanValue.
@@ -189,15 +174,13 @@
* any.
* @return boolean
*/
- private boolean getBooleanValue( String s, String attribute, XmlPullParser parser, boolean defaultValue )
- throws XmlPullParserException
- {
- if ( s != null && s.length() != 0 )
- {
- return Boolean.valueOf( s ).booleanValue();
+ private boolean getBooleanValue(String s, String attribute, XmlPullParser parser, boolean defaultValue)
+ throws XmlPullParserException {
+ if (s != null && s.length() != 0) {
+ return Boolean.valueOf(s).booleanValue();
}
return defaultValue;
- } //-- boolean getBooleanValue( String, String, XmlPullParser, String )
+ } //-- boolean getBooleanValue(String, String, XmlPullParser, String)
/**
* Method getByteValue.
@@ -210,25 +193,19 @@
* any.
* @return byte
*/
- private byte getByteValue( String s, String attribute, XmlPullParser parser, boolean strict )
- throws XmlPullParserException
- {
- if ( s != null )
- {
- try
- {
- return Byte.valueOf( s ).byteValue();
- }
- catch ( NumberFormatException nfe )
- {
- if ( strict )
- {
- throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be a byte", parser, nfe );
+ private byte getByteValue(String s, String attribute, XmlPullParser parser, boolean strict)
+ throws XmlPullParserException {
+ if (s != null) {
+ try {
+ return Byte.valueOf(s).byteValue();
+ } catch (NumberFormatException nfe) {
+ if (strict) {
+ throw new XmlPullParserException("Unable to parse element '" + attribute + "', must be a byte", parser, nfe);
}
}
}
return 0;
- } //-- byte getByteValue( String, String, XmlPullParser, boolean )
+ } //-- byte getByteValue(String, String, XmlPullParser, boolean)
/**
* Method getCharacterValue.
@@ -240,15 +217,13 @@
* any.
* @return char
*/
- private char getCharacterValue( String s, String attribute, XmlPullParser parser )
- throws XmlPullParserException
- {
- if ( s != null )
- {
- return s.charAt( 0 );
+ private char getCharacterValue(String s, String attribute, XmlPullParser parser)
+ throws XmlPullParserException {
+ if (s != null) {
+ return s.charAt(0);
}
return 0;
- } //-- char getCharacterValue( String, String, XmlPullParser )
+ } //-- char getCharacterValue(String, String, XmlPullParser)
/**
* Method getDateValue.
@@ -260,11 +235,10 @@
* any.
* @return Date
*/
- private Date getDateValue( String s, String attribute, XmlPullParser parser )
- throws XmlPullParserException
- {
- return getDateValue( s, attribute, null, parser );
- } //-- Date getDateValue( String, String, XmlPullParser )
+ private Date getDateValue(String s, String attribute, XmlPullParser parser)
+ throws XmlPullParserException {
+ return getDateValue(s, attribute, null, parser);
+ } //-- Date getDateValue(String, String, XmlPullParser)
/**
* Method getDateValue.
@@ -277,42 +251,30 @@
* any.
* @return Date
*/
- private Date getDateValue( String s, String attribute, String dateFormat, XmlPullParser parser )
- throws XmlPullParserException
- {
- if ( s != null )
- {
+ private Date getDateValue(String s, String attribute, String dateFormat, XmlPullParser parser)
+ throws XmlPullParserException {
+ if (s != null) {
String effectiveDateFormat = dateFormat;
- if ( dateFormat == null )
- {
+ if (dateFormat == null) {
effectiveDateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS";
}
- if ( "long".equals( effectiveDateFormat ) )
- {
- try
- {
- return new java.util.Date( Long.parseLong( s ) );
+ if ("long".equals(effectiveDateFormat)) {
+ try {
+ return new java.util.Date(Long.parseLong(s));
+ } catch (NumberFormatException e) {
+ throw new XmlPullParserException(e.getMessage(), parser, e);
}
- catch ( NumberFormatException e )
- {
- throw new XmlPullParserException( e.getMessage(), parser, e );
- }
- }
- else
- {
- try
- {
- DateFormat dateParser = new java.text.SimpleDateFormat( effectiveDateFormat, java.util.Locale.US );
- return dateParser.parse( s );
- }
- catch ( java.text.ParseException e )
- {
- throw new XmlPullParserException( e.getMessage(), parser, e );
+ } else {
+ try {
+ DateFormat dateParser = new java.text.SimpleDateFormat(effectiveDateFormat, java.util.Locale.US);
+ return dateParser.parse(s);
+ } catch (java.text.ParseException e) {
+ throw new XmlPullParserException(e.getMessage(), parser, e);
}
}
}
return null;
- } //-- Date getDateValue( String, String, String, XmlPullParser )
+ } //-- Date getDateValue(String, String, String, XmlPullParser)
/**
* Method getDoubleValue.
@@ -325,25 +287,19 @@
* any.
* @return double
*/
- private double getDoubleValue( String s, String attribute, XmlPullParser parser, boolean strict )
- throws XmlPullParserException
- {
- if ( s != null )
- {
- try
- {
- return Double.valueOf( s ).doubleValue();
- }
- catch ( NumberFormatException nfe )
- {
- if ( strict )
- {
- throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be a floating point number", parser, nfe );
+ private double getDoubleValue(String s, String attribute, XmlPullParser parser, boolean strict)
+ throws XmlPullParserException {
+ if (s != null) {
+ try {
+ return Double.valueOf(s).doubleValue();
+ } catch (NumberFormatException nfe) {
+ if (strict) {
+ throw new XmlPullParserException("Unable to parse element '" + attribute + "', must be a floating point number", parser, nfe);
}
}
}
return 0;
- } //-- double getDoubleValue( String, String, XmlPullParser, boolean )
+ } //-- double getDoubleValue(String, String, XmlPullParser, boolean)
/**
* Method getFloatValue.
@@ -356,25 +312,19 @@
* any.
* @return float
*/
- private float getFloatValue( String s, String attribute, XmlPullParser parser, boolean strict )
- throws XmlPullParserException
- {
- if ( s != null )
- {
- try
- {
- return Float.valueOf( s ).floatValue();
- }
- catch ( NumberFormatException nfe )
- {
- if ( strict )
- {
- throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be a floating point number", parser, nfe );
+ private float getFloatValue(String s, String attribute, XmlPullParser parser, boolean strict)
+ throws XmlPullParserException {
+ if (s != null) {
+ try {
+ return Float.valueOf(s).floatValue();
+ } catch (NumberFormatException nfe) {
+ if (strict) {
+ throw new XmlPullParserException("Unable to parse element '" + attribute + "', must be a floating point number", parser, nfe);
}
}
}
return 0;
- } //-- float getFloatValue( String, String, XmlPullParser, boolean )
+ } //-- float getFloatValue(String, String, XmlPullParser, boolean)
/**
* Method getIntegerValue.
@@ -386,11 +336,10 @@
* any.
* @return int
*/
- private int getIntegerValue( String s, String attribute, XmlPullParser parser, boolean strict )
- throws XmlPullParserException
- {
- return getIntegerValue( s, attribute, parser, strict, 0 );
- } //-- int getBooleanValue( String, String, XmlPullParser )
+ private int getIntegerValue(String s, String attribute, XmlPullParser parser, boolean strict)
+ throws XmlPullParserException {
+ return getIntegerValue(s, attribute, parser, strict, 0);
+ } //-- int getBooleanValue(String, String, XmlPullParser)
/**
* Method getIntegerValue.
@@ -403,25 +352,19 @@
* any.
* @return int
*/
- private int getIntegerValue( String s, String attribute, XmlPullParser parser, boolean strict, int defaultValue )
- throws XmlPullParserException
- {
- if ( s != null )
- {
- try
- {
- return Integer.valueOf( s ).intValue();
- }
- catch ( NumberFormatException nfe )
- {
- if ( strict )
- {
- throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be an integer", parser, nfe );
+ private int getIntegerValue(String s, String attribute, XmlPullParser parser, boolean strict, int defaultValue)
+ throws XmlPullParserException {
+ if (s != null) {
+ try {
+ return Integer.valueOf(s).intValue();
+ } catch (NumberFormatException nfe) {
+ if (strict) {
+ throw new XmlPullParserException("Unable to parse element '" + attribute + "', must be an integer", parser, nfe);
}
}
}
return defaultValue;
- } //-- int getIntegerValue( String, String, XmlPullParser, boolean, int )
+ } //-- int getIntegerValue(String, String, XmlPullParser, boolean, int)
/**
* Method getLongValue.
@@ -434,25 +377,19 @@
* any.
* @return long
*/
- private long getLongValue( String s, String attribute, XmlPullParser parser, boolean strict )
- throws XmlPullParserException
- {
- if ( s != null )
- {
- try
- {
- return Long.valueOf( s ).longValue();
- }
- catch ( NumberFormatException nfe )
- {
- if ( strict )
- {
- throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be a long integer", parser, nfe );
+ private long getLongValue(String s, String attribute, XmlPullParser parser, boolean strict)
+ throws XmlPullParserException {
+ if (s != null) {
+ try {
+ return Long.valueOf(s).longValue();
+ } catch (NumberFormatException nfe) {
+ if (strict) {
+ throw new XmlPullParserException("Unable to parse element '" + attribute + "', must be a long integer", parser, nfe);
}
}
}
return 0;
- } //-- long getLongValue( String, String, XmlPullParser, boolean )
+ } //-- long getLongValue(String, String, XmlPullParser, boolean)
/**
* Method getRequiredAttributeValue.
@@ -465,18 +402,15 @@
* any.
* @return String
*/
- private String getRequiredAttributeValue( String s, String attribute, XmlPullParser parser, boolean strict )
- throws XmlPullParserException
- {
- if ( s == null )
- {
- if ( strict )
- {
- throw new XmlPullParserException( "Missing required value for attribute '" + attribute + "'", parser, null );
+ private String getRequiredAttributeValue(String s, String attribute, XmlPullParser parser, boolean strict)
+ throws XmlPullParserException {
+ if (s == null) {
+ if (strict) {
+ throw new XmlPullParserException("Missing required value for attribute '" + attribute + "'", parser, null);
}
}
return s;
- } //-- String getRequiredAttributeValue( String, String, XmlPullParser, boolean )
+ } //-- String getRequiredAttributeValue(String, String, XmlPullParser, boolean)
/**
* Method getShortValue.
@@ -489,25 +423,19 @@
* any.
* @return short
*/
- private short getShortValue( String s, String attribute, XmlPullParser parser, boolean strict )
- throws XmlPullParserException
- {
- if ( s != null )
- {
- try
- {
- return Short.valueOf( s ).shortValue();
- }
- catch ( NumberFormatException nfe )
- {
- if ( strict )
- {
- throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be a short integer", parser, nfe );
+ private short getShortValue(String s, String attribute, XmlPullParser parser, boolean strict)
+ throws XmlPullParserException {
+ if (s != null) {
+ try {
+ return Short.valueOf(s).shortValue();
+ } catch (NumberFormatException nfe) {
+ if (strict) {
+ throw new XmlPullParserException("Unable to parse element '" + attribute + "', must be a short integer", parser, nfe);
}
}
}
return 0;
- } //-- short getShortValue( String, String, XmlPullParser, boolean )
+ } //-- short getShortValue(String, String, XmlPullParser, boolean)
/**
* Method getTrimmedValue.
@@ -515,14 +443,12 @@
* @param s a s object.
* @return String
*/
- private String getTrimmedValue( String s )
- {
- if ( s != null )
- {
+ private String getTrimmedValue(String s) {
+ if (s != null) {
s = s.trim();
}
return s;
- } //-- String getTrimmedValue( String )
+ } //-- String getTrimmedValue(String)
/**
* Method interpolatedTrimmed.
@@ -531,10 +457,9 @@
* @param context a context object.
* @return String
*/
- private String interpolatedTrimmed( String value, String context )
- {
- return getTrimmedValue( contentTransformer.transform( value, context ) );
- } //-- String interpolatedTrimmed( String, String )
+ private String interpolatedTrimmed(String value, String context) {
+ return getTrimmedValue(contentTransformer.transform(value, context));
+ } //-- String interpolatedTrimmed(String, String)
/**
* Method nextTag.
@@ -545,20 +470,16 @@
* any.
* @return int
*/
- private int nextTag( XmlPullParser parser )
- throws IOException, XmlPullParserException
- {
+ private int nextTag(XmlPullParser parser) throws IOException, XmlPullParserException {
int eventType = parser.next();
- if ( eventType == XmlPullParser.TEXT )
- {
+ if (eventType == XmlPullParser.TEXT) {
eventType = parser.next();
}
- if ( eventType != XmlPullParser.START_TAG && eventType != XmlPullParser.END_TAG )
- {
- throw new XmlPullParserException( "expected START_TAG or END_TAG not " + XmlPullParser.TYPES[eventType], parser, null );
+ if (eventType != XmlPullParser.START_TAG && eventType != XmlPullParser.END_TAG) {
+ throw new XmlPullParserException("expected START_TAG or END_TAG not " + XmlPullParser.TYPES[eventType], parser, null);
}
return eventType;
- } //-- int nextTag( XmlPullParser )
+ } //-- int nextTag(XmlPullParser)
/**
* @see ReaderFactory#newXmlReader
@@ -570,16 +491,11 @@
* any.
* @return ${root.name}
*/
- public ${root.name} read( Reader reader, boolean strict )
- throws IOException, XmlPullParserException
- {
- XmlPullParser parser = addDefaultEntities ? new MXParser(EntityReplacementMap.defaultEntityReplacementMap) : new MXParser( );
-
- parser.setInput( reader );
-
-
- return read( parser, strict );
- } //-- ${root.name} read( Reader, boolean )
+ public ${root.name} read(Reader reader, boolean strict) throws IOException, XmlPullParserException {
+ XmlPullParser parser = addDefaultEntities ? new MXParser(EntityReplacementMap.defaultEntityReplacementMap) : new MXParser();
+ parser.setInput(reader);
+ return read(parser, strict);
+ } //-- ${root.name} read(Reader, boolean)
/**
* @see ReaderFactory#newXmlReader
@@ -590,11 +506,9 @@
* any.
* @return ${root.name}
*/
- public ${root.name} read( Reader reader )
- throws IOException, XmlPullParserException
- {
- return read( reader, true );
- } //-- ${root.name} read( Reader )
+ public ${root.name} read(Reader reader) throws IOException, XmlPullParserException {
+ return read(reader, true);
+ } //-- ${root.name} read(Reader)
/**
* Method read.
@@ -606,11 +520,9 @@
* any.
* @return ${root.name}
*/
- public ${root.name} read( InputStream in, boolean strict )
- throws IOException, XmlPullParserException
- {
- return read( ReaderFactory.newXmlReader( in ), strict );
- } //-- ${root.name} read( InputStream, boolean )
+ public ${root.name} read(InputStream in, boolean strict) throws IOException, XmlPullParserException {
+ return read(ReaderFactory.newXmlReader(in), strict);
+ } //-- ${root.name} read(InputStream, boolean)
/**
* Method read.
@@ -621,11 +533,9 @@
* any.
* @return ${root.name}
*/
- public ${root.name} read( InputStream in )
- throws IOException, XmlPullParserException
- {
- return read( ReaderFactory.newXmlReader( in ) );
- } //-- ${root.name} read( InputStream )
+ public ${root.name} read(InputStream in) throws IOException, XmlPullParserException {
+ return read(ReaderFactory.newXmlReader(in));
+ } //-- ${root.name} read(InputStream)
/**
* Method read.
@@ -637,36 +547,28 @@
* any.
* @return ${root.name}
*/
- public ${root.name} read( XmlPullParser parser, boolean strict )
- throws IOException, XmlPullParserException
- {
+ public ${root.name} read(XmlPullParser parser, boolean strict) throws IOException, XmlPullParserException {
$rootUcapName $rootLcapName = null;
int eventType = parser.getEventType();
boolean parsed = false;
- while ( eventType != XmlPullParser.END_DOCUMENT )
- {
- if ( eventType == XmlPullParser.START_TAG )
- {
- if ( strict && ! "${rootTag}".equals( parser.getName() ) )
- {
- throw new XmlPullParserException( "Expected root element '${rootTag}' but found '" + parser.getName() + "'", parser, null );
- }
- else if ( parsed )
- {
+ while (eventType != XmlPullParser.END_DOCUMENT) {
+ if (eventType == XmlPullParser.START_TAG) {
+ if (strict && ! "${rootTag}".equals(parser.getName())) {
+ throw new XmlPullParserException("Expected root element '${rootTag}' but found '" + parser.getName() + "'", parser, null);
+ } else if (parsed) {
// fallback, already expected a XmlPullParserException due to invalid XML
- throw new XmlPullParserException( "Duplicated tag: '${rootTag}'", parser, null );
+ throw new XmlPullParserException("Duplicated tag: '${rootTag}'", parser, null);
}
- $rootLcapName = parse${rootUcapName}( parser, strict );
+ $rootLcapName = parse${rootUcapName}(parser, strict);
parsed = true;
}
eventType = parser.next();
}
- if ( parsed )
- {
+ if (parsed) {
return $rootLcapName;
}
- throw new XmlPullParserException( "Expected root element '${rootTag}' but found no element at all: invalid XML document", parser, null );
- } //-- ${root.name} read( XmlPullParser, boolean )
+ throw new XmlPullParserException("Expected root element '${rootTag}' but found no element at all: invalid XML document", parser, null);
+ } //-- ${root.name} read(XmlPullParser, boolean)
#foreach ( $class in $model.allClasses )
#if ( $class.name != "InputSource" && $class.name != "InputLocation" )
@@ -677,44 +579,37 @@
#foreach ( $cl in $ancestors )
#set ( $dummy = $allFields.addAll( $cl.getFields($version) ) )
#end
- private ${classUcapName} parse${classUcapName}( XmlPullParser parser, boolean strict )
- throws IOException, XmlPullParserException
- {
+ private ${classUcapName} parse${classUcapName}(XmlPullParser parser, boolean strict)
+ throws IOException, XmlPullParserException {
String tagName = parser.getName();
- ${classUcapName}.Builder ${classLcapName} = ${classUcapName}.newBuilder( true );
- for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- )
- {
- String name = parser.getAttributeName( i );
- String value = parser.getAttributeValue( i );
- if ( name.indexOf( ':' ) >= 0 )
- {
+ ${classUcapName}.Builder ${classLcapName} = ${classUcapName}.newBuilder(true);
+ for (int i = parser.getAttributeCount() - 1; i >= 0; i--) {
+ String name = parser.getAttributeName(i);
+ String value = parser.getAttributeValue(i);
+ if (name.indexOf(':') >= 0) {
// just ignore attributes with non-default namespace (for example: xmlns:xsi)
- }
#if ( $class == $root )
- else if ( "xmlns".equals( name ) )
- {
+ } else if ("xmlns".equals(name)) {
// ignore xmlns attribute in root class, which is a reserved attribute name
- }
#end
+ }
#foreach ( $field in $allFields )
#if ( $Helper.xmlFieldMetadata( $field ).attribute )
#set ( $fieldTagName = $Helper.xmlFieldMetadata( $field ).tagName )
#set ( $fieldCapName = $Helper.capitalise( $field.name ) )
- else if ( "$fieldTagName".equals( name ) )
- {
+ else if ("$fieldTagName".equals(name)) {
#if ( $field.type == "String" )
- ${classLcapName}.${field.name}( interpolatedTrimmed( value, "$fieldTagName" ) );
+ ${classLcapName}.${field.name}(interpolatedTrimmed(value, "$fieldTagName"));
#elseif ( $field.type == "boolean" || $field.type == "Boolean" )
- ${classLcapName}.${field.name}( getBooleanValue( interpolatedTrimmed( value, "$fieldTagName" ), "$fieldTagName", parser, ${field.defaultValue} ) );
+ ${classLcapName}.${field.name}(getBooleanValue(interpolatedTrimmed(value, "$fieldTagName"), "$fieldTagName", parser, ${field.defaultValue}));
#else
// TODO: type=${field.type} to=${field.to} multiplicity=${field.multiplicity}
#end
}
#end
#end
- else
- {
- checkUnknownAttribute( parser, name, tagName, strict );
+ else {
+ checkUnknownAttribute(parser, name, tagName, strict);
}
}
Set<String> parsed = new HashSet<>();
@@ -723,11 +618,9 @@
List<$field.to> ${field.name} = new ArrayList<>();
#end
#end
- while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG )
- {
- String childName = checkDuplicate( parser.getName(), parser, parsed );
- switch ( childName )
- {
+ while ((strict ? parser.nextTag() : nextTag(parser)) == XmlPullParser.START_TAG) {
+ String childName = checkDuplicate(parser.getName(), parser, parsed);
+ switch (childName) {
#set( $ift = "if" )
#foreach ( $field in $allFields )
#if ( ! $Helper.xmlFieldMetadata( $field ).attribute && ! $Helper.xmlFieldMetadata( $field ).transient )
@@ -739,65 +632,55 @@
#set ( $fieldTagName = $Helper.singular( $fieldTagName ) )
#end
#set ( $fieldCapName = $Helper.capitalise( $field.name ) )
- case "${fieldTagName}":
- {
+ case "${fieldTagName}": {
#if ( $field.type == "String" )
- ${classLcapName}.${field.name}( interpolatedTrimmed( parser.nextText(), "${fieldTagName}" ) );
+ ${classLcapName}.${field.name}(interpolatedTrimmed(parser.nextText(), "${fieldTagName}"));
break;
#elseif ( $field.type == "boolean" || $field.type == "Boolean" )
- ${classLcapName}.${field.name}( getBooleanValue( interpolatedTrimmed( parser.nextText(), "${fieldTagName}" ), "${fieldTagName}", parser, ${field.defaultValue} ) );
+ ${classLcapName}.${field.name}(getBooleanValue(interpolatedTrimmed(parser.nextText(), "${fieldTagName}"), "${fieldTagName}", parser, ${field.defaultValue}));
break;
#elseif ( $field.type == "int" )
- ${classLcapName}.${field.name}( getIntegerValue( interpolatedTrimmed( parser.nextText(), "${fieldTagName}" ), "${fieldTagName}", parser, strict, ${field.defaultValue} ) );
+ ${classLcapName}.${field.name}(getIntegerValue(interpolatedTrimmed(parser.nextText(), "${fieldTagName}"), "${fieldTagName}", parser, strict, ${field.defaultValue}));
break;
#elseif ( $field.type == "DOM" )
- ${classLcapName}.${field.name}( XmlNodeBuilder.build( parser, true ) );
+ ${classLcapName}.${field.name}(XmlNodeBuilder.build(parser, true));
break;
#elseif ( $field.type == "java.util.List" && $field.to == "String" && $field.multiplicity == "*" )
List<String> ${field.name} = new ArrayList<>();
- while ( parser.nextTag() == XmlPullParser.START_TAG )
- {
- if ( "${Helper.singular($fieldTagName)}".equals( parser.getName() ) )
- {
- ${field.name}.add( interpolatedTrimmed( parser.nextText(), "${fieldTagName}" ) );
- }
- else
- {
- checkUnknownElement( parser, strict );
+ while (parser.nextTag() == XmlPullParser.START_TAG) {
+ if ("${Helper.singular($fieldTagName)}".equals(parser.getName())) {
+ ${field.name}.add(interpolatedTrimmed(parser.nextText(), "${fieldTagName}"));
+ } else {
+ checkUnknownElement(parser, strict);
}
}
- ${classLcapName}.${field.name}( ${field.name} );
+ ${classLcapName}.${field.name}(${field.name});
break;
#elseif ( $field.type == "java.util.Properties" && $field.to == "String" && $field.multiplicity == "*" )
Map<String, String> ${field.name} = new LinkedHashMap<>();
- while ( parser.nextTag() == XmlPullParser.START_TAG )
- {
+ while (parser.nextTag() == XmlPullParser.START_TAG) {
String key = parser.getName();
String value = parser.nextText().trim();
- ${field.name}.put( key, value );
+ ${field.name}.put(key, value);
}
- ${classLcapName}.${field.name}( ${field.name} );
+ ${classLcapName}.${field.name}(${field.name});
break;
#elseif ( $field.to && $field.multiplicity == "1" )
- ${classLcapName}.${field.name}( parse${field.toClass.name}( parser, strict ) );
+ ${classLcapName}.${field.name}(parse${field.toClass.name}(parser, strict));
break;
#elseif ( $field.to && $field.multiplicity == "*" && $Helper.isFlatItems( $field ) )
- ${field.name}.add( parse${field.toClass.name}( parser, strict ) );
+ ${field.name}.add(parse${field.toClass.name}(parser, strict));
break;
#elseif ( $field.to && $field.multiplicity == "*" )
List<$field.to> ${field.name} = new ArrayList<>();
- while ( parser.nextTag() == XmlPullParser.START_TAG )
- {
- if ( "${Helper.singular($fieldTagName)}".equals( parser.getName() ) )
- {
- ${field.name}.add( parse${field.toClass.name}( parser, strict ) );
- }
- else
- {
- checkUnknownElement( parser, strict );
+ while (parser.nextTag() == XmlPullParser.START_TAG) {
+ if ("${Helper.singular($fieldTagName)}".equals(parser.getName())) {
+ ${field.name}.add(parse${field.toClass.name}(parser, strict));
+ } else {
+ checkUnknownElement(parser, strict);
}
}
- ${classLcapName}.${field.name}( ${field.name} );
+ ${classLcapName}.${field.name}(${field.name});
break;
#else
// TODO: type=${field.type} to=${field.to} multiplicity=${field.multiplicity}
@@ -807,20 +690,19 @@
#set( $ift = "else if" )
#end
#end
- default:
- {
- checkUnknownElement( parser, strict );
+ default: {
+ checkUnknownElement(parser, strict);
break;
}
}
}
#foreach ( $field in $allFields )
#if ( $Helper.isFlatItems( $field ) )
- ${classLcapName}.${field.name}( ${field.name} );
+ ${classLcapName}.${field.name}(${field.name});
#end
#end
#if ( $class == $root )
- ${classLcapName}.modelEncoding( parser.getInputEncoding() );
+ ${classLcapName}.modelEncoding(parser.getInputEncoding());
#end
return ${classLcapName}.build();
}
@@ -828,9 +710,7 @@
#end
#end
- private String checkDuplicate( String tagName, XmlPullParser parser, Set<String> parsed )
- throws XmlPullParserException
- {
+ private String checkDuplicate(String tagName, XmlPullParser parser, Set<String> parsed) throws XmlPullParserException {
#set( $aliases = { } )
#set( $flats = { } )
#foreach( $class in $model.allClasses )
@@ -849,8 +729,7 @@
#end
#end
#if ( ! ${aliases.isEmpty()} )
- switch ( tagName )
- {
+ switch (tagName) {
#foreach( $entry in $aliases.entrySet() )
case "${entry.key}":
tagName = "${entry.value}";
@@ -858,16 +737,14 @@
}
#end
#if ( ! ${flats.isEmpty()} )
- switch ( tagName )
- {
+ switch (tagName) {
#foreach( $entry in $flats.entrySet() )
case "${entry.key}":
#end
break;
default:
- if ( !parsed.add( tagName ) )
- {
- throw new XmlPullParserException( "Duplicated tag: '" + tagName + "'", parser, null );
+ if (!parsed.add(tagName)) {
+ throw new XmlPullParserException("Duplicated tag: '" + tagName + "'", parser, null);
}
}
#end
@@ -879,13 +756,11 @@
*
* @param addDefaultEntities a addDefaultEntities object.
*/
- public void setAddDefaultEntities( boolean addDefaultEntities )
- {
+ public void setAddDefaultEntities(boolean addDefaultEntities) {
this.addDefaultEntities = addDefaultEntities;
- } //-- void setAddDefaultEntities( boolean )
+ } //-- void setAddDefaultEntities(boolean)
- public static interface ContentTransformer
- {
+ public static interface ContentTransformer {
/**
* Interpolate the value read from the xpp3 document
* @param source The source value
@@ -893,7 +768,7 @@
* log stuff.
* @return The interpolated value.
*/
- String transform( String source, String fieldName );
+ String transform(String source, String fieldName);
}
}
diff --git a/src/mdo/transformer.vm b/src/mdo/transformer.vm
index 75d602f..8eaac49 100644
--- a/src/mdo/transformer.vm
+++ b/src/mdo/transformer.vm
@@ -51,84 +51,74 @@
import org.codehaus.plexus.util.xml.Xpp3Dom;
@Generated
-public class ${className}
-{
+public class ${className} {
private final Function<String, String> transformer;
- public ${className}( Function<String, String> transformer )
- {
+ public ${className}(Function<String, String> transformer) {
this.transformer = transformer;
}
/**
* Transforms the given model
*/
- public ${root.name} visit( ${root.name} target )
- {
- Objects.requireNonNull( target, "target cannot be null" );
- return transform${root.name}( target );
+ public ${root.name} visit(${root.name} target) {
+ Objects.requireNonNull(target, "target cannot be null");
+ return transform${root.name}(target);
}
/**
* The transformation function.
*/
- protected String transform( String value )
- {
- return transformer.apply( value );
+ protected String transform(String value) {
+ return transformer.apply(value);
}
#foreach ( $class in $model.allClasses )
#if ( $class.name != "InputSource" && $class.name != "InputLocation" )
#set ( $ancestors = $Helper.ancestors( $class ) )
#set ( $allFields = $Helper.xmlFields( $class ) )
- protected ${class.name} transform${class.name}( ${class.name} target )
- {
- if ( target == null )
- {
+ protected ${class.name} transform${class.name}(${class.name} target) {
+ if (target == null) {
return null;
}
- ${class.name}.Builder builder = ${class.name}.newBuilder( target );
+ ${class.name}.Builder builder = ${class.name}.newBuilder(target);
#foreach ( $field in $allFields )
- transform${field.modelClass.name}_${Helper.capitalise($field.name)}( builder, target );
+ transform${field.modelClass.name}_${Helper.capitalise($field.name)}(builder, target);
#end
return builder.build();
}
#foreach ( $field in $allFields )
#set ( $capField = ${Helper.capitalise($field.name)} )
- protected void transform${class.name}_${capField}( ${class.name}.Builder builder, ${class.name} target )
- {
+ protected void transform${class.name}_${capField}(${class.name}.Builder builder, ${class.name} target) {
#if ( $field.type == "String" )
- String newVal = transform( target.get${capField}() );
- builder.${field.name}( newVal != target.get${capField}() ? newVal : null );
+ String newVal = transform(target.get${capField}());
+ builder.${field.name}(newVal != target.get${capField}() ? newVal : null);
#elseif ( $field.type == "java.util.List" && $field.to == "String" && $field.multiplicity == "*" )
- builder.${field.name}( transform( target.get${capField}(), this::transform ) );
+ builder.${field.name}(transform(target.get${capField}(), this::transform));
#elseif ( $field.type == "java.util.Properties" && $field.to == "String" && $field.multiplicity == "*" )
Map<String, String> props = target.get${capField}();
Map<String, String> newProps = null;
- for ( Map.Entry<String, String> entry : props.entrySet() )
- {
- String newVal = transform( entry.getValue() );
- if ( newVal != null && newVal != entry.getValue() )
- {
- if ( newProps == null )
- {
+ for (Map.Entry<String, String> entry : props.entrySet()) {
+ String newVal = transform(entry.getValue());
+ if (newVal != null && newVal != entry.getValue()) {
+ if (newProps == null) {
newProps = new HashMap<>();
- newProps.putAll( props );
- builder.${field.name}( newProps );
+ newProps.putAll(props);
+ builder.${field.name}(newProps);
}
- newProps.put( entry.getKey(), newVal );
+ newProps.put(entry.getKey(), newVal);
}
}
#elseif ( $field.to && $field.multiplicity == "1" )
- ${field.to} newVal = transform${field.to}( target.get${capField}() );
- builder.${field.name}( newVal != target.get${capField}() ? newVal : null );
+ ${field.to} newVal = transform${field.to}(target.get${capField}());
+ builder.${field.name}(newVal != target.get${capField}() ? newVal : null);
#elseif ( $field.to && $field.multiplicity == "*" )
- builder.${field.name}( transform( target.get${capField}(), this::transform${field.to} ) );
+ builder.${field.name}(transform(target.get${capField}(), this::transform${field.to}));
#elseif ( $field.type == "DOM" )
- XmlNode newVal = transform( target.get${capField}() );
- builder.${field.name}( newVal != target.get${capField}() ? newVal : null );
+ XmlNode newVal = transform(target.get${capField}());
+ builder.${field.name}(newVal != target.get${capField}() ? newVal : null);
#elseif ( $field.type == "boolean" || $field.type == "int" || $field.type == "java.nio.file.Path" )
// nothing to do, the transformer only handles strings
#else
@@ -139,61 +129,49 @@
#end
#end
- protected <T> List<T> transform( List<T> list, Function<T, T> transformer )
- {
+ protected <T> List<T> transform(List<T> list, Function<T, T> transformer) {
List<T> newList = null;
- for ( int i = 0; i < list.size(); i++ )
- {
- T newVal = transformer.apply( list.get( i ) );
- if ( newVal != list.get( i ) )
- {
- if ( newList == null )
- {
- newList = new ArrayList<>( list );
+ for (int i = 0; i < list.size(); i++) {
+ T newVal = transformer.apply(list.get(i));
+ if (newVal != list.get(i)) {
+ if (newList == null) {
+ newList = new ArrayList<>(list);
}
- newList.set( i, newVal );
+ newList.set(i, newVal);
}
}
return newList;
}
- protected XmlNode transform( XmlNode node )
- {
- if ( node != null )
- {
- Xpp3Dom xpp = new Xpp3Dom( node );
- transform( xpp );
+ protected XmlNode transform(XmlNode node) {
+ if (node != null) {
+ Xpp3Dom xpp = new Xpp3Dom(node);
+ transform(xpp);
return xpp.getDom();
}
return node;
}
- protected void transform( Xpp3Dom dom )
- {
- if ( dom != null )
- {
+ protected void transform(Xpp3Dom dom) {
+ if (dom != null) {
String org, val;
// Content
org = dom.getValue();
- val = transform( org );
- if ( org != val )
- {
- dom.setValue( val );
+ val = transform(org);
+ if (org != val) {
+ dom.setValue(val);
}
// Attributes
- for ( String attr : dom.getAttributeNames() )
- {
- org = dom.getAttribute( attr );
- val = transform( org );
- if ( org != val )
- {
- dom.setAttribute( attr, val );
+ for (String attr : dom.getAttributeNames()) {
+ org = dom.getAttribute(attr);
+ val = transform(org);
+ if (org != val) {
+ dom.setAttribute(attr, val);
}
}
// Children
- for ( int i = 0, l = dom.getChildCount(); i < l; i++ )
- {
- transform( dom.getChild( i ) );
+ for (int i = 0, l = dom.getChildCount(); i < l; i++) {
+ transform(dom.getChild(i));
}
}
}
diff --git a/src/mdo/writer-ex.vm b/src/mdo/writer-ex.vm
index 903184c..fd66eed 100644
--- a/src/mdo/writer-ex.vm
+++ b/src/mdo/writer-ex.vm
@@ -67,8 +67,8 @@
import org.codehaus.plexus.util.xml.pull.XmlSerializer;
@Generated
-public class ${className}
-{
+public class ${className} {
+
//--------------------------/
//- Class/Member Variables -/
//--------------------------/
@@ -97,20 +97,18 @@
*
* @param fileComment a fileComment object.
*/
- public void setFileComment( String fileComment )
- {
+ public void setFileComment(String fileComment) {
this.fileComment = fileComment;
- } //-- void setFileComment( String )
+ } //-- void setFileComment(String)
/**
* Method setStringFormatter.
*
* @param stringFormatter
*/
- public void setStringFormatter( InputLocation.StringFormatter stringFormatter )
- {
+ public void setStringFormatter(InputLocation.StringFormatter stringFormatter) {
this.stringFormatter = stringFormatter;
- } //-- void setStringFormatter( InputLocation.StringFormatter )
+ } //-- void setStringFormatter(InputLocation.StringFormatter)
/**
* Method write.
@@ -119,17 +117,15 @@
* @param ${rootLcapName} a ${root.name} object
* @throws java.io.IOException java.io.IOException if any
*/
- public void write( Writer writer, ${root.name} ${rootLcapName} )
- throws java.io.IOException
- {
+ public void write(Writer writer, ${root.name} ${rootLcapName}) throws java.io.IOException {
XmlSerializer serializer = new MXSerializer();
- serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-indentation", " " );
- serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-line-separator", "\n" );
- serializer.setOutput( writer );
- serializer.startDocument( ${rootLcapName}.getModelEncoding(), null );
- write${root.name}( "$rootTag", ${rootLcapName}, serializer );
+ serializer.setProperty("http://xmlpull.org/v1/doc/properties.html#serializer-indentation", " ");
+ serializer.setProperty("http://xmlpull.org/v1/doc/properties.html#serializer-line-separator", "\n");
+ serializer.setOutput(writer);
+ serializer.startDocument(${rootLcapName}.getModelEncoding(), null);
+ write${root.name}("$rootTag", ${rootLcapName}, serializer);
serializer.endDocument();
- } //-- void write( Writer, ${root.name} )
+ } //-- void write(Writer, ${root.name})
/**
* Method write.
@@ -138,17 +134,15 @@
* @param ${rootLcapName} a ${root.name} object
* @throws java.io.IOException java.io.IOException if any
*/
- public void write( OutputStream stream, ${root.name} ${rootLcapName} )
- throws java.io.IOException
- {
+ public void write(OutputStream stream, ${root.name} ${rootLcapName}) throws java.io.IOException {
XmlSerializer serializer = new MXSerializer();
- serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-indentation", " " );
- serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-line-separator", "\n" );
- serializer.setOutput( stream, ${rootLcapName}.getModelEncoding() );
- serializer.startDocument( ${rootLcapName}.getModelEncoding(), null );
- write${root.name}( "$rootTag", ${rootLcapName}, serializer );
+ serializer.setProperty("http://xmlpull.org/v1/doc/properties.html#serializer-indentation", " ");
+ serializer.setProperty("http://xmlpull.org/v1/doc/properties.html#serializer-line-separator", "\n");
+ serializer.setOutput(stream, ${rootLcapName}.getModelEncoding());
+ serializer.startDocument(${rootLcapName}.getModelEncoding(), null);
+ write${root.name}("$rootTag", ${rootLcapName}, serializer);
serializer.endDocument();
- } //-- void write( OutputStream, ${root.name} )
+ } //-- void write(OutputStream, ${root.name})
/**
* Method writeDomToSerializer.
@@ -157,29 +151,21 @@
* @param serializer a serializer object.
* @throws java.io.IOException java.io.IOException if any.
*/
- protected void writeDomToSerializer( org.apache.maven.api.xml.XmlNode dom, XmlSerializer serializer )
- throws java.io.IOException
- {
- serializer.startTag( NAMESPACE, dom.getName() );
-
- for ( Map.Entry<String, String> attribute : dom.getAttributes().entrySet() )
- {
- serializer.attribute( NAMESPACE, attribute.getKey(), attribute.getValue() );
+ protected void writeDomToSerializer(org.apache.maven.api.xml.XmlNode dom, XmlSerializer serializer) throws java.io.IOException {
+ serializer.startTag(NAMESPACE, dom.getName());
+ for (Map.Entry<String, String> attribute : dom.getAttributes().entrySet()) {
+ serializer.attribute(NAMESPACE, attribute.getKey(), attribute.getValue());
}
- for ( XmlNode aChild : dom.getChildren() )
- {
- writeDomToSerializer( aChild, serializer );
+ for (XmlNode aChild : dom.getChildren()) {
+ writeDomToSerializer(aChild, serializer);
}
-
String value = dom.getValue();
- if ( value != null )
- {
- serializer.text( value );
+ if (value != null) {
+ serializer.text(value);
}
+ serializer.endTag(NAMESPACE, dom.getName());
- serializer.endTag( NAMESPACE, dom.getName() );
-
- } //-- void writeDomToSerializer( org.apache.maven.api.xml.XmlNode, XmlSerializer )
+ } //-- void writeDomToSerializer(org.apache.maven.api.xml.XmlNode, XmlSerializer)
#foreach ( $class in $model.allClasses )
@@ -187,35 +173,32 @@
#set ( $classUcapName = $Helper.capitalise( $class.name ) )
#set ( $classLcapName = $Helper.uncapitalise( $class.name ) )
#set ( $allFields = $Helper.xmlFields( $class ) )
- private void write${classUcapName}( String tagName, ${classUcapName} ${classLcapName}, XmlSerializer serializer )
- throws IOException
- {
- if ( ${classLcapName} != null )
- {
+ private void write${classUcapName}(String tagName, ${classUcapName} ${classLcapName}, XmlSerializer serializer)
+ throws IOException {
+ if (${classLcapName} != null) {
#if ( $class == $root )
- if ( this.fileComment != null )
- {
+ if (this.fileComment != null) {
serializer.comment(this.fileComment);
}
- serializer.setPrefix( "", "http://maven.apache.org/POM/4.0.0" );
- serializer.setPrefix( "xsi", "http://www.w3.org/2001/XMLSchema-instance" );
- serializer.startTag( NAMESPACE, tagName );
- serializer.attribute( "", "xsi:schemaLocation", "http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" );
+ serializer.setPrefix("", "http://maven.apache.org/POM/4.0.0");
+ serializer.setPrefix("xsi", "http://www.w3.org/2001/XMLSchema-instance");
+ serializer.startTag(NAMESPACE, tagName);
+ serializer.attribute("", "xsi:schemaLocation", "http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd");
#else
- serializer.startTag( NAMESPACE, tagName );
+ serializer.startTag(NAMESPACE, tagName);
#end
#foreach ( $field in $allFields )
#if ( $Helper.xmlFieldMetadata( $field ).attribute )
#set ( $fieldTagName = $Helper.xmlFieldMetadata( $field ).tagName )
#set ( $fieldCapName = $Helper.capitalise( $field.name ) )
#if ( $field.type == "String" )
- writeAttr( "$fieldTagName", ${classLcapName}.get${fieldCapName}(), serializer );
+ writeAttr("$fieldTagName", ${classLcapName}.get${fieldCapName}(), serializer);
#elseif ( $field.type == "boolean" )
#set ( $def = ${field.defaultValue} )
#if ( ${def} == "true" )
- writeAttr( "$fieldTagName", ${classLcapName}.is${fieldCapName}() ? null : "false", serializer );
+ writeAttr("$fieldTagName", ${classLcapName}.is${fieldCapName}() ? null : "false", serializer);
#else
- writeAttr( "$fieldTagName", ${classLcapName}.is${fieldCapName}() ? "true" : null, serializer );
+ writeAttr("$fieldTagName", ${classLcapName}.is${fieldCapName}() ? "true" : null, serializer);
#end
#else
// TODO: type=${field.type} to=${field.to} multiplicity=${field.multiplicity}
@@ -232,137 +215,112 @@
#set ( $def = ${field.defaultValue} )
#if ( $field.type == "String" )
#if ( ! $def )
- writeTag( "$fieldTagName", null, ${classLcapName}.get${fieldCapName}(), serializer, ${classLcapName} );
+ writeTag("$fieldTagName", null, ${classLcapName}.get${fieldCapName}(), serializer, ${classLcapName});
#else
- writeTag( "$fieldTagName", "${def}", ${classLcapName}.get${fieldCapName}(), serializer, ${classLcapName} );
+ writeTag("$fieldTagName", "${def}", ${classLcapName}.get${fieldCapName}(), serializer, ${classLcapName});
#end
#elseif ( $field.type == "boolean" || $field.type == "Boolean" )
#if ( ${def} == "true" )
- writeTag( "$fieldTagName", "${def}", ${classLcapName}.is${fieldCapName}() ? null : "false", serializer, ${classLcapName} );
+ writeTag("$fieldTagName", "${def}", ${classLcapName}.is${fieldCapName}() ? null : "false", serializer, ${classLcapName});
#else
- writeTag( "$fieldTagName", "${def}", ${classLcapName}.is${fieldCapName}() ? "true" : null, serializer, ${classLcapName} );
+ writeTag("$fieldTagName", "${def}", ${classLcapName}.is${fieldCapName}() ? "true" : null, serializer, ${classLcapName});
#end
#elseif ( $field.type == "int" )
- writeTag( "$fieldTagName", "${def}", Integer.toString( ${classLcapName}.get${fieldCapName}() ), serializer, ${classLcapName} );
+ writeTag("$fieldTagName", "${def}", Integer.toString(${classLcapName}.get${fieldCapName}()), serializer, ${classLcapName});
#elseif ( $field.type == "DOM" )
- writeDom( ${classLcapName}.get${fieldCapName}(), serializer );
+ writeDom(${classLcapName}.get${fieldCapName}(), serializer);
#elseif ( $field.type == "java.util.List" && $field.to == "String" && $field.multiplicity == "*" )
#set( $singularField = ${Helper.singular($fieldTagName)} )
- writeList( "$fieldTagName", ${classLcapName}.get${fieldCapName}(), serializer, ${classLcapName},
- t -> writeTag( "$singularField", null, t, serializer, null ) );
+ writeList("$fieldTagName", ${classLcapName}.get${fieldCapName}(), serializer, ${classLcapName},
+ t -> writeTag("$singularField", null, t, serializer, null));
#elseif ( $field.type == "java.util.Properties" && $field.to == "String" && $field.multiplicity == "*" )
- writeProperties( "$fieldTagName", ${classLcapName}.get${fieldCapName}(), serializer, ${classLcapName} );
+ writeProperties("$fieldTagName", ${classLcapName}.get${fieldCapName}(), serializer, ${classLcapName});
#elseif ( $field.to && $field.multiplicity == "1" )
- write${field.to}( "$fieldTagName", ${classLcapName}.get${fieldCapName}(), serializer );
+ write${field.to}("$fieldTagName", ${classLcapName}.get${fieldCapName}(), serializer);
#elseif ( $field.to && $field.multiplicity == "*" )
#set( $singularField = ${Helper.singular($fieldTagName)} )
- writeList( "$fieldTagName", $Helper.isFlatItems($field), ${classLcapName}.get${fieldCapName}(), serializer, ${classLcapName},
- t -> write${field.to}( "$singularField", t, serializer ) );
+ writeList("$fieldTagName", $Helper.isFlatItems($field), ${classLcapName}.get${fieldCapName}(), serializer, ${classLcapName},
+ t -> write${field.to}("$singularField", t, serializer));
#else
// TODO: name=${field.name} type=${field.type} to=${field.to} multiplicity=${field.multiplicity}
#end
#end
#end
- serializer.endTag( NAMESPACE, tagName );
- writeLocationTracking( ${classLcapName}, "", serializer );
+ serializer.endTag(NAMESPACE, tagName);
+ writeLocationTracking(${classLcapName}, "", serializer);
}
}
#end
#end
@FunctionalInterface
- private interface ElementWriter<T>
- {
- public void write( T t ) throws IOException;
+ private interface ElementWriter<T> {
+ public void write(T t) throws IOException;
}
- private <T> void writeList( String tagName, List<T> list, XmlSerializer serializer, InputLocationTracker locationTracker, ElementWriter<T> writer )
- throws IOException
- {
- writeList( tagName, false, list, serializer, locationTracker, writer );
+ private <T> void writeList(String tagName, List<T> list, XmlSerializer serializer, InputLocationTracker locationTracker, ElementWriter<T> writer) throws IOException {
+ writeList(tagName, false, list, serializer, locationTracker, writer);
}
- private <T> void writeList( String tagName, boolean flat, List<T> list, XmlSerializer serializer, InputLocationTracker locationTracker, ElementWriter<T> writer )
- throws IOException
- {
- if ( list != null && !list.isEmpty() )
- {
- if ( !flat )
- {
- serializer.startTag( NAMESPACE, tagName );
+ private <T> void writeList(String tagName, boolean flat, List<T> list, XmlSerializer serializer, InputLocationTracker locationTracker, ElementWriter<T> writer) throws IOException {
+ if (list != null && !list.isEmpty()) {
+ if (!flat) {
+ serializer.startTag(NAMESPACE, tagName);
}
int index = 0;
- InputLocation location = locationTracker != null ? locationTracker.getLocation( tagName ) : null;
- for ( T t : list )
- {
- writer.write( t );
- writeLocationTracking( location, Integer.valueOf( index++ ), serializer );
+ InputLocation location = locationTracker != null ? locationTracker.getLocation(tagName) : null;
+ for (T t : list) {
+ writer.write(t);
+ writeLocationTracking(location, Integer.valueOf(index++), serializer);
}
- if ( !flat )
- {
- serializer.endTag( NAMESPACE, tagName );
- writeLocationTracking( locationTracker, tagName, serializer );
+ if (!flat) {
+ serializer.endTag(NAMESPACE, tagName);
+ writeLocationTracking(locationTracker, tagName, serializer);
}
}
}
- private <T> void writeProperties( String tagName, Map<String, String> props, XmlSerializer serializer, InputLocationTracker locationTracker )
- throws IOException
- {
- if ( props != null && !props.isEmpty() )
- {
- serializer.startTag( NAMESPACE, tagName );
- InputLocation location = locationTracker != null ? locationTracker.getLocation( tagName ) : null;
- for ( Map.Entry<String, String> entry : props.entrySet() )
- {
+ private <T> void writeProperties(String tagName, Map<String, String> props, XmlSerializer serializer, InputLocationTracker locationTracker) throws IOException {
+ if (props != null && !props.isEmpty()) {
+ serializer.startTag(NAMESPACE, tagName);
+ InputLocation location = locationTracker != null ? locationTracker.getLocation(tagName) : null;
+ for (Map.Entry<String, String> entry : props.entrySet()) {
String key = entry.getKey();
- writeTag( key, null, entry.getValue(), serializer, null );
- writeLocationTracking( location, key, serializer );
+ writeTag(key, null, entry.getValue(), serializer, null);
+ writeLocationTracking(location, key, serializer);
}
- serializer.endTag( NAMESPACE, tagName );
- writeLocationTracking( locationTracker, tagName, serializer );
+ serializer.endTag(NAMESPACE, tagName);
+ writeLocationTracking(locationTracker, tagName, serializer);
}
}
- private void writeDom( XmlNode dom, XmlSerializer serializer )
- throws IOException
- {
- if ( dom != null )
- {
- serializer.startTag( NAMESPACE, dom.getName() );
- for ( Map.Entry<String, String> attr : dom.getAttributes().entrySet() )
- {
- serializer.attribute( NAMESPACE, attr.getKey(), attr.getValue() );
+ private void writeDom(XmlNode dom, XmlSerializer serializer) throws IOException {
+ if (dom != null) {
+ serializer.startTag(NAMESPACE, dom.getName());
+ for (Map.Entry<String, String> attr : dom.getAttributes().entrySet()) {
+ serializer.attribute(NAMESPACE, attr.getKey(), attr.getValue());
}
- for ( XmlNode child : dom.getChildren() )
- {
- writeDom( child, serializer );
+ for (XmlNode child : dom.getChildren()) {
+ writeDom(child, serializer);
}
String value = dom.getValue();
- if ( value != null )
- {
- serializer.text( value );
+ if (value != null) {
+ serializer.text(value);
}
- serializer.endTag( NAMESPACE, dom.getName() );
+ serializer.endTag(NAMESPACE, dom.getName());
}
}
- private void writeTag( String tagName, String defaultValue, String value, XmlSerializer serializer, InputLocationTracker locationTracker )
- throws IOException
- {
- if ( value != null && !Objects.equals( defaultValue, value ) )
- {
- serializer.startTag( NAMESPACE, tagName ).text( value ).endTag( NAMESPACE, tagName );
- writeLocationTracking( locationTracker, tagName, serializer );
+ private void writeTag(String tagName, String defaultValue, String value, XmlSerializer serializer, InputLocationTracker locationTracker) throws IOException {
+ if (value != null && !Objects.equals(defaultValue, value)) {
+ serializer.startTag(NAMESPACE, tagName).text(value).endTag(NAMESPACE, tagName);
+ writeLocationTracking(locationTracker, tagName, serializer);
}
}
- private void writeAttr( String attrName, String value, XmlSerializer serializer )
- throws IOException
- {
- if ( value != null )
- {
- serializer.attribute( NAMESPACE, attrName, value );
+ private void writeAttr(String attrName, String value, XmlSerializer serializer) throws IOException {
+ if (value != null) {
+ serializer.attribute(NAMESPACE, attrName, value);
}
}
@@ -374,15 +332,12 @@
* @param key
* @throws java.io.IOException
*/
- protected void writeLocationTracking( InputLocationTracker locationTracker, Object key, XmlSerializer serializer )
- throws java.io.IOException
- {
- InputLocation location = ( locationTracker == null ) ? null : locationTracker.getLocation( key );
- if ( location != null )
- {
- serializer.comment( toString( location ) );
+ protected void writeLocationTracking(InputLocationTracker locationTracker, Object key, XmlSerializer serializer) throws java.io.IOException {
+ InputLocation location = (locationTracker == null) ? null : locationTracker.getLocation(key);
+ if (location != null) {
+ serializer.comment(toString(location));
}
- } //-- void writeLocationTracking( InputLocationTracker, Object, XmlSerializer )
+ } //-- void writeLocationTracking(InputLocationTracker, Object, XmlSerializer)
/**
* Method toString.
@@ -390,12 +345,10 @@
* @param location
* @return String
*/
- protected String toString( InputLocation location )
- {
- if ( stringFormatter != null )
- {
- return stringFormatter.toString( location );
+ protected String toString(InputLocation location) {
+ if (stringFormatter != null) {
+ return stringFormatter.toString(location);
}
return ' ' + location.getSource().toString() + ':' + location.getLineNumber() + ' ';
- } //-- String toString( InputLocation )
+ } //-- String toString(InputLocation)
}
diff --git a/src/mdo/writer.vm b/src/mdo/writer.vm
index a589b60..3999be1 100644
--- a/src/mdo/writer.vm
+++ b/src/mdo/writer.vm
@@ -63,8 +63,8 @@
import org.codehaus.plexus.util.xml.pull.XmlSerializer;
@Generated
-public class ${className}
-{
+public class ${className} {
+
//--------------------------/
//- Class/Member Variables -/
//--------------------------/
@@ -89,10 +89,9 @@
*
* @param fileComment a fileComment object.
*/
- public void setFileComment( String fileComment )
- {
+ public void setFileComment(String fileComment) {
this.fileComment = fileComment;
- } //-- void setFileComment( String )
+ } //-- void setFileComment(String)
/**
* Method write.
@@ -101,17 +100,15 @@
* @param ${rootLcapName} a ${root.name} object
* @throws java.io.IOException java.io.IOException if any
*/
- public void write( Writer writer, ${root.name} ${rootLcapName} )
- throws java.io.IOException
- {
+ public void write(Writer writer, ${root.name} ${rootLcapName}) throws java.io.IOException {
XmlSerializer serializer = new MXSerializer();
- serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-indentation", " " );
- serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-line-separator", "\n" );
- serializer.setOutput( writer );
- serializer.startDocument( ${rootLcapName}.getModelEncoding(), null );
- write${root.name}( "$rootTag", ${rootLcapName}, serializer );
+ serializer.setProperty("http://xmlpull.org/v1/doc/properties.html#serializer-indentation", " ");
+ serializer.setProperty("http://xmlpull.org/v1/doc/properties.html#serializer-line-separator", "\n");
+ serializer.setOutput(writer);
+ serializer.startDocument(${rootLcapName}.getModelEncoding(), null);
+ write${root.name}("$rootTag", ${rootLcapName}, serializer);
serializer.endDocument();
- } //-- void write( Writer, ${root.name} )
+ } //-- void write(Writer, ${root.name})
/**
* Method write.
@@ -120,17 +117,15 @@
* @param ${rootLcapName} a ${root.name} object
* @throws java.io.IOException java.io.IOException if any
*/
- public void write( OutputStream stream, ${root.name} ${rootLcapName} )
- throws java.io.IOException
- {
+ public void write(OutputStream stream, ${root.name} ${rootLcapName}) throws java.io.IOException {
XmlSerializer serializer = new MXSerializer();
- serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-indentation", " " );
- serializer.setProperty( "http://xmlpull.org/v1/doc/properties.html#serializer-line-separator", "\n" );
- serializer.setOutput( stream, ${rootLcapName}.getModelEncoding() );
- serializer.startDocument( ${rootLcapName}.getModelEncoding(), null );
- write${root.name}( "$rootTag", ${rootLcapName}, serializer );
+ serializer.setProperty("http://xmlpull.org/v1/doc/properties.html#serializer-indentation", " ");
+ serializer.setProperty("http://xmlpull.org/v1/doc/properties.html#serializer-line-separator", "\n");
+ serializer.setOutput(stream, ${rootLcapName}.getModelEncoding());
+ serializer.startDocument(${rootLcapName}.getModelEncoding(), null);
+ write${root.name}("$rootTag", ${rootLcapName}, serializer);
serializer.endDocument();
- } //-- void write( OutputStream, ${root.name} )
+ } //-- void write(OutputStream, ${root.name})
/**
* Method writeDomToSerializer.
@@ -139,29 +134,21 @@
* @param serializer a serializer object.
* @throws java.io.IOException java.io.IOException if any.
*/
- protected void writeDomToSerializer( org.apache.maven.api.xml.XmlNode dom, XmlSerializer serializer )
- throws java.io.IOException
- {
- serializer.startTag( NAMESPACE, dom.getName() );
-
- for ( Map.Entry<String, String> attribute : dom.getAttributes().entrySet() )
- {
- serializer.attribute( NAMESPACE, attribute.getKey(), attribute.getValue() );
+ protected void writeDomToSerializer(org.apache.maven.api.xml.XmlNode dom, XmlSerializer serializer) throws java.io.IOException {
+ serializer.startTag(NAMESPACE, dom.getName());
+ for (Map.Entry<String, String> attribute : dom.getAttributes().entrySet()) {
+ serializer.attribute(NAMESPACE, attribute.getKey(), attribute.getValue());
}
- for ( XmlNode aChild : dom.getChildren() )
- {
- writeDomToSerializer( aChild, serializer );
+ for (XmlNode aChild : dom.getChildren()) {
+ writeDomToSerializer(aChild, serializer);
}
-
String value = dom.getValue();
- if ( value != null )
- {
- serializer.text( value );
+ if (value != null) {
+ serializer.text(value);
}
+ serializer.endTag(NAMESPACE, dom.getName());
- serializer.endTag( NAMESPACE, dom.getName() );
-
- } //-- void writeDomToSerializer( org.apache.maven.api.xml.XmlNode, XmlSerializer )
+ } //-- void writeDomToSerializer(org.apache.maven.api.xml.XmlNode, XmlSerializer)
#foreach ( $class in $model.allClasses )
@@ -169,35 +156,31 @@
#set ( $classUcapName = $Helper.capitalise( $class.name ) )
#set ( $classLcapName = $Helper.uncapitalise( $class.name ) )
#set ( $allFields = $Helper.xmlFields( $class ) )
- private void write${classUcapName}( String tagName, ${classUcapName} ${classLcapName}, XmlSerializer serializer )
- throws IOException
- {
- if ( ${classLcapName} != null )
- {
+ private void write${classUcapName}(String tagName, ${classUcapName} ${classLcapName}, XmlSerializer serializer) throws IOException {
+ if (${classLcapName} != null) {
#if ( $class == $root )
- if ( this.fileComment != null )
- {
+ if (this.fileComment != null) {
serializer.comment(this.fileComment);
}
- serializer.setPrefix( "", "http://maven.apache.org/POM/4.0.0" );
- serializer.setPrefix( "xsi", "http://www.w3.org/2001/XMLSchema-instance" );
- serializer.startTag( NAMESPACE, tagName );
- serializer.attribute( "", "xsi:schemaLocation", "http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" );
+ serializer.setPrefix("", "http://maven.apache.org/POM/4.0.0");
+ serializer.setPrefix("xsi", "http://www.w3.org/2001/XMLSchema-instance");
+ serializer.startTag(NAMESPACE, tagName);
+ serializer.attribute("", "xsi:schemaLocation", "http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd");
#else
- serializer.startTag( NAMESPACE, tagName );
+ serializer.startTag(NAMESPACE, tagName);
#end
#foreach ( $field in $allFields )
#if ( $Helper.xmlFieldMetadata( $field ).attribute )
#set ( $fieldTagName = $Helper.xmlFieldMetadata( $field ).tagName )
#set ( $fieldCapName = $Helper.capitalise( $field.name ) )
#if ( $field.type == "String" )
- writeAttr( "$fieldTagName", ${classLcapName}.get${fieldCapName}(), serializer );
+ writeAttr("$fieldTagName", ${classLcapName}.get${fieldCapName}(), serializer);
#elseif ( $field.type == "boolean" )
#set ( $def = ${field.defaultValue} )
#if ( ${def} == "true" )
- writeAttr( "$fieldTagName", ${classLcapName}.is${fieldCapName}() ? null : "false", serializer );
+ writeAttr("$fieldTagName", ${classLcapName}.is${fieldCapName}() ? null : "false", serializer);
#else
- writeAttr( "$fieldTagName", ${classLcapName}.is${fieldCapName}() ? "true" : null, serializer );
+ writeAttr("$fieldTagName", ${classLcapName}.is${fieldCapName}() ? "true" : null, serializer);
#end
#else
// TODO: type=${field.type} to=${field.to} multiplicity=${field.multiplicity}
@@ -214,125 +197,100 @@
#set ( $def = ${field.defaultValue} )
#if ( $field.type == "String" )
#if ( ! $def )
- writeTag( "$fieldTagName", null, ${classLcapName}.get${fieldCapName}(), serializer );
+ writeTag("$fieldTagName", null, ${classLcapName}.get${fieldCapName}(), serializer);
#else
- writeTag( "$fieldTagName", "${def}", ${classLcapName}.get${fieldCapName}(), serializer );
+ writeTag("$fieldTagName", "${def}", ${classLcapName}.get${fieldCapName}(), serializer);
#end
#elseif ( $field.type == "boolean" || $field.type == "Boolean" )
#if ( ${def} == "true" )
- writeTag( "$fieldTagName", "${def}", ${classLcapName}.is${fieldCapName}() ? null : "false", serializer );
+ writeTag("$fieldTagName", "${def}", ${classLcapName}.is${fieldCapName}() ? null : "false", serializer);
#else
- writeTag( "$fieldTagName", "${def}", ${classLcapName}.is${fieldCapName}() ? "true" : null, serializer );
+ writeTag("$fieldTagName", "${def}", ${classLcapName}.is${fieldCapName}() ? "true" : null, serializer);
#end
#elseif ( $field.type == "int" )
- writeTag( "$fieldTagName", "${def}", Integer.toString( ${classLcapName}.get${fieldCapName}() ), serializer );
+ writeTag("$fieldTagName", "${def}", Integer.toString(${classLcapName}.get${fieldCapName}()), serializer);
#elseif ( $field.type == "DOM" )
- writeDom( ${classLcapName}.get${fieldCapName}(), serializer );
+ writeDom(${classLcapName}.get${fieldCapName}(), serializer);
#elseif ( $field.type == "java.util.List" && $field.to == "String" && $field.multiplicity == "*" )
#set( $singularField = ${Helper.singular($fieldTagName)} )
- writeList( "$fieldTagName", ${classLcapName}.get${fieldCapName}(), serializer, t -> writeTag( "$singularField", "${def}", t, serializer ) );
+ writeList("$fieldTagName", ${classLcapName}.get${fieldCapName}(), serializer, t -> writeTag("$singularField", "${def}", t, serializer));
#elseif ( $field.type == "java.util.Properties" && $field.to == "String" && $field.multiplicity == "*" )
- writeProperties( "$fieldTagName", ${classLcapName}.get${fieldCapName}(), serializer );
+ writeProperties("$fieldTagName", ${classLcapName}.get${fieldCapName}(), serializer);
#elseif ( $field.to && $field.multiplicity == "1" )
- write${field.to}( "$fieldTagName", ${classLcapName}.get${fieldCapName}(), serializer );
+ write${field.to}("$fieldTagName", ${classLcapName}.get${fieldCapName}(), serializer);
#elseif ( $field.to && $field.multiplicity == "*" )
#set( $singularField = ${Helper.singular($fieldTagName)} )
- writeList( "$fieldTagName", $Helper.isFlatItems($field), ${classLcapName}.get${fieldCapName}(), serializer, t -> write${field.to}( "$singularField", t, serializer ) );
+ writeList("$fieldTagName", $Helper.isFlatItems($field), ${classLcapName}.get${fieldCapName}(), serializer, t -> write${field.to}("$singularField", t, serializer));
#else
// TODO: name=${field.name} type=${field.type} to=${field.to} multiplicity=${field.multiplicity}
#end
#end
#end
- serializer.endTag( NAMESPACE, tagName );
+ serializer.endTag(NAMESPACE, tagName);
}
}
#end
#end
@FunctionalInterface
- private interface ElementWriter<T>
- {
- public void write( T t ) throws IOException;
+ private interface ElementWriter<T> {
+ public void write(T t) throws IOException;
}
- private <T> void writeList( String tagName, List<T> list, XmlSerializer serializer, ElementWriter<T> writer )
- throws IOException
- {
- writeList( tagName, false, list, serializer, writer );
+ private <T> void writeList(String tagName, List<T> list, XmlSerializer serializer, ElementWriter<T> writer) throws IOException {
+ writeList(tagName, false, list, serializer, writer);
}
- private <T> void writeList( String tagName, boolean flat, List<T> list, XmlSerializer serializer, ElementWriter<T> writer )
- throws IOException
- {
- if ( list != null && !list.isEmpty() )
- {
- if ( !flat )
- {
- serializer.startTag( NAMESPACE, tagName );
+ private <T> void writeList(String tagName, boolean flat, List<T> list, XmlSerializer serializer, ElementWriter<T> writer) throws IOException {
+ if (list != null && !list.isEmpty()) {
+ if (!flat) {
+ serializer.startTag(NAMESPACE, tagName);
}
- for ( T t : list )
- {
- writer.write( t );
+ for (T t : list) {
+ writer.write(t);
}
- if ( !flat )
- {
- serializer.endTag( NAMESPACE, tagName );
+ if (!flat) {
+ serializer.endTag(NAMESPACE, tagName);
}
}
}
- private <T> void writeProperties( String tagName, Map<String, String> props, XmlSerializer serializer )
- throws IOException
- {
- if ( props != null && !props.isEmpty() )
- {
- serializer.startTag( NAMESPACE, tagName );
- for ( Map.Entry<String, String> entry : props.entrySet() )
- {
- writeTag( entry.getKey(), null, entry.getValue(), serializer );
+ private <T> void writeProperties(String tagName, Map<String, String> props, XmlSerializer serializer) throws IOException {
+ if (props != null && !props.isEmpty()) {
+ serializer.startTag(NAMESPACE, tagName);
+ for (Map.Entry<String, String> entry : props.entrySet()) {
+ writeTag(entry.getKey(), null, entry.getValue(), serializer);
}
- serializer.endTag( NAMESPACE, tagName );
+ serializer.endTag(NAMESPACE, tagName);
}
}
- private void writeDom( XmlNode dom, XmlSerializer serializer )
- throws IOException
- {
- if ( dom != null )
- {
- serializer.startTag( NAMESPACE, dom.getName() );
- for ( Map.Entry<String, String> attr : dom.getAttributes().entrySet() )
- {
- serializer.attribute( NAMESPACE, attr.getKey(), attr.getValue() );
+ private void writeDom(XmlNode dom, XmlSerializer serializer) throws IOException {
+ if (dom != null) {
+ serializer.startTag(NAMESPACE, dom.getName());
+ for (Map.Entry<String, String> attr : dom.getAttributes().entrySet()) {
+ serializer.attribute(NAMESPACE, attr.getKey(), attr.getValue());
}
- for ( XmlNode child : dom.getChildren() )
- {
- writeDom( child, serializer );
+ for (XmlNode child : dom.getChildren()) {
+ writeDom(child, serializer);
}
String value = dom.getValue();
- if ( value != null )
- {
- serializer.text( value );
+ if (value != null) {
+ serializer.text(value);
}
- serializer.endTag( NAMESPACE, dom.getName() );
+ serializer.endTag(NAMESPACE, dom.getName());
}
}
- private void writeTag( String tagName, String defaultValue, String value, XmlSerializer serializer )
- throws IOException
- {
- if ( value != null && !Objects.equals( defaultValue, value ) )
- {
- serializer.startTag( NAMESPACE, tagName ).text( value ).endTag( NAMESPACE, tagName );
+ private void writeTag(String tagName, String defaultValue, String value, XmlSerializer serializer) throws IOException {
+ if (value != null && !Objects.equals(defaultValue, value)) {
+ serializer.startTag(NAMESPACE, tagName).text(value).endTag(NAMESPACE, tagName);
}
}
- private void writeAttr( String attrName, String value, XmlSerializer serializer )
- throws IOException
- {
- if ( value != null )
- {
- serializer.attribute( NAMESPACE, attrName, value );
+ private void writeAttr(String attrName, String value, XmlSerializer serializer) throws IOException {
+ if (value != null) {
+ serializer.attribute(NAMESPACE, attrName, value);
}
}