From ae8284f4bbab1e45370310143b69eaae648cb369 Mon Sep 17 00:00:00 2001 From: Dominique Marcadet <Dominique.Marcadet@centralesupelec.fr> Date: Thu, 4 Jul 2019 15:33:39 +0200 Subject: [PATCH] add cleaning actions for multiple file and reentrancy support --- .../scl/validator/RiseClipseValidatorSCL.java | 9 +- .../scl/validator/nsd/BasicTypeValidator.java | 13 + .../scl/validator/nsd/CDCValidator.java | 36 +- .../nsd/ConstructedAttributeValidator.java | 21 +- ...taAttributePresenceConditionValidator.java | 6 +- .../DataObjectPresenceConditionValidator.java | 6 +- .../validator/nsd/EnumerationValidator.java | 18 +- .../GenericPresenceConditionValidator.java | 12 +- .../scl/validator/nsd/LNClassValidator.java | 27 +- .../validator/nsd/NsdEObjectValidator.java | 15 + .../scl/validator/nsd/NsdValidator.java | 11 +- ...taAttributePresenceConditionValidator.java | 1421 +++++++++++++++++ ...taAttributePresenceConditionValidator.java | 6 +- ...bDataObjectPresenceConditionValidator.java | 6 +- .../scl/validator/nsd/TypeValidator.java | 20 +- 15 files changed, 1604 insertions(+), 23 deletions(-) create mode 100644 fr.centralesupelec.edf.riseclipse.iec61850.scl.validator/src/fr/centralesupelec/edf/riseclipse/iec61850/scl/validator/nsd/OldDataAttributePresenceConditionValidator.java diff --git a/fr.centralesupelec.edf.riseclipse.iec61850.scl.validator/src/fr/centralesupelec/edf/riseclipse/iec61850/scl/validator/RiseClipseValidatorSCL.java b/fr.centralesupelec.edf.riseclipse.iec61850.scl.validator/src/fr/centralesupelec/edf/riseclipse/iec61850/scl/validator/RiseClipseValidatorSCL.java index 48e7202..2c03a5d 100644 --- a/fr.centralesupelec.edf.riseclipse.iec61850.scl.validator/src/fr/centralesupelec/edf/riseclipse/iec61850/scl/validator/RiseClipseValidatorSCL.java +++ b/fr.centralesupelec.edf.riseclipse.iec61850.scl.validator/src/fr/centralesupelec/edf/riseclipse/iec61850/scl/validator/RiseClipseValidatorSCL.java @@ -309,7 +309,7 @@ public class RiseClipseValidatorSCL { console.info( "Web site:" ); console.info( " http://wdi.supelec.fr/software/RiseClipse/" ); console.info( "" ); - console.info( "RiseClipseValidatorSCL version: 1.1.0 a10 (1 July 2019)" ); + console.info( "RiseClipseValidatorSCL version: 1.1.0 a11 (4 July 2019)" ); console.info( "" ); } @@ -334,6 +334,9 @@ public class RiseClipseValidatorSCL { } if(( nsdFiles != null ) && ( ! nsdFiles.isEmpty() )) { + // There are some static attributes + NsdValidator.initialize(); + nsdValidator = new NsdValidator( sclPg ); for( int i = 0; i < nsdFiles.size(); ++i ) { nsdValidator.addNsdDocument( nsdFiles.get( i ), console ); @@ -358,6 +361,10 @@ public class RiseClipseValidatorSCL { } if( resource != null ) { console.info( "Validating file: " + sclFile ); + // Some attributes must be re-initalialized + if( nsdValidator != null ) nsdValidator.reset(); + // Not needed for the OCL validator + // if( oclValidator != null ) oclValidator.reset(); validate( resource, sclAdapter ); } } diff --git a/fr.centralesupelec.edf.riseclipse.iec61850.scl.validator/src/fr/centralesupelec/edf/riseclipse/iec61850/scl/validator/nsd/BasicTypeValidator.java b/fr.centralesupelec.edf.riseclipse.iec61850.scl.validator/src/fr/centralesupelec/edf/riseclipse/iec61850/scl/validator/nsd/BasicTypeValidator.java index 22240c2..3cb6925 100644 --- a/fr.centralesupelec.edf.riseclipse.iec61850.scl.validator/src/fr/centralesupelec/edf/riseclipse/iec61850/scl/validator/nsd/BasicTypeValidator.java +++ b/fr.centralesupelec.edf.riseclipse.iec61850.scl.validator/src/fr/centralesupelec/edf/riseclipse/iec61850/scl/validator/nsd/BasicTypeValidator.java @@ -38,6 +38,11 @@ public abstract class BasicTypeValidator extends TypeValidator { private static HashMap< String, BasicTypeValidator > validators = new HashMap<>(); + public static void initialize() { + // No store data + //validators = new HashMap<>(); + } + public static BasicTypeValidator get( BasicType basicType ) { return validators.get( basicType.getName() ); } @@ -511,6 +516,14 @@ public abstract class BasicTypeValidator extends TypeValidator { return name; } + /* + * Called before another file is validated + */ + @Override + public void reset() { + // Nothing + } + @Override public boolean validateAbstractDataAttribute( AbstractDataAttribute ada, DiagnosticChain diagnostics ) { AbstractRiseClipseConsole.getConsole().verbose( "[NSD validation] BasicTypeValidator.validateDA( " + ada.getName() + " ) at line " + ada.getLineNumber() ); diff --git a/fr.centralesupelec.edf.riseclipse.iec61850.scl.validator/src/fr/centralesupelec/edf/riseclipse/iec61850/scl/validator/nsd/CDCValidator.java b/fr.centralesupelec.edf.riseclipse.iec61850.scl.validator/src/fr/centralesupelec/edf/riseclipse/iec61850/scl/validator/nsd/CDCValidator.java index a902c8b..c062d6d 100644 --- a/fr.centralesupelec.edf.riseclipse.iec61850.scl.validator/src/fr/centralesupelec/edf/riseclipse/iec61850/scl/validator/nsd/CDCValidator.java +++ b/fr.centralesupelec.edf.riseclipse.iec61850.scl.validator/src/fr/centralesupelec/edf/riseclipse/iec61850/scl/validator/nsd/CDCValidator.java @@ -34,10 +34,19 @@ import fr.centralesupelec.edf.riseclipse.util.AbstractRiseClipseConsole; public class CDCValidator { - private static HashMap< String, CDCValidator > validators = new HashMap<>(); + private static HashMap< String, CDCValidator > validators; + public static void initialize() { + // Allow reentrancy + validators = new HashMap<>(); + + DataAttributePresenceConditionValidator.initialize(); + SubDataObjectPresenceConditionValidator.initialize(); + } + public static CDCValidator get( String name ) { - return validators.get( name ); + if( validators == null ) return null; + return validators.get( name ); } public static void buildValidators( Stream< CDC > stream ) { @@ -45,7 +54,21 @@ public class CDCValidator { .forEach( cdc -> validators.put( cdc.getName(), new CDCValidator( cdc ))); } - private static HashSet< String > validatedDOType = new HashSet<>(); + /* + * Called before another file is validated + */ + public static void resetValidators() { + validators.values().stream().forEach( v -> v.reset() ); + } + + public void reset() { + validatedDOType = new HashSet<>(); + + dataAttributeValidatorMap.values().stream().forEach( v -> v.reset() ); + subDataObjectValidatorMap.values().stream().forEach( v -> v.reset() ); + } + + private HashSet< String > validatedDOType; private DataAttributePresenceConditionValidator dataAttributePresenceConditionValidator; private SubDataObjectPresenceConditionValidator subDataObjectPresenceConditionValidator; @@ -76,6 +99,7 @@ public class CDCValidator { } } + reset(); } public boolean validateDOType( DOType doType, DiagnosticChain diagnostics ) { @@ -83,7 +107,8 @@ public class CDCValidator { AbstractRiseClipseConsole.getConsole().verbose( "[NSD validation] CDCValidator.validateDOType( " + doType.getId() + " ) at line " + doType.getLineNumber() ); validatedDOType.add( doType.getId() ); - dataAttributePresenceConditionValidator.reset(); + dataAttributePresenceConditionValidator.resetModelData(); + doType .getDA() .stream() @@ -91,7 +116,8 @@ public class CDCValidator { boolean res = dataAttributePresenceConditionValidator.validate( doType, diagnostics ); - subDataObjectPresenceConditionValidator.reset(); + subDataObjectPresenceConditionValidator.resetModelData(); + doType .getSDO() .stream() diff --git a/fr.centralesupelec.edf.riseclipse.iec61850.scl.validator/src/fr/centralesupelec/edf/riseclipse/iec61850/scl/validator/nsd/ConstructedAttributeValidator.java b/fr.centralesupelec.edf.riseclipse.iec61850.scl.validator/src/fr/centralesupelec/edf/riseclipse/iec61850/scl/validator/nsd/ConstructedAttributeValidator.java index 826dc25..1dbf433 100644 --- a/fr.centralesupelec.edf.riseclipse.iec61850.scl.validator/src/fr/centralesupelec/edf/riseclipse/iec61850/scl/validator/nsd/ConstructedAttributeValidator.java +++ b/fr.centralesupelec.edf.riseclipse.iec61850.scl.validator/src/fr/centralesupelec/edf/riseclipse/iec61850/scl/validator/nsd/ConstructedAttributeValidator.java @@ -32,7 +32,11 @@ import fr.centralesupelec.edf.riseclipse.util.AbstractRiseClipseConsole; public class ConstructedAttributeValidator extends TypeValidator { - private static HashSet< String > validatedDAType = new HashSet<>(); + public static void initialize() { + SubDataAttributePresenceConditionValidator.initialize(); + } + + private HashSet< String > validatedDAType; private SubDataAttributePresenceConditionValidator subDataAttributePresenceConditionValidator; private HashMap< String, TypeValidator > subDataAttributeValidatorMap = new HashMap<>(); @@ -49,6 +53,18 @@ public class ConstructedAttributeValidator extends TypeValidator { AbstractRiseClipseConsole.getConsole().warning( "[NSD setup] (" + sda.getFilename() + ":" + sda.getLineNumber() + ") Type not found for DataAttribute " + sda.getName() ); } } + + reset(); + } + + /* + * Called before another file is validated + */ + @Override + public void reset() { + validatedDAType = new HashSet<>(); + + subDataAttributeValidatorMap.values().stream().forEach( v -> v.reset() ); } @Override @@ -67,7 +83,8 @@ public class ConstructedAttributeValidator extends TypeValidator { AbstractRiseClipseConsole.getConsole().verbose( "[NSD validation] ConstructedAttributeValidator.validateDAType( " + daType.getId() + " ) at line " + daType.getLineNumber() ); validatedDAType.add( daType.getId() ); - subDataAttributePresenceConditionValidator.reset(); + subDataAttributePresenceConditionValidator.resetModelData(); + daType .getBDA() .stream() diff --git a/fr.centralesupelec.edf.riseclipse.iec61850.scl.validator/src/fr/centralesupelec/edf/riseclipse/iec61850/scl/validator/nsd/DataAttributePresenceConditionValidator.java b/fr.centralesupelec.edf.riseclipse.iec61850.scl.validator/src/fr/centralesupelec/edf/riseclipse/iec61850/scl/validator/nsd/DataAttributePresenceConditionValidator.java index 4c8fea1..67e4daa 100644 --- a/fr.centralesupelec.edf.riseclipse.iec61850.scl.validator/src/fr/centralesupelec/edf/riseclipse/iec61850/scl/validator/nsd/DataAttributePresenceConditionValidator.java +++ b/fr.centralesupelec.edf.riseclipse.iec61850.scl.validator/src/fr/centralesupelec/edf/riseclipse/iec61850/scl/validator/nsd/DataAttributePresenceConditionValidator.java @@ -35,7 +35,11 @@ import fr.centralesupelec.edf.riseclipse.iec61850.scl.validator.RiseClipseValida public class DataAttributePresenceConditionValidator extends GenericPresenceConditionValidator< CDC, DOType, @Nullable DA >{ - private static HashMap< String, DataAttributePresenceConditionValidator > validators = new HashMap<>(); + private static HashMap< String, DataAttributePresenceConditionValidator > validators; + + public static void initialize() { + validators = new HashMap<>(); + } public static DataAttributePresenceConditionValidator get( CDC cdc ) { if( ! validators.containsKey( cdc.getName() )) { diff --git a/fr.centralesupelec.edf.riseclipse.iec61850.scl.validator/src/fr/centralesupelec/edf/riseclipse/iec61850/scl/validator/nsd/DataObjectPresenceConditionValidator.java b/fr.centralesupelec.edf.riseclipse.iec61850.scl.validator/src/fr/centralesupelec/edf/riseclipse/iec61850/scl/validator/nsd/DataObjectPresenceConditionValidator.java index 936bd8d..82907ea 100644 --- a/fr.centralesupelec.edf.riseclipse.iec61850.scl.validator/src/fr/centralesupelec/edf/riseclipse/iec61850/scl/validator/nsd/DataObjectPresenceConditionValidator.java +++ b/fr.centralesupelec.edf.riseclipse.iec61850.scl.validator/src/fr/centralesupelec/edf/riseclipse/iec61850/scl/validator/nsd/DataObjectPresenceConditionValidator.java @@ -42,7 +42,11 @@ import fr.centralesupelec.edf.riseclipse.util.IRiseClipseConsole; public class DataObjectPresenceConditionValidator { - private static HashMap< String, DataObjectPresenceConditionValidator > validators = new HashMap<>(); + private static HashMap< String, DataObjectPresenceConditionValidator > validators; + + public static void initialize() { + validators = new HashMap<>(); + } public static DataObjectPresenceConditionValidator get( AnyLNClass anyLNClass ) { if( ! validators.containsKey( anyLNClass.getName() )) { diff --git a/fr.centralesupelec.edf.riseclipse.iec61850.scl.validator/src/fr/centralesupelec/edf/riseclipse/iec61850/scl/validator/nsd/EnumerationValidator.java b/fr.centralesupelec.edf.riseclipse.iec61850.scl.validator/src/fr/centralesupelec/edf/riseclipse/iec61850/scl/validator/nsd/EnumerationValidator.java index 132763d..63490cb 100644 --- a/fr.centralesupelec.edf.riseclipse.iec61850.scl.validator/src/fr/centralesupelec/edf/riseclipse/iec61850/scl/validator/nsd/EnumerationValidator.java +++ b/fr.centralesupelec.edf.riseclipse.iec61850.scl.validator/src/fr/centralesupelec/edf/riseclipse/iec61850/scl/validator/nsd/EnumerationValidator.java @@ -38,7 +38,11 @@ import fr.centralesupelec.edf.riseclipse.util.AbstractRiseClipseConsole; public class EnumerationValidator extends TypeValidator { - private static HashSet< String > validatedEnumType = new HashSet<>(); + public static void initialize() { + // Nothing here + } + + private HashSet< String > validatedEnumType; // Name of EnumVal may be empty, so we use LiteralVal as key private HashMap< Integer, String > literals = new HashMap<>(); @@ -54,12 +58,24 @@ public class EnumerationValidator extends TypeValidator { .getLiteral() .stream() .forEach( e -> literals.put( e.getLiteralVal(), e.getName() )); + + reset(); } public String getName() { return name; } + /* + * Called before another file is validated + */ + @Override + public void reset() { + validatedEnumType = new HashSet<>(); + + if( inheritedFrom != null ) inheritedFrom.reset(); + } + @Override public boolean validateAbstractDataAttribute( AbstractDataAttribute ada, DiagnosticChain diagnostics ) { AbstractRiseClipseConsole.getConsole().verbose( "[NSD validation] EnumerationValidator.validateAbstractDataAttribute( " + ada.getName() + " ) at line " + ada.getLineNumber() ); diff --git a/fr.centralesupelec.edf.riseclipse.iec61850.scl.validator/src/fr/centralesupelec/edf/riseclipse/iec61850/scl/validator/nsd/GenericPresenceConditionValidator.java b/fr.centralesupelec.edf.riseclipse.iec61850.scl.validator/src/fr/centralesupelec/edf/riseclipse/iec61850/scl/validator/nsd/GenericPresenceConditionValidator.java index e664872..3d92cc8 100644 --- a/fr.centralesupelec.edf.riseclipse.iec61850.scl.validator/src/fr/centralesupelec/edf/riseclipse/iec61850/scl/validator/nsd/GenericPresenceConditionValidator.java +++ b/fr.centralesupelec.edf.riseclipse.iec61850.scl.validator/src/fr/centralesupelec/edf/riseclipse/iec61850/scl/validator/nsd/GenericPresenceConditionValidator.java @@ -102,12 +102,6 @@ public abstract class GenericPresenceConditionValidator< NsdModel extends NsdObj protected abstract String getSclModelClassName(); protected abstract String getSclComponentClassName(); - public void reset() { - for( String sclComponent : presentSclComponent.keySet() ) { - presentSclComponent.put( sclComponent, null ); - } - } - protected void addSpecification( String name, String presCond, String presCondArgs, Doc doc, int lineNumber, String fileName ) { if( presentSclComponent.containsKey( name )) { console.warning( "[NSD setup] (" + fileName + ":" + lineNumber + ") has already been added to " + getPresenceConditionValidatorName() ); @@ -541,6 +535,12 @@ public abstract class GenericPresenceConditionValidator< NsdModel extends NsdObj } } + public void resetModelData() { + for( String sclComponent : presentSclComponent.keySet() ) { + presentSclComponent.put( sclComponent, null ); + } + } + public boolean addModelData( @NonNull SclComponent sclComponent, String sclComponentName, DiagnosticChain diagnostics ) { if( ! presentSclComponent.containsKey( sclComponentName )) { diagnostics.add( new BasicDiagnostic( diff --git a/fr.centralesupelec.edf.riseclipse.iec61850.scl.validator/src/fr/centralesupelec/edf/riseclipse/iec61850/scl/validator/nsd/LNClassValidator.java b/fr.centralesupelec.edf.riseclipse.iec61850.scl.validator/src/fr/centralesupelec/edf/riseclipse/iec61850/scl/validator/nsd/LNClassValidator.java index b8c1a61..c25156c 100644 --- a/fr.centralesupelec.edf.riseclipse.iec61850.scl.validator/src/fr/centralesupelec/edf/riseclipse/iec61850/scl/validator/nsd/LNClassValidator.java +++ b/fr.centralesupelec.edf.riseclipse.iec61850.scl.validator/src/fr/centralesupelec/edf/riseclipse/iec61850/scl/validator/nsd/LNClassValidator.java @@ -34,9 +34,17 @@ import fr.centralesupelec.edf.riseclipse.util.AbstractRiseClipseConsole; public class LNClassValidator { - private static HashMap< String, LNClassValidator > validators = new HashMap<>(); + private static HashMap< String, LNClassValidator > validators; + public static void initialize() { + // Allow reentrancy + validators = new HashMap<>(); + + DataObjectPresenceConditionValidator.initialize(); + } + public static LNClassValidator get( String name ) { + if( validators == null ) return null; return validators.get( name ); } @@ -45,7 +53,20 @@ public class LNClassValidator { .forEach( lnClass -> validators.put( lnClass.getName(), new LNClassValidator( lnClass ))); } - private static HashSet< String > validatedLNodeType = new HashSet<>(); + /* + * Called before another file is validated + */ + public static void resetValidators() { + validators.values().stream().forEach( v -> v.reset() ); + } + + private void reset() { + validatedLNodeType = new HashSet<>(); + + dataObjectValidatorMap.values().stream().forEach( v -> v.reset() ); + } + + private HashSet< String > validatedLNodeType; private DataObjectPresenceConditionValidator dataObjectPresenceConditionValidator; private HashMap< String, CDCValidator > dataObjectValidatorMap = new HashMap<>(); @@ -67,6 +88,8 @@ public class LNClassValidator { lnClass = lnClass.getRefersToAbstractLNClass(); } + + reset(); } public boolean validateLNodeType( LNodeType lNodeType, DiagnosticChain diagnostics ) { diff --git a/fr.centralesupelec.edf.riseclipse.iec61850.scl.validator/src/fr/centralesupelec/edf/riseclipse/iec61850/scl/validator/nsd/NsdEObjectValidator.java b/fr.centralesupelec.edf.riseclipse.iec61850.scl.validator/src/fr/centralesupelec/edf/riseclipse/iec61850/scl/validator/nsd/NsdEObjectValidator.java index 6a0379b..986a6a3 100644 --- a/fr.centralesupelec.edf.riseclipse.iec61850.scl.validator/src/fr/centralesupelec/edf/riseclipse/iec61850/scl/validator/nsd/NsdEObjectValidator.java +++ b/fr.centralesupelec.edf.riseclipse.iec61850.scl.validator/src/fr/centralesupelec/edf/riseclipse/iec61850/scl/validator/nsd/NsdEObjectValidator.java @@ -39,6 +39,12 @@ import fr.centralesupelec.edf.riseclipse.util.AbstractRiseClipseConsole; public class NsdEObjectValidator implements EValidator { + public static void initialize() { + TypeValidator.initialize(); + CDCValidator.initialize(); + LNClassValidator.initialize(); + } + public NsdEObjectValidator( NsdResourceSetImpl nsdResourceSet ) { // Order is important ! TypeValidator.buildValidators( @@ -51,6 +57,15 @@ public class NsdEObjectValidator implements EValidator { nsdResourceSet.getLNClassStream( RiseClipseValidatorSCL.DEFAULT_NS_IDENTIFICATION ) ); } + /* + * Called before another file is validated + */ + public void reset() { + TypeValidator.resetValidators(); + CDCValidator.resetValidators(); + LNClassValidator.resetValidators(); + } + @Override public boolean validate( EObject eObject, DiagnosticChain diagnostics, Map< Object, Object > context ) { return validate( eObject.eClass(), eObject, diagnostics, context ); diff --git a/fr.centralesupelec.edf.riseclipse.iec61850.scl.validator/src/fr/centralesupelec/edf/riseclipse/iec61850/scl/validator/nsd/NsdValidator.java b/fr.centralesupelec.edf.riseclipse.iec61850.scl.validator/src/fr/centralesupelec/edf/riseclipse/iec61850/scl/validator/nsd/NsdValidator.java index bcb7a17..f6a1baa 100644 --- a/fr.centralesupelec.edf.riseclipse.iec61850.scl.validator/src/fr/centralesupelec/edf/riseclipse/iec61850/scl/validator/nsd/NsdValidator.java +++ b/fr.centralesupelec.edf.riseclipse.iec61850.scl.validator/src/fr/centralesupelec/edf/riseclipse/iec61850/scl/validator/nsd/NsdValidator.java @@ -27,7 +27,12 @@ import fr.centralesupelec.edf.riseclipse.util.IRiseClipseConsole; public class NsdValidator { + public static void initialize() { + NsdEObjectValidator.initialize(); + } + private NsdModelLoader nsdLoader; + private NsdEObjectValidator nsdEObjectValidator; public NsdValidator( @NonNull EPackage modelPackage ) { nsdLoader = new NsdModelLoader(); @@ -44,7 +49,7 @@ public class NsdValidator { level = console.setLevel( IRiseClipseConsole.ERROR_LEVEL ); } nsdLoader.getResourceSet().finalizeLoad( console ); - NsdEObjectValidator nsdEObjectValidator = new NsdEObjectValidator( nsdLoader.getResourceSet() ); + nsdEObjectValidator = new NsdEObjectValidator( nsdLoader.getResourceSet() ); validator.addChild( nsdEObjectValidator ); if( ! displayNsdMessages ) { console.setLevel( level ); @@ -55,4 +60,8 @@ public class NsdValidator { return nsdLoader; } + public void reset() { + nsdEObjectValidator.reset(); + } + } diff --git a/fr.centralesupelec.edf.riseclipse.iec61850.scl.validator/src/fr/centralesupelec/edf/riseclipse/iec61850/scl/validator/nsd/OldDataAttributePresenceConditionValidator.java b/fr.centralesupelec.edf.riseclipse.iec61850.scl.validator/src/fr/centralesupelec/edf/riseclipse/iec61850/scl/validator/nsd/OldDataAttributePresenceConditionValidator.java new file mode 100644 index 0000000..3ec2065 --- /dev/null +++ b/fr.centralesupelec.edf.riseclipse.iec61850.scl.validator/src/fr/centralesupelec/edf/riseclipse/iec61850/scl/validator/nsd/OldDataAttributePresenceConditionValidator.java @@ -0,0 +1,1421 @@ +/** + * 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.DA; +import fr.centralesupelec.edf.riseclipse.iec61850.scl.DO; +import fr.centralesupelec.edf.riseclipse.iec61850.scl.DOType; +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 OldDataAttributePresenceConditionValidator { + + private static HashMap< String, OldDataAttributePresenceConditionValidator > validators = new HashMap<>(); + + public static OldDataAttributePresenceConditionValidator get( CDC cdc ) { + if( ! validators.containsKey( cdc.getName() )) { + validators.put( cdc.getName(), new OldDataAttributePresenceConditionValidator( cdc )); + } + return validators.get( cdc.getName() ); + } + + private CDC cdc; + + // Name of the DataAttribute/DA, DA + private HashMap< String, DA > presentDA = 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 OldDataAttributePresenceConditionValidator( CDC cdc ) { + this.cdc = cdc; + + cdc + .getDataAttribute() + .stream() + .forEach( da -> addSpecification( da.getName(), da.getPresCond(), da.getPresCondArgs() ) ); + + checkSpecification(); + } + + public void reset() { + for( String da : presentDA.keySet() ) { + presentDA.put( da, null ); + } + } + + private void addSpecification( String name, String presCond, String presCondArgs ) { + if( presentDA.containsKey( name )) { + console.warning( "[NSD setup] " + name + " has already been added to OldDataAttributePresenceConditionValidator" ); + return; + } + presentDA.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: DataAttribute " + 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: DataAttribute " + 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: DataAttribute " + 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: DataAttribute " + 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: DataAttribute " + 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: DataAttribute " + 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: DataAttribute " + 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: DataAttribute " + 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: DataAttribute " + 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: DataAttribute " + 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: DataAttribute " + 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: DataAttribute " + 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: DataAttribute " + 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: DataAttribute " + 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: DataAttribute " + 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: DataAttribute " + 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: DataAttribute " + 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: DataAttribute " + 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: DataAttribute " + 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: DataAttribute " + 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( ! presentDA.containsKey( e.getValue() )) { + console.warning( "[NSD setup] the sibling of " + e.getKey() + " in PresenceCondition of DataAttribute " + e.getKey() + " is unknown" ); + } + } + } + if( mandatoryIfSiblingPresentElseOptional != null ) { + for( Entry< String, String > e : mandatoryIfSiblingPresentElseOptional.entrySet() ) { + if( ! presentDA.containsKey( e.getValue() )) { + console.warning( "[NSD setup] the sibling of " + e.getKey() + " in PresenceCondition of DataAttribute " + e.getKey() + " is unknown" ); + } + } + } + if( optionalIfSiblingPresentElseMandatory != null ) { + for( Entry< String, String > e : optionalIfSiblingPresentElseMandatory.entrySet() ) { + if( ! presentDA.containsKey( e.getValue() )) { + console.warning( "[NSD setup] the sibling of " + e.getKey() + " in PresenceCondition of DataAttribute " + e.getKey() + " is unknown" ); + } + } + } + if( forbiddenIfSiblingPresentElseMandatory != null ) { + for( Entry< String, String > e : forbiddenIfSiblingPresentElseMandatory.entrySet() ) { + if( ! presentDA.containsKey( e.getValue() )) { + console.warning( "[NSD setup] the sibling of " + e.getKey() + " in PresenceCondition of DataAttribute " + e.getKey() + " is unknown" ); + } + } + } + if( oneOrMoreIfSiblingPresentElseForbidden != null ) { + for( Entry< String, String > e : oneOrMoreIfSiblingPresentElseForbidden.entrySet() ) { + if( ! presentDA.containsKey( e.getValue() )) { + console.warning( "[NSD setup] the sibling of " + e.getKey() + " in PresenceCondition of DataAttribute " + e.getKey() + " is unknown" ); + } + } + } + if( optionalIfSiblingPresentElseForbidden != null ) { + for( Entry< String, String > e : optionalIfSiblingPresentElseForbidden.entrySet() ) { + if( ! presentDA.containsKey( e.getValue() )) { + console.warning( "[NSD setup] the sibling of " + e.getKey() + " in PresenceCondition of DataAttribute " + e.getKey() + " is unknown" ); + } + } + } + } + + public boolean addDA( DA da, DiagnosticChain diagnostics ) { + if( ! presentDA.containsKey( da.getName() )) { + diagnostics.add( new BasicDiagnostic( + Diagnostic.ERROR, + RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE, + 0, + "[NSD validation] DA " + da.getName() + " in DOType (line " + da.getParentDOType().getLineNumber() + ") not found in CDC " + cdc.getName(), + new Object[] { da } )); + return false; + } + + if( presentDA.get( da.getName() ) != null ) { + diagnostics.add( new BasicDiagnostic( + Diagnostic.ERROR, + RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE, + 0, + "[NSD validation] DA " + da.getName() + " in DOType (line " + da.getParentDOType().getLineNumber() + ") already present in CDC " + cdc.getName(), + new Object[] { da } )); + return false; + } + presentDA.put( da.getName(), da ); + return true; + } + + public boolean validate( DOType doType, DiagnosticChain diagnostics ) { + AbstractRiseClipseConsole.getConsole().verbose( "[NSD validation] OldDataAttributePresenceConditionValidator.validate(id=" + 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 ) { + AbstractRiseClipseConsole.getConsole().verbose( "[NSD validation] validation of presence condition \"M\" on DOType (id=" + doType.getId() + ") at line " + doType.getLineNumber() ); + for( String name : this.mandatory ) { + if( presentDA.get( name ) == null ) { + diagnostics.add( new BasicDiagnostic( + Diagnostic.ERROR, + RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE, + 0, + "[NSD validation] DA " + 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 ) { + AbstractRiseClipseConsole.getConsole().verbose( "[NSD validation] validation of presence condition \"O\" on DOType (id=" + doType.getId() + ") at line " + doType.getLineNumber() ); + for( String name : this.optional ) { + if( presentDA.get( name ) == null ) { + // Nothing + } + } + } + + // presCond: "F" + // Element is forbidden + // Usage in standard NSD files (version 2007B): DataObject + if( forbidden != null ) { + AbstractRiseClipseConsole.getConsole().verbose( "[NSD validation] validation of presence condition \"F\" on DOType (id=" + doType.getId() + ") at line " + doType.getLineNumber() ); + for( String name : this.forbidden ) { + if( presentDA.get( name ) != null ) { + diagnostics.add( new BasicDiagnostic( + Diagnostic.ERROR, + RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE, + 0, + "[NSD validation] DA " + 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( presentDA.get( name ) != null ) { + diagnostics.add( new BasicDiagnostic( + Diagnostic.WARNING, + RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE, + 0, + "[NSD validation] verification of PresenceCondition \"na\" for DA " + 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( presentDA.get( name ) != null ) { + diagnostics.add( new BasicDiagnostic( + Diagnostic.WARNING, + RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE, + 0, + "[NSD validation] verification of PresenceCondition \"Mmulti\" for DA " + 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( presentDA.get( name ) != null ) { + diagnostics.add( new BasicDiagnostic( + Diagnostic.WARNING, + RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE, + 0, + "[NSD validation] verification of PresenceCondition \"Omulti\" for DA " + 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 ) { + AbstractRiseClipseConsole.getConsole().verbose( "[NSD validation] validation of presence condition \"AtLeastOne\" on DOType (id=" + doType.getId() + ") at line " + doType.getLineNumber() ); + for( Entry< Integer, HashSet< String > > e1 : atLeastOne.entrySet() ) { + boolean groupOK = false; + for( String member : e1.getValue() ) { + if( presentDA.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 ) { + AbstractRiseClipseConsole.getConsole().verbose( "[NSD validation] validation of presence condition \"AtMostOne\" on DOType (id=" + doType.getId() + ") at line " + doType.getLineNumber() ); + int count = 0; + for( String s : atMostOne ) { + if( presentDA.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 ) { + AbstractRiseClipseConsole.getConsole().verbose( "[NSD validation] validation of presence condition \"AllOrNonePerGroup\" on DOType (id=" + doType.getId() + ") at line " + doType.getLineNumber() ); + for( Entry< Integer, HashSet< String > > e1 : allOrNonePerGroup.entrySet() ) { + int groupCount = 0; + for( String member : e1.getValue() ) { + if( presentDA.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 ) { + AbstractRiseClipseConsole.getConsole().verbose( "[NSD validation] validation of presence condition \"AllOnlyOneGroup\" on DOType (id=" + doType.getId() + ") at line " + doType.getLineNumber() ); + int groupNumber = 0; + for( Entry< Integer, HashSet< String > > e1 : allOnlyOneGroup.entrySet() ) { + int groupCount = 0; + for( String member : e1.getValue() ) { + if( presentDA.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 ) { + AbstractRiseClipseConsole.getConsole().verbose( "[NSD validation] validation of presence condition \"AllAtLeastOneGroup\" on DOType (id=" + doType.getId() + ") at line " + doType.getLineNumber() ); + int groupNumber = 0; + for( Entry< Integer, HashSet< String > > e1 : allAtLeastOneGroup.entrySet() ) { + int groupCount = 0; + for( String member : e1.getValue() ) { + if( presentDA.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 ) { + AbstractRiseClipseConsole.getConsole().verbose( "[NSD validation] validation of presence condition \"MF\" on DOType (id=" + doType.getId() + ") at line " + doType.getLineNumber() ); + for( Entry< String, String > entry : mandatoryIfSiblingPresentElseForbidden.entrySet() ) { + if( presentDA.get( entry.getValue() ) != null ) { + if( presentDA.get( entry.getKey() ) == null ) { + diagnostics.add( new BasicDiagnostic( + Diagnostic.ERROR, + RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE, + 0, + "[NSD validation] DA " + 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( presentDA.get( entry.getKey() ) != null ) { + diagnostics.add( new BasicDiagnostic( + Diagnostic.ERROR, + RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE, + 0, + "[NSD validation] DA " + 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 ) { + AbstractRiseClipseConsole.getConsole().verbose( "[NSD validation] validation of presence condition \"MO\" on DOType (id=" + doType.getId() + ") at line " + doType.getLineNumber() ); + for( Entry< String, String > entry : mandatoryIfSiblingPresentElseOptional.entrySet() ) { + if( presentDA.get( entry.getValue() ) != null ) { + if( presentDA.get( entry.getKey() ) == null ) { + diagnostics.add( new BasicDiagnostic( + Diagnostic.ERROR, + RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE, + 0, + "[NSD validation] DA " + 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 ) { + AbstractRiseClipseConsole.getConsole().verbose( "[NSD validation] validation of presence condition \"OM\" on DOType (id=" + doType.getId() + ") at line " + doType.getLineNumber() ); + for( Entry< String, String > entry : optionalIfSiblingPresentElseMandatory.entrySet() ) { + if( presentDA.get( entry.getValue() ) == null ) { + if( presentDA.get( entry.getKey() ) == null ) { + diagnostics.add( new BasicDiagnostic( + Diagnostic.ERROR, + RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE, + 0, + "[NSD validation] DA " + 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 ) { + AbstractRiseClipseConsole.getConsole().verbose( "[NSD validation] validation of presence condition \"FM\" on DOType (id=" + doType.getId() + ") at line " + doType.getLineNumber() ); + for( Entry< String, String > entry : forbiddenIfSiblingPresentElseMandatory.entrySet() ) { + if( presentDA.get( entry.getValue() ) != null ) { + if( presentDA.get( entry.getKey() ) != null ) { + diagnostics.add( new BasicDiagnostic( + Diagnostic.ERROR, + RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE, + 0, + "[NSD validation] DA " + 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( presentDA.get( entry.getKey() ) == null ) { + diagnostics.add( new BasicDiagnostic( + Diagnostic.ERROR, + RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE, + 0, + "[NSD validation] DA " + 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 ) { + AbstractRiseClipseConsole.getConsole().verbose( "[NSD validation] validation of presence condition \"MOcond\" on DOType (id=" + doType.getId() + ") at line " + doType.getLineNumber() ); + for( Entry< String, String > entry : mandatoryIfTextConditionElseOptional.entrySet() ) { + String doc = cdc + .getDataAttribute() + .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] DA " + 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 " + + ( presentDA.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 ) { + AbstractRiseClipseConsole.getConsole().verbose( "[NSD validation] validation of presence condition \"MFcond\" on DOType (id=" + doType.getId() + ") at line " + doType.getLineNumber() ); + for( Entry< String, String > entry : mandatoryIfTextConditionElseForbidden.entrySet() ) { + String doc = cdc + .getDataAttribute() + .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] DA " + 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 " + + ( presentDA.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 ) { + AbstractRiseClipseConsole.getConsole().verbose( "[NSD validation] validation of presence condition \"OFcond\" on DOType (id=" + doType.getId() + ") at line " + doType.getLineNumber() ); + for( Entry< String, String > entry : optionalIfTextConditionElseForbidden.entrySet() ) { + String doc = cdc + .getDataAttribute() + .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] DA " + 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 " + + ( presentDA.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( presentDA.get( name ) != null ) { + diagnostics.add( new BasicDiagnostic( + Diagnostic.WARNING, + RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE, + 0, + "[NSD validation] verification of PresenceCondition \"MmultiRange\" for DA " + 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( presentDA.get( name ) != null ) { + diagnostics.add( new BasicDiagnostic( + Diagnostic.WARNING, + RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE, + 0, + "[NSD validation] verification of PresenceCondition \"OmultiRange\" for DA " + 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( presentDA.get( name ) != null ) { + diagnostics.add( new BasicDiagnostic( + Diagnostic.WARNING, + RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE, + 0, + "[NSD validation] verification of PresenceCondition \"MFsubst\" for DA " + 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 ) { + AbstractRiseClipseConsole.getConsole().verbose( "[NSD validation] validation of presence condition \"MOln0\" on DOType (id=" + doType.getId() + ") at line " + doType.getLineNumber() ); + 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 ) { + DA da = presentDA.get( attribute ); + if( da == null ) { + diagnostics.add( new BasicDiagnostic( + Diagnostic.ERROR, + RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE, + 0, + "[NSD validation] DA " + 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 ) { + AbstractRiseClipseConsole.getConsole().verbose( "[NSD validation] validation of presence condition \"MFln0\" on DOType (id=" + doType.getId() + ") at line " + doType.getLineNumber() ); + 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 ) { + DA da = presentDA.get( attribute ); + if( da == null ) { + diagnostics.add( new BasicDiagnostic( + Diagnostic.ERROR, + RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE, + 0, + "[NSD validation] DA " + attribute + " is mandatory in DOType (line " + doType.getLineNumber() + ") with LNClass LLN0", + new Object[] { doType } )); + res = false; + } + } + } + else { + for( String attribute : mandatoryInLLN0ElseForbidden ) { + DA da = presentDA.get( attribute ); + if( da != null ) { + diagnostics.add( new BasicDiagnostic( + Diagnostic.ERROR, + RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE, + 0, + "[NSD validation] DA " + 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( presentDA.get( name ) != null ) { + diagnostics.add( new BasicDiagnostic( + Diagnostic.WARNING, + RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE, + 0, + "[NSD validation] verification of PresenceCondition \"MOlnNs\" for DA " + 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( presentDA.get( name ) != null ) { + diagnostics.add( new BasicDiagnostic( + Diagnostic.WARNING, + RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE, + 0, + "[NSD validation] verification of PresenceCondition \"MOdataNs\" for DA " + 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( presentDA.get( name ) != null ) { + diagnostics.add( new BasicDiagnostic( + Diagnostic.WARNING, + RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE, + 0, + "[NSD validation] verification of PresenceCondition \"MFscaledAV\" for DA " + 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( presentDA.get( name ) != null ) { + diagnostics.add( new BasicDiagnostic( + Diagnostic.WARNING, + RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE, + 0, + "[NSD validation] verification of PresenceCondition \"MFscaledMagV\" for DA " + 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( presentDA.get( name ) != null ) { + diagnostics.add( new BasicDiagnostic( + Diagnostic.WARNING, + RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE, + 0, + "[NSD validation] verification of PresenceCondition \"MFscaledAngV\" for DA " + 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( presentDA.get( name ) != null ) { + diagnostics.add( new BasicDiagnostic( + Diagnostic.WARNING, + RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE, + 0, + "[NSD validation] verification of PresenceCondition \"MOrms\" for DA " + 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( presentDA.get( name ) != null ) { + diagnostics.add( new BasicDiagnostic( + Diagnostic.WARNING, + RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE, + 0, + "[NSD validation] verification of PresenceCondition \"MOrootLD\" for DA " + 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( presentDA.get( name ) != null ) { + diagnostics.add( new BasicDiagnostic( + Diagnostic.WARNING, + RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE, + 0, + "[NSD validation] verification of PresenceCondition \"MOoperTm\" for DA " + 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( presentDA.get( name ) != null ) { + diagnostics.add( new BasicDiagnostic( + Diagnostic.WARNING, + RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE, + 0, + "[NSD validation] verification of PresenceCondition \"MmultiF\" for DA " + 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( presentDA.get( name ) != null ) { + diagnostics.add( new BasicDiagnostic( + Diagnostic.WARNING, + RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE, + 0, + "[NSD validation] verification of PresenceCondition \"MOsbo\" for DA " + 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( presentDA.get( name ) != null ) { + diagnostics.add( new BasicDiagnostic( + Diagnostic.WARNING, + RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE, + 0, + "[NSD validation] verification of PresenceCondition \"MOenhanced\" for DA " + 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( presentDA.get( name ) != null ) { + diagnostics.add( new BasicDiagnostic( + Diagnostic.WARNING, + RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE, + 0, + "[NSD validation] verification of PresenceCondition \"MONamPlt\" for DA " + 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 ) { + AbstractRiseClipseConsole.getConsole().verbose( "[NSD validation] validation of presence condition \"OF\" on DOType (id=" + doType.getId() + ") at line " + doType.getLineNumber() ); + for( Entry< String, String > entry : optionalIfSiblingPresentElseForbidden.entrySet() ) { + if( presentDA.get( entry.getValue() ) == null ) { + if( presentDA.get( entry.getKey() ) != null ) { + diagnostics.add( new BasicDiagnostic( + Diagnostic.ERROR, + RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE, + 0, + "[NSD validation] DA " + 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( presentDA.get( name ) != null ) { + diagnostics.add( new BasicDiagnostic( + Diagnostic.WARNING, + RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE, + 0, + "[NSD validation] verification of PresenceCondition \"MORange\" for DA " + 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( presentDA.get( name ) != null ) { + diagnostics.add( new BasicDiagnostic( + Diagnostic.WARNING, + RiseClipseValidatorSCL.DIAGNOSTIC_SOURCE, + 0, + "[NSD validation] verification of PresenceCondition \"OMSynPh\" for DA " + name + " is not implemented in DOType (line " + doType.getLineNumber() + ") with CDC " + cdc.getName(), + new Object[] { doType } )); + } + } + } + + return res; + } + +} diff --git a/fr.centralesupelec.edf.riseclipse.iec61850.scl.validator/src/fr/centralesupelec/edf/riseclipse/iec61850/scl/validator/nsd/SubDataAttributePresenceConditionValidator.java b/fr.centralesupelec.edf.riseclipse.iec61850.scl.validator/src/fr/centralesupelec/edf/riseclipse/iec61850/scl/validator/nsd/SubDataAttributePresenceConditionValidator.java index e1b2687..5cdd68e 100644 --- a/fr.centralesupelec.edf.riseclipse.iec61850.scl.validator/src/fr/centralesupelec/edf/riseclipse/iec61850/scl/validator/nsd/SubDataAttributePresenceConditionValidator.java +++ b/fr.centralesupelec.edf.riseclipse.iec61850.scl.validator/src/fr/centralesupelec/edf/riseclipse/iec61850/scl/validator/nsd/SubDataAttributePresenceConditionValidator.java @@ -31,7 +31,11 @@ import fr.centralesupelec.edf.riseclipse.iec61850.scl.validator.RiseClipseValida public class SubDataAttributePresenceConditionValidator extends GenericPresenceConditionValidator< ConstructedAttribute, DAType, @Nullable BDA >{ - private static HashMap< String, SubDataAttributePresenceConditionValidator > validators = new HashMap<>(); + private static HashMap< String, SubDataAttributePresenceConditionValidator > validators; + + public static void initialize() { + validators = new HashMap<>(); + } public static SubDataAttributePresenceConditionValidator get( ConstructedAttribute constructedAttribute ) { if( ! validators.containsKey( constructedAttribute.getName() )) { diff --git a/fr.centralesupelec.edf.riseclipse.iec61850.scl.validator/src/fr/centralesupelec/edf/riseclipse/iec61850/scl/validator/nsd/SubDataObjectPresenceConditionValidator.java b/fr.centralesupelec.edf.riseclipse.iec61850.scl.validator/src/fr/centralesupelec/edf/riseclipse/iec61850/scl/validator/nsd/SubDataObjectPresenceConditionValidator.java index 8085186..45bd12b 100644 --- a/fr.centralesupelec.edf.riseclipse.iec61850.scl.validator/src/fr/centralesupelec/edf/riseclipse/iec61850/scl/validator/nsd/SubDataObjectPresenceConditionValidator.java +++ b/fr.centralesupelec.edf.riseclipse.iec61850.scl.validator/src/fr/centralesupelec/edf/riseclipse/iec61850/scl/validator/nsd/SubDataObjectPresenceConditionValidator.java @@ -36,7 +36,11 @@ import fr.centralesupelec.edf.riseclipse.iec61850.scl.validator.RiseClipseValida public class SubDataObjectPresenceConditionValidator extends GenericPresenceConditionValidator< CDC, DOType, @Nullable SDO >{ - private static HashMap< String, SubDataObjectPresenceConditionValidator > validators = new HashMap<>(); + private static HashMap< String, SubDataObjectPresenceConditionValidator > validators; + + public static void initialize() { + validators = new HashMap<>(); + } public static SubDataObjectPresenceConditionValidator get( CDC cdc ) { if( ! validators.containsKey( cdc.getName() )) { diff --git a/fr.centralesupelec.edf.riseclipse.iec61850.scl.validator/src/fr/centralesupelec/edf/riseclipse/iec61850/scl/validator/nsd/TypeValidator.java b/fr.centralesupelec.edf.riseclipse.iec61850.scl.validator/src/fr/centralesupelec/edf/riseclipse/iec61850/scl/validator/nsd/TypeValidator.java index 4f22c62..15892c6 100644 --- a/fr.centralesupelec.edf.riseclipse.iec61850.scl.validator/src/fr/centralesupelec/edf/riseclipse/iec61850/scl/validator/nsd/TypeValidator.java +++ b/fr.centralesupelec.edf.riseclipse.iec61850.scl.validator/src/fr/centralesupelec/edf/riseclipse/iec61850/scl/validator/nsd/TypeValidator.java @@ -30,9 +30,18 @@ import fr.centralesupelec.edf.riseclipse.iec61850.scl.AbstractDataAttribute; public abstract class TypeValidator { - private static HashMap< String, TypeValidator > validators = new HashMap<>(); + private static HashMap< String, TypeValidator > validators; + + public static void initialize() { + validators = new HashMap<>(); + + BasicTypeValidator.initialize(); + EnumerationValidator.initialize(); + ConstructedAttributeValidator.initialize(); + } public static TypeValidator get( String name ) { + if( validators == null ) return null; return validators.get( name ); } @@ -48,4 +57,13 @@ public abstract class TypeValidator { } public abstract boolean validateAbstractDataAttribute( AbstractDataAttribute ada, DiagnosticChain diagnostics ); + + /* + * Called before another file is validated + */ + public static void resetValidators() { + validators.values().stream().forEach( v -> v.reset() ); + } + + public abstract void reset(); } -- GitLab