From 6a846b37497b445e008f0ebdc02d88afcb04da8e Mon Sep 17 00:00:00 2001 From: Dominique Marcadet <Dominique.Marcadet@centralesupelec.fr> Date: Mon, 20 May 2019 19:18:11 +0200 Subject: [PATCH] add SubDataObject check and some renaming, performance improvement... --- .../scl/validator/nsd/CDCValidator.java | 107 ++ .../scl/validator/nsd/DOTypeValidator.java | 48 - ...taAttributePresenceConditionValidator.java | 2 + ...peValidator.java => LNClassValidator.java} | 41 +- .../validator/nsd/NsdEObjectValidator.java | 30 +- ...bDataObjectPresenceConditionValidator.java | 1403 +++++++++++++++++ 6 files changed, 1550 insertions(+), 81 deletions(-) create mode 100644 fr.centralesupelec.edf.riseclipse.iec61850.scl.tools/src/fr/centralesupelec/edf/riseclipse/iec61850/scl/validator/nsd/CDCValidator.java delete mode 100644 fr.centralesupelec.edf.riseclipse.iec61850.scl.tools/src/fr/centralesupelec/edf/riseclipse/iec61850/scl/validator/nsd/DOTypeValidator.java rename fr.centralesupelec.edf.riseclipse.iec61850.scl.tools/src/fr/centralesupelec/edf/riseclipse/iec61850/scl/validator/nsd/{LNodeTypeValidator.java => LNClassValidator.java} (68%) create mode 100644 fr.centralesupelec.edf.riseclipse.iec61850.scl.tools/src/fr/centralesupelec/edf/riseclipse/iec61850/scl/validator/nsd/SubDataObjectPresenceConditionValidator.java diff --git a/fr.centralesupelec.edf.riseclipse.iec61850.scl.tools/src/fr/centralesupelec/edf/riseclipse/iec61850/scl/validator/nsd/CDCValidator.java b/fr.centralesupelec.edf.riseclipse.iec61850.scl.tools/src/fr/centralesupelec/edf/riseclipse/iec61850/scl/validator/nsd/CDCValidator.java new file mode 100644 index 0000000..377afdd --- /dev/null +++ b/fr.centralesupelec.edf.riseclipse.iec61850.scl.tools/src/fr/centralesupelec/edf/riseclipse/iec61850/scl/validator/nsd/CDCValidator.java @@ -0,0 +1,107 @@ +/** + * Copyright (c) 2019 CentraleSupélec & EDF. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * This file is part of the RiseClipse tool + * + * Contributors: + * Computer Science Department, CentraleSupélec + * EDF R&D + * Contacts: + * dominique.marcadet@centralesupelec.fr + * aurelie.dehouck-neveu@edf.fr + * Web site: + * http://wdi.supelec.fr/software/RiseClipse/ + */ +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 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<>(); + + 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 ) { + 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 )); + + 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; + } + +} diff --git a/fr.centralesupelec.edf.riseclipse.iec61850.scl.tools/src/fr/centralesupelec/edf/riseclipse/iec61850/scl/validator/nsd/DOTypeValidator.java b/fr.centralesupelec.edf.riseclipse.iec61850.scl.tools/src/fr/centralesupelec/edf/riseclipse/iec61850/scl/validator/nsd/DOTypeValidator.java deleted file mode 100644 index 4487953..0000000 --- a/fr.centralesupelec.edf.riseclipse.iec61850.scl.tools/src/fr/centralesupelec/edf/riseclipse/iec61850/scl/validator/nsd/DOTypeValidator.java +++ /dev/null @@ -1,48 +0,0 @@ -/** - * Copyright (c) 2019 CentraleSupélec & EDF. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * This file is part of the RiseClipse tool - * - * Contributors: - * Computer Science Department, CentraleSupélec - * EDF R&D - * Contacts: - * dominique.marcadet@centralesupelec.fr - * aurelie.dehouck-neveu@edf.fr - * Web site: - * http://wdi.supelec.fr/software/RiseClipse/ - */ -package fr.centralesupelec.edf.riseclipse.iec61850.scl.validator.nsd; - -import org.eclipse.emf.common.util.DiagnosticChain; - -import fr.centralesupelec.edf.riseclipse.iec61850.nsd.CDC; -import fr.centralesupelec.edf.riseclipse.iec61850.scl.DOType; -import fr.centralesupelec.edf.riseclipse.util.AbstractRiseClipseConsole; - -public class DOTypeValidator { - - private DataAttributePresenceConditionValidator dataAttributePresenceConditionValidator; - - public DOTypeValidator( CDC cdc ) { - dataAttributePresenceConditionValidator = DataAttributePresenceConditionValidator.get( cdc ); - } - - public boolean validateDOType( DOType doType, DiagnosticChain diagnostics ) { - AbstractRiseClipseConsole.getConsole().verbose( "[NSD] validateDOType( " + doType.getId() + " )" ); - dataAttributePresenceConditionValidator.reset(); - - doType - .getDA() - .stream() - .forEach( d -> dataAttributePresenceConditionValidator.addDA( d, diagnostics )); - - return dataAttributePresenceConditionValidator.validate( doType, diagnostics ); - - } - -} diff --git a/fr.centralesupelec.edf.riseclipse.iec61850.scl.tools/src/fr/centralesupelec/edf/riseclipse/iec61850/scl/validator/nsd/DataAttributePresenceConditionValidator.java b/fr.centralesupelec.edf.riseclipse.iec61850.scl.tools/src/fr/centralesupelec/edf/riseclipse/iec61850/scl/validator/nsd/DataAttributePresenceConditionValidator.java index cd16820..0e8f2cd 100644 --- a/fr.centralesupelec.edf.riseclipse.iec61850.scl.tools/src/fr/centralesupelec/edf/riseclipse/iec61850/scl/validator/nsd/DataAttributePresenceConditionValidator.java +++ b/fr.centralesupelec.edf.riseclipse.iec61850.scl.tools/src/fr/centralesupelec/edf/riseclipse/iec61850/scl/validator/nsd/DataAttributePresenceConditionValidator.java @@ -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" diff --git a/fr.centralesupelec.edf.riseclipse.iec61850.scl.tools/src/fr/centralesupelec/edf/riseclipse/iec61850/scl/validator/nsd/LNodeTypeValidator.java b/fr.centralesupelec.edf.riseclipse.iec61850.scl.tools/src/fr/centralesupelec/edf/riseclipse/iec61850/scl/validator/nsd/LNClassValidator.java similarity index 68% rename from fr.centralesupelec.edf.riseclipse.iec61850.scl.tools/src/fr/centralesupelec/edf/riseclipse/iec61850/scl/validator/nsd/LNodeTypeValidator.java rename to fr.centralesupelec.edf.riseclipse.iec61850.scl.tools/src/fr/centralesupelec/edf/riseclipse/iec61850/scl/validator/nsd/LNClassValidator.java index 03c08ec..a6e2fd4 100644 --- a/fr.centralesupelec.edf.riseclipse.iec61850.scl.tools/src/fr/centralesupelec/edf/riseclipse/iec61850/scl/validator/nsd/LNodeTypeValidator.java +++ b/fr.centralesupelec.edf.riseclipse.iec61850.scl.tools/src/fr/centralesupelec/edf/riseclipse/iec61850/scl/validator/nsd/LNClassValidator.java @@ -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 diff --git a/fr.centralesupelec.edf.riseclipse.iec61850.scl.tools/src/fr/centralesupelec/edf/riseclipse/iec61850/scl/validator/nsd/NsdEObjectValidator.java b/fr.centralesupelec.edf.riseclipse.iec61850.scl.tools/src/fr/centralesupelec/edf/riseclipse/iec61850/scl/validator/nsd/NsdEObjectValidator.java index 31fb0db..3eff474 100644 --- a/fr.centralesupelec.edf.riseclipse.iec61850.scl.tools/src/fr/centralesupelec/edf/riseclipse/iec61850/scl/validator/nsd/NsdEObjectValidator.java +++ b/fr.centralesupelec.edf.riseclipse.iec61850.scl.tools/src/fr/centralesupelec/edf/riseclipse/iec61850/scl/validator/nsd/NsdEObjectValidator.java @@ -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; } diff --git a/fr.centralesupelec.edf.riseclipse.iec61850.scl.tools/src/fr/centralesupelec/edf/riseclipse/iec61850/scl/validator/nsd/SubDataObjectPresenceConditionValidator.java b/fr.centralesupelec.edf.riseclipse.iec61850.scl.tools/src/fr/centralesupelec/edf/riseclipse/iec61850/scl/validator/nsd/SubDataObjectPresenceConditionValidator.java new file mode 100644 index 0000000..0c945f7 --- /dev/null +++ b/fr.centralesupelec.edf.riseclipse.iec61850.scl.tools/src/fr/centralesupelec/edf/riseclipse/iec61850/scl/validator/nsd/SubDataObjectPresenceConditionValidator.java @@ -0,0 +1,1403 @@ +/** + * Copyright (c) 2019 CentraleSupélec & EDF. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * This file is part of the RiseClipse tool + * + * Contributors: + * Computer Science Department, CentraleSupélec + * EDF R&D + * Contacts: + * dominique.marcadet@centralesupelec.fr + * aurelie.dehouck-neveu@edf.fr + * Web site: + * http://wdi.supelec.fr/software/RiseClipse/ + */ +package fr.centralesupelec.edf.riseclipse.iec61850.scl.validator.nsd; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map.Entry; + +import org.apache.commons.lang3.tuple.Pair; +import org.eclipse.emf.common.util.BasicDiagnostic; +import org.eclipse.emf.common.util.Diagnostic; +import org.eclipse.emf.common.util.DiagnosticChain; +import org.eclipse.emf.common.util.EList; + +import fr.centralesupelec.edf.riseclipse.iec61850.nsd.CDC; +import fr.centralesupelec.edf.riseclipse.iec61850.scl.AbstractDataObject; +import fr.centralesupelec.edf.riseclipse.iec61850.scl.DO; +import fr.centralesupelec.edf.riseclipse.iec61850.scl.DOType; +import fr.centralesupelec.edf.riseclipse.iec61850.scl.SDO; +import fr.centralesupelec.edf.riseclipse.iec61850.scl.validator.RiseClipseValidatorSCL; +import fr.centralesupelec.edf.riseclipse.util.AbstractRiseClipseConsole; +import fr.centralesupelec.edf.riseclipse.util.IRiseClipseConsole; + +public class SubDataObjectPresenceConditionValidator { + + private static HashMap< String, SubDataObjectPresenceConditionValidator > validators = new HashMap<>(); + + public static SubDataObjectPresenceConditionValidator get( CDC cdc ) { + if( ! validators.containsKey( cdc.getName() )) { + validators.put( cdc.getName(), new SubDataObjectPresenceConditionValidator( cdc )); + } + return validators.get( cdc.getName() ); + } + + private CDC cdc; + + // Name of the SubDataObject/SDO, SDO + private HashMap< String, SDO > presentSDO = new HashMap<>(); + + private HashSet< String > mandatory; + private HashSet< String > optional; + private HashSet< String > forbidden; + private HashSet< String > notApplicable; + private HashSet< String > mandatoryMulti; + private HashSet< String > optionalMulti; + private HashMap< Integer, HashSet< String > > atLeastOne; + private HashSet< String > atMostOne; + private HashMap< Integer, HashSet< String > > allOrNonePerGroup; + private HashMap< Integer, HashSet< String > > allOnlyOneGroup; + private HashMap< Integer, HashSet< String > > allAtLeastOneGroup; + private HashMap< String, String > mandatoryIfSiblingPresentElseForbidden; + private HashMap< String, String > mandatoryIfSiblingPresentElseOptional; + private HashMap< String, String > optionalIfSiblingPresentElseMandatory; + private HashMap< String, String > forbiddenIfSiblingPresentElseMandatory; + private HashMap< String, String > mandatoryIfTextConditionElseOptional; + private HashMap< String, String > mandatoryIfTextConditionElseForbidden; + private HashMap< String, String > optionalIfTextConditionElseForbidden; + private HashMap< String, Pair< Integer, Integer > > mandatoryMultiRange; + private HashMap< String, Pair< Integer, Integer > > optionalMultiRange; + private HashSet< String > mandatoryIfSubstitutionElseForbidden; + private HashSet< String > mandatoryInLLN0ElseOptional; + private HashSet< String > mandatoryInLLN0ElseForbidden; + private HashSet< String > mandatoryIfNameSpaceOfLogicalNodeDeviatesElseOptional; + private HashSet< String > mandatoryIfNameSpaceOfDataObjectDeviatesElseOptional; + private HashSet< String > mandatoryIfAnalogValueIncludesIElseForbidden; + private HashSet< String > mandatoryIfVectorSiblingIncludesIAsChildMagElseForbidden; + private HashSet< String > mandatoryIfVectorSiblingIncludesIAsChildAngElseForbidden; + private HashSet< String > mandatoryIfHarmonicValuesCalculatedAsRatioElseOptional; + private HashSet< String > mandatoryInRootLogicalDeviceElseOptional; + private HashSet< String > mandatoryIfControlSupportsTimeElseOptional; + private HashMap< String, String > oneOrMoreIfSiblingPresentElseForbidden; + private HashSet< String > mandatoryIfControlSupportsSecurity1ElseOptional; + private HashSet< String > mandatoryIfControlSupportsSecurity2ElseOptional; + private HashMap< String, String > optionalIfSiblingPresentElseForbidden; + private HashSet< String > mandatoryIfNameSpaceOfLogicalNodeDeviatesElseOptional2; + private HashSet< String > mandatoryIfMeasuredValueExposesRange; + private HashSet< String > optionalIfPhsRefIsSynchrophasorElseMandatory; + + private final IRiseClipseConsole console = AbstractRiseClipseConsole.getConsole(); + + public SubDataObjectPresenceConditionValidator( CDC cdc ) { + this.cdc = cdc; + + cdc + .getSubDataObject() + .stream() + .forEach( sdo -> addSpecification( sdo.getName(), sdo.getPresCond(), sdo.getPresCondArgs() ) ); + + checkSpecification(); + } + + public void reset() { + for( String sdo : presentSDO.keySet() ) { + presentSDO.put( sdo, null ); + } + } + + private void addSpecification( String name, String presCond, String presCondArgs ) { + if( presentSDO.containsKey( name )) { + console.warning( "[NSD setup] " + name + " has already been added to SubDataObjectPresenceConditionValidator" ); + return; + } + presentSDO.put( name, null ); + + switch( presCond ) { + case "M" : + // Element is mandatory + if( mandatory == null ) mandatory = new HashSet<>(); + mandatory.add( name ); + break; + case "O" : + // Element is optional + if( optional == null ) optional = new HashSet<>(); + optional.add( name ); + break; + case "F" : + // Element is forbidden + if( forbidden == null ) forbidden = new HashSet<>(); + forbidden.add( name ); + break; + case "na" : + // Element is not applicable + // -> TODO: what does it mean ? what do we have to check ? + console.warning( "[NSD setup] NOT IMPLEMENTED: SubDataObject " + name + " declared as \"na\" in PresenceCondition" ); + if( notApplicable == null ) notApplicable = new HashSet<>(); + notApplicable.add( name ); + break; + case "Mmulti" : + // At least one element shall be present; all instances have an instance number > 0 + // -> TODO: not sure what is the instance number, it is assumed to be the suffix of DO name + console.warning( "[NSD setup] NOT IMPLEMENTED: SubDataObject " + name + " declared as \"Mmulti\" in PresenceCondition" ); + if( mandatoryMulti == null ) mandatoryMulti = new HashSet<>(); + mandatoryMulti.add( name ); + break; + case "Omulti" : + // Zero or more elements may be present; all instances have an instance number > 0 + // -> TODO: not sure what is the instance number, it is assumed to be the suffix of DO name + console.warning( "[NSD setup] NOT IMPLEMENTED: SubDataObject " + name + " declared as \"Omulti\" in PresenceCondition" ); + if( optionalMulti == null ) optionalMulti = new HashSet<>(); + optionalMulti.add( name ); + break; + case "AtLeastOne" : + // Parameter n: group number (> 0). + // At least one of marked elements of a group n shall be present + if( atLeastOne == null ) atLeastOne = new HashMap<>(); + try { + Integer arg = Integer.valueOf( presCondArgs ); + if( arg <= 0 ) { + console.warning( "[NSD setup] argument of PresenceCondition \"AtLeastOne\" is not a positive integer" ); + break; + } + if( ! atLeastOne.containsKey( arg )) { + atLeastOne.put( arg, new HashSet<>() ); + } + atLeastOne.get( arg ).add( name ); + break; + } + catch( NumberFormatException e ) { + console.warning( "[NSD setup] argument of PresenceCondition \"AtLeastOne\" is not an integer" ); + break; + } + case "AtMostOne" : + // At most one of marked elements shall be present + if( atMostOne == null ) atMostOne = new HashSet<>(); + atMostOne.add( name ); + break; + case "AllOrNonePerGroup" : + // Parameter n: group number (> 0). + // All or none of the elements of a group n shall be present + if( allOrNonePerGroup == null ) allOrNonePerGroup = new HashMap<>(); + try { + Integer arg = Integer.valueOf( presCondArgs ); + if( arg <= 0 ) { + console.warning( "[NSD setup] argument of PresenceCondition \"AllOrNonePerGroup\" is not a positive integer" ); + break; + } + if( ! allOrNonePerGroup.containsKey( arg )) { + allOrNonePerGroup.put( arg, new HashSet<>() ); + } + allOrNonePerGroup.get( arg ).add( name ); + break; + } + catch( NumberFormatException e ) { + console.warning( "[NSD setup] argument of PresenceCondition \"AllOrNonePerGroup\" is not an integer" ); + break; + } + case "AllOnlyOneGroup" : + // Parameter n: group number (> 0). + // All elements of only one group n shall be present + if( allOnlyOneGroup == null ) allOnlyOneGroup = new HashMap<>(); + try { + Integer arg = Integer.valueOf( presCondArgs ); + if( arg <= 0 ) { + console.warning( "[NSD setup] argument of PresenceCondition \"AllOnlyOneGroup\" is not a positive integer" ); + break; + } + if( ! allOnlyOneGroup.containsKey( arg )) { + allOnlyOneGroup.put( arg, new HashSet<>() ); + } + allOnlyOneGroup.get( arg ).add( name ); + break; + } + catch( NumberFormatException e ) { + console.warning( "[NSD setup] argument of PresenceCondition \"AllOnlyOneGroup\" is not an integer" ); + break; + } + case "AllAtLeastOneGroup" : + // Parameter n: group number (> 0). + // All elements of at least one group n shall be present + if( allAtLeastOneGroup == null ) allAtLeastOneGroup = new HashMap<>(); + try { + Integer arg = Integer.valueOf( presCondArgs ); + if( arg <= 0 ) { + console.warning( "[NSD setup] argument of PresenceCondition \"AllAtLeastOneGroup\" is not a positive integer" ); + break; + } + if( ! allAtLeastOneGroup.containsKey( arg )) { + allAtLeastOneGroup.put( arg, new HashSet<>() ); + } + allAtLeastOneGroup.get( arg ).add( name ); + break; + } + catch( NumberFormatException e ) { + console.warning( "[NSD setup] argument of PresenceCondition \"AllAtLeastOneGroup\" is not an integer" ); + break; + } + case "MF" : + // Parameter sibling: sibling element name. + // Mandatory if sibling element is present, otherwise forbidden + if( mandatoryIfSiblingPresentElseForbidden == null ) mandatoryIfSiblingPresentElseForbidden = new HashMap<>(); + mandatoryIfSiblingPresentElseForbidden.put( name, presCondArgs ); + break; + case "MO" : + // Parameter sibling: sibling element name. + // Mandatory if sibling element is present, otherwise optional + if( mandatoryIfSiblingPresentElseOptional == null ) mandatoryIfSiblingPresentElseOptional = new HashMap<>(); + mandatoryIfSiblingPresentElseOptional.put( name, presCondArgs ); + break; + case "OM" : + // Parameter sibling: sibling element name. + // Optional if sibling element is present, otherwise mandatory + if( optionalIfSiblingPresentElseMandatory == null ) optionalIfSiblingPresentElseMandatory = new HashMap<>(); + optionalIfSiblingPresentElseMandatory.put( name, presCondArgs ); + break; + case "FM" : + // Parameter sibling: sibling element name. + // Forbidden if sibling element is present, otherwise mandatory + if( forbiddenIfSiblingPresentElseMandatory == null ) forbiddenIfSiblingPresentElseMandatory = new HashMap<>(); + forbiddenIfSiblingPresentElseMandatory.put( name, presCondArgs ); + break; + case "MOcond" : + // Parameter condID: condition number (> 0). + // Textual presence condition (non-machine processable) with reference condID to context specific text. + // If satisfied, the element is mandatory, otherwise optional + if( mandatoryIfTextConditionElseOptional == null ) mandatoryIfTextConditionElseOptional = new HashMap<>(); + try { + Integer arg = Integer.valueOf( presCondArgs ); + if( arg <= 0 ) { + console.warning( "[NSD setup] argument of PresenceCondition \"MOcond\" is not a positive integer" ); + break; + } + mandatoryIfTextConditionElseOptional.put( name, presCondArgs ); + break; + } + catch( NumberFormatException e ) { + console.warning( "[NSD setup] argument of PresenceCondition \"MOcond\" is not an integer" ); + break; + } + case "MFcond" : + // Parameter condID: condition number (> 0). + // Textual presence condition (non-machine processable) with reference condID to context specific text. + // If satisfied, the element is mandatory, otherwise forbidden + if( mandatoryIfTextConditionElseForbidden == null ) mandatoryIfTextConditionElseForbidden = new HashMap<>(); + try { + Integer arg = Integer.valueOf( presCondArgs ); + if( arg <= 0 ) { + console.warning( "[NSD setup] argument of PresenceCondition \"MFcond\" is not a positive integer" ); + break; + } + mandatoryIfTextConditionElseForbidden.put( name, presCondArgs ); + break; + } + catch( NumberFormatException e ) { + console.warning( "[NSD setup] argument of PresenceCondition \"MFcond\" is not an integer" ); + break; + } + case "OFcond" : + // Parameter condID: condition number (> 0). + // Textual presence condition (non-machine processable) with reference condID to context specific text. + // If satisfied, the element is optional, otherwise forbidden + if( optionalIfTextConditionElseForbidden == null ) optionalIfTextConditionElseForbidden = new HashMap<>(); + try { + Integer arg = Integer.valueOf( presCondArgs ); + if( arg <= 0 ) { + console.warning( "[NSD setup] argument of PresenceCondition \"MFcond\" is not a positive integer" ); + break; + } + optionalIfTextConditionElseForbidden.put( name, presCondArgs ); + break; + } + catch( NumberFormatException e ) { + console.warning( "[NSD setup] argument of PresenceCondition \"MFcond\" is not an integer" ); + break; + } + case "MmultiRange" : + // Parameters min, max: limits for instance number (> 0). + // One or more elements shall be present; all instances have an instance number within range [min, max] (see IEC 61850-7-1) + // -> TODO: not sure what is the instance number, it is assumed to be the suffix of DO name + console.warning( "[NSD setup] NOT IMPLEMENTED: SubDataObject " + name + " declared as \"MmultiRange\" in PresenceCondition" ); + if( mandatoryMultiRange == null ) mandatoryMultiRange = new HashMap<>(); + String[] limits1 = presCondArgs.split( "[ ,]+" ); + if( limits1.length != 2 ) { + console.warning( "[NSD setup] argument of PresenceCondition \"MmultiRange\" is not two integers" ); + break; + } + Integer min1 = Integer.valueOf( limits1[0] ); + if( min1 <= 0 ) { + console.warning( "[NSD setup] first argument of PresenceCondition \"MmultiRange\" is not a positive integer" ); + break; + } + Integer max1 = Integer.valueOf( limits1[1] ); + if( max1 <= 0 ) { + console.warning( "[NSD setup] second argument of PresenceCondition \"MmultiRange\" is not a positive integer" ); + break; + } + mandatoryMultiRange.put( name, Pair.of( min1, max1 )); + break; + case "OmultiRange" : + // Parameters min, max: limits for instance number (> 0). + // Zero or more elements may be present; all instances have an instance number within range [min, max] (see IEC 61850-7-1) + // -> TODO: not sure what is the instance number, it is assumed to be the suffix of DO name + console.warning( "[NSD setup] NOT IMPLEMENTED: SubDataObject " + name + " declared as \"OmultiRange\" in PresenceCondition" ); + if( optionalMultiRange == null ) optionalMultiRange = new HashMap<>(); + String[] limits2 = presCondArgs.split( "[ ,]+" ); + if( limits2.length != 2 ) { + console.warning( "[NSD setup] argument of PresenceCondition \"OmultiRange\" is not two integers" ); + break; + } + Integer min2 = Integer.valueOf( limits2[0] ); + if( min2 <= 0 ) { + console.warning( "[NSD setup] first argument of PresenceCondition \"OmultiRange\" is not a positive integer" ); + break; + } + Integer max2 = Integer.valueOf( limits2[1] ); + if( max2 <= 0 ) { + console.warning( "[NSD setup] second argument of PresenceCondition \"OmultiRange\" is not a positive integer" ); + break; + } + optionalMultiRange.put( name, Pair.of( min2, max2 )); + break; + case "MFsubst" : + // Element is mandatory if substitution is supported (for substitution, see IEC 61850-7-3), otherwise forbidden + // TODO: how do we know if substitution is supported ? + console.warning( "[NSD setup] NOT IMPLEMENTED: SubDataObject " + name + " declared as \"MFsubst\" in PresenceCondition" ); + if( mandatoryIfSubstitutionElseForbidden == null ) mandatoryIfSubstitutionElseForbidden = new HashSet<>(); + mandatoryIfSubstitutionElseForbidden.add( name ); + break; + case "MOln0" : + // Element is mandatory in the context of LLN0; otherwise optional + if( mandatoryInLLN0ElseOptional == null ) mandatoryInLLN0ElseOptional = new HashSet<>(); + mandatoryInLLN0ElseOptional.add( name ); + break; + case "MFln0" : + // Element is mandatory in the context of LLN0; otherwise forbidden + if( mandatoryInLLN0ElseForbidden == null ) mandatoryInLLN0ElseForbidden = new HashSet<>(); + mandatoryInLLN0ElseForbidden.add( name ); + break; + case "MOlnNs" : + // Element is mandatory if the name space of its logical node deviates from the name space of the containing + // logical device, otherwise optional. See IEC 61850-7-1 for use of name space + console.warning( "[NSD setup] NOT IMPLEMENTED: SubDataObject " + name + " declared as \"MOlnNs\" in PresenceCondition" ); + if( mandatoryIfNameSpaceOfLogicalNodeDeviatesElseOptional == null ) mandatoryIfNameSpaceOfLogicalNodeDeviatesElseOptional = new HashSet<>(); + mandatoryIfNameSpaceOfLogicalNodeDeviatesElseOptional.add( name ); + break; + case "MOdataNs" : + // Element is mandatory if the name space of its data object deviates from the name space of its logical node, + // otherwise optional. See IEC 61850-7-1 for use of name space + console.warning( "[NSD setup] NOT IMPLEMENTED: SubDataObject " + name + " declared as \"MOdataNs\" in PresenceCondition" ); + if( mandatoryIfNameSpaceOfDataObjectDeviatesElseOptional == null ) mandatoryIfNameSpaceOfDataObjectDeviatesElseOptional = new HashSet<>(); + mandatoryIfNameSpaceOfDataObjectDeviatesElseOptional.add( name ); + break; + case "MFscaledAV" : + // Element is mandatory* if any sibling elements of type AnalogueValue include 'i' as a child, otherwise forbidden. + // *Even though devices without floating point capability cannot exchange floating point values through ACSI services, + // the description of scaling remains mandatory for their (SCL) configuration + console.warning( "[NSD setup] NOT IMPLEMENTED: SubDataObject " + name + " declared as \"MFscaledAV\" in PresenceCondition" ); + if( mandatoryIfAnalogValueIncludesIElseForbidden == null ) mandatoryIfAnalogValueIncludesIElseForbidden = new HashSet<>(); + mandatoryIfAnalogValueIncludesIElseForbidden.add( name ); + break; + case "MFscaledMagV" : + // Element is mandatory* if any sibling elements of type Vector include 'i' as a child of their 'mag' attribute, otherwise forbidden. + // *See MFscaledAV + console.warning( "[NSD setup] NOT IMPLEMENTED: SubDataObject " + name + " declared as \"MFscaledMagV\" in PresenceCondition" ); + if( mandatoryIfVectorSiblingIncludesIAsChildMagElseForbidden == null ) mandatoryIfVectorSiblingIncludesIAsChildMagElseForbidden = new HashSet<>(); + mandatoryIfVectorSiblingIncludesIAsChildMagElseForbidden.add( name ); + break; + case "MFscaledAngV" : + // Element is mandatory* if any sibling elements of type Vector include 'i' as a child of their 'ang' attribute, otherwise forbidden. + // *See MFscaledAV + console.warning( "[NSD setup] NOT IMPLEMENTED: SubDataObject " + name + " declared as \"MFscaledAngV\" in PresenceCondition" ); + if( mandatoryIfVectorSiblingIncludesIAsChildAngElseForbidden == null ) mandatoryIfVectorSiblingIncludesIAsChildAngElseForbidden = new HashSet<>(); + mandatoryIfVectorSiblingIncludesIAsChildAngElseForbidden.add( name ); + break; + case "MOrms" : + // Element is mandatory if the harmonic values in the context are calculated as a ratio to RMS value + // (value of data attribute 'hvRef' is 'rms'), optional otherwise + console.warning( "[NSD setup] NOT IMPLEMENTED: SubDataObject " + name + " declared as \"MOrms\" in PresenceCondition" ); + if( mandatoryIfHarmonicValuesCalculatedAsRatioElseOptional == null ) mandatoryIfHarmonicValuesCalculatedAsRatioElseOptional = new HashSet<>(); + mandatoryIfHarmonicValuesCalculatedAsRatioElseOptional.add( name ); + break; + case "MOrootLD" : + // Element is mandatory in the context of a root logical device; otherwise it is optional + console.warning( "[NSD setup] NOT IMPLEMENTED: SubDataObject " + name + " declared as \"MOrootLD\" in PresenceCondition" ); + if( mandatoryInRootLogicalDeviceElseOptional == null ) mandatoryInRootLogicalDeviceElseOptional = new HashSet<>(); + mandatoryInRootLogicalDeviceElseOptional.add( name ); + break; + case "MOoperTm" : + // Element is mandatory if at least one controlled object on the IED supports time activation service; otherwise it is optional + console.warning( "[NSD setup] NOT IMPLEMENTED: SubDataObject " + name + " declared as \"MOoperTm\" in PresenceCondition" ); + if( mandatoryIfControlSupportsTimeElseOptional == null ) mandatoryIfControlSupportsTimeElseOptional = new HashSet<>(); + mandatoryIfControlSupportsTimeElseOptional.add( name ); + break; + case "MmultiF" : + // Parameter sibling: sibling element name. + // One or more elements must be present if sibling element is present, otherwise forbidden + console.warning( "[NSD setup] NOT IMPLEMENTED: SubDataObject " + name + " declared as \"MmultiF\" in PresenceCondition" ); + if( oneOrMoreIfSiblingPresentElseForbidden == null ) oneOrMoreIfSiblingPresentElseForbidden = new HashMap<>(); + oneOrMoreIfSiblingPresentElseForbidden.put( name, presCondArgs ); + break; + case "MOsbo" : + // Element is mandatory if declared control model supports 'sbo-with-normal-security' or 'sbo-with-enhanced-security', + // otherwise optional and value is of no impact + console.warning( "[NSD setup] NOT IMPLEMENTED: SubDataObject " + name + " declared as \"MOsbo\" in PresenceCondition" ); + if( mandatoryIfControlSupportsSecurity1ElseOptional == null ) mandatoryIfControlSupportsSecurity1ElseOptional = new HashSet<>(); + mandatoryIfControlSupportsSecurity1ElseOptional.add( name ); + break; + case "MOenhanced" : + // Element is mandatory if declared control model supports 'direct-with-enhanced-security' or 'sbo-with-enhanced-security', + // otherwise optional and value is of no impact + console.warning( "[NSD setup] NOT IMPLEMENTED: SubDataObject " + name + " declared as \"MOenhanced\" in PresenceCondition" ); + if( mandatoryIfControlSupportsSecurity2ElseOptional == null ) mandatoryIfControlSupportsSecurity2ElseOptional = new HashSet<>(); + mandatoryIfControlSupportsSecurity2ElseOptional.add( name ); + break; + case "MONamPlt" : + // Element is mandatory if the name space of its logical node deviates from the name space of the containing + // logical device, otherwise optional. See IEC 61850-7-1 for use of name space + // TODO: same as "MOlnNs" ? + console.warning( "[NSD setup] NOT IMPLEMENTED: SubDataObject " + name + " declared as \"MONamPlt\" in PresenceCondition" ); + if( mandatoryIfNameSpaceOfLogicalNodeDeviatesElseOptional2 == null ) mandatoryIfNameSpaceOfLogicalNodeDeviatesElseOptional2 = new HashSet<>(); + mandatoryIfNameSpaceOfLogicalNodeDeviatesElseOptional2.add( name ); + break; + case "OF" : + // Parameter sibling: sibling element name. + // Optional if sibling element is present, otherwise forbidden + if( optionalIfSiblingPresentElseForbidden == null ) optionalIfSiblingPresentElseForbidden = new HashMap<>(); + optionalIfSiblingPresentElseForbidden.put( name, presCondArgs ); + break; + case "MORange" : + // Element is mandatory if the measured value associated (amplitude respectively angle) exposes the range eventing + // (with the attribute range respectively rangeAng) + console.warning( "[NSD setup] NOT IMPLEMENTED: SubDataObject " + name + " declared as \"MORange\" in PresenceCondition" ); + if( mandatoryIfMeasuredValueExposesRange == null ) mandatoryIfMeasuredValueExposesRange = new HashSet<>(); + mandatoryIfMeasuredValueExposesRange.add( name ); + break; + case "OMSynPh" : + // This attribute is optional if value of 'phsRef'' is Synchrophasor otherwise Mandatory]]></Doc> + console.warning( "[NSD setup] NOT IMPLEMENTED: SubDataObject " + name + " declared as \"OMSynPh\" in PresenceCondition" ); + if( optionalIfPhsRefIsSynchrophasorElseMandatory == null ) optionalIfPhsRefIsSynchrophasorElseMandatory = new HashSet<>(); + optionalIfPhsRefIsSynchrophasorElseMandatory.add( name ); + break; + default: + console.warning( "[NSD setup] the PresenceCondition " + presCond + " of AnyLNClass " + name + " is unknown" ); + break; + } + + } + + private void checkSpecification() { + // TODO: do we have to check the presence of the sibling in inherited AbstractLNClass ? + if( mandatoryIfSiblingPresentElseForbidden != null ) { + for( Entry< String, String > e : mandatoryIfSiblingPresentElseForbidden.entrySet() ) { + if( ! presentSDO.containsKey( e.getValue() )) { + console.warning( "[NSD setup] the sibling of " + e.getKey() + " in PresenceCondition of DataObject " + e.getKey() + " is unknown" ); + } + } + } + if( mandatoryIfSiblingPresentElseOptional != null ) { + for( Entry< String, String > e : mandatoryIfSiblingPresentElseOptional.entrySet() ) { + if( ! presentSDO.containsKey( e.getValue() )) { + console.warning( "[NSD setup] the sibling of " + e.getKey() + " in PresenceCondition of DataObject " + e.getKey() + " is unknown" ); + } + } + } + if( optionalIfSiblingPresentElseMandatory != null ) { + for( Entry< String, String > e : optionalIfSiblingPresentElseMandatory.entrySet() ) { + if( ! presentSDO.containsKey( e.getValue() )) { + console.warning( "[NSD setup] the sibling of " + e.getKey() + " in PresenceCondition of DataObject " + e.getKey() + " is unknown" ); + } + } + } + if( forbiddenIfSiblingPresentElseMandatory != null ) { + for( Entry< String, String > e : forbiddenIfSiblingPresentElseMandatory.entrySet() ) { + if( ! presentSDO.containsKey( e.getValue() )) { + console.warning( "[NSD setup] the sibling of " + e.getKey() + " in PresenceCondition of DataObject " + e.getKey() + " is unknown" ); + } + } + } + if( oneOrMoreIfSiblingPresentElseForbidden != null ) { + for( Entry< String, String > e : oneOrMoreIfSiblingPresentElseForbidden.entrySet() ) { + if( ! presentSDO.containsKey( e.getValue() )) { + console.warning( "[NSD setup] the sibling of " + e.getKey() + " in PresenceCondition of DataObject " + e.getKey() + " is unknown" ); + } + } + } + if( optionalIfSiblingPresentElseForbidden != null ) { + for( Entry< String, String > e : optionalIfSiblingPresentElseForbidden.entrySet() ) { + if( ! presentSDO.containsKey( e.getValue() )) { + console.warning( "[NSD setup] the sibling of " + e.getKey() + " in PresenceCondition of DataObject " + e.getKey() + " is unknown" ); + } + } + } + } + + public boolean addSDO( SDO sdo, DiagnosticChain diagnostics ) { + if( ! presentSDO.containsKey( sdo.getName() )) { + diagnostics.add( new BasicDiagnostic( + Diagnostic.ERROR, + RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE, + 0, + "[NSD validation] SDO " + sdo.getName() + " in DOType (line " + sdo.getParentDOType().getLineNumber() + ") not found in CDC " + cdc.getName(), + new Object[] { sdo } )); + return false; + } + + if( presentSDO.get( sdo.getName() ) != null ) { + diagnostics.add( new BasicDiagnostic( + Diagnostic.ERROR, + RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE, + 0, + "[NSD validation] SDO " + sdo.getName() + " in DOType (line " + sdo.getParentDOType().getLineNumber() + ") already present in CDC " + cdc.getName(), + new Object[] { sdo } )); + return false; + } + presentSDO.put( sdo.getName(), sdo ); + return true; + } + + public boolean validate( DOType doType, DiagnosticChain diagnostics ) { + AbstractRiseClipseConsole.getConsole().verbose( "[NSD validation] SubDataObjectPresenceConditionValidator.validate( " + doType.getId() + " ) at line " + doType.getLineNumber() ); + + boolean res = true; + + // presCond: "M" + // Element is mandatory + // Usage in standard NSD files (version 2007B): DataObject and DataAttribute and SubDataAttribute + if( mandatory != null ) { + for( String name : this.mandatory ) { + if( presentSDO.get( name ) == null ) { + diagnostics.add( new BasicDiagnostic( + Diagnostic.ERROR, + RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE, + 0, + "[NSD validation] SDO " + name + " is mandatory in DOType (line " + doType.getLineNumber() + ") with CDC " + cdc.getName(), + new Object[] { doType } )); + res = false; + } + } + } + + // presCond: "O" + // Element is optional + // Usage in standard NSD files (version 2007B): DataObject and DataAttribute and SubDataAttribute + if( optional != null ) { + for( String name : this.optional ) { + if( presentSDO.get( name ) == null ) { + // Nothing + } + } + } + + // presCond: "F" + // Element is forbidden + // Usage in standard NSD files (version 2007B): DataObject + if( forbidden != null ) { + for( String name : this.forbidden ) { + if( presentSDO.get( name ) != null ) { + diagnostics.add( new BasicDiagnostic( + Diagnostic.ERROR, + RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE, + 0, + "[NSD validation] SDO " + name + " is forbidden in DOType (line " + doType.getLineNumber() + ") with CDC " + cdc.getName(), + new Object[] { doType } )); + res = false; + } + } + } + + // presCond: "na" + // Element is not applicable + // Usage in standard NSD files (version 2007B): only for dsPresCond + // -> TODO: what does it mean ? what do we have to check ? + if( notApplicable != null ) { + for( String name : notApplicable ) { + if( presentSDO.get( name ) != null ) { + diagnostics.add( new BasicDiagnostic( + Diagnostic.WARNING, + RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE, + 0, + "[NSD validation] verification of PresenceCondition \"na\" for SDO " + name + " is not implemented in DOType (line " + doType.getLineNumber() + ") with CDC " + cdc.getName(), + new Object[] { doType } )); + } + } + } + + // presCond: "Mmulti" + // At least one element shall be present; all instances have an instance number > 0 + // Usage in standard NSD files (version 2007B): DataObject + if( mandatoryMulti != null ) { + for( String name : mandatoryMulti ) { + if( presentSDO.get( name ) != null ) { + diagnostics.add( new BasicDiagnostic( + Diagnostic.WARNING, + RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE, + 0, + "[NSD validation] verification of PresenceCondition \"Mmulti\" for SDO " + name + " is not implemented in DOType (line " + doType.getLineNumber() + ") with CDC " + cdc.getName(), + new Object[] { doType } )); + } + } + } + + // presCond: "Omulti" + // Zero or more elements may be present; all instances have an instance number > 0 + // Usage in standard NSD files (version 2007B): DataObject + if( optionalMulti != null ) { + for( String name : optionalMulti ) { + if( presentSDO.get( name ) != null ) { + diagnostics.add( new BasicDiagnostic( + Diagnostic.WARNING, + RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE, + 0, + "[NSD validation] verification of PresenceCondition \"Omulti\" for SDO " + name + " is not implemented in DOType (line " + doType.getLineNumber() + ") with CDC " + cdc.getName(), + new Object[] { doType } )); + } + } + } + + // presCond: "AtLeastOne" + // Parameter n: group number (> 0). + // At least one of marked elements of a group n shall be present + // Usage in standard NSD files (version 2007B): DataObject and SubDataObject and DataAttribute and SubDataAttribute + if( atLeastOne != null ) { + for( Entry< Integer, HashSet< String > > e1 : atLeastOne.entrySet() ) { + boolean groupOK = false; + for( String member : e1.getValue() ) { + if( presentSDO.get( member ) != null ) { + groupOK = true; + break; + } + } + if( ! groupOK ) { + diagnostics.add( new BasicDiagnostic( + Diagnostic.ERROR, + RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE, + 0, + "[NSD validation] group " + e1.getKey() + " has no elements in DOType (line " + doType.getLineNumber() + ") with CDC " + cdc.getName(), + new Object[] { doType } )); + res = false; + } + } + } + + // presCond: "AtMostOne" : + // At most one of marked elements shall be present + // Usage in standard NSD files (version 2007B): DataObject + if( atMostOne != null ) { + int count = 0; + for( String s : atMostOne ) { + if( presentSDO.get( s ) != null ) { + ++count; + } + } + if( count > 1 ) { + diagnostics.add( new BasicDiagnostic( + Diagnostic.ERROR, + RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE, + 0, + "[NSD validation] LNodeType (line " + doType.getLineNumber() + ") with CDC " + cdc.getName() + " has more than one element marked AtMostOne", + new Object[] { doType } )); + res = false; + } + } + + // presCond: "AllOrNonePerGroup" : + // Parameter n: group number (> 0). + // All or none of the elements of a group n shall be present + // Usage in standard NSD files (version 2007B): DataAttribute + if( allOrNonePerGroup != null ) { + for( Entry< Integer, HashSet< String > > e1 : allOrNonePerGroup.entrySet() ) { + int groupCount = 0; + for( String member : e1.getValue() ) { + if( presentSDO.get( member ) != null ) { + ++groupCount; + } + } + if(( groupCount > 0 ) && (groupCount < e1.getValue().size() )) { + diagnostics.add( new BasicDiagnostic( + Diagnostic.ERROR, + RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE, + 0, + "[NSD validation] group " + e1.getKey() + " has neither none nor all elements in DOType (line " + doType.getLineNumber() + ") with CDC " + cdc.getName(), + new Object[] { doType } )); + res = false; + } + } + } + + // presCond: "AllOnlyOneGroup" : + // Parameter n: group number (> 0). + // All elements of only one group n shall be present + // Usage in standard NSD files (version 2007B): DataObject and SubDataAttribute + if( allOnlyOneGroup != null ) { + int groupNumber = 0; + for( Entry< Integer, HashSet< String > > e1 : allOnlyOneGroup.entrySet() ) { + int groupCount = 0; + for( String member : e1.getValue() ) { + if( presentSDO.get( member ) != null ) { + ++groupCount; + } + } + if(( groupCount > 0 ) && (groupCount < e1.getValue().size() )) { + diagnostics.add( new BasicDiagnostic( + Diagnostic.ERROR, + RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE, + 0, + "[NSD validation] group " + e1.getKey() + " has neither none nor all elements in DOType (line " + doType.getLineNumber() + ") with CDC " + cdc.getName(), + new Object[] { doType } )); + res = false; + } + else if( groupCount > 0 ) { + if( groupNumber == 0 ) { + groupNumber = e1.getKey(); + } + else { + diagnostics.add( new BasicDiagnostic( + Diagnostic.ERROR, + RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE, + 0, + "[NSD validation] LNodeType (line " + doType.getLineNumber() + ") with CDC " + cdc.getName() + " has several groups with all elements", + new Object[] { doType } )); + res = false; + } + } + } + if( groupNumber == 0 ) { + diagnostics.add( new BasicDiagnostic( + Diagnostic.ERROR, + RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE, + 0, + "[NSD validation] no group in DOType (line " + doType.getLineNumber() + ") with CDC " + cdc.getName() + " has all elements", + new Object[] { doType } )); + res = false; + } + } + + // presCond: "AllAtLeastOneGroup" : + // Parameter n: group number (> 0). + // All elements of at least one group n shall be present + // Usage in standard NSD files (version 2007B): DataAttribute + if( allAtLeastOneGroup != null ) { + int groupNumber = 0; + for( Entry< Integer, HashSet< String > > e1 : allAtLeastOneGroup.entrySet() ) { + int groupCount = 0; + for( String member : e1.getValue() ) { + if( presentSDO.get( member ) != null ) { + ++groupCount; + } + } + if( groupCount == e1.getValue().size() ) { + groupNumber = e1.getKey(); + } + } + if( groupNumber == 0 ) { + diagnostics.add( new BasicDiagnostic( + Diagnostic.ERROR, + RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE, + 0, + "[NSD validation] no group in DOType (line " + doType.getLineNumber() + ") with CDC " + cdc.getName() + " has all elements", + new Object[] { doType } )); + res = false; + } + } + + // presCond: "MF" : + // Parameter sibling: sibling element name. + // Mandatory if sibling element is present, otherwise forbidden + // Usage in standard NSD files (version 2007B): DataObject + if( mandatoryIfSiblingPresentElseForbidden != null ) { + for( Entry< String, String > entry : mandatoryIfSiblingPresentElseForbidden.entrySet() ) { + if( presentSDO.get( entry.getValue() ) != null ) { + if( presentSDO.get( entry.getKey() ) == null ) { + diagnostics.add( new BasicDiagnostic( + Diagnostic.ERROR, + RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE, + 0, + "[NSD validation] SDO " + entry.getKey() + " is mandatory in DOType (line " + doType.getLineNumber() + ") with LNClass " + + cdc.getName() + " because sibling " + entry.getValue() + " is present", + new Object[] { doType } )); + res = false; + } + } + else { + if( presentSDO.get( entry.getKey() ) != null ) { + diagnostics.add( new BasicDiagnostic( + Diagnostic.ERROR, + RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE, + 0, + "[NSD validation] SDO " + entry.getKey() + " is forbidden in DOType (line " + doType.getLineNumber() + ") with LNClass " + + cdc.getName() + " because sibling " + entry.getValue() + " is not present", + new Object[] { doType } )); + res = false; + } + } + } + } + + // presCond: "MO" : + // Parameter sibling: sibling element name. + // Mandatory if sibling element is present, otherwise optional + // Usage in standard NSD files (version 2007B): DataAttribute + if( mandatoryIfSiblingPresentElseOptional != null ) { + for( Entry< String, String > entry : mandatoryIfSiblingPresentElseOptional.entrySet() ) { + if( presentSDO.get( entry.getValue() ) != null ) { + if( presentSDO.get( entry.getKey() ) == null ) { + diagnostics.add( new BasicDiagnostic( + Diagnostic.ERROR, + RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE, + 0, + "[NSD validation] SDO " + entry.getKey() + " is mandatory in DOType (line " + doType.getLineNumber() + ") with LNClass " + + cdc.getName() + " because sibling " + entry.getValue() + " is present", + new Object[] { doType } )); + res = false; + } + } + } + } + + // presCond: "OM" : + // Parameter sibling: sibling element name. + // Optional if sibling element is present, otherwise mandatory + // Usage in standard NSD files (version 2007B): None + if( optionalIfSiblingPresentElseMandatory != null ) { + for( Entry< String, String > entry : optionalIfSiblingPresentElseMandatory.entrySet() ) { + if( presentSDO.get( entry.getValue() ) == null ) { + if( presentSDO.get( entry.getKey() ) == null ) { + diagnostics.add( new BasicDiagnostic( + Diagnostic.ERROR, + RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE, + 0, + "[NSD validation] SDO " + entry.getKey() + " is mandatory in DOType (line " + doType.getLineNumber() + ") with LNClass " + + cdc.getName() + " because sibling " + entry.getValue() + " is not present", + new Object[] { doType } )); + res = false; + } + } + } + } + + // presCond: "FM" : + // Parameter sibling: sibling element name. + // Forbidden if sibling element is present, otherwise mandatory + // Usage in standard NSD files (version 2007B): None + if( forbiddenIfSiblingPresentElseMandatory != null ) { + for( Entry< String, String > entry : forbiddenIfSiblingPresentElseMandatory.entrySet() ) { + if( presentSDO.get( entry.getValue() ) != null ) { + if( presentSDO.get( entry.getKey() ) != null ) { + diagnostics.add( new BasicDiagnostic( + Diagnostic.ERROR, + RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE, + 0, + "[NSD validation] SDO " + entry.getKey() + " is forbidden in DOType (line " + doType.getLineNumber() + ") with LNClass " + + cdc.getName() + " because sibling " + entry.getValue() + " is present", + new Object[] { doType } )); + res = false; + } + } + else { + if( presentSDO.get( entry.getKey() ) == null ) { + diagnostics.add( new BasicDiagnostic( + Diagnostic.ERROR, + RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE, + 0, + "[NSD validation] SDO " + entry.getKey() + " is mandatory in DOType (line " + doType.getLineNumber() + ") with LNClass " + + cdc.getName() + " because sibling " + entry.getValue() + " is not present", + new Object[] { doType } )); + res = false; + } + } + } + } + + // presCond: "MOcond" : + // Parameter condID: condition number (> 0). + // Textual presence condition (non-machine processable) with reference condID to context specific text. + // If satisfied, the element is mandatory, otherwise optional + // Usage in standard NSD files (version 2007B): DataObject + if( mandatoryIfTextConditionElseOptional != null ) { + for( Entry< String, String > entry : mandatoryIfTextConditionElseOptional.entrySet() ) { + String doc = cdc + .getSubDataObject() + .stream() + .filter( d -> d.getName().equals( entry.getKey() )) + .findFirst() + .map( x -> x.getRefersToPresCondArgsDoc() ) + .map( p -> p.getMixed() ) + .map( p -> p.get( 0 ) ) + .map( p -> p.getValue() ) + .map( p -> p.toString() ) + .orElse( null ); + + diagnostics.add( new BasicDiagnostic( + Diagnostic.WARNING, + RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE, + 0, + "[NSD validation] SDO " + entry.getKey() + " is mandatory in DOType (line " + doType.getLineNumber() + ") with CDC " + + cdc.getName() + " if textual condition number " + entry.getValue() + " (not evaluated) is true, else optional. It is " + + ( presentSDO.get( entry.getKey() ) == null ? "absent." : "present." ) + ( doc != null ? " Textual condition is: \"" + doc + "\"." : "" ), + new Object[] { doType } )); + } + } + + // presCond: "MFcond" : + // Parameter condID: condition number (> 0). + // Textual presence condition (non-machine processable) with reference condID to context specific text. + // If satisfied, the element is mandatory, otherwise forbidden + // Usage in standard NSD files (version 2007B): DataObject + if( mandatoryIfTextConditionElseForbidden != null ) { + for( Entry< String, String > entry : mandatoryIfTextConditionElseForbidden.entrySet() ) { + String doc = cdc + .getSubDataObject() + .stream() + .filter( d -> d.getName().equals( entry.getKey() )) + .findFirst() + .map( x -> x.getRefersToPresCondArgsDoc() ) + .map( p -> p.getMixed() ) + .map( p -> p.get( 0 ) ) + .map( p -> p.getValue() ) + .map( p -> p.toString() ) + .orElse( null ); + + diagnostics.add( new BasicDiagnostic( + Diagnostic.WARNING, + RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE, + 0, + "[NSD validation] SDO " + entry.getKey() + " is mandatory in DOType (line " + doType.getLineNumber() + ") with CDC " + + cdc.getName() + " if textual condition number " + entry.getValue() + " (not evaluated) is true, else forbidden. It is " + + ( presentSDO.get( entry.getKey() ) == null ? "absent." : "present." ) + ( doc != null ? " Textual condition is: \"" + doc + "\"." : "" ), + new Object[] { doType } )); + } + } + + // presCond: "OFcond" : + // Parameter condID: condition number (> 0). + // Textual presence condition (non-machine processable) with reference condID to context specific text. + // If satisfied, the element is optional, otherwise forbidden + // Usage in standard NSD files (version 2007B): DataObject + if( optionalIfTextConditionElseForbidden != null ) { + for( Entry< String, String > entry : optionalIfTextConditionElseForbidden.entrySet() ) { + String doc = cdc + .getSubDataObject() + .stream() + .filter( d -> d.getName().equals( entry.getKey() )) + .findFirst() + .map( x -> x.getRefersToPresCondArgsDoc() ) + .map( p -> p.getMixed() ) + .map( p -> p.get( 0 ) ) + .map( p -> p.getValue() ) + .map( p -> p.toString() ) + .orElse( null ); + + diagnostics.add( new BasicDiagnostic( + Diagnostic.WARNING, + RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE, + 0, + "[NSD validation] SDO " + entry.getKey() + " is optional in DOType (line " + doType.getLineNumber() + ") with CDC " + + cdc.getName() + " if textual condition number " + entry.getValue() + " (not evaluated) is true, else forbidden. It is " + + ( presentSDO.get( entry.getKey() ) == null ? "absent." : "present." ) + ( doc != null ? " Textual condition is: \"" + doc + "\"." : "" ), + new Object[] { doType } )); + } + } + + // presCond: "MmultiRange" : + // Parameters min, max: limits for instance number (> 0). + // One or more elements shall be present; all instances have an instance number within range [min, max] (see IEC 61850-7-1) + // Usage in standard NSD files (version 2007B): None + if( mandatoryMultiRange != null ) { + for( String name : mandatoryMultiRange.keySet() ) { + if( presentSDO.get( name ) != null ) { + diagnostics.add( new BasicDiagnostic( + Diagnostic.WARNING, + RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE, + 0, + "[NSD validation] verification of PresenceCondition \"MmultiRange\" for SDO " + name + " is not implemented in DOType (line " + doType.getLineNumber() + ") with CDC " + cdc.getName(), + new Object[] { doType } )); + } + } + } + + // presCond: "OmultiRange" : + // Parameters min, max: limits for instance number (> 0). + // Zero or more elements may be present; all instances have an instance number within range [min, max] (see IEC 61850-7-1) + // Usage in standard NSD files (version 2007B): DataObject + if( optionalMultiRange != null ) { + for( String name : optionalMultiRange.keySet() ) { + if( presentSDO.get( name ) != null ) { + diagnostics.add( new BasicDiagnostic( + Diagnostic.WARNING, + RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE, + 0, + "[NSD validation] verification of PresenceCondition \"OmultiRange\" for SDO " + name + " is not implemented in DOType (line " + doType.getLineNumber() + ") with CDC " + cdc.getName(), + new Object[] { doType } )); + } + } + } + + // presCond: "MFsubst" : + // Element is mandatory if substitution is supported (for substitution, see IEC 61850-7-3), otherwise forbidden + // Usage in standard NSD files (version 2007B): DataAttribute + // TODO + if( mandatoryIfSubstitutionElseForbidden != null ) { + for( String name : mandatoryIfSubstitutionElseForbidden ) { + if( presentSDO.get( name ) != null ) { + diagnostics.add( new BasicDiagnostic( + Diagnostic.WARNING, + RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE, + 0, + "[NSD validation] verification of PresenceCondition \"MFsubst\" for SDO " + name + " is not implemented in DOType (line " + doType.getLineNumber() + ") with CDC " + cdc.getName(), + new Object[] { doType } )); + } + } + } + + // presCond: "MOln0" : + // Element is mandatory in the context of LLN0; otherwise optional + // Usage in standard NSD files (version 2007B): DataAttribute + if( mandatoryInLLN0ElseOptional != null ) { + EList< AbstractDataObject > adoList = doType.getReferredByAbstractDataObject(); + for( AbstractDataObject ado : adoList ) { + if( ado instanceof DO ) { + DO do_ = ( DO ) ado; + if( "LLN0".equals( do_.getParentLNodeType().getLnClass() )) { + for( String attribute : mandatoryInLLN0ElseOptional ) { + SDO sdo = presentSDO.get( attribute ); + if( sdo == null ) { + diagnostics.add( new BasicDiagnostic( + Diagnostic.ERROR, + RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE, + 0, + "[NSD validation] SDO " + attribute + " is mandatory in DOType (line " + doType.getLineNumber() + ") with LNClass LLN0", + new Object[] { doType } )); + res = false; + } + } + } + } + else { + // ado instanceof SDO + } + } + } + + // presCond: "MFln0" : + // Element is mandatory in the context of LLN0; otherwise forbidden + // Usage in standard NSD files (version 2007B): DataAttribute + if( mandatoryInLLN0ElseForbidden != null ) { + EList< AbstractDataObject > adoList = doType.getReferredByAbstractDataObject(); + for( AbstractDataObject ado : adoList ) { + if( ado instanceof DO ) { + DO do_ = ( DO ) ado; + if( "LLN0".equals( do_.getParentLNodeType().getLnClass() )) { + for( String attribute : mandatoryInLLN0ElseForbidden ) { + SDO sdo = presentSDO.get( attribute ); + if( sdo == null ) { + diagnostics.add( new BasicDiagnostic( + Diagnostic.ERROR, + RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE, + 0, + "[NSD validation] SDO " + attribute + " is mandatory in DOType (line " + doType.getLineNumber() + ") with LNClass LLN0", + new Object[] { doType } )); + res = false; + } + } + } + else { + for( String attribute : mandatoryInLLN0ElseForbidden ) { + SDO sdo = presentSDO.get( attribute ); + if( sdo != null ) { + diagnostics.add( new BasicDiagnostic( + Diagnostic.ERROR, + RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE, + 0, + "[NSD validation] SDO " + attribute + " is forbidden in DOType (line " + doType.getLineNumber() + ") with LNClass " + do_.getParentLNodeType().getLnClass(), + new Object[] { doType } )); + res = false; + } + } + } + } + else { + // ado instanceof SDO + } + } + } + + // presCond: "MOlnNs" : + // Element is mandatory if the name space of its logical node deviates from the name space of the containing + // logical device, otherwise optional. See IEC 61850-7-1 for use of name space + // Usage in standard NSD files (version 2007B): DataAttribute + // TODO: The meaning is not clear. + if( mandatoryIfNameSpaceOfLogicalNodeDeviatesElseOptional != null ) { + for( String name : mandatoryIfNameSpaceOfLogicalNodeDeviatesElseOptional ) { + if( presentSDO.get( name ) != null ) { + diagnostics.add( new BasicDiagnostic( + Diagnostic.WARNING, + RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE, + 0, + "[NSD validation] verification of PresenceCondition \"MOlnNs\" for SDO " + name + " is not implemented in DOType (line " + doType.getLineNumber() + ") with CDC " + cdc.getName(), + new Object[] { doType } )); + } + } + } + + // presCond: "MOdataNs" : + // Element is mandatory if the name space of its data object deviates from the name space of its logical node, + // otherwise optional. See IEC 61850-7-1 for use of name space + // Usage in standard NSD files (version 2007B): DataAttribute + // TODO: The meaning is not clear. + if( mandatoryIfNameSpaceOfDataObjectDeviatesElseOptional != null ) { + for( String name : mandatoryIfNameSpaceOfDataObjectDeviatesElseOptional ) { + if( presentSDO.get( name ) != null ) { + diagnostics.add( new BasicDiagnostic( + Diagnostic.WARNING, + RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE, + 0, + "[NSD validation] verification of PresenceCondition \"MOdataNs\" for SDO " + name + " is not implemented in DOType (line " + doType.getLineNumber() + ") with CDC " + cdc.getName(), + new Object[] { doType } )); + } + } + } + + // presCond: "MFscaledAV" : + // Element is mandatory* if any sibling elements of type AnalogueValue include 'i' as a child, otherwise forbidden. + // *Even though devices without floating point capability cannot exchange floating point values through ACSI services, + // the description of scaling remains mandatory for their (SCL) configuration + // Usage in standard NSD files (version 2007B): DataAttribute + // TODO + if( mandatoryIfAnalogValueIncludesIElseForbidden != null ) { + for( String name : mandatoryIfAnalogValueIncludesIElseForbidden ) { + if( presentSDO.get( name ) != null ) { + diagnostics.add( new BasicDiagnostic( + Diagnostic.WARNING, + RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE, + 0, + "[NSD validation] verification of PresenceCondition \"MFscaledAV\" for SDO " + name + " is not implemented in DOType (line " + doType.getLineNumber() + ") with CDC " + cdc.getName(), + new Object[] { doType } )); + } + } + } + + // presCond: "MFscaledMagV" : + // Element is mandatory* if any sibling elements of type Vector include 'i' as a child of their 'mag' attribute, otherwise forbidden. + // *See MFscaledAV + // Usage in standard NSD files (version 2007B): DataAttribute + // TODO + if( mandatoryIfVectorSiblingIncludesIAsChildMagElseForbidden != null ) { + for( String name : mandatoryIfVectorSiblingIncludesIAsChildMagElseForbidden ) { + if( presentSDO.get( name ) != null ) { + diagnostics.add( new BasicDiagnostic( + Diagnostic.WARNING, + RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE, + 0, + "[NSD validation] verification of PresenceCondition \"MFscaledMagV\" for SDO " + name + " is not implemented in DOType (line " + doType.getLineNumber() + ") with CDC " + cdc.getName(), + new Object[] { doType } )); + } + } + } + + // presCond: "MFscaledAngV" : + // Element is mandatory* if any sibling elements of type Vector include 'i' as a child of their 'ang' attribute, otherwise forbidden. + // *See MFscaledAV + // Usage in standard NSD files (version 2007B): DataAttribute + // TODO + if( mandatoryIfVectorSiblingIncludesIAsChildAngElseForbidden != null ) { + for( String name : mandatoryIfVectorSiblingIncludesIAsChildAngElseForbidden ) { + if( presentSDO.get( name ) != null ) { + diagnostics.add( new BasicDiagnostic( + Diagnostic.WARNING, + RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE, + 0, + "[NSD validation] verification of PresenceCondition \"MFscaledAngV\" for SDO " + name + " is not implemented in DOType (line " + doType.getLineNumber() + ") with CDC " + cdc.getName(), + new Object[] { doType } )); + } + } + } + + // presCond: "MOrms" : + // Element is mandatory if the harmonic values in the context are calculated as a ratio to RMS value + // (value of data attribute 'hvRef' is 'rms'), optional otherwise + // Usage in standard NSD files (version 2007B): DataAttribute + // TODO + if( mandatoryIfHarmonicValuesCalculatedAsRatioElseOptional != null ) { + for( String name : mandatoryIfHarmonicValuesCalculatedAsRatioElseOptional ) { + if( presentSDO.get( name ) != null ) { + diagnostics.add( new BasicDiagnostic( + Diagnostic.WARNING, + RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE, + 0, + "[NSD validation] verification of PresenceCondition \"MOrms\" for SDO " + name + " is not implemented in DOType (line " + doType.getLineNumber() + ") with CDC " + cdc.getName(), + new Object[] { doType } )); + } + } + } + + // presCond: "MOrootLD" : + // Element is mandatory in the context of a root logical device; otherwise it is optional + // Usage in standard NSD files (version 2007B): DataObject + if( mandatoryInRootLogicalDeviceElseOptional != null ) { + for( String name : mandatoryInRootLogicalDeviceElseOptional ) { + if( presentSDO.get( name ) != null ) { + diagnostics.add( new BasicDiagnostic( + Diagnostic.WARNING, + RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE, + 0, + "[NSD validation] verification of PresenceCondition \"MOrootLD\" for SDO " + name + " is not implemented in DOType (line " + doType.getLineNumber() + ") with CDC " + cdc.getName(), + new Object[] { doType } )); + } + } + } + + // presCond: "MOoperTm" : + // Element is mandatory if at least one controlled object on the IED supports time activation service; otherwise it is optional + // Usage in standard NSD files (version 2007B): DataAttribute + // TODO + if( mandatoryIfControlSupportsTimeElseOptional != null ) { + for( String name : mandatoryIfControlSupportsTimeElseOptional ) { + if( presentSDO.get( name ) != null ) { + diagnostics.add( new BasicDiagnostic( + Diagnostic.WARNING, + RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE, + 0, + "[NSD validation] verification of PresenceCondition \"MOoperTm\" for SDO " + name + " is not implemented in DOType (line " + doType.getLineNumber() + ") with CDC " + cdc.getName(), + new Object[] { doType } )); + } + } + } + + // presCond: "MmultiF" : + // Parameter sibling: sibling element name. + // One or more elements must be present if sibling element is present, otherwise forbidden + // Usage in standard NSD files (version 2007B): DataObject + // TODO: One or more elements ? Is there an instance number ? + if( oneOrMoreIfSiblingPresentElseForbidden != null ) { + for( String name : oneOrMoreIfSiblingPresentElseForbidden.keySet() ) { + if( presentSDO.get( name ) != null ) { + diagnostics.add( new BasicDiagnostic( + Diagnostic.WARNING, + RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE, + 0, + "[NSD validation] verification of PresenceCondition \"MmultiF\" for SDO " + name + " is not implemented in DOType (line " + doType.getLineNumber() + ") with CDC " + cdc.getName(), + new Object[] { doType } )); + } + } + } + + // presCond: "MOsbo" : + // Element is mandatory if declared control model supports 'sbo-with-normal-security' or 'sbo-with-enhanced-security', + // otherwise optional and value is of no impact + // Usage in standard NSD files (version 2007B): DataAttribute + // TODO + if( mandatoryIfControlSupportsSecurity1ElseOptional != null ) { + for( String name : mandatoryIfControlSupportsSecurity1ElseOptional ) { + if( presentSDO.get( name ) != null ) { + diagnostics.add( new BasicDiagnostic( + Diagnostic.WARNING, + RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE, + 0, + "[NSD validation] verification of PresenceCondition \"MOsbo\" for SDO " + name + " is not implemented in DOType (line " + doType.getLineNumber() + ") with CDC " + cdc.getName(), + new Object[] { doType } )); + } + } + } + + // presCond: "MOenhanced" : + // Element is mandatory if declared control model supports 'direct-with-enhanced-security' or 'sbo-with-enhanced-security', + // otherwise optional and value is of no impact + // Usage in standard NSD files (version 2007B): DataAttribute + // TODO + if( mandatoryIfControlSupportsSecurity2ElseOptional != null ) { + for( String name : mandatoryIfControlSupportsSecurity2ElseOptional ) { + if( presentSDO.get( name ) != null ) { + diagnostics.add( new BasicDiagnostic( + Diagnostic.WARNING, + RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE, + 0, + "[NSD validation] verification of PresenceCondition \"MOenhanced\" for SDO " + name + " is not implemented in DOType (line " + doType.getLineNumber() + ") with CDC " + cdc.getName(), + new Object[] { doType } )); + } + } + } + + // presCond: "MONamPlt" : + // Element is mandatory if the name space of its logical node deviates from the name space of the containing + // logical device, otherwise optional. See IEC 61850-7-1 for use of name space + // Usage in standard NSD files (version 2007B): DataObject + // TODO: same as "MOlnNs" ? + if( mandatoryIfNameSpaceOfLogicalNodeDeviatesElseOptional2 != null ) { + for( String name : mandatoryIfNameSpaceOfLogicalNodeDeviatesElseOptional2 ) { + if( presentSDO.get( name ) != null ) { + diagnostics.add( new BasicDiagnostic( + Diagnostic.WARNING, + RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE, + 0, + "[NSD validation] verification of PresenceCondition \"MONamPlt\" for SDO " + name + " is not implemented in DOType (line " + doType.getLineNumber() + ") with CDC " + cdc.getName(), + new Object[] { doType } )); + } + } + } + + // presCond: "OF" : + // Parameter sibling: sibling element name. + // Optional if sibling element is present, otherwise forbidden + // Usage in standard NSD files (version 2007B): DataObject and DataAttribute + if( optionalIfSiblingPresentElseForbidden != null ) { + for( Entry< String, String > entry : optionalIfSiblingPresentElseForbidden.entrySet() ) { + if( presentSDO.get( entry.getValue() ) == null ) { + if( presentSDO.get( entry.getKey() ) != null ) { + diagnostics.add( new BasicDiagnostic( + Diagnostic.ERROR, + RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE, + 0, + "[NSD validation] SDO " + entry.getKey() + " is forbidden in DOType (line " + doType.getLineNumber() + ") with LNClass " + + cdc.getName() + " because sibling " + entry.getValue() + " is not present", + new Object[] { doType } )); + res = false; + } + } + } + } + + // presCond: "MORange" : + // Element is mandatory if the measured value associated (amplitude respectively angle) exposes the range eventing + // (with the attribute range respectively rangeAng) + // Usage in standard NSD files (version 2007B): SubDataAttribute + // TODO + if( mandatoryIfMeasuredValueExposesRange != null ) { + for( String name : mandatoryIfMeasuredValueExposesRange ) { + if( presentSDO.get( name ) != null ) { + diagnostics.add( new BasicDiagnostic( + Diagnostic.WARNING, + RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE, + 0, + "[NSD validation] verification of PresenceCondition \"MORange\" for SDO " + name + " is not implemented in DOType (line " + doType.getLineNumber() + ") with CDC " + cdc.getName(), + new Object[] { doType } )); + } + } + } + + // presCond: "OMSynPh" : + // This attribute is optional if value of 'phsRef'' is Synchrophasor otherwise Mandatory]]></Doc> + // Usage in standard NSD files (version 2007B): SubDataObject + // TODO + if( optionalIfPhsRefIsSynchrophasorElseMandatory != null ) { + for( String name : optionalIfPhsRefIsSynchrophasorElseMandatory ) { + if( presentSDO.get( name ) != null ) { + diagnostics.add( new BasicDiagnostic( + Diagnostic.WARNING, + RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE, + 0, + "[NSD validation] verification of PresenceCondition \"OMSynPh\" for SDO " + name + " is not implemented in DOType (line " + doType.getLineNumber() + ") with CDC " + cdc.getName(), + new Object[] { doType } )); + } + } + } + + return res; + } + +} -- GitLab