Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [rmf-dev] Reading a ReqIF file

Hello Kay,

I just had a look at your code - here are my comments:

My current problem is to not knowing, if I'm reading a ReqIF file in
the correct way, so please take a look at the attached code example.

Generally, this looks correct for using EMF without the Eclipse infrastructure.  It is preferrable to write code like that in the form of a unit test, though.  I rewrote your test file as a Unit test (including a main() method that launches the unit test).

What makes me astonished is that it seems that I'm not able to read a
file which was absolutely valid in ProR 0.1.0, and why do I have
to 'register' EPackages related to - I think - ProR to read a file
with 0.2.0-tool-extensions?

Actually, I am unsure about that myself.  I *thought* the core could handle unrecognised ToolExtensions.  I even found the code for this in the ReqIF core, but I am unsure why that case is not handled.

@Mark:  Did you have a chance to look at this?  The problem is that RMF stops when no handler for the tool extensions is found, and RMF throws the trace below.  I would have expected RMF to recover from this and to attach the list of problems related to the tool extensions to the ResourceSet.

org.eclipse.emf.ecore.resource.Resource$IOWrappedException: Package with uri 'http://pror.org/presentation/configuration' not found. (file:///home/jastram/rmf/org.eclipse.rmf/reqif-test/src/test/resources/test-1.reqif, 392, 119)
    at org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.handleErrors(XMLLoadImpl.java:83)
    at org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.load(XMLLoadImpl.java:191)
    at org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.doLoad(XMLResourceImpl.java:242)
    at org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:1511)
    at org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:1290)
    at reqif.reqif_writer.App2.readPlease(App2.java:91)
    at reqif.reqif_writer.App2.testValid0_1_0(App2.java:62)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:592)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
    at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: org.eclipse.emf.ecore.xmi.PackageNotFoundException: Package with uri 'http://pror.org/presentation/configuration' not found. (file:///home/jastram/rmf/org.eclipse.rmf/reqif-test/src/test/resources/test-1.reqif, 392, 119)
    at org.eclipse.emf.ecore.xmi.impl.XMLHandler.getPackageForURI(XMLHandler.java:2591)
    at org.eclipse.emf.ecore.xmi.impl.XMLHandler.getFactoryForPrefix(XMLHandler.java:2422)
    at org.eclipse.rmf.internal.serialization.ReqIFXMLSAXHandler.handleObject(ReqIFXMLSAXHandler.java:117)
    at org.eclipse.rmf.internal.serialization.ReqIFXMLSAXHandler.processElement(ReqIFXMLSAXHandler.java:82)
    at org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHandler.java:1001)
    at org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHandler.java:712)
    at org.eclipse.rmf.internal.serialization.ReqIFXMLSAXHandler.startElement(ReqIFXMLSAXHandler.java:59)
    at org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown Source)
    at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
    at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
    at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
    at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
    at org.apache.xerces.jaxp.SAXParserImpl.parse(Unknown Source)
    at org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.load(XMLLoadImpl.java:181)
    ... 28 more


Best,

- Michael


I think it must be possible to read ReqIF files with the reqif packages
ignoring any tool-extensions. Think about the 0.1.0 file
as written by another tool from another vendor...

Best regards
	Kay


_______________________________________________
rmf-dev mailing list
rmf-dev@xxxxxxxxxxx
http://dev.eclipse.org/mailman/listinfo/rmf-dev


--
Michael Jastram +49 (162) 274 83 94 http://jastram.de
Geschäftsführer Formal Mind GmbH http://formalmind.com
Wissenschaftler Heinrich Heine Universität Düsseldorf http://www.stups.uni-duesseldorf.de
Vorsitzender rheinjug e.V. http://rheinjug.de
Project Lead Eclipse Requirements Modeling Framework http://eclipse.org/rmf
package reqif.reqif_writer;

import java.io.IOException;
import java.util.UUID;

import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.xmi.XMLResource;
import org.eclipse.emf.ecore.xml.namespace.XMLNamespacePackage;
import org.eclipse.rmf.reqif10.ReqIF;
import org.eclipse.rmf.reqif10.ReqIF10Package;
import org.eclipse.rmf.reqif10.datatypes.DatatypesPackage;
import org.eclipse.rmf.reqif10.xhtml.XhtmlPackage;
import org.eclipse.rmf.serialization.ReqIFResourceFactoryImpl;
import org.eclipse.rmf.serialization.ReqIFResourceSetImpl;
import org.junit.Test;
import org.junit.runner.JUnitCore;
import org.junit.runner.Result;
import org.junit.runner.notification.Failure;


public class App2 {
	
	public static final String VALID_0_1_0 = "src/test/resources/test-1.reqif";
	public static final String VALID_0_2_0 = "src/test/resources/TC3000_E000_S10_Reference_20120412_2336_broerkens.reqif";
	public static final String VALID_REQIF = "src/test/resources/TC1300_without_namespaceprefix.reqif";
	public static final String TARGET_NAME_BASE = "work/test-dest-";

	/**
	 * Allows running unit tests as Java application
	 * @param args
	 */
	public static void main(String[] args) {
		Result result = JUnitCore.runClasses(App2.class);
		if (!result.wasSuccessful()) {
			System.out.println("\nFAILURES: \n");
			for (Failure failure: result.getFailures()) {
				System.out.println(failure);
				
			}
		}
	}

	/** Returns a unique test file name */
	private String generateTargetName() {
		return TARGET_NAME_BASE + UUID.randomUUID() + ".reqif";
	}

	@Test
	public void testValidReqif() throws Exception {
		registerEPackageStd();
		ReqIF reqif = readPlease(VALID_REQIF);
		justWritePlease(generateTargetName(), reqif);

	}

	@Test
	public void testValid0_1_0() throws Exception {
		registerEPackageStd();
		ReqIF reqif = readPlease(VALID_0_1_0);
		justWritePlease(generateTargetName(), reqif);

	}

	@Test
	public void testValid0_2_0() throws Exception {
		registerEPackageStd();
		ReqIF reqif = readPlease(VALID_0_2_0);
		justWritePlease(generateTargetName(), reqif);

	}

	private static void registerEPackageStd() {
		EPackage.Registry.INSTANCE.clear();
		EPackage.Registry.INSTANCE.put(ReqIF10Package.eNS_URI,
				ReqIF10Package.eINSTANCE);
		EPackage.Registry.INSTANCE.put(XhtmlPackage.eNS_URI,
				XhtmlPackage.eINSTANCE);
		EPackage.Registry.INSTANCE.put(DatatypesPackage.eNS_URI,
				DatatypesPackage.eINSTANCE);
		EPackage.Registry.INSTANCE.put(XMLNamespacePackage.eNS_URI,
				XMLNamespacePackage.eINSTANCE);
	}

	private static ReqIF readPlease(final String fileName) throws IOException {
		ReqIFResourceSetImpl resourceSet = aResourceSetPlease();
		URI uri = URI.createURI(fileName, true);
		XMLResource resource = (XMLResource) resourceSet.createResource(uri);
		resource.load(null);

		EList<EObject> rootObjects = resource.getContents();

		if (rootObjects.isEmpty())
			throw new RuntimeException("Oops! Empty!");

		ReqIF reqif = (ReqIF) rootObjects.get(0);

		return reqif;
	}

	private static ReqIFResourceSetImpl aResourceSetPlease() {

		ReqIFResourceSetImpl resourceSet = new ReqIFResourceSetImpl();
		resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap()
				.put("reqif", new ReqIFResourceFactoryImpl());

		return resourceSet;
	}

	private static void justWritePlease(final String destFileName, ReqIF reqif)
		throws IOException {
		System.out.println("Writing: " + destFileName);

	ReqIFResourceSetImpl resourceSet = aResourceSetPlease();
	URI uri = URI.createURI(destFileName, true);
	XMLResource resource = (XMLResource) resourceSet.createResource(uri);
	resource.getContents().add(reqif);
	resource.save(null);
}
}

Back to the top