[MOXy] post-processing after unmarshalling

View: New views
5 Messages — Rating Filter:   Alert me  

[MOXy] post-processing after unmarshalling

by polly.c.chang :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

Is there a way for EclipseLink to call a handler to do post-processing work after unmarshalling a certain class?  I found some information in the documentation about the XMLUnmarshalListener, but it seems to listen to unmarshal events for everything.  Is there something else that I can attach to just one class or one XMLDescriptor?

Thanks,
Polly


Re: [MOXy] post-processing after unmarshalling

by Matt MacIvor :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Polly,

You can add a DescriptorEventListener on a given XMLDescriptor's event
manager (descriptor.getEventManager().addListener(listener)).

For moxy, the only event that's invoked on DescriptorEventListeners is
the postBuild event, which will be invoked after an object is finished
being built. From your email, it sounds like that event callback should
do the trick though.

Hope this helps,

-Matt

polly.c.chang wrote:

>Hi,
>
>Is there a way for EclipseLink to call a handler to do post-processing work
>after unmarshalling a certain class?  I found some information in the
>documentation about the XMLUnmarshalListener, but it seems to listen to
>unmarshal events for everything.  Is there something else that I can attach
>to just one class or one XMLDescriptor?
>
>Thanks,
>Polly
>
>
>  
>
_______________________________________________
eclipselink-users mailing list
eclipselink-users@...
https://dev.eclipse.org/mailman/listinfo/eclipselink-users

Re: [MOXy] post-processing after unmarshalling

by polly.c.chang :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Matt,

This looks great!  I just need a few more clarifications:

1.  In DescriptorEvent, do I use getObject() or getOriginalObject() to get the object with the unmarshalled data?

2.  It looks like it's possible to use this in the project.xml file using the <events xsi:type="event-policy"/>  element.  Is that right?  I can see by the schema to put the name of the event listener class in the "event-listener" element, but should I also set "post-build-method" element?

3.  Just out of curiosity in case I need this later, do you have another event callback for marshalling?

Thanks!
--Polly

Matt MacIvor wrote:
Hi Polly,

You can add a DescriptorEventListener on a given XMLDescriptor's event
manager (descriptor.getEventManager().addListener(listener)).

For moxy, the only event that's invoked on DescriptorEventListeners is
the postBuild event, which will be invoked after an object is finished
being built. From your email, it sounds like that event callback should
do the trick though.

Hope this helps,

-Matt

polly.c.chang wrote:

>Hi,
>
>Is there a way for EclipseLink to call a handler to do post-processing work
>after unmarshalling a certain class?  I found some information in the
>documentation about the XMLUnmarshalListener, but it seems to listen to
>unmarshal events for everything.  Is there something else that I can attach
>to just one class or one XMLDescriptor?
>
>Thanks,
>Polly
>
>
>  
>
_______________________________________________
eclipselink-users mailing list
eclipselink-users@eclipse.org
https://dev.eclipse.org/mailman/listinfo/eclipselink-users

Re: [MOXy] post-processing after unmarshalling

by Matt MacIvor :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Polly,

1. You would want to use the getObject() method to get back your Object. getOriginalObject is used for events like postClone or postMerge where you may want access to the original object. OXM doesn't use any cloning so that OriginalObject wouldn't be set.

2. I believe you would just need to set the event-listener element in your deployment XML.

3. In ORM projects, there's a lot of different descriptor events that get called, but in OXM, currently, only the postBuild event gets raised. The XMLMarshalListener API provides pre and post marshal events, but those would be raised for every object (similar to JAXB event listeners) and not on a per-descriptor basis.

-Matt

polly.c.chang wrote:
Hi Matt,

This looks great!  I just need a few more clarifications:

1.  In DescriptorEvent, do I use getObject() or getOriginalObject() to get
the object with the unmarshalled data?

2.  It looks like it's possible to use this in the project.xml file using
the <events xsi:type="event-policy"/>  element.  Is that right?  I can see
by the schema to put the name of the event listener class in the
"event-listener" element, but should I also set "post-build-method" element?

3.  Just out of curiosity in case I need this later, do you have another
event callback for marshalling?

Thanks!
--Polly


Matt MacIvor wrote:
  
Hi Polly,

You can add a DescriptorEventListener on a given XMLDescriptor's event 
manager (descriptor.getEventManager().addListener(listener)).

For moxy, the only event that's invoked on DescriptorEventListeners is 
the postBuild event, which will be invoked after an object is finished 
being built. From your email, it sounds like that event callback should 
do the trick though.

Hope this helps,

-Matt

polly.c.chang wrote:

    
Hi,

Is there a way for EclipseLink to call a handler to do post-processing
      
work
  
after unmarshalling a certain class?  I found some information in the
documentation about the XMLUnmarshalListener, but it seems to listen to
unmarshal events for everything.  Is there something else that I can
      
attach
  
to just one class or one XMLDescriptor?

Thanks,
Polly


 

      
_______________________________________________
eclipselink-users mailing list
eclipselink-users@...
https://dev.eclipse.org/mailman/listinfo/eclipselink-users


    

  

_______________________________________________
eclipselink-users mailing list
eclipselink-users@...
https://dev.eclipse.org/mailman/listinfo/eclipselink-users

Re: [MOXy] post-processing after unmarshalling

by polly.c.chang :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Matt,

I tested this just now, and the event listener works exactly as you described.  It suits my needs perfectly.  :)

The xml to use in the project.xml is also like you described:

<events xsi:type="event-policy">
        <event-listeners>
                <event-listener>com.foo.MyEventListener</event-listener>
        </event-listeners>
</events>

Thank you so much!  btw, you might want to update the documentation here to say that XML Descriptors are supported for event handlers:
http://wiki.eclipse.org/Configuring_a_Descriptor_(ELUG)#Configuring_a_Descriptor_Event_Listener_as_an_Event_Handler

Thanks!

--Polly  


Matt MacIvor wrote:
Hi Polly,

1. You would want to use the getObject() method to get back your
Object. getOriginalObject is used for events like postClone or
postMerge where you may want access to the original object. OXM doesn't
use any cloning so that OriginalObject wouldn't be set.

2. I believe you would just need to set the event-listener element in
your deployment XML.

3. In ORM projects, there's a lot of different descriptor events that
get called, but in OXM, currently, only the postBuild event gets
raised. The XMLMarshalListener API provides pre and post marshal
events, but those would be raised for every object (similar to JAXB
event listeners) and not on a per-descriptor basis.

-Matt