Commit c56fb3af authored by Dominique Marcadet's avatar Dominique Marcadet

create superclass GenericPresenceCondiitonValidator

to avoid much of duplicated code.
Not yet done for DataObjectPresenceCondiitonValidator.
parent 5fe034e7
......@@ -18,7 +18,6 @@
*/
package fr.centralesupelec.edf.riseclipse.iec61850.scl.validator.nsd;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
......
......@@ -45,11 +45,12 @@ public class CDCValidator {
.forEach( cdc -> validators.put( cdc.getName(), new CDCValidator( cdc )));
}
private static HashSet< String > validatedDOType = new HashSet<>();
private DataAttributePresenceConditionValidator dataAttributePresenceConditionValidator;
private SubDataObjectPresenceConditionValidator subDataObjectPresenceConditionValidator;
private HashMap< String, TypeValidator > dataAttributeValidatorMap = new HashMap<>();
private HashMap< String, CDCValidator > subDataObjectValidatorMap = new HashMap<>();
private HashSet< DOType > validatedDOType = new HashSet<>();
private CDCValidator( CDC cdc ) {
dataAttributePresenceConditionValidator = DataAttributePresenceConditionValidator.get( cdc );
......@@ -78,15 +79,15 @@ public class CDCValidator {
}
public boolean validateDOType( DOType doType, DiagnosticChain diagnostics ) {
if( validatedDOType.contains( doType )) return true;
if( validatedDOType.contains( doType.getId() )) return true;
AbstractRiseClipseConsole.getConsole().verbose( "[NSD validation] CDCValidator.validateDOType( " + doType.getId() + " ) at line " + doType.getLineNumber() );
validatedDOType.add( doType );
validatedDOType.add( doType.getId() );
dataAttributePresenceConditionValidator.reset();
doType
.getDA()
.stream()
.forEach( d -> dataAttributePresenceConditionValidator.addDA( d, diagnostics ));
.forEach( d -> dataAttributePresenceConditionValidator.addModelData( d, d.getName(), diagnostics ));
boolean res = dataAttributePresenceConditionValidator.validate( doType, diagnostics );
......@@ -94,7 +95,7 @@ public class CDCValidator {
doType
.getSDO()
.stream()
.forEach( d -> subDataObjectPresenceConditionValidator.addSDO( d, diagnostics ));
.forEach( d -> subDataObjectPresenceConditionValidator.addModelData( d, d.getName(), diagnostics ));
res = subDataObjectPresenceConditionValidator.validate( doType, diagnostics ) && res;
......
......@@ -32,9 +32,10 @@ import fr.centralesupelec.edf.riseclipse.util.AbstractRiseClipseConsole;
public class ConstructedAttributeValidator extends TypeValidator {
private static HashSet< String > validatedDAType = new HashSet<>();
private SubDataAttributePresenceConditionValidator subDataAttributePresenceConditionValidator;
private HashMap< String, TypeValidator > subDataAttributeValidatorMap = new HashMap<>();
private HashSet< DAType > validatedDAType = new HashSet<>();
public ConstructedAttributeValidator( ConstructedAttribute contructedAttribute ) {
subDataAttributePresenceConditionValidator = SubDataAttributePresenceConditionValidator.get( contructedAttribute );
......@@ -62,15 +63,15 @@ public class ConstructedAttributeValidator extends TypeValidator {
}
private boolean validateDAType( DAType daType, DiagnosticChain diagnostics ) {
if( validatedDAType.contains( daType )) return true;
if( validatedDAType.contains( daType.getId() )) return true;
AbstractRiseClipseConsole.getConsole().verbose( "[NSD validation] ConstructedAttributeValidator.validateDAType( " + daType.getId() + " ) at line " + daType.getLineNumber() );
validatedDAType.add( daType );
validatedDAType.add( daType.getId() );
subDataAttributePresenceConditionValidator.reset();
daType
.getBDA()
.stream()
.forEach( bda -> subDataAttributePresenceConditionValidator.addBDA( bda, diagnostics ));
.forEach( bda -> subDataAttributePresenceConditionValidator.addModelData( bda, bda.getName(), diagnostics ));
boolean res = subDataAttributePresenceConditionValidator.validate( daType, diagnostics );
......
......@@ -37,11 +37,12 @@ import fr.centralesupelec.edf.riseclipse.util.AbstractRiseClipseConsole;
public class EnumerationValidator extends TypeValidator {
private static HashSet< String > validatedEnumType = new HashSet<>();
private HashMap< String, Integer > literals = new HashMap<>();
private String name;
private String inheritedFromName;
private EnumerationValidator inheritedFrom;
private HashSet< EnumType > validatedEnumType = new HashSet<>();
public EnumerationValidator( Enumeration enumeration ) {
this.name = enumeration.getName();
......@@ -139,9 +140,9 @@ public class EnumerationValidator extends TypeValidator {
}
public boolean validateEnumType( EnumType enumType, DiagnosticChain diagnostics ) {
if( validatedEnumType.contains( enumType )) return true;
if( validatedEnumType.contains( enumType.getId() )) return true;
AbstractRiseClipseConsole.getConsole().verbose( "[NSD validation] EnumerationValidator.validateEnumType( " + enumType.getId() + " ) at line " + enumType.getLineNumber() );
validatedEnumType.add( enumType );
validatedEnumType.add( enumType.getId() );
boolean res = true;
......
......@@ -45,9 +45,10 @@ public class LNClassValidator {
.forEach( lnClass -> validators.put( lnClass.getName(), new LNClassValidator( lnClass )));
}
private static HashSet< String > validatedLNodeType = new HashSet<>();
private DataObjectPresenceConditionValidator dataObjectPresenceConditionValidator;
private HashMap< String, CDCValidator > dataObjectValidatorMap = new HashMap<>();
private HashSet< LNodeType > validatedLNodeType = new HashSet<>();
private LNClassValidator( AnyLNClass anyLNClass ) {
dataObjectPresenceConditionValidator = DataObjectPresenceConditionValidator.get( anyLNClass );
......@@ -69,9 +70,9 @@ public class LNClassValidator {
}
public boolean validateLNodeType( LNodeType lNodeType, DiagnosticChain diagnostics ) {
if( validatedLNodeType.contains( lNodeType )) return true;
if( validatedLNodeType.contains( lNodeType.getId() )) return true;
AbstractRiseClipseConsole.getConsole().verbose( "[NSD validation] LNClassValidator.validateLNodeType( " + lNodeType.getId() + " ) at line " + lNodeType.getLineNumber() );
validatedLNodeType.add( lNodeType );
validatedLNodeType.add( lNodeType.getId() );
boolean res = true;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment