You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@abdera.apache.org by Vasudeva Nori <va...@gmail.com> on 2008/05/03 08:20:26 UTC
creating a writer
The following code fragment on Abdera's Extension web page shows a "json":
writer.
writer json = abdera.getWriterFactory().getWriter("json");
entry.writeTo(json, System.out);
is it possible to create a writer for "foo_format" and do the following
Writer json = abdera.getWriterFactory().getWriter("foo_format");
entry.writeTo(json, System.out);
If so, how does one "associate" foo_format writer to "foo_format"? any
pointer to doing this in abdera would be great.
thanks
Re: creating a writer
Posted by James M Snell <ja...@gmail.com>.
Checked in.
- James
David Calavera wrote:
> Hi, I've created a ticket into the jira and I've submited a patch:
>
> https://issues.apache.org/jira/browse/ABDERA-156
>
> On Fri, May 9, 2008 at 10:01 PM, Vasudeva Nori <va...@gmail.com> wrote:
>
>> I would like to propose a couple of changes/additions to the mechanism of
>> writing custom writers (& parsers) in abdera.
>>
>> Right now, Custom writers are to be declared in
>> META-INF/services/org.apache.abdera.writer.NamedWriter file
>> I was looking for a way to dynamically bind a "new writer" I have at
>> runtime, because in the system I am working with, there is no way to
>> statically enumerate the writers in a file.
>> Turns out it is not difficult at all. AbderaConfiguration has
>> addNamedWriters(NamedWriter) method that can be used to do this.
>>
>> so, here is my proposal: why not make this method part of the Configuration
>> interface.
>> Is there a strong reason to not do this?
>>
>> right now, code to add NamedWriter at runtime looks like this
>> JSONWriter jsonWriter = new JSONWriter();
>> Configuration config = getAbdera().getConfiguration();
>> if (config instanceof AbderaConfiguration) {
>> ((AbderaConfiguration)config).addNamedWriter(jsonWriter);
>> }
>>
>> instead, I would like to remove the cast to AbderaConfiguration and make it
>> cleaner.
>
>
> instead of remove the cast, I've added the add method to the Configuration
> interface, so you can write this:
>
> getAbdera().getConfiguration().addNamedWriter(jsonWriter);
>
>
>>
>> and, BTW, I noticed there is no error handling in AbderaConfiguration.java
>> to make sure a writer for "name1" doesn't already exist before adding it to
>> "Map<String,NamedWriter> writers" struct.
>> have to submit a patch for it one of these days to fix this. unless James
>> or
>> someone else gets to it sooner :)
>
>
> I've added this check to all "add" methods, so if the NamedParser,
> NamedWriter, ExtensionFactory or StreamWriter already exist the
> configuration class shows a warning.
>
>
>>
>> thanks
>>
>> On Sat, May 3, 2008 at 2:38 AM, David Calavera <da...@gmail.com>
>> wrote:
>>
>>> Yep, you can look at the custom writers section into the wiki:
>>>
>>> http://cwiki.apache.org/confluence/display/ABDERA/Custom+Writers
>>>
>>> On Sat, May 3, 2008 at 8:20 AM, Vasudeva Nori <va...@gmail.com>
>> wrote:
>>>> The following code fragment on Abdera's Extension web page shows a
>>> "json":
>>>> writer.
>>>> writer json = abdera.getWriterFactory().getWriter("json");
>>>> entry.writeTo(json, System.out);
>>>>
>>>> is it possible to create a writer for "foo_format" and do the following
>>>>
>>>> Writer json = abdera.getWriterFactory().getWriter("foo_format");
>>>> entry.writeTo(json, System.out);
>>>> If so, how does one "associate" foo_format writer to "foo_format"? any
>>>> pointer to doing this in abdera would be great.
>>>>
>>>> thanks
>>>>
>>>
>>>
>>> --
>>> David Calavera
>>> http://www.thinkincode.net
>>>
>
>
>
Re: creating a writer
Posted by David Calavera <da...@gmail.com>.
Hi, I've created a ticket into the jira and I've submited a patch:
https://issues.apache.org/jira/browse/ABDERA-156
On Fri, May 9, 2008 at 10:01 PM, Vasudeva Nori <va...@gmail.com> wrote:
> I would like to propose a couple of changes/additions to the mechanism of
> writing custom writers (& parsers) in abdera.
>
> Right now, Custom writers are to be declared in
> META-INF/services/org.apache.abdera.writer.NamedWriter file
> I was looking for a way to dynamically bind a "new writer" I have at
> runtime, because in the system I am working with, there is no way to
> statically enumerate the writers in a file.
> Turns out it is not difficult at all. AbderaConfiguration has
> addNamedWriters(NamedWriter) method that can be used to do this.
>
> so, here is my proposal: why not make this method part of the Configuration
> interface.
> Is there a strong reason to not do this?
>
> right now, code to add NamedWriter at runtime looks like this
> JSONWriter jsonWriter = new JSONWriter();
> Configuration config = getAbdera().getConfiguration();
> if (config instanceof AbderaConfiguration) {
> ((AbderaConfiguration)config).addNamedWriter(jsonWriter);
> }
>
> instead, I would like to remove the cast to AbderaConfiguration and make it
> cleaner.
instead of remove the cast, I've added the add method to the Configuration
interface, so you can write this:
getAbdera().getConfiguration().addNamedWriter(jsonWriter);
>
>
> and, BTW, I noticed there is no error handling in AbderaConfiguration.java
> to make sure a writer for "name1" doesn't already exist before adding it to
> "Map<String,NamedWriter> writers" struct.
> have to submit a patch for it one of these days to fix this. unless James
> or
> someone else gets to it sooner :)
I've added this check to all "add" methods, so if the NamedParser,
NamedWriter, ExtensionFactory or StreamWriter already exist the
configuration class shows a warning.
>
>
> thanks
>
> On Sat, May 3, 2008 at 2:38 AM, David Calavera <da...@gmail.com>
> wrote:
>
> > Yep, you can look at the custom writers section into the wiki:
> >
> > http://cwiki.apache.org/confluence/display/ABDERA/Custom+Writers
> >
> > On Sat, May 3, 2008 at 8:20 AM, Vasudeva Nori <va...@gmail.com>
> wrote:
> >
> > > The following code fragment on Abdera's Extension web page shows a
> > "json":
> > > writer.
> > > writer json = abdera.getWriterFactory().getWriter("json");
> > > entry.writeTo(json, System.out);
> > >
> > > is it possible to create a writer for "foo_format" and do the following
> > >
> > > Writer json = abdera.getWriterFactory().getWriter("foo_format");
> > > entry.writeTo(json, System.out);
> > > If so, how does one "associate" foo_format writer to "foo_format"? any
> > > pointer to doing this in abdera would be great.
> > >
> > > thanks
> > >
> >
> >
> >
> > --
> > David Calavera
> > http://www.thinkincode.net
> >
>
--
David Calavera
http://www.thinkincode.net
Re: creating a writer
Posted by Vasudeva Nori <va...@gmail.com>.
I would like to propose a couple of changes/additions to the mechanism of
writing custom writers (& parsers) in abdera.
Right now, Custom writers are to be declared in
META-INF/services/org.apache.abdera.writer.NamedWriter file
I was looking for a way to dynamically bind a "new writer" I have at
runtime, because in the system I am working with, there is no way to
statically enumerate the writers in a file.
Turns out it is not difficult at all. AbderaConfiguration has
addNamedWriters(NamedWriter) method that can be used to do this.
so, here is my proposal: why not make this method part of the Configuration
interface.
Is there a strong reason to not do this?
right now, code to add NamedWriter at runtime looks like this
JSONWriter jsonWriter = new JSONWriter();
Configuration config = getAbdera().getConfiguration();
if (config instanceof AbderaConfiguration) {
((AbderaConfiguration)config).addNamedWriter(jsonWriter);
}
instead, I would like to remove the cast to AbderaConfiguration and make it
cleaner.
and, BTW, I noticed there is no error handling in AbderaConfiguration.java
to make sure a writer for "name1" doesn't already exist before adding it to
"Map<String,NamedWriter> writers" struct.
have to submit a patch for it one of these days to fix this. unless James or
someone else gets to it sooner :)
thanks
On Sat, May 3, 2008 at 2:38 AM, David Calavera <da...@gmail.com>
wrote:
> Yep, you can look at the custom writers section into the wiki:
>
> http://cwiki.apache.org/confluence/display/ABDERA/Custom+Writers
>
> On Sat, May 3, 2008 at 8:20 AM, Vasudeva Nori <va...@gmail.com> wrote:
>
> > The following code fragment on Abdera's Extension web page shows a
> "json":
> > writer.
> > writer json = abdera.getWriterFactory().getWriter("json");
> > entry.writeTo(json, System.out);
> >
> > is it possible to create a writer for "foo_format" and do the following
> >
> > Writer json = abdera.getWriterFactory().getWriter("foo_format");
> > entry.writeTo(json, System.out);
> > If so, how does one "associate" foo_format writer to "foo_format"? any
> > pointer to doing this in abdera would be great.
> >
> > thanks
> >
>
>
>
> --
> David Calavera
> http://www.thinkincode.net
>
Re: creating a writer
Posted by David Calavera <da...@gmail.com>.
Yep, you can look at the custom writers section into the wiki:
http://cwiki.apache.org/confluence/display/ABDERA/Custom+Writers
On Sat, May 3, 2008 at 8:20 AM, Vasudeva Nori <va...@gmail.com> wrote:
> The following code fragment on Abdera's Extension web page shows a "json":
> writer.
> writer json = abdera.getWriterFactory().getWriter("json");
> entry.writeTo(json, System.out);
>
> is it possible to create a writer for "foo_format" and do the following
>
> Writer json = abdera.getWriterFactory().getWriter("foo_format");
> entry.writeTo(json, System.out);
> If so, how does one "associate" foo_format writer to "foo_format"? any
> pointer to doing this in abdera would be great.
>
> thanks
>
--
David Calavera
http://www.thinkincode.net