Commit 6a846b37 authored by Dominique Marcadet's avatar Dominique Marcadet

add SubDataObject check

and some renaming, performance improvement...
parent d269f38f
......@@ -18,31 +18,90 @@
*/
package fr.centralesupelec.edf.riseclipse.iec61850.scl.validator.nsd;
import java.util.HashMap;
import java.util.HashSet;
import java.util.stream.Stream;
import org.eclipse.emf.common.util.DiagnosticChain;
import fr.centralesupelec.edf.riseclipse.iec61850.nsd.CDC;
import fr.centralesupelec.edf.riseclipse.iec61850.nsd.SubDataObject;
import fr.centralesupelec.edf.riseclipse.iec61850.scl.DOType;
import fr.centralesupelec.edf.riseclipse.iec61850.scl.SDO;
import fr.centralesupelec.edf.riseclipse.util.AbstractRiseClipseConsole;
public class DOTypeValidator {
public class CDCValidator {
private static HashMap< String, CDCValidator > validators = new HashMap<>();
public static CDCValidator get( String name ) {
return validators.get( name );
}
public static void buildValidators( Stream< CDC > stream ) {
stream
.forEach( cdc -> validators.put( cdc.getName(), new CDCValidator( cdc )));
}
private DataAttributePresenceConditionValidator dataAttributePresenceConditionValidator;
private SubDataObjectPresenceConditionValidator subDataObjectPresenceConditionValidator;
private HashMap< String, CDCValidator > subDataObjectValidatorMap = new HashMap<>();
private HashSet< DOType > validatedDOType = new HashSet<>();
public DOTypeValidator( CDC cdc ) {
private CDCValidator( CDC cdc ) {
dataAttributePresenceConditionValidator = DataAttributePresenceConditionValidator.get( cdc );
subDataObjectPresenceConditionValidator = SubDataObjectPresenceConditionValidator.get( cdc );
for( SubDataObject sdo : cdc.getSubDataObject() ) {
CDCValidator validator = CDCValidator.get( sdo.getType() );
if( validator != null ) {
subDataObjectValidatorMap.put( sdo.getName(), validator );
}
else {
AbstractRiseClipseConsole.getConsole().warning( "[NSD setup] CDC not found for SubDataObject " + sdo.getName() );
}
}
}
public boolean validateDOType( DOType doType, DiagnosticChain diagnostics ) {
AbstractRiseClipseConsole.getConsole().verbose( "[NSD] validateDOType( " + doType.getId() + " )" );
dataAttributePresenceConditionValidator.reset();
if( validatedDOType.contains( doType )) return true;
AbstractRiseClipseConsole.getConsole().verbose( "[NSD validation] CDCValidator.validateDOType( " + doType.getId() + " ) at line " + doType.getLineNumber() );
validatedDOType.add( doType );
dataAttributePresenceConditionValidator.reset();
doType
.getDA()
.stream()
.forEach( d -> dataAttributePresenceConditionValidator.addDA( d, diagnostics ));
return dataAttributePresenceConditionValidator.validate( doType, diagnostics );
boolean res = dataAttributePresenceConditionValidator.validate( doType, diagnostics );
subDataObjectPresenceConditionValidator.reset();
doType
.getSDO()
.stream()
.forEach( d -> subDataObjectPresenceConditionValidator.addSDO( d, diagnostics ));
res = subDataObjectPresenceConditionValidator.validate( doType, diagnostics ) && res;
for( SDO sdo : doType.getSDO() ) {
CDCValidator validator = subDataObjectValidatorMap.get( sdo.getName() );
if( validator != null ) {
if( sdo.getRefersToDOType() != null ) {
AbstractRiseClipseConsole.getConsole().verbose( "[NSD validation] validateDOType( " + doType.getId() + " ) on sdo " + sdo.getName() );
res = validator.validateDOType( sdo.getRefersToDOType(), diagnostics ) && res;
}
else {
AbstractRiseClipseConsole.getConsole().warning( "[NSD validation] while validating DOType (line " + doType.getLineNumber() + "): DOType for SDO " + sdo.getName() + " not found" );
}
}
else {
AbstractRiseClipseConsole.getConsole().warning( "[NSD validation] while validating DOType (line " + doType.getLineNumber() + "): validator for SDO " + sdo.getType() + " not found" );
}
}
return res;
}
}
......@@ -562,6 +562,8 @@ public class DataAttributePresenceConditionValidator {
}
public boolean validate( DOType doType, DiagnosticChain diagnostics ) {
AbstractRiseClipseConsole.getConsole().verbose( "[NSD validation] DataAttributePresenceConditionValidator.validate( " + doType.getId() + " ) at line " + doType.getLineNumber() );
boolean res = true;
// presCond: "M"
......
......@@ -19,31 +19,45 @@
package fr.centralesupelec.edf.riseclipse.iec61850.scl.validator.nsd;
import java.util.HashMap;
import java.util.HashSet;
import java.util.stream.Stream;
import org.eclipse.emf.common.util.DiagnosticChain;
import fr.centralesupelec.edf.riseclipse.iec61850.nsd.AnyLNClass;
import fr.centralesupelec.edf.riseclipse.iec61850.nsd.CDC;
import fr.centralesupelec.edf.riseclipse.iec61850.nsd.DataObject;
import fr.centralesupelec.edf.riseclipse.iec61850.nsd.LNClass;
import fr.centralesupelec.edf.riseclipse.iec61850.scl.DO;
import fr.centralesupelec.edf.riseclipse.iec61850.scl.DOType;
import fr.centralesupelec.edf.riseclipse.iec61850.scl.LNodeType;
import fr.centralesupelec.edf.riseclipse.util.AbstractRiseClipseConsole;
public class LNodeTypeValidator {
public class LNClassValidator {
private static HashMap< String, LNClassValidator > validators = new HashMap<>();
public static LNClassValidator get( String name ) {
return validators.get( name );
}
public static void buildValidators( Stream< LNClass > stream ) {
stream
.forEach( lnClass -> validators.put( lnClass.getName(), new LNClassValidator( lnClass )));
}
private DataObjectPresenceConditionValidator dataObjectPresenceConditionValidator;
private HashMap< String, DOTypeValidator > doTypeValidatorMap = new HashMap<>();
private HashMap< String, CDCValidator > dataObjectValidatorMap = new HashMap<>();
private HashSet< LNodeType > validatedLNodeType = new HashSet<>();
public LNodeTypeValidator( AnyLNClass anyLNClass ) {
private LNClassValidator( AnyLNClass anyLNClass ) {
dataObjectPresenceConditionValidator = DataObjectPresenceConditionValidator.get( anyLNClass );
AnyLNClass lnClass = anyLNClass;
while( lnClass != null ) {
for( DataObject do_ : lnClass.getDataObject() ) {
CDC cdc = do_.getRefersToCDC();
if( cdc != null ) {
doTypeValidatorMap.put( do_.getName(), new DOTypeValidator( cdc ));
if( CDCValidator.get( do_.getType() ) != null ) {
dataObjectValidatorMap.put( do_.getName(), CDCValidator.get( do_.getType() ));
AbstractRiseClipseConsole.getConsole().verbose( "[NSD setup] CDC for DataObject " + do_.getName() + " found with type " + do_.getType() );
}
else {
AbstractRiseClipseConsole.getConsole().warning( "[NSD setup] CDC for DataObject " + do_.getName() + " not found" );
......@@ -55,16 +69,19 @@ public class LNodeTypeValidator {
}
public boolean validateLNodeType( LNodeType lNodeType, DiagnosticChain diagnostics ) {
AbstractRiseClipseConsole.getConsole().verbose( "[NSD] validateLNodeType( " + lNodeType.getId() + " )" );
if( validatedLNodeType.contains( lNodeType )) return true;
AbstractRiseClipseConsole.getConsole().verbose( "[NSD validation] LNClassValidator.validateLNodeType( " + lNodeType.getId() + " ) at line " + lNodeType.getLineNumber() );
validatedLNodeType.add( lNodeType );
boolean res = true;
dataObjectPresenceConditionValidator.reset();
lNodeType
.getDO()
.stream()
.forEach( d -> dataObjectPresenceConditionValidator.addDO( d, diagnostics ));
res = res && dataObjectPresenceConditionValidator.validate( lNodeType, diagnostics );
res = dataObjectPresenceConditionValidator.validate( lNodeType, diagnostics ) && res;
for( DO do_ : lNodeType.getDO() ) {
DOType doType = do_.getRefersToDOType();
......@@ -81,9 +98,9 @@ public class LNodeTypeValidator {
//AbstractRiseClipseConsole.getConsole().error( "[NSD validation] Unexpected DO name " + do_.getName() + " in LNodeType (line " + do_.getParentLNodeType().getLineNumber() );
continue;
}
DOTypeValidator validator = doTypeValidatorMap.get( names[0] );
CDCValidator validator = dataObjectValidatorMap.get( names[0] );
if( validator != null ) {
res = res && validator.validateDOType( doType, diagnostics );
res = validator.validateDOType( doType, diagnostics ) && res;
}
else {
// This error will be detected in DataObjectPresenceConditionValidator.addDO() who will check if it is right if dataNs attribute is present
......
......@@ -41,22 +41,13 @@ import fr.centralesupelec.edf.riseclipse.util.AbstractRiseClipseConsole;
public class NsdEObjectValidator implements EValidator {
private NsdResourceSetImpl nsdResourceSet;
private HashMap< String, AnyLNValidator > anyLNValidatorMap = new HashMap<>();
private HashMap< String, LNodeTypeValidator > lNodeTypeValidatorMap = new HashMap<>();
private HashMap< String, LNClassValidator > lNodeTypeValidatorMap = new HashMap<>();
public NsdEObjectValidator( NsdResourceSetImpl nsdResourceSet ) {
this.nsdResourceSet = nsdResourceSet;
}
public void initializeValidationData() {
nsdResourceSet
.getLNClassStream()
.forEach( lnClass -> anyLNValidatorMap.put( lnClass.getName(), new AnyLNValidator( lnClass )));
nsdResourceSet
.getLNClassStream()
.forEach( lnClass -> lNodeTypeValidatorMap.put( lnClass.getName(), new LNodeTypeValidator( lnClass )));
// Order is important
CDCValidator.buildValidators( nsdResourceSet.getCDCStream() );
LNClassValidator.buildValidators( nsdResourceSet.getLNClassStream() );
}
@Override
......@@ -67,10 +58,6 @@ public class NsdEObjectValidator implements EValidator {
@Override
public boolean validate( EClass eClass, EObject eObject, DiagnosticChain diagnostics, Map< Object, Object > context ) {
if( this.anyLNValidatorMap == null ) {
this.initializeValidationData();
}
SclSwitch< Boolean > sw = new SclSwitch< Boolean >() {
@Override
......@@ -80,6 +67,7 @@ public class NsdEObjectValidator implements EValidator {
@Override
public Boolean caseLNodeType( LNodeType lNodeType ) {
AbstractRiseClipseConsole.getConsole().verbose( "[NSD validation] NsdEObjectValidator.validate( " + lNodeType.getId() + " ) at line " + lNodeType.getLineNumber() );
return validateLNodeType( lNodeType, diagnostics );
}
......@@ -126,12 +114,12 @@ public class NsdEObjectValidator implements EValidator {
AbstractRiseClipseConsole.getConsole().verbose( "[NSD validation] NsdEObjectValidator.validateLNodeType( " + lNodeType.getLnClass() + " )" );
// Check that LNodeType has valid LNClass
if( this.anyLNValidatorMap.containsKey( lNodeType.getLnClass() )) {
if( LNClassValidator.get( lNodeType.getLnClass() ) != null ) {
AbstractRiseClipseConsole.getConsole().verbose( "[NSD validation] LNClass " + lNodeType.getLnClass()
+ " found for LNodeType at line " + lNodeType.getLineNumber() );
// LNodeTypeValidator validates LNodeType content
return lNodeTypeValidatorMap.get( lNodeType.getLnClass() ).validateLNodeType( lNodeType, diagnostics );
// LNClassValidator validates LNodeType content
return LNClassValidator.get( lNodeType.getLnClass() ).validateLNodeType( lNodeType, diagnostics );
}
// A specific LNodeType:
......@@ -178,7 +166,7 @@ public class NsdEObjectValidator implements EValidator {
RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE,
0,
"[NSD validation] LNClass " + lNodeType.getLnClass() + " not found for LNodeType at line " + lNodeType.getLineNumber()
+ " and DA \"lnNs\" in DO \"NamPlt\" not found",
+ " and DA \"lnNs\" in DO \"NamPlt\" not found",
new Object[] { lNodeType } ));
return false;
}
......
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