Skip to content
Snippets Groups Projects
Commit 4c3ce267 authored by Dominique Marcadet's avatar Dominique Marcadet
Browse files

set line number of NsdObject

parent 36edb76f
No related branches found
No related tags found
1 merge request!26Resolve "add line number in messages"
/**
* 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.nsd.util;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.eclipse.emf.ecore.xmi.XMLHelper;
import org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
public class NsdLoadImpl extends XMLLoadImpl {
public NsdLoadImpl( XMLHelper helper ) {
super( helper );
}
public DefaultHandler makeDefaultHandler() {
return new NsdXmlHandler( resource, helper, options );
}
@Override
protected SAXParser makeParser() throws ParserConfigurationException, SAXException {
SAXParserFactory f = SAXParserFactory.newInstance();
f.setNamespaceAware( true );
return f.newSAXParser();
}
}
......@@ -20,6 +20,7 @@
package fr.centralesupelec.edf.riseclipse.iec61850.nsd.util;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.xmi.XMLLoad;
import org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl;
import fr.centralesupelec.edf.riseclipse.util.IRiseClipseConsole;
......@@ -44,6 +45,11 @@ public class NsdResourceImpl extends XMLResourceImpl implements IRiseClipseResou
super( uri );
}
@Override
protected XMLLoad createXMLLoad() {
return new NsdLoadImpl( createXMLHelper() );
}
@Override
public void printStatistics( IRiseClipseConsole console ) {
// TODO !
......
/**
* 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.nsd.util;
import java.util.Map;
import java.util.Stack;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.xmi.XMLHelper;
import org.eclipse.emf.ecore.xmi.XMLResource;
import org.eclipse.emf.ecore.xmi.impl.SAXXMLHandler;
import fr.centralesupelec.edf.riseclipse.iec61850.nsd.NsdObject;
import fr.centralesupelec.edf.riseclipse.util.AbstractRiseClipseConsole;
public class NsdXmlHandler extends SAXXMLHandler {
private Stack< Integer > lineNumbers;
public NsdXmlHandler( XMLResource xmiResource, XMLHelper helper, Map< ?, ? > options ) {
super( xmiResource, helper, options );
lineNumbers = new Stack< Integer >();
}
@Override
public void startElement( String uri, String localName, String name ) {
lineNumbers.push( this.locator.getLineNumber() );
super.startElement( uri, localName, name );
}
@Override
protected void processObject( EObject object ) {
if( lineNumbers.empty() ) {
AbstractRiseClipseConsole.getConsole().warning( "NsdXmlHandler: linenumber stack empty !" );
}
else {
int lineNumber = lineNumbers.peek();
if( object instanceof NsdObject ) {
(( NsdObject ) object ).setLineNumber( lineNumber );
}
}
// TODO: error message
super.processObject( object );
}
@Override
public void endElement( String uri, String localName, String name ) {
if( lineNumbers.empty() ) {
AbstractRiseClipseConsole.getConsole().warning( "NsdXmlHandler: linenumber stack empty !" );
}
else {
lineNumbers.pop();
}
super.endElement( uri, localName, name );
}
@Override
public void endDocument() {
super.endDocument();
if( ! lineNumbers.empty() ) {
AbstractRiseClipseConsole.getConsole().warning( "NsdXmlHandler: linenumber stack not empty !" );
while( ! lineNumbers.empty() ) {
AbstractRiseClipseConsole.getConsole().warning( lineNumbers.pop() );
}
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment