Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » ResourceSetImpl.createResource(URI) does not work with content type binding
ResourceSetImpl.createResource(URI) does not work with content type binding [message #431542] Wed, 15 July 2009 16:11 Go to next message
Michael  Mühlberg is currently offline Michael MühlbergFriend
Messages: 33
Registered: July 2009
Member
Hello,

In my plugin I have defined a content type and bound an EMF content parser
with it:

<extension point="org.eclipse.emf.ecore.content_parser">
<parser
class=" com.mm.mmdsl.MmDslExecutableExtensionFactory:org.eclipse.xte xt.resource.XtextResourceFactory "
contentTypeIdentifier="com.mm.mmdsltest">
</parser>
</extension>
<extension point="org.eclipse.core.contenttype.contentTypes">
<content-type
file-extensions="mmdsltest"
id="com.mm.mmdsltest"
name="com.mm.mmdsltest"
priority="normal">
</content-type>
</extension>

Now I want to create a resource via a call like this, or to be precise, the
XtextDocument does it

resourceSet.createResource(URI.createFileURI("mmtest.mmdsltest "))

Inside of ResourceSetImpl, which is called, one can see the following code
sequence

/*
* Javadoc copied from interface.
*/
public Resource createResource(URI uri)
{
return createResource(uri, null);
}


/*
* Javadoc copied from interface.
*/
public Resource createResource(URI uri, String contentType)
{
Resource.Factory resourceFactory =
getResourceFactoryRegistry().getFactory(uri, contentType);
if (resourceFactory != null)
{
Resource result = resourceFactory.createResource(uri);
getResources().add(result);
return result;
}
else
{
return null;
}
}

In my opinion the call in the first method createResource(URI)

createResource(uri, null)

is a bug, because the second method createResource(URI, String) then does
not use content type lookup (like it is also documented in its JavaDoc).

But I would expect that createResource(URI) would do a content type lookup!

The first method createResource(URI) should not call the second one, instead
it should look like in the following

public Resource createResource(URI uri)
{
Resource.Factory resourceFactory =
getResourceFactoryRegistry().getFactory(uri); // this call does a content
type lookup !!
if (resourceFactory != null)
{
Resource result = resourceFactory.createResource(uri);
getResources().add(result);
return result;
}
else
{
return null;
}
}

Can anyone confirm my expectations? If yes, I'm going to report the bug.

I'm using the Galileo Incubation Release, build 20090619-0625.

Ciao, Michael
Re: ResourceSetImpl.createResource(URI) does not work with content type binding [message #431546 is a reply to message #431542] Wed, 15 July 2009 19:48 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30692
Registered: July 2009
Senior Member
Michael,

Comments below.


Michael Mühlberg wrote:
> Hello,
>
> In my plugin I have defined a content type and bound an EMF content parser
> with it:
>
> <extension point="org.eclipse.emf.ecore.content_parser">
> <parser
> class=" com.mm.mmdsl.MmDslExecutableExtensionFactory:org.eclipse.xte xt.resource.XtextResourceFactory "
> contentTypeIdentifier="com.mm.mmdsltest">
> </parser>
> </extension>
> <extension point="org.eclipse.core.contenttype.contentTypes">
> <content-type
> file-extensions="mmdsltest"
> id="com.mm.mmdsltest"
> name="com.mm.mmdsltest"
> priority="normal">
> </content-type>
> </extension>
>
> Now I want to create a resource via a call like this, or to be precise, the
> XtextDocument does it
>
> resourceSet.createResource(URI.createFileURI("mmtest.mmdsltest "))
>
The general assumption is that createResource will typically create a
new resource. I.e., there is no content in it get to analyze for
content type.
> Inside of ResourceSetImpl, which is called, one can see the following code
> sequence
>
> /*
> * Javadoc copied from interface.
> */
> public Resource createResource(URI uri)
> {
> return createResource(uri, null);
> }
>
>
> /*
> * Javadoc copied from interface.
> */
> public Resource createResource(URI uri, String contentType)
> {
> Resource.Factory resourceFactory =
> getResourceFactoryRegistry().getFactory(uri, contentType);
> if (resourceFactory != null)
> {
> Resource result = resourceFactory.createResource(uri);
> getResources().add(result);
> return result;
> }
> else
> {
> return null;
> }
> }
>
> In my opinion the call in the first method createResource(URI)
>
> createResource(uri, null)
>
I don't agree.
> is a bug, because the second method createResource(URI, String) then does
> not use content type lookup (like it is also documented in its JavaDoc).
>
And that's done for the reason I explained.
> But I would expect that createResource(URI) would do a content type lookup!
>
If you are creating a new resource presumably you know the content type,
so specify it explicitly. If you're not creating a new resource, use
getResource(..., true).
> The first method createResource(URI) should not call the second one, instead
> it should look like in the following
>
> public Resource createResource(URI uri)
> {
> Resource.Factory resourceFactory =
> getResourceFactoryRegistry().getFactory(uri); // this call does a content
> type lookup !!
> if (resourceFactory != null)
> {
> Resource result = resourceFactory.createResource(uri);
> getResources().add(result);
> return result;
> }
> else
> {
> return null;
> }
> }
>
> Can anyone confirm my expectations? If yes, I'm going to report the bug.
>
No, I disagree and I won't change it.
> I'm using the Galileo Incubation Release, build 20090619-0625.
>
> Ciao, Michael
>
>
>
Re: ResourceSetImpl.createResource(URI) does not work with content type binding [message #431552 is a reply to message #431546] Thu, 16 July 2009 07:26 Go to previous messageGo to next message
Michael  Mühlberg is currently offline Michael MühlbergFriend
Messages: 33
Registered: July 2009
Member
ok, I will hand it over to Xtext as a requirement.

If I understand you correctly they have to determine the content type before
and, if present, have to call createResource(URI, String) instead of
createResource(URI). Is that more or less correct?

Ciao, Michael



"Ed Merks" <Ed.Merks@gmail.com> wrote in message
news:h3lbq4$mgg$1@build.eclipse.org...
> Michael,
>
> Comments below.
>
>
> Michael M
Re: ResourceSetImpl.createResource(URI) does not work with content type binding [message #431553 is a reply to message #431546] Thu, 16 July 2009 10:31 Go to previous messageGo to next message
Michael  Mühlberg is currently offline Michael MühlbergFriend
Messages: 33
Registered: July 2009
Member
Sorry Ed, but I read again the JavaDoc for method

ResourceSet.createResource(URI)

and there stands that the method getFactory(URI) of the registry is called,
which is not the case!

/**
* Creates a new resource, of the appropriate type, and returns it.
* <p>
* It delegates to the resource factory {@link #getResourceFactoryRegistry
registry}
* to determine the {@link Resource.Factory.Registry#getFactory(URI) correct}
factory,
* and then it uses that factory to {@link Resource.Factory#createResource
create} the resource
* and adds it to the {@link #getResources contents}.
* If there is no registered factory, <code>null</code> will be returned;
* when running within Eclipse,
* a default XMI factory will be registered,
* and this will never return <code>null</code>.
* </p>
* @param uri the URI of the resource to create.
* @return a new resource, or <code>null</code> if no factory is registered.
*/

Ciao, Michael


"Ed Merks" <Ed.Merks@gmail.com> wrote in message
news:h3lbq4$mgg$1@build.eclipse.org...
> Michael,
>
> Comments below.
>
>
> Michael M
Re: ResourceSetImpl.createResource(URI) does not work with content type binding [message #431556 is a reply to message #431553] Thu, 16 July 2009 15:13 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30692
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------010600010003030700060409
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 8bit

Michael,

Comments below...

With respect to your other comment, if a resource exists already, use
getResource, not createResource. If it doesn't there's no way to know
the content type other than to specify it explicitly...


Michael M
Re: ResourceSetImpl.createResource(URI) does not work with content type binding [message #431577 is a reply to message #431556] Fri, 17 July 2009 10:29 Go to previous messageGo to next message
Michael  Mühlberg is currently offline Michael MühlbergFriend
Messages: 33
Registered: July 2009
Member
This is a multi-part message in MIME format.

------=_NextPart_000_0009_01CA06DA.348D8ED0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hello Ed,

ok, I get you. I was misleaded my the fact that Xtext calls the createor =
in a read scenario. Then they do in fact a read in their =
XtextResourceFactory instead of a creation, at least this is my first =
impression. I'm going to ask them about that.

Nevertheless I can not completely agree with you. You say that parsing a =
content does not make sense when the resource is going to be created =
because then there is no content present, ok. This is clearly true.

But, the content type extension point =
org.eclipse.core.contenttype.contentTypes not only has a describer (the =
parser) but also a file name, an extension and who know what else. So, =
also in the case where the content is still empty, it is reasonable to =
be aware of an eventual content type definition during the creation =
phase.

When I determine the content type, e.g. by the name (!) of the file (see =
my extension point definition below, com.mm.mmdsltest), I want clearly =
that then the correct Resource Factory (below =
com.mm.mmdsl.MmDslExecutableExtensionFactory:org.eclipse.xte xt.resource.X=
textResourceFactory) is taken in order to create my file. Clear, there =
is no content to be parsed, but, perhaps I want to do other things.

With the call of getFactory(URI, String =3D null) you explicitely hinder =
one from a how ever defined content type binding possibility. That's the =
point.

Ciao, Michael



"Ed Merks" <Ed.Merks@gmail.com> wrote in message =
news:h3ng2q$lbd$1@build.eclipse.org...
Michael,

Comments below...

With respect to your other comment, if a resource exists already, use =
getResource, not createResource. If it doesn't there's no way to know =
the content type other than to specify it explicitly...


Michael M=FChlberg wrote:=20
Sorry Ed, but I read again the JavaDoc for method

ResourceSet.createResource(URI)

and there stands that the method getFactory(URI) of the registry is =
called,=20
which is not the case!
Ultimately it is because be null is passed.
/**
* Returns the resource factory appropriate for the given URI
* with the given {@link URIConverter#contentDescription(URI, =
Map) content type} identifier.
* <p>
* An implementation will (typically) use
* the URI's {@link URI#scheme scheme} to search the {@link =
#getProtocolToFactoryMap protocol} map
* the URI's {@link URI#fileExtension file extension} to search =
{@link #getExtensionToFactoryMap extension} map,
* and the given content type identifier to search the {@link =
#getContentTypeToFactoryMap() content type} map.
* It will {@link =
org.eclipse.emf.ecore.resource.Resource.Factory.Descriptor#c reateFactory =
convert}
* a resulting descriptor into a factory.
* It may choose to provide additional mechanisms and algorithms =
to determine a factory appropriate for the given URI.
* </p>
* @param uri the URI.
* @param contentType the content type of the URI or =
<code>null</code> if a content type should not be used during lookup.
* @return the resource factory appropriate for the given URI =
with the content content type, or <code>null</code> if there isn't one.
* @see ResourceSet#createResource(URI)
* @since 2.4
*/
Factory getFactory(URI uri, String contentType);=20
/**
* Creates a new resource, of the appropriate type, and returns it.
* <p>
* It delegates to the resource factory {@link =
#getResourceFactoryRegistry=20
registry}
* to determine the {@link Resource.Factory.Registry#getFactory(URI) =
correct}=20
factory,
* and then it uses that factory to {@link =
Resource.Factory#createResource=20
create} the resource
* and adds it to the {@link #getResources contents}.
* If there is no registered factory, <code>null</code> will be returned;
* when running within Eclipse,
* a default XMI factory will be registered,
* and this will never return <code>null</code>.
* </p>
* @param uri the URI of the resource to create.
* @return a new resource, or <code>null</code> if no factory is =
registered.
*/

Ciao, Michael


"Ed Merks" <Ed.Merks@gmail.com> wrote in message=20
news:h3lbq4$mgg$1@build.eclipse.org...
Michael,

Comments below.


Michael M=FChlberg wrote:
Hello,

In my plugin I have defined a content type and bound an EMF content=20
parser with it:

<extension point=3D"org.eclipse.emf.ecore.content_parser">
<parser

class=3D" com.mm.mmdsl.MmDslExecutableExtensionFactory:org.eclipse.xte xt.r=
esource.XtextResourceFactory"
contentTypeIdentifier=3D"com.mm.mmdsltest">
</parser>
</extension>
<extension point=3D"org.eclipse.core.contenttype.contentTypes">
<content-type
file-extensions=3D"mmdsltest"
id=3D"com.mm.mmdsltest"
name=3D"com.mm.mmdsltest"
priority=3D"normal">
</content-type>
</extension>

Now I want to create a resource via a call like this, or to be precise,=20
the XtextDocument does it

resourceSet.createResource(URI.createFileURI("mmtest.mmdsltest "))

The general assumption is that createResource will typically =
create a new=20
resource. I.e., there is no content in it get to analyze for content=20
type.
Inside of ResourceSetImpl, which is called, one can see the =
following=20
code sequence

/*
* Javadoc copied from interface.
*/
public Resource createResource(URI uri)
{
return createResource(uri, null);
}


/*
* Javadoc copied from interface.
*/
public Resource createResource(URI uri, String contentType)
{
Resource.Factory resourceFactory =3D=20
getResourceFactoryRegistry().getFactory(uri, contentType);
if (resourceFactory !=3D null)
{
Resource result =3D resourceFactory.createResource(uri);
getResources().add(result);
return result;
}
else
{
return null;
}
}

In my opinion the call in the first method createResource(URI)

createResource(uri, null)

I don't agree.
is a bug, because the second method createResource(URI, String) then =
does=20
not use content type lookup (like it is also documented in its JavaDoc).

And that's done for the reason I explained.
But I would expect that createResource(URI) would do a content type=20
lookup!

If you are creating a new resource presumably you know the content =
type,=20
so specify it explicitly. If you're not creating a new resource, use=20
getResource(..., true).
The first method createResource(URI) should not call the second one, =

instead it should look like in the following

public Resource createResource(URI uri)
{
Resource.Factory resourceFactory =3D=20
getResourceFactoryRegistry().getFactory(uri); // this call does a=20
content type lookup !!
if (resourceFactory !=3D null)
{
Resource result =3D resourceFactory.createResource(uri);
getResources().add(result);
return result;
}
else
{
return null;
}
}

Can anyone confirm my expectations? If yes, I'm going to report the bug.

No, I disagree and I won't change it.
I'm using the Galileo Incubation Release, build 20090619-0625.

Ciao, Michael



=20


------=_NextPart_000_0009_01CA06DA.348D8ED0
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=3Dtext/html;charset=3DISO-8859-1 =
http-equiv=3DContent-Type>
<META name=3DGENERATOR content=3D"MSHTML 8.00.6001.18783">
<STYLE></STYLE>
</HEAD>
<BODY dir=3Dltr bgColor=3D#ffffff text=3D#000000>
<DIV><FONT size=3D2 face=3DArial>Hello Ed,</FONT></DIV>
<DIV><FONT size=3D2 face=3DArial></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2 face=3DArial>ok, I get you. I was misleaded my the =
fact that=20
Xtext calls the createor in a read scenario. Then they do in fact a read =
in=20
their XtextResourceFactory instead of a creation, at least this is my =
first=20
impression. I'm going to ask them about that.</FONT></DIV>
<DIV><FONT size=3D2 face=3DArial></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2 face=3DArial>Nevertheless I can not completely agree =
with you.=20
You say that parsing a content does not make sense when the resource is =
going to=20
be created because then there is no content present, ok. This is clearly =

true.</FONT></DIV>
<DIV><FONT size=3D2 face=3DArial></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2 face=3DArial>But, the content type extension point =
<FONT=20
size=3D3>org.eclipse.core.contenttype.contentTypes </FONT>not only has a =
describer=20
(the parser) but also a file name, an extension and who know what else. =
So, also=20
in the case where the content is still empty, it is reasonable to be =
aware of an=20
eventual content type definition during the creation phase.</FONT></DIV>
<DIV><FONT size=3D2 face=3DArial></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2 face=3DArial>When I determine the content type, e.g. =
by the name=20
(!) of the file (see my extension point definition below, =
com.mm.mmdsltest), I=20
want clearly that then the correct Resource Factory (below <FONT=20
size=3D3> com.mm.mmdsl.MmDslExecutableExtensionFactory:org.eclipse.xte xt.r=
esource.XtextResourceFactory)=20
</FONT></FONT><FONT size=3D2 face=3DArial>is taken in order to create my =
file.=20
Clear, there is no content to be parsed, but, perhaps I want to do other =

things.</FONT></DIV>
<DIV><FONT size=3D2 face=3DArial></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2 face=3DArial>With the call of getFactory(URI, String =
=3D null) you=20
explicitely&nbsp;hinder one from a how ever defined content type binding =

possibility. That's the point.</FONT></DIV>
<DIV><FONT size=3D2 face=3DArial></FONT><FONT size=3D2 =
face=3DArial></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2 face=3DArial>Ciao, Michael</FONT></DIV>
<DIV><FONT size=3D2 face=3DArial></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2 face=3DArial></FONT><FONT size=3D2 =
face=3DArial></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2 face=3DArial></FONT>&nbsp;</DIV>
<BLOCKQUOTE=20
style=3D"BORDER-LEFT: #000000 2px solid; PADDING-LEFT: 5px; =
PADDING-RIGHT: 0px; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px"=20
dir=3Dltr>
<DIV>"Ed Merks" &lt;<A=20
href=3D"mailto:Ed.Merks@gmail.com">Ed.Merks@gmail.com</A>&gt; wrote in =
message=20
<A=20
=
href=3D"news:h3ng2q$lbd$1@build.eclipse.org">news:h3ng2q$lbd$1@build.ecli=
pse.org</A>...</DIV>Michael,<BR><BR>Comments=20
below...<BR><BR>With respect to your other comment, if a resource =
exists=20
already, use getResource, not createResource.&nbsp; If it doesn't =
there's no=20
way to know the content type other than to specify it=20
explicitly...<BR><BR><BR>Michael M=FChlberg wrote:=20
<BLOCKQUOTE cite=3Dmid:h3mvhf$et7$1@build.eclipse.org =
type=3D"cite"><PRE wrap=3D"">Sorry Ed, but I read again the JavaDoc for =
method

ResourceSet.createResource(URI)

and there stands that the method getFactory(URI) of the registry is =
called,=20
which is not the case!
</PRE></BLOCKQUOTE>Ultimately it is because be null is=20
passed.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
/**<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * Returns the resource =
factory=20
appropriate for the given URI<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
* with=20
the given {@link URIConverter#contentDescription(URI, Map) content =
type}=20
identifier.<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; *=20
&lt;p&gt;<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * An implementation =
will=20
(typically) use<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * the URI's =
{@link=20
URI#scheme scheme} to search the {@link #getProtocolToFactoryMap =
protocol}=20
map<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * the URI's {@link=20
URI#fileExtension file extension} to search {@link =
#getExtensionToFactoryMap=20
extension} map,<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * and the =
given=20
content type identifier to search the {@link =
#getContentTypeToFactoryMap()=20
content type} map.<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * It will =
{@link=20
=
org.eclipse.emf.ecore.resource.Resource.Factory.Descriptor#c reateFactory =

convert}<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * a resulting =
descriptor into=20
a factory.<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * It may choose to =
provide=20
additional mechanisms and algorithms to determine a factory =
appropriate for=20
the given URI.<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; *=20
&lt;/p&gt;<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * @param uri the=20
URI.<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * @param contentType the =
content=20
type of the URI <B>or &lt;code&gt;null&lt;/code&gt; if a content type =
should=20
not be used during lookup.</B><BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
*=20
@return the resource factory appropriate for the given URI with the =
content=20
content type, or &lt;code&gt;null&lt;/code&gt; if there isn't=20
one.<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * @see=20
=
ResourceSet#createResource(URI)<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
*=20
@since 2.4<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =20
*/<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Factory getFactory(URI uri, =
String=20
contentType);=20
<BLOCKQUOTE cite=3Dmid:h3mvhf$et7$1@build.eclipse.org =
type=3D"cite"><PRE wrap=3D"">/**
* Creates a new resource, of the appropriate type, and returns it.
* &lt;p&gt;
* It delegates to the resource factory {@link =
#getResourceFactoryRegistry=20
registry}
* to determine the {@link Resource.Factory.Registry#getFactory(URI) =
correct}=20
factory,
* and then it uses that factory to {@link =
Resource.Factory#createResource=20
create} the resource
* and adds it to the {@link #getResources contents}.
* If there is no registered factory, &lt;code&gt;null&lt;/code&gt; will =
be returned;
* when running within Eclipse,
* a default XMI factory will be registered,
* and this will never return &lt;code&gt;null&lt;/code&gt;.
* &lt;/p&gt;
* @param uri the URI of the resource to create.
* @return a new resource, or &lt;code&gt;null&lt;/code&gt; if no factory =
is registered.
*/

Ciao, Michael


"Ed Merks" <A class=3Dmoz-txt-link-rfc2396E =
href=3D"mailto:Ed.Merks@gmail.com">&lt;Ed.Merks@gmail.com&gt;</A> wrote =
in message=20
<A class=3Dmoz-txt-link-freetext =
href=3D"news:h3lbq4$mgg$1@build.eclipse.org">news:h3lbq4$mgg$1@build.ecli=
pse.org</A>...
</PRE>
<BLOCKQUOTE type=3D"cite"><PRE wrap=3D"">Michael,

Comments below.


Michael M=FChlberg wrote:
</PRE>
<BLOCKQUOTE type=3D"cite"><PRE wrap=3D"">Hello,

In my plugin I have defined a content type and bound an EMF content=20
parser with it:

&lt;extension point=3D"org.eclipse.emf.ecore.content_parser"&gt;
&lt;parser

class=3D" com.mm.mmdsl.MmDslExecutableExtensionFactory:org.eclipse.xte xt.r=
esource.XtextResourceFactory"
contentTypeIdentifier=3D"com.mm.mmdsltest"&gt;
&lt;/parser&gt;
&lt;/extension&gt;
&lt;extension point=3D"org.eclipse.core.contenttype.contentTypes"&gt;
&lt;content-type
file-extensions=3D"mmdsltest"
id=3D"com.mm.mmdsltest"
name=3D"com.mm.mmdsltest"
priority=3D"normal"&gt;
&lt;/content-type&gt;
&lt;/extension&gt;

Now I want to create a resource via a call like this, or to be precise,=20
the XtextDocument does it

resourceSet.createResource(URI.createFileURI("mmtest.mmdsltest "))

</PRE></BLOCKQUOTE><PRE wrap=3D"">The general assumption is that =
createResource will typically create a new=20
resource. I.e., there is no content in it get to analyze for content=20
type.
</PRE>
<BLOCKQUOTE type=3D"cite"><PRE wrap=3D"">Inside of =
ResourceSetImpl, which is called, one can see the following=20
code sequence

/*
* Javadoc copied from interface.
*/
public Resource createResource(URI uri)
{
return createResource(uri, null);
}


/*
* Javadoc copied from interface.
*/
public Resource createResource(URI uri, String contentType)
{
Resource.Factory resourceFactory =3D=20
getResourceFactoryRegistry().getFactory(uri, contentType);
if (resourceFactory !=3D null)
{
Resource result =3D resourceFactory.createResource(uri);
getResources().add(result);
return result;
}
else
{
return null;
}
}

In my opinion the call in the first method createResource(URI)

createResource(uri, null)

</PRE></BLOCKQUOTE><PRE wrap=3D"">I don't agree.
</PRE>
<BLOCKQUOTE type=3D"cite"><PRE wrap=3D"">is a bug, because the =
second method createResource(URI, String) then does=20
not use content type lookup (like it is also documented in its JavaDoc).

</PRE></BLOCKQUOTE><PRE wrap=3D"">And that's done for the reason I =
explained.
</PRE>
<BLOCKQUOTE type=3D"cite"><PRE wrap=3D"">But I would expect that =
createResource(URI) would do a content type=20
lookup!

</PRE></BLOCKQUOTE><PRE wrap=3D"">If you are creating a new =
resource presumably you know the content type,=20
so specify it explicitly. If you're not creating a new resource, use=20
getResource(..., true).
</PRE>
<BLOCKQUOTE type=3D"cite"><PRE wrap=3D"">The first method =
createResource(URI) should not call the second one,=20
instead it should look like in the following

public Resource createResource(URI uri)
{
Resource.Factory resourceFactory =3D=20
getResourceFactoryRegistry().getFactory(uri); // this call does a=20
content type lookup !!
if (resourceFactory !=3D null)
{
Resource result =3D resourceFactory.createResource(uri);
getResources().add(result);
return result;
}
else
{
return null;
}
}

Can anyone confirm my expectations? If yes, I'm going to report the bug.

</PRE></BLOCKQUOTE><PRE wrap=3D"">No, I disagree and I won't =
change it.
</PRE>
<BLOCKQUOTE type=3D"cite"><PRE wrap=3D"">I'm using the Galileo =
Incubation Release, build 20090619-0625.

Ciao, Michael



</PRE></BLOCKQUOTE></BLOCKQUOTE><PRE wrap=3D""><!---->

</PRE></BLOCKQUOTE></BLOCKQUOTE></BODY></HTML>

------=_NextPart_000_0009_01CA06DA.348D8ED0--
Re: ResourceSetImpl.createResource(URI) does not work with content type binding [message #431582 is a reply to message #431577] Fri, 17 July 2009 15:02 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30692
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------050001050202010100040301
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 8bit

Michael,

Comments below.

Michael M
Re: ResourceSetImpl.createResource(URI) does not work with content type binding [message #431658 is a reply to message #431582] Tue, 21 July 2009 06:34 Go to previous messageGo to next message
Michael  Mühlberg is currently offline Michael MühlbergFriend
Messages: 33
Registered: July 2009
Member
This is a multi-part message in MIME format.

------=_NextPart_000_0009_01CA09DE.19CF82E0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

I can not define my registration based only on the extension because I =
have the same extension in different "environments" (backend version for =
example). So, my hope was that I can define a content handler via the =
mentioned extension point and only because somewhere in Xtext one calls

ResourceSetImpl.createResource(URI)

instead of first asking the resource factory registry (which is aware of =
content type binding) and then calling the returned resource factory to =
create the resource (see my code snippet below), it does not work.

I don't understand why you are requesting me to define a registration =
based on an extension. Exactly this is not possible in my scenario. You =
are also saying that content type binding is not supported by the call =
above, but the JavaDoc says that it should be supported and a slight =
change in the code would do that.

Sorry, but I don't understand your standpoint here.

Ciao, Michael



"Ed Merks" <Ed.Merks@gmail.com> wrote in message =
news:h3q3pr$eqs$1@build.eclipse.org...
Michael,

Comments below.

Michael M=FChlberg wrote:=20
Hello Ed,

ok, I get you. I was misleaded my the fact that Xtext calls the =
createor in a read scenario. Then they do in fact a read in their =
XtextResourceFactory instead of a creation, at least this is my first =
impression. I'm going to ask them about that.

Nevertheless I can not completely agree with you. You say that =
parsing a content does not make sense when the resource is going to be =
created because then there is no content present, ok. This is clearly =
true.

But, the content type extension point =
org.eclipse.core.contenttype.contentTypes not only has a describer (the =
parser) but also a file name, an extension and who know what else.=20
Yes, but that's not how EMF is designed and EMF's design works stand =
alone independent of anything the platform implements.

So, also in the case where the content is still empty, it is =
reasonable to be aware of an eventual content type definition during the =
creation phase.
Clearly looking at the syntax of the URI has nothing to do with =
content, so to me it's a misnomer.


When I determine the content type, e.g. by the name (!) of the file =
(see my extension point definition below, com.mm.mmdsltest), I want =
clearly that then the correct Resource Factory (below =
com.mm.mmdsl.MmDslExecutableExtensionFactory:org.eclipse.xte xt.resource.X=
textResourceFactory) is taken in order to create my file.
In EMF you'll need to define something based on the extension in that =
case. That's fully supported to and is completely orthogonal to =
"proper" content type recognition with in my opinion is based on =
content.=20

Clear, there is no content to be parsed, but, perhaps I want to do =
other things.

With the call of getFactory(URI, String =3D null) you explicitely =
hinder one from a how ever defined content type binding possibility. =
That's the point.
Define a registration based on extension and nothing is hindered.=20


Ciao, Michael



"Ed Merks" <Ed.Merks@gmail.com> wrote in message =
news:h3ng2q$lbd$1@build.eclipse.org...
Michael,

Comments below...

With respect to your other comment, if a resource exists already, =
use getResource, not createResource. If it doesn't there's no way to =
know the content type other than to specify it explicitly...


Michael M=FChlberg wrote:=20
Sorry Ed, but I read again the JavaDoc for method

ResourceSet.createResource(URI)

and there stands that the method getFactory(URI) of the registry is =
called,=20
which is not the case!
Ultimately it is because be null is passed.
/**
* Returns the resource factory appropriate for the given =
URI
* with the given {@link =
URIConverter#contentDescription(URI, Map) content type} identifier.
* <p>
* An implementation will (typically) use
* the URI's {@link URI#scheme scheme} to search the {@link =
#getProtocolToFactoryMap protocol} map
* the URI's {@link URI#fileExtension file extension} to =
search {@link #getExtensionToFactoryMap extension} map,
* and the given content type identifier to search the =
{@link #getContentTypeToFactoryMap() content type} map.
* It will {@link =
org.eclipse.emf.ecore.resource.Resource.Factory.Descriptor#c reateFactory =
convert}
* a resulting descriptor into a factory.
* It may choose to provide additional mechanisms and =
algorithms to determine a factory appropriate for the given URI.
* </p>
* @param uri the URI.
* @param contentType the content type of the URI or =
<code>null</code> if a content type should not be used during lookup.
* @return the resource factory appropriate for the given =
URI with the content content type, or <code>null</code> if there isn't =
one.
* @see ResourceSet#createResource(URI)
* @since 2.4
*/
Factory getFactory(URI uri, String contentType);=20
/**
* Creates a new resource, of the appropriate type, and returns it.
* <p>
* It delegates to the resource factory {@link =
#getResourceFactoryRegistry=20
registry}
* to determine the {@link Resource.Factory.Registry#getFactory(URI) =
correct}=20
factory,
* and then it uses that factory to {@link =
Resource.Factory#createResource=20
create} the resource
* and adds it to the {@link #getResources contents}.
* If there is no registered factory, <code>null</code> will be returned;
* when running within Eclipse,
* a default XMI factory will be registered,
* and this will never return <code>null</code>.
* </p>
* @param uri the URI of the resource to create.
* @return a new resource, or <code>null</code> if no factory is =
registered.
*/

Ciao, Michael


"Ed Merks" <Ed.Merks@gmail.com> wrote in message=20
news:h3lbq4$mgg$1@build.eclipse.org...
Michael,

Comments below.


Michael M=FChlberg wrote:
Hello,

In my plugin I have defined a content type and bound an EMF content=20
parser with it:

<extension point=3D"org.eclipse.emf.ecore.content_parser">
<parser

class=3D" com.mm.mmdsl.MmDslExecutableExtensionFactory:org.eclipse.xte xt.r=
esource.XtextResourceFactory"
contentTypeIdentifier=3D"com.mm.mmdsltest">
</parser>
</extension>
<extension point=3D"org.eclipse.core.contenttype.contentTypes">
<content-type
file-extensions=3D"mmdsltest"
id=3D"com.mm.mmdsltest"
name=3D"com.mm.mmdsltest"
priority=3D"normal">
</content-type>
</extension>

Now I want to create a resource via a call like this, or to be precise,=20
the XtextDocument does it

resourceSet.createResource(URI.createFileURI("mmtest.mmdsltest "))

The general assumption is that createResource will typically =
create a new=20
resource. I.e., there is no content in it get to analyze for content=20
type.
Inside of ResourceSetImpl, which is called, one can see the =
following=20
code sequence

/*
* Javadoc copied from interface.
*/
public Resource createResource(URI uri)
{
return createResource(uri, null);
}


/*
* Javadoc copied from interface.
*/
public Resource createResource(URI uri, String contentType)
{
Resource.Factory resourceFactory =3D=20
getResourceFactoryRegistry().getFactory(uri, contentType);
if (resourceFactory !=3D null)
{
Resource result =3D resourceFactory.createResource(uri);
getResources().add(result);
return result;
}
else
{
return null;
}
}

In my opinion the call in the first method createResource(URI)

createResource(uri, null)

I don't agree.
is a bug, because the second method createResource(URI, String) then =
does=20
not use content type lookup (like it is also documented in its JavaDoc).

And that's done for the reason I explained.
But I would expect that createResource(URI) would do a content type=20
lookup!

If you are creating a new resource presumably you know the content =
type,=20
so specify it explicitly. If you're not creating a new resource, use=20
getResource(..., true).
The first method createResource(URI) should not call the second one, =

instead it should look like in the following

public Resource createResource(URI uri)
{
Resource.Factory resourceFactory =3D=20
getResourceFactoryRegistry().getFactory(uri); // this call does a=20
content type lookup !!
if (resourceFactory !=3D null)
{
Resource result =3D resourceFactory.createResource(uri);
getResources().add(result);
return result;
}
else
{
return null;
}
}

Can anyone confirm my expectations? If yes, I'm going to report the bug.

No, I disagree and I won't change it.
I'm using the Galileo Incubation Release, build 20090619-0625.

Ciao, Michael



=20


------=_NextPart_000_0009_01CA09DE.19CF82E0
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=3Dtext/html;charset=3DISO-8859-1 =
http-equiv=3DContent-Type>
<META name=3DGENERATOR content=3D"MSHTML 8.00.6001.18783"></HEAD>
<BODY bgColor=3D#ffffff text=3D#000000>
<DIV><FONT size=3D2 face=3DArial>I can not define my registration based =
only on the=20
extension because I have the same extension in different "environments" =
(backend=20
version for example). So, my hope was that I can define a content =
handler via=20
the mentioned extension point and only because somewhere in Xtext one=20
calls</FONT></DIV>
<DIV><FONT size=3D2 face=3DArial></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2 =
face=3DArial>ResourceSetImpl.createResource(URI)</FONT></DIV >
<DIV><FONT size=3D2 face=3DArial></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2 face=3DArial>instead of first asking the resource =
factory=20
registry (which is aware of content type binding) and then calling the =
returned=20
resource factory to create the resource (see my code snippet below), it =
does not=20
work.</FONT></DIV>
<DIV><FONT size=3D2 face=3DArial></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2 face=3DArial>I don't understand why you are =
requesting me to=20
define a registration based on an extension. Exactly this is not =
possible in my=20
scenario. You are also saying that content type binding is not supported =
by the=20
call above, but the JavaDoc says that it should be supported and a =
slight change=20
in the code would do that.</FONT></DIV>
<DIV><FONT size=3D2 face=3DArial></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2 face=3DArial>Sorry, but I don't understand your =
standpoint=20
here.</FONT></DIV>
<DIV><FONT size=3D2 face=3DArial></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2 face=3DArial>Ciao, Michael</FONT></DIV>
<DIV><FONT size=3D2 face=3DArial></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2 face=3DArial></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2 face=3DArial></FONT>&nbsp;</DIV>
<BLOCKQUOTE=20
style=3D"BORDER-LEFT: #000000 2px solid; PADDING-LEFT: 5px; =
PADDING-RIGHT: 0px; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px"=20
dir=3Dltr>
<DIV>"Ed Merks" &lt;<A=20
href=3D"mailto:Ed.Merks@gmail.com">Ed.Merks@gmail.com</A>&gt; wrote in =
message=20
<A=20
=
href=3D"news:h3q3pr$eqs$1@build.eclipse.org">news:h3q3pr$eqs$1@build.ecli=
pse.org</A>...</DIV>Michael,<BR><BR>Comments=20
below.<BR><BR>Michael M=FChlberg wrote:=20
<BLOCKQUOTE cite=3Dmid:h3pjpv$ir7$1@build.eclipse.org type=3D"cite">
<META name=3DGENERATOR content=3D"MSHTML 8.00.6001.18783">
<STYLE></STYLE>

<DIV><FONT size=3D2 face=3DArial>Hello Ed,</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2 face=3DArial>ok, I get you. I was misleaded my =
the fact that=20
Xtext calls the createor in a read scenario. Then they do in fact a =
read in=20
their XtextResourceFactory instead of a creation, at least this is =
my first=20
impression. I'm going to ask them about that.</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2 face=3DArial>Nevertheless I can not completely =
agree with=20
you. You say that parsing a content does not make sense when the =
resource is=20
going to be created because then there is no content present, ok. =
This is=20
clearly true.</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2 face=3DArial>But, the content type extension =
point <FONT=20
size=3D3>org.eclipse.core.contenttype.contentTypes </FONT>not only =
has a=20
describer (the parser) but also a file name, an extension and who =
know what=20
else. </FONT></DIV></BLOCKQUOTE>Yes, but that's not how EMF is =
designed and=20
EMF's design works stand alone independent of anything the platform=20
implements.<BR>
<BLOCKQUOTE cite=3Dmid:h3pjpv$ir7$1@build.eclipse.org type=3D"cite">
<DIV><FONT size=3D2 face=3DArial>So, also in the case where the =
content is still=20
empty, it is reasonable to be aware of an eventual content type =
definition=20
during the creation phase.</FONT></DIV></BLOCKQUOTE>Clearly looking =
at the=20
syntax of the URI has nothing to do with content, so to me it's a=20
misnomer.<BR>
<BLOCKQUOTE cite=3Dmid:h3pjpv$ir7$1@build.eclipse.org type=3D"cite">
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2 face=3DArial>When I determine the content type, =
e.g. by the=20
name (!) of the file (see my extension point definition below,=20
com.mm.mmdsltest), I want clearly that then the correct Resource =
Factory=20
(below <FONT=20
=
size=3D3> com.mm.mmdsl.MmDslExecutableExtensionFactory:org.eclipse.xte xt.r=
esource.XtextResourceFactory)=20
</FONT></FONT><FONT size=3D2 face=3DArial>is taken in order to =
create my=20
file.</FONT></DIV></BLOCKQUOTE>In EMF you'll need to define =
something based on=20
the extension in that case.&nbsp; That's fully supported to and is =
completely=20
orthogonal to "proper" content type recognition with in my opinion is =
based on=20
content. <BR>
<BLOCKQUOTE cite=3Dmid:h3pjpv$ir7$1@build.eclipse.org type=3D"cite">
<DIV><FONT size=3D2 face=3DArial>Clear, there is no content to be =
parsed, but,=20
perhaps I want to do other things.</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2 face=3DArial>With the call of getFactory(URI, =
String =3D null)=20
you explicitely&nbsp;hinder one from a how ever defined content type =
binding=20
possibility. That's the point.</FONT></DIV></BLOCKQUOTE>Define a =
registration=20
based on extension and nothing is hindered. <BR>
<BLOCKQUOTE cite=3Dmid:h3pjpv$ir7$1@build.eclipse.org type=3D"cite">
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2 face=3DArial>Ciao, Michael</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<BLOCKQUOTE=20
style=3D"BORDER-LEFT: rgb(0,0,0) 2px solid; PADDING-LEFT: 5px; =
PADDING-RIGHT: 0px; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px"=20
dir=3Dltr>
<DIV>"Ed Merks" &lt;<A href=3D"mailto:Ed.Merks@gmail.com"=20
moz-do-not-send=3D"true">Ed.Merks@gmail.com</A>&gt; wrote in =
message <A=20
href=3D"news:h3ng2q$lbd$1@build.eclipse.org"=20
=
moz-do-not-send=3D"true">news:h3ng2q$lbd$1@build.eclipse.org</A>...</DIV>=
Michael,<BR><BR>Comments=20
below...<BR><BR>With respect to your other comment, if a resource =
exists=20
already, use getResource, not createResource.&nbsp; If it doesn't =
there's=20
no way to know the content type other than to specify it=20
explicitly...<BR><BR><BR>Michael M=FChlberg wrote:=20
<BLOCKQUOTE cite=3Dmid:h3mvhf$et7$1@build.eclipse.org =
type=3D"cite"><PRE wrap=3D"">Sorry Ed, but I read again the JavaDoc for =
method

ResourceSet.createResource(URI)

and there stands that the method getFactory(URI) of the registry is =
called,=20
which is not the case!
</PRE></BLOCKQUOTE>Ultimately it is because be null is=20
passed.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
/**<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * Returns the resource =
factory=20
appropriate for the given =
URI<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; *=20
with the given {@link URIConverter#contentDescription(URI, Map) =
content=20
type} identifier.<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; *=20
&lt;p&gt;<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * An =
implementation will=20
(typically) use<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * the =
URI's {@link=20
URI#scheme scheme} to search the {@link #getProtocolToFactoryMap =
protocol}=20
map<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * the URI's {@link=20
URI#fileExtension file extension} to search {@link=20
#getExtensionToFactoryMap extension}=20
map,<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * and the given =
content type=20
identifier to search the {@link #getContentTypeToFactoryMap() =
content=20
type} map.<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * It will =
{@link=20
=
org.eclipse.emf.ecore.resource.Resource.Factory.Descriptor#c reateFactory =

convert}<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * a resulting =
descriptor=20
into a factory.<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * It may =
choose to=20
provide additional mechanisms and algorithms to determine a =
factory=20
appropriate for the given =
URI.<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; *=20
&lt;/p&gt;<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * @param uri =
the=20
URI.<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * @param contentType =
the=20
content type of the URI <B>or &lt;code&gt;null&lt;/code&gt; if a =
content=20
type should not be used during=20
lookup.</B><BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * @return the =
resource=20
factory appropriate for the given URI with the content content =
type, or=20
&lt;code&gt;null&lt;/code&gt; if there isn't=20
one.<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * @see=20
=
ResourceSet#createResource(URI)<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
*=20
@since 2.4<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =20
*/<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Factory getFactory(URI uri, =
String=20
contentType);=20
<BLOCKQUOTE cite=3Dmid:h3mvhf$et7$1@build.eclipse.org =
type=3D"cite"><PRE wrap=3D"">/**
* Creates a new resource, of the appropriate type, and returns it.
* &lt;p&gt;
* It delegates to the resource factory {@link =
#getResourceFactoryRegistry=20
registry}
* to determine the {@link Resource.Factory.Registry#getFactory(URI) =
correct}=20
factory,
* and then it uses that factory to {@link =
Resource.Factory#createResource=20
create} the resource
* and adds it to the {@link #getResources contents}.
* If there is no registered factory, &lt;code&gt;null&lt;/code&gt; will =
be returned;
* when running within Eclipse,
* a default XMI factory will be registered,
* and this will never return &lt;code&gt;null&lt;/code&gt;.
* &lt;/p&gt;
* @param uri the URI of the resource to create.
* @return a new resource, or &lt;code&gt;null&lt;/code&gt; if no factory =
is registered.
*/

Ciao, Michael


"Ed Merks" <A class=3Dmoz-txt-link-rfc2396E =
href=3D"mailto:Ed.Merks@gmail.com" =
moz-do-not-send=3D"true">&lt;Ed.Merks@gmail.com&gt;</A> wrote in message =

<A class=3Dmoz-txt-link-freetext =
href=3D"news:h3lbq4$mgg$1@build.eclipse.org" =
moz-do-not-send=3D"true">news:h3lbq4$mgg$1@build.eclipse.org</A>...
</PRE>
<BLOCKQUOTE type=3D"cite"><PRE wrap=3D"">Michael,

Comments below.


Michael M=FChlberg wrote:
</PRE>
<BLOCKQUOTE type=3D"cite"><PRE wrap=3D"">Hello,

In my plugin I have defined a content type and bound an EMF content=20
parser with it:

&lt;extension point=3D"org.eclipse.emf.ecore.content_parser"&gt;
&lt;parser

class=3D" com.mm.mmdsl.MmDslExecutableExtensionFactory:org.eclipse.xte xt.r=
esource.XtextResourceFactory"
contentTypeIdentifier=3D"com.mm.mmdsltest"&gt;
&lt;/parser&gt;
&lt;/extension&gt;
&lt;extension point=3D"org.eclipse.core.contenttype.contentTypes"&gt;
&lt;content-type
file-extensions=3D"mmdsltest"
id=3D"com.mm.mmdsltest"
name=3D"com.mm.mmdsltest"
priority=3D"normal"&gt;
&lt;/content-type&gt;
&lt;/extension&gt;

Now I want to create a resource via a call like this, or to be precise,=20
the XtextDocument does it

resourceSet.createResource(URI.createFileURI("mmtest.mmdsltest "))

</PRE></BLOCKQUOTE><PRE wrap=3D"">The general assumption is that =
createResource will typically create a new=20
resource. I.e., there is no content in it get to analyze for content=20
type.
</PRE>
<BLOCKQUOTE type=3D"cite"><PRE wrap=3D"">Inside of =
ResourceSetImpl, which is called, one can see the following=20
code sequence

/*
* Javadoc copied from interface.
*/
public Resource createResource(URI uri)
{
return createResource(uri, null);
}


/*
* Javadoc copied from interface.
*/
public Resource createResource(URI uri, String contentType)
{
Resource.Factory resourceFactory =3D=20
getResourceFactoryRegistry().getFactory(uri, contentType);
if (resourceFactory !=3D null)
{
Resource result =3D resourceFactory.createResource(uri);
getResources().add(result);
return result;
}
else
{
return null;
}
}

In my opinion the call in the first method createResource(URI)

createResource(uri, null)

</PRE></BLOCKQUOTE><PRE wrap=3D"">I don't agree.
</PRE>
<BLOCKQUOTE type=3D"cite"><PRE wrap=3D"">is a bug, because the =
second method createResource(URI, String) then does=20
not use content type lookup (like it is also documented in its JavaDoc).

</PRE></BLOCKQUOTE><PRE wrap=3D"">And that's done for the reason I =
explained.
</PRE>
<BLOCKQUOTE type=3D"cite"><PRE wrap=3D"">But I would expect =
that createResource(URI) would do a content type=20
lookup!

</PRE></BLOCKQUOTE><PRE wrap=3D"">If you are creating a new =
resource presumably you know the content type,=20
so specify it explicitly. If you're not creating a new resource, use=20
getResource(..., true).
</PRE>
<BLOCKQUOTE type=3D"cite"><PRE wrap=3D"">The first method =
createResource(URI) should not call the second one,=20
instead it should look like in the following

public Resource createResource(URI uri)
{
Resource.Factory resourceFactory =3D=20
getResourceFactoryRegistry().getFactory(uri); // this call does a=20
content type lookup !!
if (resourceFactory !=3D null)
{
Resource result =3D resourceFactory.createResource(uri);
getResources().add(result);
return result;
}
else
{
return null;
}
}

Can anyone confirm my expectations? If yes, I'm going to report the bug.

</PRE></BLOCKQUOTE><PRE wrap=3D"">No, I disagree and I won't =
change it.
</PRE>
<BLOCKQUOTE type=3D"cite"><PRE wrap=3D"">I'm using the Galileo =
Incubation Release, build 20090619-0625.

Ciao, Michael



</PRE></BLOCKQUOTE></BLOCKQUOTE><PRE wrap=3D""><!---->

=
</PRE></BLOCKQUOTE></BLOCKQUOTE></BLOCKQUOTE></BLOCKQUOTE ></BODY></HTML>

------=_NextPart_000_0009_01CA09DE.19CF82E0--
Re: ResourceSetImpl.createResource(URI) does not work with content type binding [message #431680 is a reply to message #431658] Tue, 21 July 2009 14:17 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30692
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------020505070106020805030509
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 8bit

Michael,

Comments below.


Michael M
Re: ResourceSetImpl.createResource(URI) does not work with content type binding [message #431712 is a reply to message #431680] Wed, 22 July 2009 14:34 Go to previous messageGo to next message
Michael  Mühlberg is currently offline Michael MühlbergFriend
Messages: 33
Registered: July 2009
Member
This is a multi-part message in MIME format.

------=_NextPart_000_009D_01CA0AEA.4388E330
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Ed,

with the extension point

org.eclipse.emf.ecore.content_parser

one is able to define a resorce factory for a specific content type:

<extension point=3D"org.eclipse.emf.ecore.content_parser">
<parser
class=3D"com.mm.MyResourceFactory"
contentTypeIdentifier=3D"com.mm.mycontenttype">
</parser>

This resource factory is then also responsible for the creation of a =
resource that has the specified content (type). Ok.

The content type can be defined via the extension point

org.eclipse.core.contenttype.contentTypes, e.g.

<extension point=3D"org.eclipse.core.contenttype.contentTypes">
<content-type
file-extensions=3D"mmcontent"
id=3D"com.mm.mycontenttype"
name=3D"mmcontentfilename"
priority=3D"normal">
</content-type>
</extension>

One sees that one can define a content type in various ways, e.g. by =
specifying the extension (mmcontent) of the file AND ALSO via specifying =
the name of the file (mmcontentfilename). Note that my use case is =
different but I think with this example my point gets clearer.

If I call now

ResourceSetImpl.createResource(URI)

with the URI for the file C:\<somewhere>\mmcontentfilename.mmcontent

the registered resource factory com.mm.MyResourceFactory IS NOT CALLED, =
but it should, shouldn't it? Instead the generically registered factory =
XmiResourceFactory is called (which registered for files with the =
extension " * ")

As far as I could see it, the documentation of the method =
createResource(URI) implies that it would be called.

And, in fact, it would if the method would call

getFactory(uri)

instead of delegating to createResource(URI, String) which inside calls

getFactory(uri, null)

Puuh, I hope we understand eachother now :)

Ciao, Michael




"Ed Merks" <Ed.Merks@gmail.com> wrote in message =
news:h44im1$k6i$3@build.eclipse.org...
Michael,

Comments below.


Michael M=FChlberg wrote:=20
I can not define my registration based only on the extension because =
I have the same extension in different "environments" (backend version =
for example).=20
I can imagine, but how then does one determine the content type of a =
file that doesn't exist and has not content?

So, my hope was that I can define a content handler via the =
mentioned extension point and only because somewhere in Xtext one calls
I don't get how that can determine the content type based on extension =
and no content though...


ResourceSetImpl.createResource(URI)

instead of first asking the resource factory registry (which is =
aware of content type binding) and then calling the returned resource =
factory to create the resource (see my code snippet below), it does not =
work.

I don't understand why you are requesting me to define a =
registration based on an extension.
I don't understand what magic you think would determine a content type =
without content based only on the extension when you've just explained =
that this isn't possible because a given extension can be used for =
different types of content. It seems clear to me that you need to use =
the createResource method where you explicitly specify the content =
type...

Exactly this is not possible in my scenario. You are also saying =
that content type binding is not supported by the call above, but the =
JavaDoc says that it should be supported and a slight change in the code =
would do that.

Sorry, but I don't understand your standpoint here.
Clearly there is a communication gap. If a file exists, use =
getResource to load it and then the content type will be determined =
properly. If no file exists, you've just explained that the content =
type can't be determined just from the extension and hence you must =
specify it; of course that's already supported..


Ciao, Michael



"Ed Merks" <Ed.Merks@gmail.com> wrote in message =
news:h3q3pr$eqs$1@build.eclipse.org...
Michael,

Comments below.

Michael M=FChlberg wrote:=20
Hello Ed,

ok, I get you. I was misleaded my the fact that Xtext calls the =
createor in a read scenario. Then they do in fact a read in their =
XtextResourceFactory instead of a creation, at least this is my first =
impression. I'm going to ask them about that.

Nevertheless I can not completely agree with you. You say that =
parsing a content does not make sense when the resource is going to be =
created because then there is no content present, ok. This is clearly =
true.

But, the content type extension point =
org.eclipse.core.contenttype.contentTypes not only has a describer (the =
parser) but also a file name, an extension and who know what else.=20
Yes, but that's not how EMF is designed and EMF's design works =
stand alone independent of anything the platform implements.

So, also in the case where the content is still empty, it is =
reasonable to be aware of an eventual content type definition during the =
creation phase.
Clearly looking at the syntax of the URI has nothing to do with =
content, so to me it's a misnomer.


When I determine the content type, e.g. by the name (!) of the =
file (see my extension point definition below, com.mm.mmdsltest), I want =
clearly that then the correct Resource Factory (below =
com.mm.mmdsl.MmDslExecutableExtensionFactory:org.eclipse.xte xt.resource.X=
textResourceFactory) is taken in order to create my file.
In EMF you'll need to define something based on the extension in =
that case. That's fully supported to and is completely orthogonal to =
"proper" content type recognition with in my opinion is based on =
content.=20

Clear, there is no content to be parsed, but, perhaps I want to =
do other things.

With the call of getFactory(URI, String =3D null) you =
explicitely hinder one from a how ever defined content type binding =
possibility. That's the point.
Define a registration based on extension and nothing is hindered.=20


Ciao, Michael



"Ed Merks" <Ed.Merks@gmail.com> wrote in message =
news:h3ng2q$lbd$1@build.eclipse.org...
Michael,

Comments below...

With respect to your other comment, if a resource exists =
already, use getResource, not createResource. If it doesn't there's no =
way to know the content type other than to specify it explicitly...


Michael M=FChlberg wrote:=20
Sorry Ed, but I read again the JavaDoc for method

ResourceSet.createResource(URI)

and there stands that the method getFactory(URI) of the registry is =
called,=20
which is not the case!
Ultimately it is because be null is passed.
/**
* Returns the resource factory appropriate for the =
given URI
* with the given {@link =
URIConverter#contentDescription(URI, Map) content type} identifier.
* <p>
* An implementation will (typically) use
* the URI's {@link URI#scheme scheme} to search the =
{@link #getProtocolToFactoryMap protocol} map
* the URI's {@link URI#fileExtension file extension} to =
search {@link #getExtensionToFactoryMap extension} map,
* and the given content type identifier to search the =
{@link #getContentTypeToFactoryMap() content type} map.
* It will {@link =
org.eclipse.emf.ecore.resource.Resource.Factory.Descriptor#c reateFactory =
convert}
* a resulting descriptor into a factory.
* It may choose to provide additional mechanisms and =
algorithms to determine a factory appropriate for the given URI.
* </p>
* @param uri the URI.
* @param contentType the content type of the URI or =
<code>null</code> if a content type should not be used during lookup.
* @return the resource factory appropriate for the =
given URI with the content content type, or <code>null</code> if there =
isn't one.
* @see ResourceSet#createResource(URI)
* @since 2.4
*/
Factory getFactory(URI uri, String contentType);=20
/**
* Creates a new resource, of the appropriate type, and returns it.
* <p>
* It delegates to the resource factory {@link =
#getResourceFactoryRegistry=20
registry}
* to determine the {@link Resource.Factory.Registry#getFactory(URI) =
correct}=20
factory,
* and then it uses that factory to {@link =
Resource.Factory#createResource=20
create} the resource
* and adds it to the {@link #getResources contents}.
* If there is no registered factory, <code>null</code> will be returned;
* when running within Eclipse,
* a default XMI factory will be registered,
* and this will never return <code>null</code>.
* </p>
* @param uri the URI of the resource to create.
* @return a new resource, or <code>null</code> if no factory is =
registered.
*/

Ciao, Michael


"Ed Merks" <Ed.Merks@gmail.com> wrote in message=20
news:h3lbq4$mgg$1@build.eclipse.org...
Michael,

Comments below.


Michael M=FChlberg wrote:
Hello,

In my plugin I have defined a content type and bound an EMF content=20
parser with it:

<extension point=3D"org.eclipse.emf.ecore.content_parser">
<parser

class=3D" com.mm.mmdsl.MmDslExecutableExtensionFactory:org.eclipse.xte xt.r=
esource.XtextResourceFactory"
contentTypeIdentifier=3D"com.mm.mmdsltest">
</parser>
</extension>
<extension point=3D"org.eclipse.core.contenttype.contentTypes">
<content-type
file-extensions=3D"mmdsltest"
id=3D"com.mm.mmdsltest"
name=3D"com.mm.mmdsltest"
priority=3D"normal">
</content-type>
</extension>

Now I want to create a resource via a call like this, or to be precise,=20
the XtextDocument does it

resourceSet.createResource(URI.createFileURI("mmtest.mmdsltest "))

The general assumption is that createResource will typically =
create a new=20
resource. I.e., there is no content in it get to analyze for content=20
type.
Inside of ResourceSetImpl, which is called, one can see the =
following=20
code sequence

/*
* Javadoc copied from interface.
*/
public Resource createResource(URI uri)
{
return createResource(uri, null);
}


/*
* Javadoc copied from interface.
*/
public Resource createResource(URI uri, String contentType)
{
Resource.Factory resourceFactory =3D=20
getResourceFactoryRegistry().getFactory(uri, contentType);
if (resourceFactory !=3D null)
{
Resource result =3D resourceFactory.createResource(uri);
getResources().add(result);
return result;
}
else
{
return null;
}
}

In my opinion the call in the first method createResource(URI)

createResource(uri, null)

I don't agree.
is a bug, because the second method createResource(URI, String) then =
does=20
not use content type lookup (like it is also documented in its JavaDoc).

And that's done for the reason I explained.
But I would expect that createResource(URI) would do a content type=20
lookup!

If you are creating a new resource presumably you know the content =
type,=20
so specify it explicitly. If you're not creating a new resource, use=20
getResource(..., true).
The first method createResource(URI) should not call the second one, =

instead it should look like in the following

public Resource createResource(URI uri)
{
Resource.Factory resourceFactory =3D=20
getResourceFactoryRegistry().getFactory(uri); // this call does a=20
content type lookup !!
if (resourceFactory !=3D null)
{
Resource result =3D resourceFactory.createResource(uri);
getResources().add(result);
return result;
}
else
{
return null;
}
}

Can anyone confirm my expectations? If yes, I'm going to report the bug.

No, I disagree and I won't change it.
I'm using the Galileo Incubation Release, build 20090619-0625.

Ciao, Michael



=20


------=_NextPart_000_009D_01CA0AEA.4388E330
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=3Dtext/html;charset=3DISO-8859-1 =
http-equiv=3DContent-Type>
<META name=3DGENERATOR content=3D"MSHTML 8.00.6001.18783"></HEAD>
<BODY dir=3Dltr bgColor=3D#ffffff text=3D#000000>
<DIV><FONT size=3D2 face=3DArial>Ed,</FONT></DIV>
<DIV><FONT size=3D2 face=3DArial></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2 face=3DArial>with the extension point</FONT></DIV>
<DIV><FONT size=3D2 face=3DArial></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2 =
face=3DArial>org.eclipse.emf.ecore.content_parser</FONT></DIV >
<DIV><FONT size=3D2 face=3DArial></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2 face=3DArial>one is able to define a resorce factory =
for a=20
specific content type:</FONT></DIV>
<DIV><FONT size=3D2 face=3DArial></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2 face=3DArial>&lt;extension=20
point=3D"org.eclipse.emf.ecore.content_parser"&gt;<BR >&nbsp;&nbsp;&nbsp; =

&lt;parser</FONT></DIV>
<DIV><FONT size=3D2 face=3DArial>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
class=3D"com.mm.MyResourceFactory"</FONT></DIV>
<DIV><FONT size=3D2 face=3DArial>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
contentTypeIdentifier=3D"com.mm.mycontenttype"&gt;<BR >&lt;/parser&gt;<BR>=
</FONT></DIV>
<DIV><FONT size=3D2 face=3DArial>This resource factory is then also =
responsible for=20
the creation of a resource that has the specified content (type).=20
Ok.</FONT></DIV>
<DIV><FONT size=3D2 face=3DArial></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2 face=3DArial>The content type can be defined via the =
extension=20
point</FONT></DIV>
<DIV><FONT size=3D2 face=3DArial></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2 =
face=3DArial>org.eclipse.core.contenttype.contentTypes,=20
e.g.</FONT></DIV>
<DIV><FONT size=3D2 face=3DArial></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2 face=3DArial>&lt;extension=20
point=3D"org.eclipse.core.contenttype.contentTypes"&gt; <BR>&nbsp;&nbsp;&n=
bsp;=20
&lt;content-type<BR>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
file-extensions=3D"mmcontent"<BR>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
id=3D"com.mm.mycontenttype"<BR>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
name=3D"mmcontentfilename"<BR>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
priority=3D"normal"&gt;<BR>&nbsp;&nbsp;&nbsp;=20
&lt;/content-type&gt;<BR>&lt;/extension&gt; <BR></FONT></DIV>
<DIV><FONT size=3D2 face=3DArial>One sees that one can define a content =
type in=20
various ways, e.g. by specifying the extension (mmcontent) of the file =
AND ALSO=20
via specifying the name of the file (mmcontentfilename). </FONT><FONT =
size=3D2=20
face=3DArial>Note that my use case is different but I think with this =
example my=20
point gets clearer.</FONT></DIV>
<DIV><FONT size=3D2 face=3DArial></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2 face=3DArial>If I call now</FONT></DIV>
<DIV><FONT size=3D2 face=3DArial></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2 =
face=3DArial>ResourceSetImpl.createResource(URI)</FONT></DIV >
<DIV><FONT size=3D2 face=3DArial></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2 face=3DArial>with the URI for the file=20
C:\&lt;somewhere&gt;\mmcontentfilename.mmcontent</FONT ></DIV>
<DIV><FONT size=3D2 face=3DArial></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2 face=3DArial>the registered resource factory=20
com.mm.MyResourceFactory IS NOT CALLED, but it should, shouldn't it? =
Instead the=20
generically registered factory XmiResourceFactory is called (which =
registered=20
for files with the extension " * ")</FONT></DIV>
<DIV><FONT size=3D2 face=3DArial></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2 face=3DArial>As far as I could see it, the =
documentation of the=20
method createResource(URI) implies that it would be called.</FONT></DIV>
<DIV><FONT size=3D2 face=3DArial></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2 face=3DArial>And, in fact, it would if the method =
would=20
call</FONT></DIV>
<DIV><FONT size=3D2 face=3DArial></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2 face=3DArial>getFactory(uri)</FONT></DIV>
<DIV><FONT size=3D2 face=3DArial></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2 face=3DArial>instead of delegating to =
createResource(URI,=20
String) which inside calls</FONT></DIV>
<DIV><FONT size=3D2 face=3DArial></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2 face=3DArial>getFactory(uri, null)</FONT></DIV>
<DIV><FONT size=3D2 face=3DArial></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2 face=3DArial>Puuh, I hope we understand eachother =
now=20
:)</FONT></DIV>
<DIV><FONT size=3D2 face=3DArial></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2 face=3DArial>Ciao, Michael</FONT></DIV>
<DIV><FONT size=3D2 face=3DArial></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2 face=3DArial>&nbsp;</DIV></FONT>
<DIV><FONT size=3D2 face=3DArial></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2 face=3DArial></FONT>&nbsp;</DIV>
<BLOCKQUOTE=20
style=3D"BORDER-LEFT: #000000 2px solid; PADDING-LEFT: 5px; =
PADDING-RIGHT: 0px; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px"=20
dir=3Dltr>
<DIV>"Ed Merks" &lt;<A=20
href=3D"mailto:Ed.Merks@gmail.com">Ed.Merks@gmail.com</A>&gt; wrote in =
message=20
<A=20
=
href=3D"news:h44im1$k6i$3@build.eclipse.org">news:h44im1$k6i$3@build.ecli=
pse.org</A>...</DIV>Michael,<BR><BR>Comments=20
below.<BR><BR><BR>Michael M=FChlberg wrote:=20
<BLOCKQUOTE cite=3Dmid:h43ni2$asc$1@build.eclipse.org type=3D"cite">
<META name=3DGENERATOR content=3D"MSHTML 8.00.6001.18783">
<DIV><FONT size=3D2 face=3DArial>I can not define my registration =
based only on=20
the extension because I have the same extension in different =
"environments"=20
(backend version for example). </FONT></DIV></BLOCKQUOTE>I can =
imagine, but=20
how then does one determine the content type of a file that doesn't =
exist and=20
has not content?<BR>
<BLOCKQUOTE cite=3Dmid:h43ni2$asc$1@build.eclipse.org type=3D"cite">
<DIV><FONT size=3D2 face=3DArial>So, my hope was that I can define a =
content=20
handler via the mentioned extension point and only because somewhere =
in=20
Xtext one calls</FONT></DIV></BLOCKQUOTE>I don't get how that can =
determine=20
the content type based on extension and no content though...<BR>
<BLOCKQUOTE cite=3Dmid:h43ni2$asc$1@build.eclipse.org type=3D"cite">
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2=20
face=3DArial>ResourceSetImpl.createResource(URI)</FONT></DIV >
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2 face=3DArial>instead of first asking the =
resource factory=20
registry (which is aware of content type binding) and then calling =
the=20
returned resource factory to create the resource (see my code =
snippet=20
below), it does not work.</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2 face=3DArial>I don't understand why you are =
requesting me to=20
define a registration based on an =
extension.</FONT></DIV></BLOCKQUOTE>I don't=20
understand what magic you think would determine a content type without =
content=20
based only on the extension when you've just explained that this isn't =

possible because a given extension can be used for different types of=20
content.&nbsp; It seems clear to me that you need to use the =
createResource=20
method where you explicitly specify the content type...<BR>
<BLOCKQUOTE cite=3Dmid:h43ni2$asc$1@build.eclipse.org type=3D"cite">
<DIV><FONT size=3D2 face=3DArial>Exactly this is not possible in my =
scenario.=20
You are also saying that content type binding is not supported by =
the call=20
above, but the JavaDoc says that it should be supported and a slight =
change=20
in the code would do that.</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2 face=3DArial>Sorry, but I don't understand your =
standpoint=20
here.</FONT></DIV></BLOCKQUOTE>Clearly there is a communication =
gap.&nbsp; If=20
a file exists, use getResource to load it and then the content type =
will be=20
determined properly.&nbsp; If no file exists, you've just explained =
that the=20
content type can't be determined just from the extension and hence you =
must=20
specify it; of course that's already supported..<BR>
<BLOCKQUOTE cite=3Dmid:h43ni2$asc$1@build.eclipse.org type=3D"cite">
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2 face=3DArial>Ciao, Michael</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<BLOCKQUOTE=20
style=3D"BORDER-LEFT: rgb(0,0,0) 2px solid; PADDING-LEFT: 5px; =
PADDING-RIGHT: 0px; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px"=20
dir=3Dltr>
<DIV>"Ed Merks" &lt;<A href=3D"mailto:Ed.Merks@gmail.com"=20
moz-do-not-send=3D"true">Ed.Merks@gmail.com</A>&gt; wrote in =
message <A=20
href=3D"news:h3q3pr$eqs$1@build.eclipse.org"=20
=
moz-do-not-send=3D"true">news:h3q3pr$eqs$1@build.eclipse.org</A>...</DIV>=
Michael,<BR><BR>Comments=20
below.<BR><BR>Michael M=FChlberg wrote:=20
<BLOCKQUOTE cite=3Dmid:h3pjpv$ir7$1@build.eclipse.org =
type=3D"cite">
<META name=3DGENERATOR content=3D"MSHTML 8.00.6001.18783">
<STYLE></STYLE>

<DIV><FONT size=3D2 face=3DArial>Hello Ed,</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2 face=3DArial>ok, I get you. I was misleaded =
my the fact=20
that Xtext calls the createor in a read scenario. Then they do =
in fact a=20
read in their XtextResourceFactory instead of a creation, at =
least this=20
is my first impression. I'm going to ask them about =
that.</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2 face=3DArial>Nevertheless I can not =
completely agree=20
with you. You say that parsing a content does not make sense =
when the=20
resource is going to be created because then there is no content =

present, ok. This is clearly true.</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2 face=3DArial>But, the content type extension =
point <FONT=20
size=3D3>org.eclipse.core.contenttype.contentTypes </FONT>not =
only has a=20
describer (the parser) but also a file name, an extension and =
who know=20
what else. </FONT></DIV></BLOCKQUOTE>Yes, but that's not how EMF =
is=20
designed and EMF's design works stand alone independent of =
anything the=20
platform implements.<BR>
<BLOCKQUOTE cite=3Dmid:h3pjpv$ir7$1@build.eclipse.org =
type=3D"cite">
<DIV><FONT size=3D2 face=3DArial>So, also in the case where the =
content is=20
still empty, it is reasonable to be aware of an eventual content =
type=20
definition during the creation =
phase.</FONT></DIV></BLOCKQUOTE>Clearly=20
looking at the syntax of the URI has nothing to do with content, =
so to me=20
it's a misnomer.<BR>
<BLOCKQUOTE cite=3Dmid:h3pjpv$ir7$1@build.eclipse.org =
type=3D"cite">
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2 face=3DArial>When I determine the content =
type, e.g. by=20
the name (!) of the file (see my extension point definition =
below,=20
com.mm.mmdsltest), I want clearly that then the correct Resource =
Factory=20
(below <FONT=20
=
size=3D3> com.mm.mmdsl.MmDslExecutableExtensionFactory:org.eclipse.xte xt.r=
esource.XtextResourceFactory)=20
</FONT></FONT><FONT size=3D2 face=3DArial>is taken in order to =
create my=20
file.</FONT></DIV></BLOCKQUOTE>In EMF you'll need to define =
something=20
based on the extension in that case.&nbsp; That's fully supported =
to and=20
is completely orthogonal to "proper" content type recognition with =
in my=20
opinion is based on content. <BR>
<BLOCKQUOTE cite=3Dmid:h3pjpv$ir7$1@build.eclipse.org =
type=3D"cite">
<DIV><FONT size=3D2 face=3DArial>Clear, there is no content to =
be parsed,=20
but, perhaps I want to do other things.</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2 face=3DArial>With the call of =
getFactory(URI, String =3D=20
null) you explicitely&nbsp;hinder one from a how ever defined =
content=20
type binding possibility. That's the=20
point.</FONT></DIV></BLOCKQUOTE>Define a registration based on =
extension=20
and nothing is hindered. <BR>
<BLOCKQUOTE cite=3Dmid:h3pjpv$ir7$1@build.eclipse.org =
type=3D"cite">
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2 face=3DArial>Ciao, Michael</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<BLOCKQUOTE=20
style=3D"BORDER-LEFT: rgb(0,0,0) 2px solid; PADDING-LEFT: 5px; =
PADDING-RIGHT: 0px; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px"=20
dir=3Dltr>
<DIV>"Ed Merks" &lt;<A href=3D"mailto:Ed.Merks@gmail.com"=20
moz-do-not-send=3D"true">Ed.Merks@gmail.com</A>&gt; wrote in =
message <A=20
href=3D"news:h3ng2q$lbd$1@build.eclipse.org"=20
=
moz-do-not-send=3D"true">news:h3ng2q$lbd$1@build.eclipse.org</A>...</DIV>=
Michael,<BR><BR>Comments=20
below...<BR><BR>With respect to your other comment, if a =
resource=20
exists already, use getResource, not createResource.&nbsp; If =
it=20
doesn't there's no way to know the content type other than to =
specify=20
it explicitly...<BR><BR><BR>Michael M=FChlberg wrote:=20
<BLOCKQUOTE cite=3Dmid:h3mvhf$et7$1@build.eclipse.org =
type=3D"cite"><PRE wrap=3D"">Sorry Ed, but I read again the JavaDoc for =
method

ResourceSet.createResource(URI)

and there stands that the method getFactory(URI) of the registry is =
called,=20
which is not the case!
</PRE></BLOCKQUOTE>Ultimately it is because be null is=20
passed.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
/**<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * Returns the =
resource=20
factory appropriate for the given=20
URI<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * with the given =
{@link=20
URIConverter#contentDescription(URI, Map) content type}=20
identifier.<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; *=20
&lt;p&gt;<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * An =
implementation=20
will (typically) use<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * =
the=20
URI's {@link URI#scheme scheme} to search the {@link=20
#getProtocolToFactoryMap protocol}=20
map<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * the URI's {@link =

URI#fileExtension file extension} to search {@link=20
#getExtensionToFactoryMap extension}=20
map,<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * and the given =
content=20
type identifier to search the {@link =
#getContentTypeToFactoryMap()=20
content type} map.<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * =
It will=20
{@link=20
=
org.eclipse.emf.ecore.resource.Resource.Factory.Descriptor#c reateFactory =

convert}<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * a resulting =

descriptor into a =
factory.<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; *=20
It may choose to provide additional mechanisms and algorithms =
to=20
determine a factory appropriate for the given=20
URI.<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; *=20
&lt;/p&gt;<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * @param =
uri the=20
URI.<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * @param =
contentType the=20
content type of the URI <B>or &lt;code&gt;null&lt;/code&gt; if =
a=20
content type should not be used during=20
lookup.</B><BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * @return =
the=20
resource factory appropriate for the given URI with the =
content=20
content type, or &lt;code&gt;null&lt;/code&gt; if there isn't=20
one.<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * @see=20
=
ResourceSet#createResource(URI)<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =20
* @since 2.4<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =20
*/<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Factory getFactory(URI =
uri,=20
String contentType);=20
<BLOCKQUOTE cite=3Dmid:h3mvhf$et7$1@build.eclipse.org =
type=3D"cite"><PRE wrap=3D"">/**
* Creates a new resource, of the appropriate type, and returns it.
* &lt;p&gt;
* It delegates to the resource factory {@link =
#getResourceFactoryRegistry=20
registry}
* to determine the {@link Resource.Factory.Registry#getFactory(URI) =
correct}=20
factory,
* and then it uses that factory to {@link =
Resource.Factory#createResource=20
create} the resource
* and adds it to the {@link #getResources contents}.
* If there is no registered factory, &lt;code&gt;null&lt;/code&gt; will =
be returned;
* when running within Eclipse,
* a default XMI factory will be registered,
* and this will never return &lt;code&gt;null&lt;/code&gt;.
* &lt;/p&gt;
* @param uri the URI of the resource to create.
* @return a new resource, or &lt;code&gt;null&lt;/code&gt; if no factory =
is registered.
*/

Ciao, Michael


"Ed Merks" <A class=3Dmoz-txt-link-rfc2396E =
href=3D"mailto:Ed.Merks@gmail.com" =
moz-do-not-send=3D"true">&lt;Ed.Merks@gmail.com&gt;</A> wrote in message =

<A class=3Dmoz-txt-link-freetext =
href=3D"news:h3lbq4$mgg$1@build.eclipse.org" =
moz-do-not-send=3D"true">news:h3lbq4$mgg$1@build.eclipse.org</A>...
</PRE>
<BLOCKQUOTE type=3D"cite"><PRE wrap=3D"">Michael,

Comments below.


Michael M=FChlberg wrote:
</PRE>
<BLOCKQUOTE type=3D"cite"><PRE wrap=3D"">Hello,

In my plugin I have defined a content type and bound an EMF content=20
parser with it:

&lt;extension point=3D"org.eclipse.emf.ecore.content_parser"&gt;
&lt;parser

class=3D" com.mm.mmdsl.MmDslExecutableExtensionFactory:org.eclipse.xte xt.r=
esource.XtextResourceFactory"
contentTypeIdentifier=3D"com.mm.mmdsltest"&gt;
&lt;/parser&gt;
&lt;/extension&gt;
&lt;extension point=3D"org.eclipse.core.contenttype.contentTypes"&gt;
&lt;content-type
file-extensions=3D"mmdsltest"
id=3D"com.mm.mmdsltest"
name=3D"com.mm.mmdsltest"
priority=3D"normal"&gt;
&lt;/content-type&gt;
&lt;/extension&gt;

Now I want to create a resource via a call like this, or to be precise,=20
the XtextDocument does it

resourceSet.createResource(URI.createFileURI("mmtest.mmdsltest "))

</PRE></BLOCKQUOTE><PRE wrap=3D"">The general assumption is that =
createResource will typically create a new=20
resource. I.e., there is no content in it get to analyze for content=20
type.
</PRE>
<BLOCKQUOTE type=3D"cite"><PRE wrap=3D"">Inside of =
ResourceSetImpl, which is called, one can see the following=20
code sequence

/*
* Javadoc copied from interface.
*/
public Resource createResource(URI uri)
{
return createResource(uri, null);
}


/*
* Javadoc copied from interface.
*/
public Resource createResource(URI uri, String contentType)
{
Resource.Factory resourceFactory =3D=20
getResourceFactoryRegistry().getFactory(uri, contentType);
if (resourceFactory !=3D null)
{
Resource result =3D resourceFactory.createResource(uri);
getResources().add(result);
return result;
}
else
{
return null;
}
}

In my opinion the call in the first method createResource(URI)

createResource(uri, null)

</PRE></BLOCKQUOTE><PRE wrap=3D"">I don't agree.
</PRE>
<BLOCKQUOTE type=3D"cite"><PRE wrap=3D"">is a bug, because =
the second method createResource(URI, String) then does=20
not use content type lookup (like it is also documented in its JavaDoc).

</PRE></BLOCKQUOTE><PRE wrap=3D"">And that's done for the reason I =
explained.
</PRE>
<BLOCKQUOTE type=3D"cite"><PRE wrap=3D"">But I would =
expect that createResource(URI) would do a content type=20
lookup!

</PRE></BLOCKQUOTE><PRE wrap=3D"">If you are creating a new =
resource presumably you know the content type,=20
so specify it explicitly. If you're not creating a new resource, use=20
getResource(..., true).
</PRE>
<BLOCKQUOTE type=3D"cite"><PRE wrap=3D"">The first method =
createResource(URI) should not call the second one,=20
instead it should look like in the following

public Resource createResource(URI uri)
{
Resource.Factory resourceFactory =3D=20
getResourceFactoryRegistry().getFactory(uri); // this call does a=20
content type lookup !!
if (resourceFactory !=3D null)
{
Resource result =3D resourceFactory.createResource(uri);
getResources().add(result);
return result;
}
else
{
return null;
}
}

Can anyone confirm my expectations? If yes, I'm going to report the bug.

</PRE></BLOCKQUOTE><PRE wrap=3D"">No, I disagree and I won't =
change it.
</PRE>
<BLOCKQUOTE type=3D"cite"><PRE wrap=3D"">I'm using the =
Galileo Incubation Release, build 20090619-0625.

Ciao, Michael



</PRE></BLOCKQUOTE></BLOCKQUOTE><PRE wrap=3D""><!---->

=
</PRE></BLOCKQUOTE></BLOCKQUOTE></BLOCKQUOTE></BLOCKQUOTE ></BLOCKQUOTE></=
BLOCKQUOTE></BODY></HTML>

------=_NextPart_000_009D_01CA0AEA.4388E330--
Re: ResourceSetImpl.createResource(URI) does not work with content type binding [message #431742 is a reply to message #431712] Thu, 23 July 2009 15:18 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30692
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------080908050507020900020002
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 8bit

Michael,

Comments below.

Michael M
Re: ResourceSetImpl.createResource(URI) does not work with content type binding [message #431765 is a reply to message #431742] Fri, 24 July 2009 07:58 Go to previous messageGo to next message
Michael  Mühlberg is currently offline Michael MühlbergFriend
Messages: 33
Registered: July 2009
Member
This is a multi-part message in MIME format.

------=_NextPart_000_002D_01CA0C45.3DD75780
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hello Ed,

this means then that, if one wants that the own resource factory =
(com.mm.MyResourceFactory) is called instead of the generic one =
(XmiResourceFactor), e.g. if one wants to pre fill the content with =
something, one has to use

ResourceSetImpl.createResource(URI, String)

with the id of the content type as last parameter and doing the content =
type resolution before this call. Is that correct?

Changing the JavaDoc accordingly would be very good and ok for me.

Thanks and ciao, Michael



"Ed Merks" <Ed.Merks@gmail.com> wrote in message =
news:h49v0f$ucs$1@build.eclipse.org...
Michael,

Comments below.

Michael M=FChlberg wrote:=20
Ed,

with the extension point

org.eclipse.emf.ecore.content_parser

one is able to define a resorce factory for a specific content type:

<extension point=3D"org.eclipse.emf.ecore.content_parser">
<parser
class=3D"com.mm.MyResourceFactory"
contentTypeIdentifier=3D"com.mm.mycontenttype">
</parser>

This resource factory is then also responsible for the creation of a =
resource that has the specified content (type). Ok.

The content type can be defined via the extension point

org.eclipse.core.contenttype.contentTypes, e.g.

<extension point=3D"org.eclipse.core.contenttype.contentTypes">
<content-type
file-extensions=3D"mmcontent"
id=3D"com.mm.mycontenttype"
name=3D"mmcontentfilename"
priority=3D"normal">
</content-type>
</extension>

One sees that one can define a content type in various ways, e.g. by =
specifying the extension (mmcontent) of the file AND ALSO via specifying =
the name of the file (mmcontentfilename).
Yes, this is Eclipse basic content type support.

Note that my use case is different but I think with this example my =
point gets clearer.

If I call now

ResourceSetImpl.createResource(URI)

with the URI for the file C:\<somewhere>\mmcontentfilename.mmcontent

the registered resource factory com.mm.MyResourceFactory IS NOT =
CALLED, but it should, shouldn't it?
No, because the assumption is you are creating a resource and there is =
no content to analyze. Given you are creating a resource, don't you =
know the content type of what you intend to store in there?

Instead the generically registered factory XmiResourceFactory is =
called (which registered for files with the extension " * ")
Yes, because without content that's the best you can do assuming there =
is no content.


As far as I could see it, the documentation of the method =
createResource(URI) implies that it would be called.
I'd change the documentation sooner than I would the implementation.


And, in fact, it would if the method would call

getFactory(uri)

instead of delegating to createResource(URI, String) which inside =
calls

getFactory(uri, null)

Puuh, I hope we understand eachother now :)
Hopefully I've been clear that createResource is generally intended to =
be called for creating new resources without existing content...


Ciao, Michael




"Ed Merks" <Ed.Merks@gmail.com> wrote in message =
news:h44im1$k6i$3@build.eclipse.org...
Michael,

Comments below.


Michael M=FChlberg wrote:=20
I can not define my registration based only on the extension =
because I have the same extension in different "environments" (backend =
version for example).=20
I can imagine, but how then does one determine the content type of =
a file that doesn't exist and has not content?

So, my hope was that I can define a content handler via the =
mentioned extension point and only because somewhere in Xtext one calls
I don't get how that can determine the content type based on =
extension and no content though...


ResourceSetImpl.createResource(URI)

instead of first asking the resource factory registry (which is =
aware of content type binding) and then calling the returned resource =
factory to create the resource (see my code snippet below), it does not =
work.

I don't understand why you are requesting me to define a =
registration based on an extension.
I don't understand what magic you think would determine a content =
type without content based only on the extension when you've just =
explained that this isn't possible because a given extension can be used =
for different types of content. It seems clear to me that you need to =
use the createResource method where you explicitly specify the content =
type...

Exactly this is not possible in my scenario. You are also saying =
that content type binding is not supported by the call above, but the =
JavaDoc says that it should be supported and a slight change in the code =
would do that.

Sorry, but I don't understand your standpoint here.
Clearly there is a communication gap. If a file exists, use =
getResource to load it and then the content type will be determined =
properly. If no file exists, you've just explained that the content =
type can't be determined just from the extension and hence you must =
specify it; of course that's already supported..


Ciao, Michael



"Ed Merks" <Ed.Merks@gmail.com> wrote in message =
news:h3q3pr$eqs$1@build.eclipse.org...
Michael,

Comments below.

Michael M=FChlberg wrote:=20
Hello Ed,

ok, I get you. I was misleaded my the fact that Xtext calls =
the createor in a read scenario. Then they do in fact a read in their =
XtextResourceFactory instead of a creation, at least this is my first =
impression. I'm going to ask them about that.

Nevertheless I can not completely agree with you. You say =
that parsing a content does not make sense when the resource is going to =
be created because then there is no content present, ok. This is clearly =
true.

But, the content type extension point =
org.eclipse.core.contenttype.contentTypes not only has a describer (the =
parser) but also a file name, an extension and who know what else.=20
Yes, but that's not how EMF is designed and EMF's design works =
stand alone independent of anything the platform implements.

So, also in the case where the content is still empty, it is =
reasonable to be aware of an eventual content type definition during the =
creation phase.
Clearly looking at the syntax of the URI has nothing to do =
with content, so to me it's a misnomer.


When I determine the content type, e.g. by the name (!) of =
the file (see my extension point definition below, com.mm.mmdsltest), I =
want clearly that then the correct Resource Factory (below =
com.mm.mmdsl.MmDslExecutableExtensionFactory:org.eclipse.xte xt.resource.X=
textResourceFactory) is taken in order to create my file.
In EMF you'll need to define something based on the extension =
in that case. That's fully supported to and is completely orthogonal to =
"proper" content type recognition with in my opinion is based on =
content.=20

Clear, there is no content to be parsed, but, perhaps I want =
to do other things.

With the call of getFactory(URI, String =3D null) you =
explicitely hinder one from a how ever defined content type binding =
possibility. That's the point.
Define a registration based on extension and nothing is =
hindered.=20


Ciao, Michael



"Ed Merks" <Ed.Merks@gmail.com> wrote in message =
news:h3ng2q$lbd$1@build.eclipse.org...
Michael,

Comments below...

With respect to your other comment, if a resource exists =
already, use getResource, not createResource. If it doesn't there's no =
way to know the content type other than to specify it explicitly...


Michael M=FChlberg wrote:=20
Sorry Ed, but I read again the JavaDoc for method

ResourceSet.createResource(URI)

and there stands that the method getFactory(URI) of the registry is =
called,=20
which is not the case!
Ultimately it is because be null is passed.
/**
* Returns the resource factory appropriate for the =
given URI
* with the given {@link =
URIConverter#contentDescription(URI, Map) content type} identifier.
* <p>
* An implementation will (typically) use
* the URI's {@link URI#scheme scheme} to search the =
{@link #getProtocolToFactoryMap protocol} map
* the URI's {@link URI#fileExtension file =
extension} to search {@link #getExtensionToFactoryMap extension} map,
* and the given content type identifier to search =
the {@link #getContentTypeToFactoryMap() content type} map.
* It will {@link =
org.eclipse.emf.ecore.resource.Resource.Factory.Descriptor#c reateFactory =
convert}
* a resulting descriptor into a factory.
* It may choose to provide additional mechanisms =
and algorithms to determine a factory appropriate for the given URI.
* </p>
* @param uri the URI.
* @param contentType the content type of the URI or =
<code>null</code> if a content type should not be used during lookup.
* @return the resource factory appropriate for the =
given URI with the content content type, or <code>null</code> if there =
isn't one.
* @see ResourceSet#createResource(URI)
* @since 2.4
*/
Factory getFactory(URI uri, String contentType);=20
/**
* Creates a new resource, of the appropriate type, and returns it.
* <p>
* It delegates to the resource factory {@link =
#getResourceFactoryRegistry=20
registry}
* to determine the {@link Resource.Factory.Registry#getFactory(URI) =
correct}=20
factory,
* and then it uses that factory to {@link =
Resource.Factory#createResource=20
create} the resource
* and adds it to the {@link #getResources contents}.
* If there is no registered factory, <code>null</code> will be returned;
* when running within Eclipse,
* a default XMI factory will be registered,
* and this will never return <code>null</code>.
* </p>
* @param uri the URI of the resource to create.
* @return a new resource, or <code>null</code> if no factory is =
registered.
*/

Ciao, Michael


"Ed Merks" <Ed.Merks@gmail.com> wrote in message=20
news:h3lbq4$mgg$1@build.eclipse.org...
Michael,

Comments below.


Michael M=FChlberg wrote:
Hello,

In my plugin I have defined a content type and bound an EMF content=20
parser with it:

<extension point=3D"org.eclipse.emf.ecore.content_parser">
<parser

class=3D" com.mm.mmdsl.MmDslExecutableExtensionFactory:org.eclipse.xte xt.r=
esource.XtextResourceFactory"
contentTypeIdentifier=3D"com.mm.mmdsltest">
</parser>
</extension>
<extension point=3D"org.eclipse.core.contenttype.contentTypes">
<content-type
file-extensions=3D"mmdsltest"
id=3D"com.mm.mmdsltest"
name=3D"com.mm.mmdsltest"
priority=3D"normal">
</content-type>
</extension>

Now I want to create a resource via a call like this, or to be precise,=20
the XtextDocument does it

resourceSet.createResource(URI.createFileURI("mmtest.mmdsltest "))

The general assumption is that createResource will typically =
create a new=20
resource. I.e., there is no content in it get to analyze for content=20
type.
Inside of ResourceSetImpl, which is called, one can see the =
following=20
code sequence

/*
* Javadoc copied from interface.
*/
public Resource createResource(URI uri)
{
return createResource(uri, null);
}


/*
* Javadoc copied from interface.
*/
public Resource createResource(URI uri, String contentType)
{
Resource.Factory resourceFactory =3D=20
getResourceFactoryRegistry().getFactory(uri, contentType);
if (resourceFactory !=3D null)
{
Resource result =3D resourceFactory.createResource(uri);
getResources().add(result);
return result;
}
else
{
return null;
}
}

In my opinion the call in the first method createResource(URI)

createResource(uri, null)

I don't agree.
is a bug, because the second method createResource(URI, String) then =
does=20
not use content type lookup (like it is also documented in its JavaDoc).

And that's done for the reason I explained.
But I would expect that createResource(URI) would do a content type=20
lookup!

If you are creating a new resource presumably you know the content =
type,=20
so specify it explicitly. If you're not creating a new resource, use=20
getResource(..., true).
The first method createResource(URI) should not call the second one, =

instead it should look like in the following

public Resource createResource(URI uri)
{
Resource.Factory resourceFactory =3D=20
getResourceFactoryRegistry().getFactory(uri); // this call does a=20
content type lookup !!
if (resourceFactory !=3D null)
{
Resource result =3D resourceFactory.createResource(uri);
getResources().add(result);
return result;
}
else
{
return null;
}
}

Can anyone confirm my expectations? If yes, I'm going to report the bug.

No, I disagree and I won't change it.
I'm using the Galileo Incubation Release, build 20090619-0625.

Ciao, Michael



=20


------=_NextPart_000_002D_01CA0C45.3DD75780
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE></TITLE>
<META content=3Dtext/html;charset=3DISO-8859-1 =
http-equiv=3DContent-Type>
<META name=3DGENERATOR content=3D"MSHTML 8.00.6001.18783"></HEAD>
<BODY bgColor=3D#ffffff text=3D#000000>
<DIV><FONT size=3D2 face=3DArial>Hello Ed,</FONT></DIV>
<DIV><FONT size=3D2 face=3DArial></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2 face=3DArial>this means then that, if one wants that =
the own=20
resource factory (com.mm.MyResourceFactory)&nbsp;is called instead of =
the=20
generic one (XmiResourceFactor), e.g. if one wants to pre fill the =
content with=20
something, one has to use</FONT></DIV>
<DIV><FONT size=3D2 face=3DArial></FONT>&nbsp;</DIV>
<DIV>
<DIV><FONT size=3D2 face=3DArial>ResourceSetImpl.createResource(URI,=20
String)</FONT></DIV>
<DIV><FONT size=3D2 face=3DArial></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2 face=3DArial>with the id of the content type as last =
parameter=20
and doing the content type resolution before this call. Is that=20
correct?</FONT></DIV>
<DIV><FONT size=3D2 face=3DArial></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2 face=3DArial>Changing the JavaDoc accordingly would =
be very good=20
and ok for me.</FONT></DIV>
<DIV><FONT size=3D2 face=3DArial></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2 face=3DArial>Thanks and ciao, Michael</FONT></DIV>
<DIV><FONT size=3D2 face=3DArial></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2 face=3DArial></FONT>&nbsp;</DIV></DIV>
<DIV><FONT size=3D2 face=3DArial></FONT>&nbsp;</DIV>
<BLOCKQUOTE=20
style=3D"BORDER-LEFT: #000000 2px solid; PADDING-LEFT: 5px; =
PADDING-RIGHT: 0px; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px"=20
dir=3Dltr>
<DIV>"Ed Merks" &lt;<A=20
href=3D"mailto:Ed.Merks@gmail.com">Ed.Merks@gmail.com</A>&gt; wrote in =
message=20
<A=20
=
href=3D"news:h49v0f$ucs$1@build.eclipse.org">news:h49v0f$ucs$1@build.ecli=
pse.org</A>...</DIV>Michael,<BR><BR>Comments=20
below.<BR><BR>Michael M=FChlberg wrote:=20
<BLOCKQUOTE cite=3Dmid:h4781a$4ba$1@build.eclipse.org type=3D"cite">
<META name=3DGENERATOR content=3D"MSHTML 8.00.6001.18783">
<DIV><FONT size=3D2 face=3DArial>Ed,</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2 face=3DArial>with the extension =
point</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2=20
face=3DArial>org.eclipse.emf.ecore.content_parser</FONT></DIV >
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2 face=3DArial>one is able to define a resorce =
factory for a=20
specific content type:</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2 face=3DArial>&lt;extension=20
=
point=3D"org.eclipse.emf.ecore.content_parser"&gt;<BR >&nbsp;&nbsp;&nbsp; =

&lt;parser</FONT></DIV>
<DIV><FONT size=3D2 face=3DArial>&nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;=20
class=3D"com.mm.MyResourceFactory"</FONT></DIV>
<DIV><FONT size=3D2 face=3DArial>&nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;=20
=
contentTypeIdentifier=3D"com.mm.mycontenttype"&gt;<BR >&lt;/parser&gt;<BR>=
</FONT></DIV>
<DIV><FONT size=3D2 face=3DArial>This resource factory is then also =
responsible=20
for the creation of a resource that has the specified content =
(type).=20
Ok.</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2 face=3DArial>The content type can be defined via =
the=20
extension point</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2 =
face=3DArial>org.eclipse.core.contenttype.contentTypes,=20
e.g.</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2 face=3DArial>&lt;extension=20
=
point=3D"org.eclipse.core.contenttype.contentTypes"&gt; <BR>&nbsp;&nbsp;&n=
bsp;=20
&lt;content-type<BR>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
file-extensions=3D"mmcontent"<BR>&nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;=20
id=3D"com.mm.mycontenttype"<BR>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =

name=3D"mmcontentfilename"<BR>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
priority=3D"normal"&gt;<BR>&nbsp;&nbsp;&nbsp;=20
&lt;/content-type&gt;<BR>&lt;/extension&gt; <BR></FONT></DIV>
<DIV><FONT size=3D2 face=3DArial>One sees that one can define a =
content type in=20
various ways, e.g. by specifying the extension (mmcontent) of the =
file AND=20
ALSO via specifying the name of the file=20
(mmcontentfilename).</FONT></DIV></BLOCKQUOTE>Yes, this is Eclipse =
basic=20
content type support.<BR>
<BLOCKQUOTE cite=3Dmid:h4781a$4ba$1@build.eclipse.org type=3D"cite">
<DIV><FONT size=3D2 face=3DArial></FONT><FONT size=3D2 =
face=3DArial>Note that my use=20
case is different but I think with this example my point gets=20
clearer.</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2 face=3DArial>If I call now</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2=20
face=3DArial>ResourceSetImpl.createResource(URI)</FONT></DIV >
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2 face=3DArial>with the URI for the file=20
C:\&lt;somewhere&gt;\mmcontentfilename.mmcontent</FONT ></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2 face=3DArial>the registered resource factory=20
com.mm.MyResourceFactory IS NOT CALLED, but it should, shouldn't=20
it?</FONT></DIV></BLOCKQUOTE>No, because the assumption is you are =
creating a=20
resource and there is no content to analyze.&nbsp; Given you are =
creating a=20
resource, don't you know the content type of what you intend to store =
in=20
there?<BR>
<BLOCKQUOTE cite=3Dmid:h4781a$4ba$1@build.eclipse.org type=3D"cite">
<DIV><FONT size=3D2 face=3DArial>Instead the generically registered =
factory=20
XmiResourceFactory is called (which registered for files with the =
extension=20
" * ")</FONT></DIV></BLOCKQUOTE>Yes, because without content that's =
the best=20
you can do assuming there is no content.<BR>
<BLOCKQUOTE cite=3Dmid:h4781a$4ba$1@build.eclipse.org type=3D"cite">
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2 face=3DArial>As far as I could see it, the =
documentation of=20
the method createResource(URI) implies that it would be=20
called.</FONT></DIV></BLOCKQUOTE>I'd change the documentation sooner =
than I=20
would the implementation.<BR>
<BLOCKQUOTE cite=3Dmid:h4781a$4ba$1@build.eclipse.org type=3D"cite">
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2 face=3DArial>And, in fact, it would if the =
method would=20
call</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2 face=3DArial>getFactory(uri)</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2 face=3DArial>instead of delegating to =
createResource(URI,=20
String) which inside calls</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2 face=3DArial>getFactory(uri, null)</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2 face=3DArial>Puuh, I hope we understand =
eachother now=20
:)</FONT></DIV></BLOCKQUOTE>Hopefully I've been clear that =
createResource is=20
generally intended to be called for creating new resources without =
existing=20
content...<BR>
<BLOCKQUOTE cite=3Dmid:h4781a$4ba$1@build.eclipse.org type=3D"cite">
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2 face=3DArial>Ciao, Michael</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2 face=3DArial></FONT>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<BLOCKQUOTE=20
style=3D"BORDER-LEFT: rgb(0,0,0) 2px solid; PADDING-LEFT: 5px; =
PADDING-RIGHT: 0px; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px"=20
dir=3Dltr>
<DIV>"Ed Merks" &lt;<A href=3D"mailto:Ed.Merks@gmail.com"=20
moz-do-not-send=3D"true">Ed.Merks@gmail.com</A>&gt; wrote in =
message <A=20
href=3D"news:h44im1$k6i$3@build.eclipse.org"=20
=
moz-do-not-send=3D"true">news:h44im1$k6i$3@build.eclipse.org</A>...</DIV>=
Michael,<BR><BR>Comments=20
below.<BR><BR><BR>Michael M=FChlberg wrote:=20
<BLOCKQUOTE cite=3Dmid:h43ni2$asc$1@build.eclipse.org =
type=3D"cite">
<META name=3DGENERATOR content=3D"MSHTML 8.00.6001.18783">
<DIV><FONT size=3D2 face=3DArial>I can not define my =
registration based only=20
on the extension because I have the same extension in different=20
"environments" (backend version for example). =
</FONT></DIV></BLOCKQUOTE>I=20
can imagine, but how then does one determine the content type of a =
file=20
that doesn't exist and has not content?<BR>
<BLOCKQUOTE cite=3Dmid:h43ni2$asc$1@build.eclipse.org =
type=3D"cite">
<DIV><FONT size=3D2 face=3DArial>So, my hope was that I can =
define a content=20
handler via the mentioned extension point and only because =
somewhere in=20
Xtext one calls</FONT></DIV></BLOCKQUOTE>I don't get how that =
can=20
determine the content type based on extension and no content =
though...<BR>
<BLOCKQUOTE cite=3Dmid:h43ni2$asc$1@build.eclipse.org =
type=3D"cite">
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2=20
face=3DArial>ResourceSetImpl.createResource(URI)</FONT></DIV >
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2 face=3DArial>instead of first asking the =
resource=20
factory registry (which is aware of content type binding) and =
then=20
calling the returned resource factory to create the resource =
(see my=20
code snippet below), it does not work.</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2 face=3DArial>I don't understand why you are =
requesting=20
me to define a registration based on an=20
extension.</FONT></DIV></BLOCKQUOTE>I don't understand what magic =
you=20
think would determine a content type without content based only on =
the=20
extension when you've just explained that this isn't possible =
because a=20
given extension can be used for different types of content.&nbsp; =
It seems=20
clear to me that you need to use the createResource method where =
you=20
explicitly specify the content type...<BR>
<BLOCKQUOTE cite=3Dmid:h43ni2$asc$1@build.eclipse.org =
type=3D"cite">
<DIV><FONT size=3D2 face=3DArial>Exactly this is not possible in =
my=20
scenario. You are also saying that content type binding is not =
supported=20
by the call above, but the JavaDoc says that it should be =
supported and=20
a slight change in the code would do that.</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2 face=3DArial>Sorry, but I don't understand =
your=20
standpoint here.</FONT></DIV></BLOCKQUOTE>Clearly there is a =
communication=20
gap.&nbsp; If a file exists, use getResource to load it and then =
the=20
content type will be determined properly.&nbsp; If no file exists, =
you've=20
just explained that the content type can't be determined just from =
the=20
extension and hence you must specify it; of course that's already=20
supported..<BR>
<BLOCKQUOTE cite=3Dmid:h43ni2$asc$1@build.eclipse.org =
type=3D"cite">
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2 face=3DArial>Ciao, Michael</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<BLOCKQUOTE=20
style=3D"BORDER-LEFT: rgb(0,0,0) 2px solid; PADDING-LEFT: 5px; =
PADDING-RIGHT: 0px; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px"=20
dir=3Dltr>
<DIV>"Ed Merks" &lt;<A href=3D"mailto:Ed.Merks@gmail.com"=20
moz-do-not-send=3D"true">Ed.Merks@gmail.com</A>&gt; wrote in =
message <A=20
href=3D"news:h3q3pr$eqs$1@build.eclipse.org"=20
=
moz-do-not-send=3D"true">news:h3q3pr$eqs$1@build.eclipse.org</A>...</DIV>=
Michael,<BR><BR>Comments=20
below.<BR><BR>Michael M=FChlberg wrote:=20
<BLOCKQUOTE cite=3Dmid:h3pjpv$ir7$1@build.eclipse.org =
type=3D"cite">
<META name=3DGENERATOR content=3D"MSHTML 8.00.6001.18783">
<STYLE></STYLE>

<DIV><FONT size=3D2 face=3DArial>Hello Ed,</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2 face=3DArial>ok, I get you. I was =
misleaded my the=20
fact that Xtext calls the createor in a read scenario. Then =
they do=20
in fact a read in their XtextResourceFactory instead of a =
creation,=20
at least this is my first impression. I'm going to ask them =
about=20
that.</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2 face=3DArial>Nevertheless I can not =
completely agree=20
with you. You say that parsing a content does not make sense =
when=20
the resource is going to be created because then there is no =
content=20
present, ok. This is clearly true.</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2 face=3DArial>But, the content type =
extension point=20
<FONT size=3D3>org.eclipse.core.contenttype.contentTypes =
</FONT>not=20
only has a describer (the parser) but also a file name, an =
extension=20
and who know what else. </FONT></DIV></BLOCKQUOTE>Yes, but =
that's not=20
how EMF is designed and EMF's design works stand alone =
independent of=20
anything the platform implements.<BR>
<BLOCKQUOTE cite=3Dmid:h3pjpv$ir7$1@build.eclipse.org =
type=3D"cite">
<DIV><FONT size=3D2 face=3DArial>So, also in the case where =
the content=20
is still empty, it is reasonable to be aware of an eventual =
content=20
type definition during the creation=20
phase.</FONT></DIV></BLOCKQUOTE>Clearly looking at the syntax =
of the=20
URI has nothing to do with content, so to me it's a =
misnomer.<BR>
<BLOCKQUOTE cite=3Dmid:h3pjpv$ir7$1@build.eclipse.org =
type=3D"cite">
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2 face=3DArial>When I determine the =
content type, e.g.=20
by the name (!) of the file (see my extension point =
definition=20
below, com.mm.mmdsltest), I want clearly that then the =
correct=20
Resource Factory (below <FONT=20
=
size=3D3> com.mm.mmdsl.MmDslExecutableExtensionFactory:org.eclipse.xte xt.r=
esource.XtextResourceFactory)=20
</FONT></FONT><FONT size=3D2 face=3DArial>is taken in order =
to create my=20
file.</FONT></DIV></BLOCKQUOTE>In EMF you'll need to define =
something=20
based on the extension in that case.&nbsp; That's fully =
supported to=20
and is completely orthogonal to "proper" content type =
recognition with=20
in my opinion is based on content. <BR>
<BLOCKQUOTE cite=3Dmid:h3pjpv$ir7$1@build.eclipse.org =
type=3D"cite">
<DIV><FONT size=3D2 face=3DArial>Clear, there is no content =
to be=20
parsed, but, perhaps I want to do other things.</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2 face=3DArial>With the call of =
getFactory(URI, String=20
=3D null) you explicitely&nbsp;hinder one from a how ever =
defined=20
content type binding possibility. That's the=20
point.</FONT></DIV></BLOCKQUOTE>Define a registration based on =

extension and nothing is hindered. <BR>
<BLOCKQUOTE cite=3Dmid:h3pjpv$ir7$1@build.eclipse.org =
type=3D"cite">
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2 face=3DArial>Ciao, Michael</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<BLOCKQUOTE=20
style=3D"BORDER-LEFT: rgb(0,0,0) 2px solid; PADDING-LEFT: =
5px; PADDING-RIGHT: 0px; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px"=20
dir=3Dltr>
<DIV>"Ed Merks" &lt;<A href=3D"mailto:Ed.Merks@gmail.com"=20
moz-do-not-send=3D"true">Ed.Merks@gmail.com</A>&gt; wrote =
in message=20
<A href=3D"news:h3ng2q$lbd$1@build.eclipse.org"=20
=
moz-do-not-send=3D"true">news:h3ng2q$lbd$1@build.eclipse.org</A>...</DIV>=
Michael,<BR><BR>Comments=20
below...<BR><BR>With respect to your other comment, if a =
resource=20
exists already, use getResource, not createResource.&nbsp; =
If it=20
doesn't there's no way to know the content type other than =
to=20
specify it explicitly...<BR><BR><BR>Michael M=FChlberg =
wrote:=20
<BLOCKQUOTE cite=3Dmid:h3mvhf$et7$1@build.eclipse.org =
type=3D"cite"><PRE wrap=3D"">Sorry Ed, but I read again the JavaDoc for =
method

ResourceSet.createResource(URI)

and there stands that the method getFactory(URI) of the registry is =
called,=20
which is not the case!
</PRE></BLOCKQUOTE>Ultimately it is because be null is=20
passed.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
/**<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * Returns the =
resource=20
factory appropriate for the given=20
URI<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * with the =
given=20
{@link URIConverter#contentDescription(URI, Map) content =
type}=20
identifier.<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; *=20
&lt;p&gt;<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * An=20
implementation will (typically)=20
use<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * the URI's =
{@link=20
URI#scheme scheme} to search the {@link =
#getProtocolToFactoryMap=20
protocol} map<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * =
the URI's=20
{@link URI#fileExtension file extension} to search {@link=20
#getExtensionToFactoryMap extension}=20
map,<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * and the =
given=20
content type identifier to search the {@link=20
#getContentTypeToFactoryMap() content type}=20
map.<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * It will =
{@link=20
=
org.eclipse.emf.ecore.resource.Resource.Factory.Descriptor#c reateFactory =

convert}<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * a =
resulting=20
descriptor into a =
factory.<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =20
* It may choose to provide additional mechanisms and =
algorithms to=20
determine a factory appropriate for the given=20
URI.<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; *=20
&lt;/p&gt;<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * =
@param uri=20
the URI.<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * @param=20
contentType the content type of the URI <B>or=20
&lt;code&gt;null&lt;/code&gt; if a content type should not =
be used=20
during lookup.</B><BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
*=20
@return the resource factory appropriate for the given URI =
with=20
the content content type, or &lt;code&gt;null&lt;/code&gt; =
if=20
there isn't one.<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * =
@see=20
=
ResourceSet#createResource(URI)<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =20
* @since 2.4<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =20
*/<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Factory =
getFactory(URI uri,=20
String contentType);=20
<BLOCKQUOTE cite=3Dmid:h3mvhf$et7$1@build.eclipse.org =
type=3D"cite"><PRE wrap=3D"">/**
* Creates a new resource, of the appropriate type, and returns it.
* &lt;p&gt;
* It delegates to the resource factory {@link =
#getResourceFactoryRegistry=20
registry}
* to determine the {@link Resource.Factory.Registry#getFactory(URI) =
correct}=20
factory,
* and then it uses that factory to {@link =
Resource.Factory#createResource=20
create} the resource
* and adds it to the {@link #getResources contents}.
* If there is no registered factory, &lt;code&gt;null&lt;/code&gt; will =
be returned;
* when running within Eclipse,
* a default XMI factory will be registered,
* and this will never return &lt;code&gt;null&lt;/code&gt;.
* &lt;/p&gt;
* @param uri the URI of the resource to create.
* @return a new resource, or &lt;code&gt;null&lt;/code&gt; if no factory =
is registered.
*/

Ciao, Michael


"Ed Merks" <A class=3Dmoz-txt-link-rfc2396E =
href=3D"mailto:Ed.Merks@gmail.com" =
moz-do-not-send=3D"true">&lt;Ed.Merks@gmail.com&gt;</A> wrote in message =

<A class=3Dmoz-txt-link-freetext =
href=3D"news:h3lbq4$mgg$1@build.eclipse.org" =
moz-do-not-send=3D"true">news:h3lbq4$mgg$1@build.eclipse.org</A>...
</PRE>
<BLOCKQUOTE type=3D"cite"><PRE wrap=3D"">Michael,

Comments below.


Michael M=FChlberg wrote:
</PRE>
<BLOCKQUOTE type=3D"cite"><PRE wrap=3D"">Hello,

In my plugin I have defined a content type and bound an EMF content=20
parser with it:

&lt;extension point=3D"org.eclipse.emf.ecore.content_parser"&gt;
&lt;parser

class=3D" com.mm.mmdsl.MmDslExecutableExtensionFactory:org.eclipse.xte xt.r=
esource.XtextResourceFactory"
contentTypeIdentifier=3D"com.mm.mmdsltest"&gt;
&lt;/parser&gt;
&lt;/extension&gt;
&lt;extension point=3D"org.eclipse.core.contenttype.contentTypes"&gt;
&lt;content-type
file-extensions=3D"mmdsltest"
id=3D"com.mm.mmdsltest"
name=3D"com.mm.mmdsltest"
priority=3D"normal"&gt;
&lt;/content-type&gt;
&lt;/extension&gt;

Now I want to create a resource via a call like this, or to be precise,=20
the XtextDocument does it

resourceSet.createResource(URI.createFileURI("mmtest.mmdsltest "))

</PRE></BLOCKQUOTE><PRE wrap=3D"">The general assumption is that =
createResource will typically create a new=20
resource. I.e., there is no content in it get to analyze for content=20
type.
</PRE>
<BLOCKQUOTE type=3D"cite"><PRE wrap=3D"">Inside of =
ResourceSetImpl, which is called, one can see the following=20
code sequence

/*
* Javadoc copied from interface.
*/
public Resource createResource(URI uri)
{
return createResource(uri, null);
}


/*
* Javadoc copied from interface.
*/
public Resource createResource(URI uri, String contentType)
{
Resource.Factory resourceFactory =3D=20
getResourceFactoryRegistry().getFactory(uri, contentType);
if (resourceFactory !=3D null)
{
Resource result =3D resourceFactory.createResource(uri);
getResources().add(result);
return result;
}
else
{
return null;
}
}

In my opinion the call in the first method createResource(URI)

createResource(uri, null)

</PRE></BLOCKQUOTE><PRE wrap=3D"">I don't agree.
</PRE>
<BLOCKQUOTE type=3D"cite"><PRE wrap=3D"">is a bug, =
because the second method createResource(URI, String) then does=20
not use content type lookup (like it is also documented in its JavaDoc).

</PRE></BLOCKQUOTE><PRE wrap=3D"">And that's done for the reason I =
explained.
</PRE>
<BLOCKQUOTE type=3D"cite"><PRE wrap=3D"">But I would =
expect that createResource(URI) would do a content type=20
lookup!

</PRE></BLOCKQUOTE><PRE wrap=3D"">If you are creating a new =
resource presumably you know the content type,=20
so specify it explicitly. If you're not creating a new resource, use=20
getResource(..., true).
</PRE>
<BLOCKQUOTE type=3D"cite"><PRE wrap=3D"">The first =
method createResource(URI) should not call the second one,=20
instead it should look like in the following

public Resource createResource(URI uri)
{
Resource.Factory resourceFactory =3D=20
getResourceFactoryRegistry().getFactory(uri); // this call does a=20
content type lookup !!
if (resourceFactory !=3D null)
{
Resource result =3D resourceFactory.createResource(uri);
getResources().add(result);
return result;
}
else
{
return null;
}
}

Can anyone confirm my expectations? If yes, I'm going to report the bug.

</PRE></BLOCKQUOTE><PRE wrap=3D"">No, I disagree and I won't =
change it.
</PRE>
<BLOCKQUOTE type=3D"cite"><PRE wrap=3D"">I'm using the =
Galileo Incubation Release, build 20090619-0625.

Ciao, Michael



</PRE></BLOCKQUOTE></BLOCKQUOTE><PRE wrap=3D""><!---->

=
</PRE></BLOCKQUOTE></BLOCKQUOTE></BLOCKQUOTE></BLOCKQUOTE ></BLOCKQUOTE></=
BLOCKQUOTE></BLOCKQUOTE></BLOCKQUOTE></BODY></HTML>

------=_NextPart_000_002D_01CA0C45.3DD75780--
Re: ResourceSetImpl.createResource(URI) does not work with content type binding [message #431772 is a reply to message #431765] Fri, 24 July 2009 15:14 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 30692
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------010501050702080800050804
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 8bit

Michael,

Yes, one should use the explicit content type you know you are going to
put into the new resource. Presumably there is no way to determine this
given there is no existing content to analyze but rather you know what
new content you will be adding. In theory, you might even put in a
different type of content than might already exist in the file system...


Michael M
Previous Topic:make only particular EReferences considered by the CrossReferencer?
Next Topic:Resolving proxies
Goto Forum:
  


Current Time: Sat Dec 14 02:24:04 GMT 2019

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

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

Back to the top