Skip to content

Commit 9ba65d8

Browse files
committed
rename parameter and flag
leave out negation
1 parent c24cf75 commit 9ba65d8

File tree

5 files changed

+16
-14
lines changed

5 files changed

+16
-14
lines changed

modello-core/src/main/java/org/codehaus/modello/ModelloParameterConstants.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,12 @@ public class ModelloParameterConstants
7272
public static final String EXTENDED_CLASSNAME_SUFFIX = "modello.xpp3.extended.suffix";
7373

7474
/**
75-
* Boolean flag relaxing XSD generation with regards to mandatory elements.
76-
* If set to {@code true} will not require mandatory elements in the XML which can be useful if the XML is post processed (e.g. POM merging with parents)
75+
* Boolean flag enforcing existence of mandatory elements in the XSD.
76+
* If set to {@code false} will not require mandatory elements in the XML which can be useful if the XML is post processed (e.g. POM merging with parents)
77+
* where mandatory elements might be contributed by sources outside the XML.
7778
* @since 2.1
7879
*/
79-
public static final String XSD_MANDATORY_ELEMENTS_NOT_ENFORCED = "modello.xsd.mandatory.element.not.enforced";
80+
public static final String XSD_ENFORCE_MANDATORY_ELEMENTS = "modello.xsd.enforce.mandatory.element";
8081
private ModelloParameterConstants()
8182
{
8283
}

modello-maven-plugin/src/main/java/org/codehaus/modello/maven/ModelloXsdMojo.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@ public class ModelloXsdMojo
4848
/**
4949
* Boolean flag relaxing XSD generation with regards to mandatory elements.
5050
* If set to {@code true} will not require mandatory elements in the XML which can be useful if the XML is post processed (e.g. POM merging with parents).
51-
* The default value is true for backwards compatibility reasons, but should be set to false for most cases.
51+
* The default value is {@code false} for backwards compatibility reasons, but should be set to {@code true} for most cases.
5252
* @since 2.1.0
5353
*/
54-
@Parameter( defaultValue = "true")
55-
private boolean areMandatoryElementsNotEnforced;
54+
@Parameter( defaultValue = "false")
55+
private boolean enforceMandatoryElements;
5656

5757
/**
5858
*
@@ -74,7 +74,7 @@ protected void customizeParameters( Properties parameters )
7474
{
7575
parameters.put( ModelloParameterConstants.OUTPUT_XSD_FILE_NAME, xsdFileName );
7676
}
77-
parameters.put( ModelloParameterConstants.XSD_MANDATORY_ELEMENTS_NOT_ENFORCED, areMandatoryElementsNotEnforced );
77+
parameters.put( ModelloParameterConstants.XSD_ENFORCE_MANDATORY_ELEMENTS, enforceMandatoryElements );
7878
}
7979

8080
protected boolean producesCompilableResult()

modello-plugins/modello-plugin-xsd/src/main/java/org/codehaus/modello/plugin/xsd/XsdGenerator.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ private void generateXsd( Properties parameters )
8787

8888
// we assume parameters not null
8989
String xsdFileName = parameters.getProperty( ModelloParameterConstants.OUTPUT_XSD_FILE_NAME );
90-
boolean areMandatoryElementsEnforced = !Boolean.valueOf( parameters.getProperty( ModelloParameterConstants.XSD_MANDATORY_ELEMENTS_NOT_ENFORCED ) );
90+
boolean enforceMandatoryElements = Boolean.parseBoolean( parameters.getProperty( ModelloParameterConstants.XSD_ENFORCE_MANDATORY_ELEMENTS ) );
9191

9292
File f = new File( directory, objectModel.getId() + "-" + getGeneratedVersion() + ".xsd" );
9393

@@ -139,7 +139,7 @@ private void generateXsd( Properties parameters )
139139
// Traverse from root so "abstract" models aren't included
140140
int initialCapacity = objectModel.getClasses( getGeneratedVersion() ).size();
141141
writeComplexTypeDescriptor( w, objectModel, root, new HashSet<ModelClass>( initialCapacity ),
142-
areMandatoryElementsEnforced );
142+
enforceMandatoryElements );
143143

144144
w.endElement();
145145
}
@@ -186,7 +186,7 @@ private static void writeDocumentation( XMLWriter w, String version, String desc
186186
}
187187

188188
private void writeComplexTypeDescriptor( XMLWriter w, Model objectModel, ModelClass modelClass,
189-
Set<ModelClass> written, boolean areMandatoryElementsEnforced )
189+
Set<ModelClass> written, boolean enforceMandatoryElements )
190190
{
191191
written.add( modelClass );
192192

@@ -244,7 +244,7 @@ private void writeComplexTypeDescriptor( XMLWriter w, Model objectModel, ModelCl
244244
{
245245
w.startElement( "xs:element" );
246246

247-
if ( !areMandatoryElementsEnforced || !field.isRequired() )
247+
if ( !enforceMandatoryElements || !field.isRequired() )
248248
{
249249
// Usually, would only do this if the field is not "required", but due to inheritance, it may be
250250
// present, even if not here, so we need to let it slide
@@ -433,7 +433,7 @@ else if ( xsdType == null )
433433
{
434434
if ( !written.contains( fieldModelClass ) )
435435
{
436-
writeComplexTypeDescriptor( w, objectModel, fieldModelClass, written, areMandatoryElementsEnforced );
436+
writeComplexTypeDescriptor( w, objectModel, fieldModelClass, written, enforceMandatoryElements );
437437
}
438438
}
439439
}

modello-plugins/modello-plugin-xsd/src/test/java/org/codehaus/modello/plugin/xsd/FeaturesXsdGeneratorTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
import org.codehaus.modello.AbstractModelloGeneratorTest;
2626
import org.codehaus.modello.ModelloException;
27+
import org.codehaus.modello.ModelloParameterConstants;
2728
import org.codehaus.modello.core.ModelloCore;
2829
import org.codehaus.modello.model.Model;
2930
import org.xml.sax.SAXParseException;
@@ -56,7 +57,8 @@ public void testXsdGenerator()
5657
Model model = modello.loadModel( getXmlResourceReader( "/features.mdo" ) );
5758

5859
Properties parameters = getModelloParameters( "1.0.0" );
59-
60+
parameters.setProperty( ModelloParameterConstants.XSD_ENFORCE_MANDATORY_ELEMENTS, "true" );
61+
6062
modello.generate( model, "xsd", parameters );
6163

6264
SchemaFactory sf = SchemaFactory.newInstance( XMLConstants.W3C_XML_SCHEMA_NS_URI );

modello-plugins/modello-plugin-xsd/src/test/java/org/codehaus/modello/plugin/xsd/ModelloXsdGeneratorTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ public void testXsdGenerator()
5656
ModelloCore modello = (ModelloCore) lookup( ModelloCore.ROLE );
5757

5858
Properties parameters = getModelloParameters( "1.4.0" );
59-
parameters.setProperty( ModelloParameterConstants.XSD_MANDATORY_ELEMENTS_NOT_ENFORCED, "true" );
6059

6160
Model model = modello.loadModel( getTestFile( "../../src/main/mdo/modello.mdo" ) );
6261

0 commit comments

Comments
 (0)