<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Steven She at woggie.net &#187; ecore</title>
	<atom:link href="http://www.woggie.net/tag/ecore/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.woggie.net</link>
	<description>The life of a PhD Candidate in Software Engineering</description>
	<lastBuildDate>Mon, 25 Oct 2010 14:33:09 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Loading an Ecore model without initializing all necessary packages or schemas</title>
		<link>http://www.woggie.net/2008/03/29/loading-an-ecore-model-without-initializing-all-necessary-packages-or-schemas/</link>
		<comments>http://www.woggie.net/2008/03/29/loading-an-ecore-model-without-initializing-all-necessary-packages-or-schemas/#comments</comments>
		<pubDate>Sat, 29 Mar 2008 17:57:26 +0000</pubDate>
		<dc:creator>Steven She</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[ecore]]></category>
		<category><![CDATA[emf]]></category>
		<category><![CDATA[serialization]]></category>

		<guid isPermaLink="false">http://www.woggie.net/2008/03/29/loading-an-ecore-model-without-initializing-all-necessary-packages-or-schemas/</guid>
		<description><![CDATA[Here&#8217;s a small snippet of code to load an Ecore resource without having to initialize all the necessary packages needed to read all elements. This is useful if we&#8217;re interested in only a subset of the schema elements that are present in the Ecore model. public static EList open&#40;File file&#41; throws IOException &#123; ResourceSet resourceSet [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a small snippet of code to load an Ecore resource without having to initialize all the necessary packages needed to read all elements. This is useful if we&#8217;re interested in only a subset of the schema elements that are present in the Ecore model.</p>

<div class="wp_syntax"><div class="code"><pre class="java5" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> EList open<span style="color: #009900;">&#40;</span><span style="color: #003399; font-weight: bold;">File</span> file<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399; font-weight: bold;">IOException</span> <span style="color: #009900;">&#123;</span>
	ResourceSet resourceSet = <span style="color: #000000; font-weight: bold;">new</span> ResourceSetImpl<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">//Initialize the FSML Package information (ie. URI)</span>
	MyPackageImpl.<span style="color: #006633;">init</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">//Set OPTION_RECORD_UNKNOWN_FEATURE prior to calling getResource</span>
	Resource.<span style="color: #006633;">Factory</span>.<span style="color: #003399; font-weight: bold;">Registry</span>.<span style="color: #006633;">INSTANCE</span>.<span style="color: #006633;">getExtensionToFactoryMap</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span>
		<span style="color: #0000ff;">&quot;*&quot;</span>, <span style="color: #000000; font-weight: bold;">new</span> EcoreResourceFactoryImpl<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			@<span style="color: #003399; font-weight: bold;">Override</span>
			<span style="color: #000000; font-weight: bold;">public</span> Resource createResource<span style="color: #009900;">&#40;</span><span style="color: #003399; font-weight: bold;">URI</span> uri<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			XMIResourceImpl resource = <span style="color: #009900;">&#40;</span>XMIResourceImpl<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">super</span>.<span style="color: #006633;">createResource</span><span style="color: #009900;">&#40;</span>uri<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			resource.<span style="color: #006633;">getDefaultLoadOptions</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span>XMLResource.<span style="color: #006633;">OPTION_RECORD_UNKNOWN_FEATURE</span>, <span style="color: #003399; font-weight: bold;">Boolean</span>.<span style="color: #006633;">TRUE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000000; font-weight: bold;">return</span> resource<span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	XMIResource resource = <span style="color: #009900;">&#40;</span>XMIResource<span style="color: #009900;">&#41;</span> resourceSet.<span style="color: #006633;">getResource</span><span style="color: #009900;">&#40;</span>
	<span style="color: #003399; font-weight: bold;">URI</span>.<span style="color: #006633;">createFileURI</span><span style="color: #009900;">&#40;</span>file.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>,
	<span style="color: #006600; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">//Unknown elements will appear in this map</span>
	<span style="color: #003399; font-weight: bold;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>resource.<span style="color: #006633;">getEObjectToExtensionMap</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	resource.<span style="color: #006633;">load</span><span style="color: #009900;">&#40;</span><span style="color: #003399; font-weight: bold;">Collections</span>.<span style="color: #006633;">EMPTY_MAP</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">return</span> resource.<span style="color: #006633;">getContents</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Be aware that any unrecognized elements will be null in the retrieved Ecore model.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.woggie.net/2008/03/29/loading-an-ecore-model-without-initializing-all-necessary-packages-or-schemas/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

