Ce serveur Gitlab sera éteint le 30 juin 2020, pensez à migrer vos projets vers les serveurs gitlab-research.centralesupelec.fr et gitlab-student.centralesupelec.fr !

Commit 7cd20e76 authored by Dominique Marcadet's avatar Dominique Marcadet

Keep only NSD validation for the moment. Renames files.

parent 39ab06bc
......@@ -19,4 +19,5 @@ Require-Bundle: org.eclipse.core.runtime,
fr.centralesupelec.edf.riseclipse.iec61850.scl.edit,
fr.centralesupelec.edf.riseclipse.validation.ocl,
fr.centralesupelec.edf.riseclipse.iec61850.nsd,
fr.centralesupelec.edf.riseclipse.iec61850.nsd.edit
fr.centralesupelec.edf.riseclipse.iec61850.nsd.edit,
org.eclipse.ocl.xtext.oclinecore
......@@ -19,6 +19,7 @@
package fr.centralesupelec.edf.riseclipse.iec61850.scl.validator;
import java.util.Map;
import java.util.Optional;
import org.eclipse.emf.common.util.DiagnosticChain;
import org.eclipse.emf.common.util.EList;
......@@ -31,22 +32,26 @@ import org.eclipse.emf.ecore.resource.Resource;
import fr.centralesupelec.edf.riseclipse.iec61850.nsd.DocumentRoot;
import fr.centralesupelec.edf.riseclipse.iec61850.nsd.BasicType;
import fr.centralesupelec.edf.riseclipse.iec61850.nsd.CDC;
import fr.centralesupelec.edf.riseclipse.iec61850.nsd.DataAttribute;
import fr.centralesupelec.edf.riseclipse.iec61850.nsd.DataObject;
import fr.centralesupelec.edf.riseclipse.iec61850.nsd.LNClass;
import fr.centralesupelec.edf.riseclipse.iec61850.nsd.NS;
import fr.centralesupelec.edf.riseclipse.iec61850.nsd.util.NsdResourceSetImpl;
import fr.centralesupelec.edf.riseclipse.iec61850.scl.AnyLN;
import fr.centralesupelec.edf.riseclipse.iec61850.scl.DA;
import fr.centralesupelec.edf.riseclipse.iec61850.scl.DAI;
import fr.centralesupelec.edf.riseclipse.iec61850.scl.DOI;
import fr.centralesupelec.edf.riseclipse.iec61850.scl.DOType;
import fr.centralesupelec.edf.riseclipse.iec61850.scl.LNode;
import fr.centralesupelec.edf.riseclipse.iec61850.scl.LNodeType;
import fr.centralesupelec.edf.riseclipse.util.AbstractRiseClipseConsole;
public class NSDEObjectValidator implements EValidator {
public class NsdEObjectValidator implements EValidator {
private NS ns;
private NsdResourceSetImpl nsdResourceSet;
public NSDEObjectValidator( Resource nsdResource ) {
DocumentRoot root = (DocumentRoot) nsdResource.getContents().get( 0 );
ns = (NS) root.getNS();
public NsdEObjectValidator( NsdResourceSetImpl nsdResourceSet ) {
this.nsdResourceSet = nsdResourceSet;
}
@Override
......@@ -59,22 +64,22 @@ public class NSDEObjectValidator implements EValidator {
Map< Object, Object > context ) {
switch(eClass.getName()) {
case "LNode":
LNode lnd = (LNode) eObject;
return validateLN(lnd.getLnClass());
case "LNodeType":
LNodeType lnt = (LNodeType) eObject;
return validateLN(lnt.getLnClass());
// case "LNode":
// LNode lnd = (LNode) eObject;
// return validateLN(lnd.getLnClass());
// case "LNodeType":
// LNodeType lnt = (LNodeType) eObject;
// return validateLN(lnt.getLnClass());
case "LN0":
case "LN":
AnyLN ln = (AnyLN) eObject;
return validateLN(ln.getLnClass());
case "DOType":
DOType dot = (DOType) eObject;
return validateDO(dot.getCdc());
case "DA":
DA da = (DA) eObject;
return validateDA(da.getBType());
return validateLN(ln);
// case "DOType":
// DOType dot = (DOType) eObject;
// return validateDO(dot.getCdc());
// case "DA":
// DA da = (DA) eObject;
// return validateDA(da.getBType());
default:
return false;
}
......@@ -92,57 +97,81 @@ public class NSDEObjectValidator implements EValidator {
}
public boolean validateLN(String lnClassName) {
AbstractRiseClipseConsole.getConsole().info( "NSDEObjectValidator.validateLN( " + lnClassName + " )" );
if(ns.getLNClasses() != null) {
EList<LNClass> lnClass = ns.getLNClasses().getLNClass();
for(int i = 0; i < lnClass.size(); i++) {
if(lnClassName.equals(lnClass.get(i).getName())) {
//log("is valid");
return true;
}
}
//log("is not valid");
public boolean validateLN(AnyLN ln) {
AbstractRiseClipseConsole.getConsole().info( "NSDEObjectValidator.validateLN( " + ln.getLnClass() + " )" );
// TODO: inheritance of LNClass must be taken into account
Optional< LNClass > lnClassFound = nsdResourceSet.getLNClassStream().filter( lNClass -> lNClass.getName().equals( ln.getLnClass() )).findAny();
if( ! lnClassFound.isPresent() ) {
AbstractRiseClipseConsole.getConsole().error( "ln.getLnClass() not found in NSD files" );
return false;
} else {
return true;
}
}
public boolean validateDO(String cdcName) {
AbstractRiseClipseConsole.getConsole().info( "NSDEObjectValidator.validateDO( " + cdcName + " )" );
if(ns.getCDCs() != null) {
EList<CDC> cdc = ns.getCDCs().getCDC();
for(int i = 0; i < cdc.size(); i++) {
if(cdcName.equals(cdc.get(i).getName())) {
//log("is valid");
return true;
}
}
//log("is not valid");
return false;
} else {
return true;
AbstractRiseClipseConsole.getConsole().info( "found ln.getLnClass() in NSD files" );
// lnClassFound contains DataObject which describes allowed DOI in LN
for( DOI doi : ln.getDOI() ) {
Optional< DataObject > dataObjectFound = lnClassFound.get().getDataObject().stream().filter( dataObject -> dataObject.getName().equals( doi.getName()) ).findAny();
if( ! dataObjectFound.isPresent() ) {
// TODO: add message
return false;
}
// dataObjectFound refers to a CDC which describes allowed DAI in DOI
CDC cdcFound = dataObjectFound.get().getRefersToCDC();
for( DAI dai : doi.getDAI() ) {
Optional< DataAttribute > dataAttributeFound = cdcFound.getDataAttribute().stream().filter( dataAttribute -> dataAttribute.getName().equals( dai.getName() ) ).findAny();
if( ! dataAttributeFound.isPresent() ) {
// TODO: add message
return false;
}
// TODO: is there anything else to check ?
}
// TODO: check that compulsory DataObject in cdcFound are present in doi
}
}
// TODO: check that compulsory DataAttribute in lnClassFound are present in ln
public boolean validateDA(String basicTypeName) {
AbstractRiseClipseConsole.getConsole().info( "NSDEObjectValidator.validateDA( " + basicTypeName + " )" );
if(ns.getBasicTypes() != null) {
EList<BasicType> basicTypes = ns.getBasicTypes().getBasicType();
for(int i = 0; i < basicTypes.size(); i++) {
if(basicTypeName.equals(basicTypes.get(i).getName())) {
//log("is valid");
return true;
}
}
//log("is not valid");
return false;
} else {
return true;
}
return true;
}
// public boolean validateDO(String cdcName) {
// AbstractRiseClipseConsole.getConsole().info( "NSDEObjectValidator.validateDO( " + cdcName + " )" );
// if(ns.getCDCs() != null) {
// EList<CDC> cdc = ns.getCDCs().getCDC();
// for(int i = 0; i < cdc.size(); i++) {
// if(cdcName.equals(cdc.get(i).getName())) {
// //log("is valid");
// return true;
// }
// }
// //log("is not valid");
// return false;
// } else {
// return true;
// }
// }
//
// public boolean validateDA(String basicTypeName) {
// AbstractRiseClipseConsole.getConsole().info( "NSDEObjectValidator.validateDA( " + basicTypeName + " )" );
// if(ns.getBasicTypes() != null) {
// EList<BasicType> basicTypes = ns.getBasicTypes().getBasicType();
// for(int i = 0; i < basicTypes.size(); i++) {
// if(basicTypeName.equals(basicTypes.get(i).getName())) {
// //log("is valid");
// return true;
// }
// }
// //log("is not valid");
// return false;
// } else {
// return true;
// }
// }
public void log(String message) {
AbstractRiseClipseConsole.getConsole().info(message);
......
......@@ -18,24 +18,39 @@
*/
package fr.centralesupelec.edf.riseclipse.iec61850.scl.validator;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import org.eclipse.emf.common.util.Diagnostic;
import org.eclipse.emf.ecore.EDataType;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.EValidator;
import org.eclipse.emf.ecore.EValidator.SubstitutionLabelProvider;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.util.Diagnostician;
//import org.eclipse.ocl.pivot.delegate.OCLDelegateDomain;
import org.eclipse.emf.edit.provider.IItemLabelProvider;
import fr.centralesupelec.edf.riseclipse.iec61850.nsd.NsdPackage;
import fr.centralesupelec.edf.riseclipse.iec61850.nsd.provider.NsdItemProviderAdapterFactory;
import fr.centralesupelec.edf.riseclipse.iec61850.nsd.util.NsdResourceFactoryImpl;
import fr.centralesupelec.edf.riseclipse.iec61850.nsd.util.NsdResourceSetImpl;
import fr.centralesupelec.edf.riseclipse.util.IRiseClipseConsole;
import fr.centralesupelec.edf.riseclipse.util.RiseClipseModelLoader;
import fr.centralesupelec.edf.riseclipse.util.TextRiseClipseConsole;
public class NSDModelLoader extends RiseClipseModelLoader {
public class NsdModelLoader extends RiseClipseModelLoader {
public NSDModelLoader( IRiseClipseConsole console ) {
public NsdModelLoader( IRiseClipseConsole console ) {
super( console );
}
@Override
public void reset() {
super.reset();
super.reset(new NsdResourceSetImpl() );
// Register the appropriate resource factory to handle all file
// extensions.
......@@ -46,6 +61,11 @@ public class NSDModelLoader extends RiseClipseModelLoader {
getResourceSet().getPackageRegistry().put( NsdPackage.eNS_URI, NsdPackage.eINSTANCE );
}
@Override
public NsdResourceSetImpl getResourceSet() {
return ( NsdResourceSetImpl ) super.getResourceSet();
}
public Resource loadWithoutValidation( String name ) {
Object eValidator = EValidator.Registry.INSTANCE.remove( NsdPackage.eINSTANCE );
......@@ -59,12 +79,51 @@ public class NSDModelLoader extends RiseClipseModelLoader {
public static void main( String[] args ) {
IRiseClipseConsole console = new TextRiseClipseConsole();
NSDModelLoader loader = new NSDModelLoader( console );
//console.setLevel( IRiseClipseConsole.ERROR_LEVEL );
NsdModelLoader loader = new NsdModelLoader( console );
org.eclipse.ocl.xtext.oclinecore.OCLinEcoreStandaloneSetup.doSetup();
Map<Object, Object> context = new HashMap< Object, Object >();
SubstitutionLabelProvider substitutionLabelProvider = new EValidator.SubstitutionLabelProvider() {
@Override
public String getValueLabel( EDataType eDataType, Object value ) {
return Diagnostician.INSTANCE.getValueLabel( eDataType, value );
}
@Override
public String getObjectLabel( EObject eObject ) {
NsdItemProviderAdapterFactory adapter = new NsdItemProviderAdapterFactory();
IItemLabelProvider labelProvider = ( IItemLabelProvider ) adapter .adapt( eObject, IItemLabelProvider.class );
return labelProvider.getText( eObject );
}
@Override
public String getFeatureLabel( EStructuralFeature eStructuralFeature ) {
return Diagnostician.INSTANCE.getFeatureLabel( eStructuralFeature );
}
};
context.put(EValidator.SubstitutionLabelProvider.class, substitutionLabelProvider );
for( int i = 0; i < args.length; ++i ) {
@SuppressWarnings( "unused" )
Resource resource = loader.load( args[i] );
if( resource == null ) continue;
if( resource.getContents().size() == 0 ) continue;
Diagnostic diagnostic = Diagnostician.INSTANCE.validate( resource.getContents().get( 0 ), context );
if( diagnostic.getSeverity() == Diagnostic.ERROR || diagnostic.getSeverity() == Diagnostic.WARNING ) {
for( Iterator< Diagnostic > d = diagnostic.getChildren().iterator(); d.hasNext(); ) {
Diagnostic childDiagnostic = d.next();
switch( childDiagnostic.getSeverity() ) {
case Diagnostic.ERROR:
case Diagnostic.WARNING:
console.error( "\t" + childDiagnostic.getMessage() );
}
}
}
}
loader.getResourceSet().buildExplicitLinks( console );
}
}
......@@ -38,25 +38,27 @@ import org.eclipse.emf.edit.provider.IItemLabelProvider;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.ocl.pivot.validation.ComposedEValidator;
import fr.centralesupelec.edf.riseclipse.iec61850.nsd.util.NsdResourceSetImpl;
import fr.centralesupelec.edf.riseclipse.util.IRiseClipseConsole;
public class NSDValidator {
public class NsdValidator {
private @NonNull EPackage modelPackage;
private ComposedEValidator validator;
private NsdModelLoader nsdLoader;
public NSDValidator( @NonNull EPackage modelPackage ) {
this.modelPackage = modelPackage;
validator = ComposedEValidator.install( modelPackage );
public NsdValidator( @NonNull ComposedEValidator validator, IRiseClipseConsole console ) {
nsdLoader = new NsdModelLoader( console );
validator.addChild( new NsdEObjectValidator( nsdLoader.getResourceSet() ));
}
public boolean addNSDDocument( Resource resource, IRiseClipseConsole console ) {
NSDEObjectValidator nsdObjectValidator = new NSDEObjectValidator( resource );
validator.addChild( nsdObjectValidator );
return true;
public void addNsdDocument( String nsdFile, IRiseClipseConsole console ) {
console.info( "Loading nsd: " + nsdFile );
nsdLoader.load( nsdFile );
}
public void validate( Resource resource, final AdapterFactory adapter, IRiseClipseConsole console ) {
nsdLoader.getResourceSet().buildExplicitLinks( console );
Map<Object, Object> context = new HashMap< Object, Object >();
SubstitutionLabelProvider substitutionLabelProvider = new EValidator.SubstitutionLabelProvider() {
......
......@@ -30,22 +30,24 @@ import fr.centralesupelec.edf.riseclipse.validation.ocl.OCLValidator;
//import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.ocl.pivot.validation.ComposedEValidator;
public class RiseClipseValidatorSCL {
private static OCLValidator oclValidator;
//private static OCLValidator oclValidator;
private static SclItemProviderAdapterFactory sclAdapter;
private static SCLModelLoader sclLoader;
private static NSDValidator nsdValidator;
private static boolean oclValidation = false;
private static NsdValidator nsdValidator;
//private static boolean oclValidation = false;
private static boolean nsdValidation = false;
private static NsdItemProviderAdapterFactory nsdAdapter;
public static void usage( IRiseClipseConsole console ) {
console.setLevel( IRiseClipseConsole.INFO_LEVEL );
console.info( "java -jar RiseClipseValidatorSCL.jar [--verbose] [--make-explicit-links] [<oclFile> | <nsdFile> | <sclFile>]*" );
console.info( "Files ending with \".ocl\" are considered OCL files, "
+ "files ending with \\\".nsd\\\" are considered NSD files, "
console.info( /*"Files ending with \".ocl\" are considered OCL files, "
+*/ "files ending with \\\".nsd\\\" are considered NSD files, "
+ "all others are considered SCL files" );
System.exit( -1 );
}
......@@ -56,7 +58,6 @@ public class RiseClipseValidatorSCL {
console.setLevel( IRiseClipseConsole.INFO_LEVEL );
displayLegal( console );
console.setLevel( IRiseClipseConsole.WARNING_LEVEL );
if( args.length == 0 ) usage( console );
......@@ -80,15 +81,15 @@ public class RiseClipseValidatorSCL {
}
}
ArrayList< File > oclFiles = new ArrayList<>();
//ArrayList< String > oclFiles = new ArrayList<>();
ArrayList< String > nsdFiles = new ArrayList<>();
ArrayList< String > sclFiles = new ArrayList<>();
for( int i = posFiles; i < args.length; ++i ) {
if( args[i].endsWith( ".ocl" )) {
oclFiles.add( new File( args[i] ));
/*if( args[i].endsWith( ".ocl" )) {
oclFiles.add( args[i] );
oclValidation = true;
}
else if( args[i].endsWith( ".nsd" )) {
else*/ if( args[i].endsWith( ".nsd" )) {
nsdFiles.add( args[i] );
nsdValidation = true;
}
......@@ -97,7 +98,7 @@ public class RiseClipseValidatorSCL {
}
}
prepare( console, oclFiles, nsdFiles );
prepare( console, /*oclFiles,*/ nsdFiles );
for( int i = 0; i < sclFiles.size(); ++i ) {
run( console, make_explicit_links, sclFiles.get( i ));
}
......@@ -122,29 +123,24 @@ public class RiseClipseValidatorSCL {
console.info( "" );
}
public static void prepare( IRiseClipseConsole console, ArrayList< File > oclFiles, ArrayList< String > nsdFiles ) {
if( oclValidation ) {
oclValidator = new OCLValidator( SclPackage.eINSTANCE, true );
public static void prepare( IRiseClipseConsole console, /*ArrayList< String > oclFiles,*/ ArrayList< String > nsdFiles ) {
@NonNull
ComposedEValidator validator = ComposedEValidator.install( SclPackage.eINSTANCE );
/*if( oclValidation ) {
oclValidator = new OCLValidator( validator, true );
for( int i = 0; i < oclFiles.size(); ++i ) {
console.info( "Loading ocl: " + oclFiles.get( i ));
// workaround for bug 486872
// File file = new File( oclFiles.get( i ));
// URI uri = file.isFile() ? URI.createFileURI( file.getAbsolutePath() ) : URI.createURI( oclFiles.get( i ));
// oclFiles.add( uri );
// ocl.addOCLDocument( uri, console );
oclValidator.addOCLDocument( oclFiles.get( i ), console );
}
}
}*/
if( nsdValidation ) {
nsdValidator = new NSDValidator( SclPackage.eINSTANCE );
NSDModelLoader nsdLoader = new NSDModelLoader( console );
nsdValidator = new NsdValidator( validator, console );
for( int i = 0; i < nsdFiles.size(); ++i ) {
console.info( "Loading nsd: " + nsdFiles.get( i ));
nsdValidator.addNSDDocument( nsdLoader.load( nsdFiles.get( i )), console );
nsdValidator.addNsdDocument( nsdFiles.get( i ), console );
}
nsdAdapter = new NsdItemProviderAdapterFactory();
//nsdAdapter = new NsdItemProviderAdapterFactory();
}
sclLoader = new SCLModelLoader( console );
......@@ -159,13 +155,13 @@ public class RiseClipseValidatorSCL {
sclLoader.finalizeLoad();
}
if( resource != null ) {
if( oclValidation ) {
/*if( oclValidation ) {
console.info( "Validating file: " + sclFile + " with OCL" );
oclValidator.validate( resource, sclAdapter, console );
}
}*/
if( nsdValidation ) {
console.info( "Validating file: " + sclFile + " with NSD" );
nsdValidator.validate( resource, nsdAdapter, console );
nsdValidator.validate( resource, sclAdapter, console );
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment