Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Loading XML with multiple schemalocations
Loading XML with multiple schemalocations [message #1231342] Tue, 14 January 2014 12:13 Go to next message
Mt Naj is currently offline Mt NajFriend
Messages: 8
Registered: January 2014
Junior Member
I have an xml instance of my meta-model which I am trying to load and validate against multiple ecore models. My ecore models were generated from one XSD which is used to validate this XML instance. I can load my XML file if it only contains elements from the root ecore model. However, If I include any elements that reference a object from another ecore model, I get any NullPointerException. I have placed the all the correct schema locations within the XML file.

My xml file looks like this.

<XX:DocumentRoot
xmlns:XX='adaptive/XX' 
	xmlns:ADGENERAL='adaptive/ADCOMBINE' 
	xmlns:xsi='XMLSchema-instance...url' 
xsi:schemaLocation="adaptive/XX ./resources/XMIExport.ecore 
	adaptive/ADGENERAL  ./resources/adgeneral.ecore"
>
	<XX:XMI>
		<XX:XMI.Header>
<XX:XMI.Metamodel xmi.name='com.adaptive.Combined' xmi.version='1.1'/>
		</XX:XMI.Header>
		<XX:XMI.Content>
			[b]<ADGENERAL:Dependency>
	    		</ADGENERAL:Dependency>[/b]
		</XX:XMI.Content>
	</XX:XMI>
</XX:DocumentRoot>


The exception is:

Exception in thread "main" java.lang.NullPointerException
	at org.eclipse.emf.ecore.xmi.impl.XMLHandler.createObjectFromFeatureType(XMLHandler.java:2164)
	at org.eclipse.emf.ecore.xmi.impl.XMLHandler.createObject(XMLHandler.java:2042)
	at org.eclipse.emf.ecore.xmi.impl.XMLHandler.handleFeature(XMLHandler.java:1847)
	at org.eclipse.emf.ecore.xmi.impl.XMLHandler.processElement(XMLHandler.java:1030)
	at org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHandler.java:1008)
	at org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHandler.java:719)
	at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:504)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(XMLDocumentFragmentScannerImpl.java:1370)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2763)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:647)
	at 


Thanks in advance,
Mohammed
Re: Loading XML with multiple schemalocations [message #1231440 is a reply to message #1231342] Tue, 14 January 2014 17:31 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Mohammed,

Comments below.

On 14/01/2014 5:30 PM, Mohammed Najim wrote:
> I have an xml instance of my meta-model which I am trying to load and
> validate against multiple ecore models. My ecore models were generated
> from one XSD which is used to validate this XML instance. I can load
> my XML file if it only contains elements from the root ecore model.
> However, If I include any elements that reference a object from
> another ecore model, I get any NullPointerException.
The stack trace suggests (it your line numbers match up) that you have a
feature without a type:

factory = eClass.getEPackage().getEFactoryInstance();

That sounds like a problem in the referenced instance's Ecore model.

> I have placed the all the correct schema locations within the XML file.
> My xml file looks like this.
> <XX:DocumentRoot
Have you been serializing instance not using your generated resource
factory? Because this looks like an XMI serialization
> xmlns:XX='adaptive/XX' xmlns:ADGENERAL='adaptive/ADCOMBINE'
> xmlns:xsi='XMLSchema-instance...url'
> xsi:schemaLocation="adaptive/XX ./resources/XMIExport.ecore
> adaptive/ADGENERAL ./resources/adgeneral.ecore"
Where do the quotes end? Did you add these by hand? Is there something
fishy that it's not a list of namespace location pairs?
>>
> <XX:XMI>
> <XX:XMI.Header>
> <XX:XMI.Metamodel xmi.name='com.adaptive.Combined' xmi.version='1.1'/>
> </XX:XMI.Header>
> <XX:XMI.Content>
> <ADGENERAL:Dependency>
> </ADGENERAL:Dependency>

> </XX:XMI.Content>
> </XX:XMI>
> </XX:DocumentRoot>
>
>
> The exception is:
>
>
> Exception in thread "main" java.lang.NullPointerException
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.createObjectFromFeatureType(XMLHandler.java:2164)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.createObject(XMLHandler.java:2042)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.handleFeature(XMLHandler.java:1847)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.processElement(XMLHandler.java:1030)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHandler.java:1008)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHandler.java:719)
> at
> com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:504)
> at
> com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(XMLDocumentFragmentScannerImpl.java:1370)
> at
> com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2763)
> at
> com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:647)
> at
>
> Thanks in advance,
> Mohammed


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Loading XML with multiple schemalocations [message #1231762 is a reply to message #1231440] Wed, 15 January 2014 10:37 Go to previous messageGo to next message
Mt Naj is currently offline Mt NajFriend
Messages: 8
Registered: January 2014
Junior Member
I tried "factory = eClass.getEPackage().getEFactoryInstance();" the stack trace stayed the same.

Yes we have been serializing without using any generated resource factory.

The quoted of the xmi was generated using metadata manager tool, then I generated XSD off that XMI. The XSD's are then used to generate the score model for which I would like to validate the original XML file against.

The quoted xml code snippet is the whole XML instance. I changed the namespaces just for this post because the forum would not accept the URL's.

My java code is able to load the instances of "AdaptiveGenericXMIExport.ecore" model, but throws the null pointed exception if I have any element from another ecore model.

My java code is:

	public static void xmlLoader( String uri){
		ResourceSet load_resourceSet = new ResourceSetImpl();

		// Register XML Factory implementation to handle files with any
		// extension
		load_resourceSet.getResourceFactoryRegistry()
				.getExtensionToFactoryMap().put("*",
						new XMLResourceFactoryImpl());
		
		// Create empty resource with the given URI
		Resource load_resource = load_resourceSet.getResource(URI
			.createURI(uri), true);
		
		printAllConents(load_resource);
	}	
public static void printAllConents(Resource resource){
		for (TreeIterator iter = EcoreUtil.getAllContents(resource, true); iter.hasNext(); )
		{
			EObject eObject = (EObject)iter.next();
			EClass eClasses = eObject.eClass();
			System.out.println(eClasses.getName());
		}
	}


This prints out if no elements from any other ecore model:

DocumentRoot
XMIType
XMI.HeaderType
XMI.MetamodelType
XMI.ContentType
Re: Loading XML with multiple schemalocations [message #1231770 is a reply to message #1231762] Wed, 15 January 2014 10:51 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Comments below.

On 15/01/2014 11:37 AM, Mt Naj wrote:
> I tried "factory = eClass.getEPackage().getEFactoryInstance();" the
> stack trace stayed the same.
> Yes we have been serializing without using any generated resource
> factory.
Hmmm.
> The quoted of the xmi was generated using metadata manager tool,
I'm not sure what that is.
> then I generated XSD off that XMI.
That doesn't sound terribly sensible. XMI serializations are not really
describable via a sensible schema.
> The XSD's are then used to generate the score model for which I would
> like to validate the original XML file against.
> The quoted xml code snippet is the whole XML instance. I changed the
> namespaces just for this post because the forum would not accept the
> URL's.
>
> My java code is able to load the instances of
> "AdaptiveGenericXMIExport.ecore" model, but throws the null pointed
> exception if I have any element from another ecore model.
> My java code is:
>
>
> public static void xmlLoader( String uri){
> ResourceSet load_resourceSet = new ResourceSetImpl();
>
> // Register XML Factory implementation to handle files with any
> // extension
> load_resourceSet.getResourceFactoryRegistry()
> .getExtensionToFactoryMap().put("*",
> new XMLResourceFactoryImpl());
EMF generates code (invoke Generate Test and look at the
XyzExample.java), so you should consider doing the things you see
there. E.g., ensuring that packages are registered and the generated
resource factory is registered (assuming of course you're doing all this
stand alone, not in a running Eclipse application).
>
> // Create empty resource with the given URI
> Resource load_resource = load_resourceSet.getResource(URI
> .createURI(uri), true);
>
> printAllConents(load_resource);
> }
> public static void printAllConents(Resource resource){
> for (TreeIterator iter = EcoreUtil.getAllContents(resource,
> true); iter.hasNext(); )
> {
> EObject eObject = (EObject)iter.next();
> EClass eClasses = eObject.eClass();
> System.out.println(eClasses.getName());
> }
> }
>
>
> This prints out if no elements from any other ecore model:
No doubt because the load failed, but I can't guess what state your
models are in, nor does the approach you're describing seem all that
sensible.
>
> DocumentRoot
> XMIType
> XMI.HeaderType
> XMI.MetamodelType
> XMI.ContentType


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Mapping Model:InstanceType Name or Extending Model
Next Topic:EMF and dynamic meta-models
Goto Forum:
  


Current Time: Fri Apr 26 19:17:00 GMT 2024

Powered by FUDForum. Page generated in 0.02854 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top