|
|
Re: createResource() returns null, what am I missing? [message #1020275 is a reply to message #1020243] |
Sun, 17 March 2013 19:52 |
Nigel Daniels Messages: 66 Registered: July 2009 |
Member |
|
|
Hi Ed,
thanks for that, it's now working. I appreciate the help.
Nigel
On 17/03/2013 17:30, Ed Willink wrote:
> Hi
>
> You may get on better using the extension factory map for extensions.
>
> Regards
>
> Ed Willink
>
> On 17/03/2013 17:19, Nigel Daniels wrote:
>> Hi,
>>
>> I'm trying to use EMF in a servlet so I'm having to create a lot of
>> the default environment by hand. To start up my model I'm trying to do
>> the following:
>>
>> FlowchartPackage flowchartPackage = FlowchartPackage.eINSTANCE;
>> FlowchartFactory flowchartFactory = FlowchartFactory.eINSTANCE;
>>
>> // Create a resource set and register the package and resource factory
>> ResourceSet resourceSet = new ResourceSetImpl();
>> resourceSet.getPackageRegistry().put(flowchartPackage.getNsURI(),
>> flowchartPackage);
>> resourceSet.getResourceFactoryRegistry().getContentTypeToFactoryMap().put(fileExtension,
>> new XMIResourceFactoryImpl());
>>
>> // Generate the root object
>> FlowDiagram flowDiagram = flowchartFactory.createFlowDiagram();
>> EcoreUtil.setID(flowDiagram, EcoreUtil.generateUUID());
>>
>> // Create the file uri & resource to save
>> File file = new File("test." + fileExtension);
>> URI fileURI = URI.createURI(file.getAbsolutePath());
>>
>> /////// This returns null?
>> Resource resource = resourceSet.createResource(fileURI);
>> /////// This causes a null pointer exception as a result
>> resource.getContents().add(flowDiagram);
>>
>> I thought that adding the package and the XMI resource factory by hand
>> was all I required to create resouces but I must be missing something.
>> Any suggestions on what I need to do?
>>
>> Thanks for any help, Nigel.
>
|
|
|
Re: createResource() returns null, what am I missing? [message #1020281 is a reply to message #1020243] |
Sun, 17 March 2013 20:15 |
Nigel Daniels Messages: 66 Registered: July 2009 |
Member |
|
|
Hi Ed,
thanks for that, it's now working. I appreciate the help.
Nigel
On 17/03/2013 17:30, Ed Willink wrote:
> Hi
>
> You may get on better using the extension factory map for extensions.
>
> Regards
>
> Ed Willink
>
> On 17/03/2013 17:19, Nigel Daniels wrote:
>> Hi,
>>
>> I'm trying to use EMF in a servlet so I'm having to create a lot of
>> the default environment by hand. To start up my model I'm trying to do
>> the following:
>>
>> FlowchartPackage flowchartPackage = FlowchartPackage.eINSTANCE;
>> FlowchartFactory flowchartFactory = FlowchartFactory.eINSTANCE;
>>
>> // Create a resource set and register the package and resource factory
>> ResourceSet resourceSet = new ResourceSetImpl();
>> resourceSet.getPackageRegistry().put(flowchartPackage.getNsURI(),
>> flowchartPackage);
>> resourceSet.getResourceFactoryRegistry().getContentTypeToFactoryMap().put(fileExtension,
>> new XMIResourceFactoryImpl());
>>
>> // Generate the root object
>> FlowDiagram flowDiagram = flowchartFactory.createFlowDiagram();
>> EcoreUtil.setID(flowDiagram, EcoreUtil.generateUUID());
>>
>> // Create the file uri & resource to save
>> File file = new File("test." + fileExtension);
>> URI fileURI = URI.createURI(file.getAbsolutePath());
>>
>> /////// This returns null?
>> Resource resource = resourceSet.createResource(fileURI);
>> /////// This causes a null pointer exception as a result
>> resource.getContents().add(flowDiagram);
>>
>> I thought that adding the package and the XMI resource factory by hand
>> was all I required to create resouces but I must be missing something.
>> Any suggestions on what I need to do?
>>
>> Thanks for any help, Nigel.
>
|
|
|
Powered by
FUDForum. Page generated in 0.03597 seconds